title: CMake add_subdirectory()
body: <p><strong>Introduction:</strong></p>
  
  <p>I am trying to use CMake to obtain cross platform compilation scripts (for VS 9.0 on a Windows32 and Makefiles for Unix).</p>
  
  <p>I am experiencing something i can't understand about add_subdirectory().</p>
  
  <p>Let me show you my code :</p>
  
  <p><strong>Context:</strong></p>
  
  <p>My architecture for a module named "module1" is something like this :</p>
  
  <ul>
  <li>CMakeLists.txt</li>
  <li>include/
  <ul>
  <li>file1.h</li>
  <li>file2.h</li>
  <li>*.h</li>
  </ul></li>
  <li>src/
  <ul>
  <li>file1.cpp</li>
  <li>file2.cpp</li>
  <li>*.cpp</li>
  </ul></li>
  <li>test/
  <ul>
  <li>CMakeLists.txt</li>
  <li>src/
  <ul>
  <li>testfile1.cpp</li>
  <li>testfile2.cpp</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>The architecture of my whole application is composed of these modules which are in themselves projects that could work independantly.</p>
  
  <p><strong>My goals:</strong></p>
  
  <ol>
  <li><p>I want to compile my module as a library</p></li>
  <li><p>I want to test the library with the code in the test/ folder</p></li>
  </ol>
  
  <p>Here are the CMakeLists i wrote :</p>
  
  <p><em><strong>This one is the CMakeLists.txt in the root directory of my module.</em></strong></p>
  
  <pre><code>#ENSURE MINIMUM VERSION OF CMAKE
  cmake_minimum_required(VERSION 2.8)
  
  #CONFIGURATION OF THE PROJECT   
      #NAME OF THE PROJECT    
       project(MyProject)
  
      #OUTPUT OF THE PROJECT  
      set(LIBRARY_OUTPUT_PATH lib/${CMAKE_BUILD_TYPE}) 
  
      #ADD THE HEADERS OF THE LIBRARY BEING CREATED   
      include_directories(include)
  
      #ADD 3rd PARTY OPENCV LIBRARIES     
      find_package(OpenCV REQUIRED)       
  
      #ADD 3rd PARTY XERCES LIBRARIES
      include_directories(${XERCES_INCLUDE_DIR})
      link_directories(${XERCES_LIB_DIR})     
      set(Xerces_LIBS xerces-c_3D.lib)
  
  
  #CONFIGURATION OF THE LIBRARY   
  file(GLOB_RECURSE MYPROJECT_MODULE_CXX src/*)   
  file(GLOB_RECURSE MYPROJECT_MODULE_HDR include/*)       
  
  #NAME OF THE PRESENT LIBRARY    
  set(MYPROJECT_MODULE_LIB_NAME myModuleLib)
  add_library(${MYPROJECT_MODULE_LIB_NAME}
          SHARED
          ${MYPROJECT_MODULE_CXX}
          ${MYPROJECT_MODULE_HDR}
          )   
  target_link_libraries(${MYPROJECT_MODULE_LIB_NAME}
                 ${OpenCV_LIBS}
                 ${Xerces_LIBS}
                 )
  
  #CONTINUE IN THE SUB FOLDERS
  add_subdirectory(test)
  </code></pre>
  
  <p><em><strong>And then, in the test/ folder, here is the CMakeLists.txt</em></strong></p>
  
  <pre><code>#ENSURE MINIMUM VERSION OF CMAKE
  cmake_minimum_required(VERSION 2.8)
  
  #CONFIGURATION OF THE PROJECT
      #NAME OF THE PROJECT
      project(MyProjectTest)
  
      #OUTPUT OF THE PROJECT
      set(EXECUTABLE_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})
  
      #ADD OUR TESTED LIBRARY
      include_directories(../include)
      link_directories(../build/lib/${CMAKE_BUILD_TYPE})
  
  
  #CONFIGURATION OF THE EXE
      file(GLOB_RECURSE MYPROJECT_MODULE_TEST_CXX src/*)
  
      #NAME OF THE PRESENT EXECUTABLE
      set(MYPROJECT_MODULE_TEST_BIN_NAME myModuleTest)
      add_executable(${MYPROJECT_MODULE_TEST_BIN_NAME}
                 ${MYPROJECT_MODULE_TEST_CXX}
                 )
      target_link_libraries(${MYPROJECT_MODULE_TEST_BIN_NAME}
                    ${MYPROJECT_MODULE_LIB_NAME}
                    )
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>The CMake outputs a correct MyProject.sln Visual Studio 9.0 solution, which compiles successfully in my library linked with OpenCV and Xerces (and other 3rd part libraries). However the test binary did not output any MyProjectTest.sln.</p>
  
  <p><strong>I thought, (<a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command%3aadd_subdirectory" rel="nofollow">and read in the CMake documentation</a>) that add_subdirectory(dir) was used to do CMake in the following sub directory (i mean, the name could not be clearer :p !), so shouldn't it continue CMake in the test/ directory and create my MyProjectTest.sln solution ?</strong></p>
  
  <p>I use the GUI CMake to run the root CMakeLists.txt in a build directory that i create in the root of my module. When I explore the build directory that's where I can find my MyProjet.sln, a test/ folder, but no MyProjectTest.sln in it !</p>