CMake: include_directories not propagating from a subdirectory

I decided to include a library in my project (more precisely, yaml-cpp ). Since both projects (yaml-cpp and mine) use CMAKE to build, I decided to try placing the yaml-cpp directory inside my root directory and just use add_subdirectory(yaml-cpp) and target_link_libraries(${EXECUTABLE_NAME} foolib yaml-cpp) , so as yaml-cpp CMakeLists.txt already contains

 include_directories(${YAML_CPP_SOURCE_DIR}/include) # ... add_library(yaml-cpp ${sources} ${public_headers} ${private_headers} ${contrib_sources} ${contrib_public_headers} ${contrib_private_headers} ) 

... and I should be fine for both include and target library. But, as it turns out, when compiling, I get the following error:

P: \ zpp \ TheGameShow \ TGS.cpp (16): fatal error C1083: cannot include include file: 'yaml-cpp / yaml.h': no ​​such file or directory

... if I do not duplicate the line include_directories(${YAML_CPP_SOURCE_DIR}/include) in my own CMakeLists.txt

My question is: is this the desired behavior? Shouldn't distribute include directories from subdirectories to root directories? Am I doing something wrong?

edit: I am using Visual Studio 2010 and CMake 2.8.6

+4
source share
1 answer

Yes, this is the desired behavior. Nothing extends to higher level CMakeLists.txt. The only exception is cache values ​​(created by various find_ * and set(VAR 123 CACHE STRING) and set(VAR 123 PARENT_SCOPE) .

+5
source

Source: https://habr.com/ru/post/1389702/


All Articles