title: CMake static library dependencies not propagating with ExternalProject_Add
body: <p>I'm currently in the process of trying to get an executable to link properly with all the dependencies it needs.</p>
  
  <p>Here is an example structure of the dependencies:</p>
  
  <pre><code>exe -&gt; libA -&gt; libB
  </code></pre>
  
  <p><code>exe</code> and <code>libA</code> have their own repositories. <code>exe</code> pulls in <code>libA</code> something like this:</p>
  
  <pre><code>add_executable(exe ${sources})
  
  ExternalProject_Add(
      libA
      GIT_REPOSITORY http://some/git/url/libA.git
      ...
  )
  
  target_include_directories(exe PRIVATE ${libA_includes})
  target_link_libraries(exe ${libA_libs}/libA.a)
  
  add_dependencies(exe libA)
  </code></pre>
  
  <p><code>libA</code> pulls in <code>libB</code> in a similar fashion:</p>
  
  <pre><code>add_library(libA STATIC ${sources})
  
  ExternalProject_Add(
      libB
      URL http://some/artifact/repo/libB.tgz
      ...
  )
  
  target_include_directories(libA PRIVATE ${libB_includes})
  target_link_libraries(libA ${libB_libs}/libB.a)
  
  add_dependencies(libA libB)
  </code></pre>
  
  <p>I can build <code>libA</code> fine, along with a test executable that properly links against <code>libB</code>. However, when I try to build <code>exe</code>, it only links against <code>libA</code> but not <code>libB</code>. How can I get CMake to know that the dependency between <code>libA</code> and <code>libB</code> shouldn't be lost through ExternalProject?</p>
  
  <p>Edit:</p>
  
  <p>I've created some dependency graphs to hopefully clarify what I want:</p>
  
  <p>Actual:</p>
  
  <p><img src="https://i.stack.imgur.com/2GyaL.png" alt="exe actual"> <img src="https://i.stack.imgur.com/xHvlQ.png" alt="libA actual"></p>
  
  <p>What I expect:</p>
  
  <p><img src="https://i.stack.imgur.com/qpLoE.png" alt="expected"></p>
  
  <p>Any help would be greatly appreciated. Thanks.</p>
  
  <p>Edit 2:</p>
  
  <p>I ended up using the following as a solution:</p>
  
  <p>In libA's CMakeLists.txt (where <code>${MODULE_NAME}</code> is some module's name within libA):</p>
  
  <pre><code>export(TARGETS ${MODULE_NAME}
         NAMESPACE "${CMAKE_PROJECT_NAME}-"
         APPEND FILE ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}-targets.cmake)
  </code></pre>
  
  <p>In exe's CMakeLists.txt:</p>
  
  <pre><code>ExternalProject_Add(
      libA ...
  )
  
  ExternalProject_Get_Property(libA source_dir)
  ExternalProject_Get_Property(libA binary_dir)
  
  target_include_directories(${PROJECT_NAME} PRIVATE ${source_dir})
  
  set(LIBA_TARGETS_FILE ${binary_dir}/libA-targets.cmake)
  if(EXISTS ${LIBA_TARGETS_FILE})
      include(${LIBA_TARGETS_FILE})
      target_link_libraries(${MODULE_NAME} libA-module_in_liba)
  endif()
  
  add_dependencies(${MODULE_NAME} libA)
  </code></pre>
  
  <p>Note: this does now require the project to be built using two runs of <code>cmake</code> as follows:</p>
  
  <pre><code>mkdir build; cd build
  cmake .. # initial configuration
  make # download the external projects
  cmake .. # be able to include targets cmake file from external projects
  make # this should now link everything properly
  </code></pre>