title: How do I correctly create dependencies between targets in CMake?
body: <p>I am trying to use CMake to set up some simple dependencies between a C++ project and the libraries that it uses.</p>
  
  <p>The set up is as follows</p>
  
  <ul>
  <li>Project
  
  <ul>
  <li>Dependency</li>
  </ul></li>
  </ul>
  
  <p>Project itself contains source files that include headers from <code>Dependency</code> and when the executable is built it needs to be linked against <code>Dependency</code>'s static library.</p>
  
  <p>So far I can get this to work, but I have to specify the include directories of <code>Dependency</code> in the <code>CMakeLists.txt</code> file for <code>Project</code> manually. I want this to be pulled out automatically, and I have explored the option of using the <code>find_package()</code> command to do so with limited success and making things much more complicated.</p>
  
  <p>All I want to do is have <code>Dependency</code> built before <code>Project</code> and have <code>Project</code> link against the library and have its include directories. Is there a simple concise way of achieving this?</p>
  
  <p>My current CMake files:</p>
  
  <p><code>Project</code>, file <code>CMakeLists.txt</code>:</p>
  
  <pre><code>cmake_minimum_required (VERSION 2.6)
  project (Project)
  include_directories ("${PROJECT_SOURCE_DIR}/Project")
  add_subdirectory (Dependency)
  add_executable (Project main.cpp)
  target_link_libraries (Project Dependency)
  add_dependencies(Project Dependency)
  </code></pre>
  
  <p><code>Dependency</code>, file <code>CMakeLists.txt</code>:</p>
  
  <pre><code>project(Dependency)
  add_library(Dependency SomethingToCompile.cpp)
  target_link_libraries(Dependency)
  </code></pre>