这是我的项目树:
project
| + src
| + external
| | + foo
| | | + include
| | | | - foo.hpp
| | | + src
| | | | - foo.cpp
| | | | - CMakeLists.txt
| | | - CMakeLists.txt
| | + CMakeLists.txt
| + src
| | - main.cpp
| - CMakeLists.txt
foo.cpp 包括 foo.hpp:
// foo.cpp
#include "foo.hpp"
现在的问题是在顶部 CMake 中包含目录成功找到 foo.hpp,但如果我包含在子项目中它不会。有什么理由吗?(在编译可执行文件之前包含目录)。
// project/CMakeLists.txt
include_directories(external/foo/include) //OK
add_subdirectory(external)
add_executable(main main.cpp)
target_link_libraries(main foo)
// project/external/CMakeLists.txt
add_subdirectory(foo)
// project/external/foo/CMakeLists.txt
include_directories(include) // NOT WORKING
add_subdirectory(src)
// project/external/foo/src/CMakeLists.txt
add_library(foo foo.cpp)