[CMake] target_include_directories target issue

Wojciech Mamrak wmamrak at gmail.com
Sun Nov 16 05:56:05 EST 2014


Hello,

the docs claim:

"Specify include directories or targets to use when compiling a given target."

Here is a little test of it. Project directory:

Foo
  CMakeLists.txt
  FooSrc
    a.h
    a.cpp
  Bar
    main.cpp

And CMakeLists.txt:

cmake_minimum_required(VERSION 3.0)

project(FooBar)

add_library(Foo FooSrc/a.h FooSrc/a.cpp)

target_include_directories(Foo PUBLIC G:/some_directory)

if (TARGET Foo)
    message("Foo is a target!")
endif()

add_executable(Bar Bar/main.cpp)

target_include_directories(Bar PRIVATE Foo)

According to the docs, Bar's include directories should contain at
least "G:/some_directory", but it contains
"${PROJECT_SOURCE_DIR}/Foo". Why?

If I replace the last line with target_link_libraries(Bar PRIVATE
Foo), then Bar's include directories meet my expectations.

regards


More information about the CMake mailing list