Forwarding to the list and replying to some parts. > I removed add_subdirectories and added path to each of the source > file according to your instruction and things worked! I just have a > quick question: why should I remove the add_subdirectories in the src > CMakeLists.txt? I thought add_subdirectories should tell cmake to look > for files in the directories?
add_subdirectory() tells CMake that there's yet another listfile (CMakeLists.txt) in a subdirectory, which will be processed recursively until no further listfiles are found inside. Then the normal procedural flow continues. So it doesn't say anything about project files, just that new script code that might involve the project files needs to be processed. >>> Toplevel >>> >>> |----- CMakeLists.txt >>> >>> |----- src --------|------CMakeLists.txt >>> >>> | >>> |------common---------------|-------CMakeLists.txt >>> >>> | |------dir1-----| >>> |------- src1.h >>> >>> | |-----CMakeLists.txt >>> >>> |----bin |-----src2.c >>> >>> |-----src3.c >> >> It's quite hard to figure out what's going on here, but I assume src1.h >> is under src/common. Please post the output of 'tree' command next time, >> if you are on a Unix. >> >>> set(src_files src1.h src2.c src3.c) >> >> You don't have to add headers as target dependencies unless you program >> in an IDE (just fyi). >> >>> CMakeLists.txt in common and dir1 are empty. >> >> So, either partially move your CMake scripts into these subdirectories, >> or don't do `add_subdirectory()`. For example: >> >> src/CMakeLists.txt: >> add_executable(exec dir1/src1.c dir1/src2.c dir1/src3.c) >> target_include_directories(exec PRIVATE >> "${CMAKE_CURRENT_SOURCE_DIR}/common") -- Alex -- 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: https://cmake.org/mailman/listinfo/cmake