As the name implies, target_include_directories
only affects one target. So when you set target_include_directories(${PROJECT_NAME} PUBLIC Lib/headers/)
, this adds to the include path for the executable target named ${PROJECT_NAME}
but not to the include path for the library name_of_lib
.
To fix this, you can add the include path for your library in the lower level CMakeLists.txt
:
target_include_directories(name_of_lib PUBLIC headers)
As a bonus, because it's PUBLIC
, this path is also automatically added to any target that depends on name_of_lib
. So in the top-level CMakeLists.txt
, you can remove this line:
target_include_directories(${PROJECT_NAME} PUBLIC Lib/headers/)
Aside, this line looks useless and can probably be removed as well:
target_link_directories(${PROJECT_NAME} PRIVATE Lib/headers/)
Link libraries are not usually placed in headers directories.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…