title: CMake library adjacent subdir dependency
body: <p>I've the following directory structure</p>
  
  <pre><code>A                                  # produces libA
    CMakeLists.txt
    includes
      file.h
    sources
      file.cpp
  B                                  # produces libB depends on libA
    CMakeLists.txt
    includes
       ...
    sources
       ...
  app                                # produces executable, depends on libA and libB
    CMakeLists.txt
    includes
      ...
    sources
      ...
  </code></pre>
  
  <p>I want both <code>libA.so</code> and <code>libB.so</code> be independently available and usable by other applications as well as <code>app</code>. </p>
  
  <p>What is the clean way to manage this using CMake.</p>
  
  <p>in <code>A/CMakeLists.txt</code></p>
  
  <pre><code>INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/includes)
  ...
  ADD_LIBRARY(a SHARED ${A_SOURCES})
  </code></pre>
  
  <p>in <code>B/CMakeLists.txt</code></p>
  
  <pre><code>INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/includes)
  ADD_sUBDIRECTORY(../A)
  # ^^^ This wont work
  ...
  ADD_LIBRARY(b SHARED ${B_SOURCES})
  </code></pre>
  
  <p>Same problem will occur in <code>app/CMakeLists.txt</code> You cannot ADD_SUBDIRECTORY a sibling</p>
  
  <p>I don't want to hardcode paths with explicit directory names. I think I am not alone more people have faced the same. So what is the regularly practiced solution for this ?</p>
  
  <p>Should I place <code>A/a.cmake</code> and <code>B/b.cmake</code> and declare <code>A_INCLUDE_DIRS</code> and <code>B_INCLUDE_DIRS</code>. but again A is not a sub directory of B</p>
  
  <p>If I make <code>B/a.cmake</code>, <code>app/a.cmake</code> and <code>app/b.cmake</code> files and <code>SET</code> variables <code>INCLUDE_DIRS</code> there and include them in their CMakeLists.txt ? But is this the standard way to solve this problem ? or would this even work ?</p>
  
  <p><strong>Problem 2</strong></p>
  
  <p>Another thing I've tried to place a <code>main.cpp</code> and <code>CMakeLists.txt</code> on root (e.g. parent of app, a, b). There I can <code>ADD_SUBDIRECTORY(A)</code> easily as its really a subdirectory. I did </p>
  
  <pre><code>SET(A_INCLUDE_DIRS
    ${CMAKE_CURRENT_SOURCE_DIR}/includes
  )
  </code></pre>
  
  <p>on <code>A/CMakeLists.txt</code>. and expected to get that variable in root/CMakeLists.txt, which didn't work. But it works If I use <code>PARENT_SCOPE</code> or <code>SCOPE</code> with <code>SET</code> But I don't know whether this is okay to configure such a way or its a hack ?</p>