title: Add subdirectory as a library to CMakeLists.txt
body: <p>TLDR: I have two projects(Project A &amp; B) using CMakeLists.txt, both build executables and they work separately. Now, I want to use Project A as a library in Project B, let's call this Project AB. How do I do it?</p>
  <p>Current Directory Structures :</p>
  <p>Project A</p>
  <pre><code>rootA
   |- bin
   |   |-
   |- build
   |   |-
   |- external-includes
   |- CMakeLists.txt with add_subdirectory(libraryA)
   |- libraryA
       |- main.cpp (uses library_A in an example program)
       |- library_A.cpp
       |- library_A.h
       |- Other .h and .cpp files library_A uses
       |- CMakeLists.txt having add_executable (library_A main.cpp library_A.cpp ....)
  </code></pre>
  <p>Project B</p>
  <pre><code>rootB
   |- bin
   |   |-
   |- build
   |   |-
   |- external-includes
   |- CMakeLists.txt with add_subdirectory(libraryB)
   |- libraryB
       |- main.cpp
       |- library_B.cpp
       |- library_B.h
       |- Other .h and .cpp files library_B uses
       |- CMakeLists.txt having add_executable (library_B main.cpp library_B.cpp ....)
  </code></pre>
  <p>Project AB</p>
  <pre><code>rootAB
   |- bin
   |   |-
   |- build
   |   |-
   |- external-includes
   |- rootA 
   |- CMakeLists.txt with add_subdirectory(libraryB)
   |- libraryB
       |- main.cpp
       |- library_B.cpp
       |- library_B.h
       |- Other .h and .cpp files library_B uses
       |- CMakeLists.txt having add_executable (library_B main.cpp library_B.cpp .....)
  </code></pre>
  <p>What I've tried so far:</p>
  <p>I've tried adding <code>include_directories(rootA/libraryA)</code> and <code>add_sudirectory(rootA)</code> to rootAB/CMakeLists.txt and <code>#include &lt;library_A.h&gt;</code> to rootAB/libraryB/main.cpp, then it complains about linking errors(unresolved external symbol). If I add <code>#include &lt;library_A.cpp&gt;</code> , it will complain about other linking errors from library A, which don't occur if I build library_A separately. Probably what I want to do is to build library_A as a (static) library and link it in ProjectAB (preferably using current directory structure and modifications to CMakeLists.txt(s)). How to do so?</p>