I decided to include a library (more specifically yaml-cpp) in my project. Since both the projects (yaml-cpp and mine) are using CMAKE for building I decided to try and place the yaml-cpp directory inside my root directory and just use add_subdirectory(yaml-cpp) and target_link_libraries(${EXECUTABLE_NAME} foolib yaml-cpp), since yaml-cpp’s 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 on both includes and the library target. But as it turns out, upon compilation I get the following error:
P:\zpp\TheGameShow\TGS.cpp(16): fatal error C1083: Cannot open include file: ‘yaml-cpp/yaml.h’: No such file or directory
…unless I duplicate the line include_directories(${YAML_CPP_SOURCE_DIR}/include) in my own CMakeLists.txt
My question is: Is it the desired behavior? Shouldn’t the include directories propagate from subdirectories to root directories? Am I doing something wrong?
edit: I am using Visual Studio 2010 and CMake 2.8.6
Yes, it’s desired behavior. Nothing is being propagated to the higher-level CMakeLists.txt. The only exception – cache values (created by various find_* and
set(VAR 123 CACHE STRING)andset(VAR 123 PARENT_SCOPE).