I seem to be having trouble setting the include path (-I
) using the include_directories()
command in CMake. My project directory is as follows:
Root
| - CMakeLists.txt
| - libs
| - | - CMakeLists.txt
| - | - inc
| - | - | - // lib specific includes
| - | - src
| - | - | - // lib specific sources
| - proj1
| - | - CMakeLists.txt
| - | - inc
| - | - | - // proj1 specific includes
| - | - src
| - | - | - // proj1 specific sources
The root CMakeLists.txt
file looks like so:
project(ROOT)
add_subdirectory(libs)
add_subdirectory(proj1)
The CMakeLists.txt
file under libs
:
project(lib)
add_library(lib STATIC ${lib_hdrs} ${lib_srcs}) // for conciseness, omitted set()
And lastly, the CMakeLists.txt
file under proj1
:
project(proj1)
include_directories("${ROOT_SOURCE_DIR}/lib/inc") # <- problem line?
add_executable(proj1 ${proj1_srcs})
target_link_libraries(proj1 lib)
The goal is to create the library from the source and header files in libs, then link against the executable generated under proj1. Proj1 has some files that #include
stuff in libs include, so I need to add the directories to be used with -I
. Based on the documentation, that's what include_directories()
is supposed to do. However despite explicitly setting that and following it with a debug message(${INCLUDE_DIRECTORIES})
, the INCLUDE_DIRECTORIES
variable is an empty string, and no directories are specified for the include path, so my compilation of proj1 fails.
I've also attempted removing the quotes around ${ROOT_SOURCE_DIR}/inc
to see if that helped but no luck.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…