title: CMake make add_library depend on ExternalProject_Add
body: <p><strong>TLDR:</strong> I would like to ask CMake to wait for <code>ExternalProject_Add</code> to complete before it attempts to move on to the next subdirectory and build a library that happens to use one of the files of the external project. In other words, I like to declare an external project as a dependency for a shared library. </p>
  
  <p><strong>More Description:</strong></p>
  
  <p>Suppose that my CMake project has two directories: <code>thirdparty</code> and <code>src</code>. My top-level <code>CMakeLists.txt</code> file has:</p>
  
  <pre><code>add_subdirectory(thirdparty)
  add_subdirectory(src)
  </code></pre>
  
  <p><code>thirdparty/CMakeLists.txt</code> contains multiple <code>ExternalProject_Add</code> commands. My original intention was to pull and build all these external projects and then move on to building my own libraries and executables in  <code>src</code>. Unfortunately, this didn't go as I planned:</p>
  
  <p>One of my external projects is called <code>libsvm</code>. And my <code>src/CMakeLists.txt</code> has the following:</p>
  
  <pre><code>set(Libsvm_SOURCE_FILES
      ${PROJECT_BINARY_DIR}/thirdparty/libsvm/src/libsvm/svm.cpp
  )
  
  include_directories(
      ${Libsvm_INCLUDE_DIR}
  )
  
  add_library(
      mysvm
    SHARED
      ${Libsvm_SOURCE_FILES}
  )
  </code></pre>
  
  <p>Now the problem I am facing with is that CMake is unable to find ${Libsvm_SOURCE_FILES}, apparently because this step is being executed before the <code>ExternalProject_Add</code> in my <code>thirdparty/CMakeLists.txt</code> file is executed.</p>
  
  <p>I would like to declare this external project as a dependency for this library.</p>
  
  <p><strong>Broader Question:</strong>
  Is there a clean way to force CMake to finish everything in first subdirectory before moving on to the next? If not, do you recommend that I make any change in the hierarchy and organization of my CMakeLists files?</p>
  
  <p>Thanks!</p>