I have the following directory structure: src/ +---- foo/ | +--- foobar/ +---- bar/
src/CMakeLists adds the foo and bar subdirectories src/foo/CMakeLists adds the foobar subdirectory src/foobar/CMakeLists and src/bar/CMakeLists create 2 executables (foobar and bar) $ cat src/CMakeLists.txt cmake_minimum_required (VERSION 3.2.2) project (cmake_test CXX) add_subdirectory (foo) add_subdirectory (bar) $ cat src/foo/CMakeLists.txt add_subdirectory (foobar) $ cat src/foo/foobar/CMakeLists.txt add_executable(foobar main.cpp) $ cat src/bar/CMakeLists.txt add_executable(bar main.cpp) I generate the makefiles: $ mkdir build && cd build $ cmake .. I can build foobar and bar by specifying "make foobar" and "make bar" from the build root directory ~src/build/ $ make foobar [100%] Built target foobar ~src/build/ $ make bar [100%] Built target bar However, if I am in the build/foo directory, then nothing happens if I "make foobar". ~src/build/foo/ $ make foobar I believe this is because make considers foobar to be a directory it needs to create, and since it exists, there is nothing to do. This is different behaviour to when I'm in the build root directory and "make bar". In this instance "bar" is also a directory, but make behaves differently in this instance, and builds the bar target. I'm guessing because in the root makefile "bar" is a phony target, but in the foo makefile, "foobar" isn't. If I just type "make" in the foo subdirectory, then all targets defined in this part of the tree are built correctly. It is just specifying a target with the same name as a subdirectory from a location that is deeper than the built root that doesn't work. How can I enable building from somewhere *inside* the build tree of targets that have the same name as their enclosing directory? A github repo with the code presented here is at: https://github.com/skebanga/nested_cmake TIA Steve
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers