[CMake] target_include_directories target issue
Luis Felipe Dominguez Vega
lfdominguez at estudiantes.uci.cu
Mon Nov 17 03:21:19 EST 2014
That's because the include directory is obtained in dependends. The
documentation say that when the library is imported by dependends of a target,
the dependant target obtain all the PUBLIC and INTERFACE include directories,
so, with the command
target_include_directories(Bar PRIVATE Foo)
You are populating the property INCLUDE_DIRECTORIES of the target Bar, only
with Foo. Just figure it, how cmake can guess that the Bar target depends of
Foo target, you are only telling that add the DIRECTORY Foo to the PRIVATE
INCLUDE_DIRECTORIES of Bar. The command
target_include_directories
In a reduced form is target_include_directories (<target> [PRIVATE | PUBLIC |
INTERFACE] <directories_to_include_not_targets>
So, if you think that the command is getting the Foo as a target, noup, is
getting as a directory.
-----------------------------------------------------------
On Sunday 16 November 2014 11:56:05 AM Wojciech Mamrak wrote:
> 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