[CMake] target_include_directories target issue

Wojciech Mamrak wmamrak at gmail.com
Mon Nov 17 09:46:35 EST 2014


Hello,

> 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.

Because the docs say so:
"Specify include directories or targets to use when compiling a given target.".

regards


2014-11-17 9:21 GMT+01:00 Luis Felipe Dominguez Vega
<lfdominguez at estudiantes.uci.cu>:
> 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
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake


More information about the CMake mailing list