title: cmake order of execution of add_subdirectory command
body: <p>I have a dependency problem in my cmake configuration.
  When I start building from root directory of the project, it always gives an error. When I disable <code>add_subdirectory(application)</code> where I use <code>LibCalcBin</code>, it builds the <code>library</code> successfully. Then, I can build the <code>application</code>. </p>
  
  <p>Why cmake don't build the <code>library</code> first then the <code>application</code> as I have specified in the order of add_subdirectory commands. Is there any way to resolve this issue? Thanks. </p>
  
  <h1>Error</h1>
  
  <pre><code>Please set them or make sure they are set and tested correctly in the CMake files:
  LibCalcBin
      linked by target "run" in directory ...
  </code></pre>
  
  <h1>./CMakeList.txt (Root Directory)</h1>
  
  <pre><code>cmake_minimum_required(VERSION 3.3)
  project(DLLAbstract)
  
  # specify where to put executable
  SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
  
  # specify where to put binaries
  SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
  
  # compile and build library
  add_subdirectory(library)
  
  # compile and build application
  add_subdirectory(application)
  </code></pre>
  
  <h1>./library</h1>
  
  <pre><code>set(src LibCalc.cpp Calculator.cpp)
  
  add_definitions(-DDLL_EXPORT)
  
  add_library(LibCalc SHARED ${src})
  </code></pre>
  
  <h1>./application</h1>
  
  <pre><code>set(Src main.cpp)
  
  find_path(LibCalcHeader
      NAMES 
          LibCalc.hpp
      PATHS 
          ${PROJECT_SOURCE_DIR}/library
  )
  
  find_library(LibCalcBin
      NAMES 
          LibCalc
      PATHS 
          ${PROJECT_SOURCE_DIR}/bin/Debug
          ${PROJECT_SOURCE_DIR}/bin/Release
          ${PROJECT_SOURCE_DIR}/bin
  )
  
  include_directories(${LibCalcHeader})
  
  add_executable(run ${Src})
  
  target_link_libraries(run ${LibCalcBin})
  </code></pre>