This is my project tree:
project
| + src
| + external
| | + foo
| | | + include
| | | | - foo.hpp
| | | + src
| | | | - foo.cpp
| | | | - CMakeLists.txt
| | | - CMakeLists.txt
| | + CMakeLists.txt
| + src
| | - main.cpp
| - CMakeLists.txt
foo.cpp includes foo.hpp:
// foo.cpp
#include "foo.hpp"
Now the problem is that including the directory in the top CMake successfully find foo.hpp,
but if I include in the subproject it doesn't. Any reason for it? (directories are included before the executable is compiled).
// 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)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…