# INCLUDE\_DIRECTORIES target property not reporting "indirect" ones

**URL:** https://discourse.cmake.org/t/include-directories-target-property-not-reporting-indirect-ones/4493
**Category:** Usage
**Created:** [November 16, 2021, 5:39pm UTC](https://discourse.cmake.org/t/include-directories-target-property-not-reporting-indirect-ones/4493 "2021-11-16T17:39:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ingolf](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/i/977dab/32.png) [@ingolf](https://discourse.cmake.org/u/ingolf)
#### Post date: [November 16, 2021, 5:39pm UTC](https://discourse.cmake.org/t/include-directories-target-property-not-reporting-indirect-ones/4493/1 "2021-11-16T17:39:58Z")

</div>

Hi,

in my project, there is

```auto
add_library(foo source1.c)
target_include_directories(foo PUBLIC foo_library_includes)

add library(bar source2.c)
target_link_libraries(bar PRIVATE foo)

```

Whenever I actually _compile_ `bar`, `foo_library_includes` is correctly added to the include path.

However, I’d like to use a function like the following

```auto
function(add_special_target library)
    get_target_property(dirs ${library} INCLUDE_DIRECTORIES)
    transmogrify(dirs) # macro prepends some prefix to each element in dirs
    add_custom_target(${library}.special
        COMMAND "special_processor ${dirs} further_arguments"
    )
endfunction()

```

In fact, the custom command does a bit more, but I hope you get the intention.

Unfortunately, when using `add_special_target(bar)` after all the above definitions, the `get_target_property()` will not deliver the `foo_library_includes` although they are made applicable when _building_ the `bar` target.

What is the correct way to solve the problem? (CMake 3.21.3 here)

I acknowledge that similar questions have been posted before (like [this](https://discourse.cmake.org/t/interface-include-directories-not-transitive-for-target-link-libraries/4028) or [this one](https://discourse.cmake.org/t/transitive-dependencies-for-include-directories-break/4035)). However I do not yet see how generator expressions would help me here: `set (dirs $<TARGET_PROPERTY:${library},INCLUDE_DIRECTORIES>)` instead of `get_target_property()` won’t work, right?

Kind regards  
Ingolf

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 16, 2021, 8:33pm UTC](https://discourse.cmake.org/t/include-directories-target-property-not-reporting-indirect-ones/4493/2 "2021-11-16T20:33:18Z")

</div>

> [@ingolf](#):
>
> What is the correct way to solve the problem?

Use generator expressions. You can do something like this to put a prefix on each (in this case, `-I`, quotes, and newlines):

[https://gitlab.kitware.com/vtk/vtk/-/blob/dfb84f04bcd786b6198ee375c25055a4ec47b0ae/CMake/vtkModuleWrapPython.cmake#L168-172](https://gitlab.kitware.com/vtk/vtk/-/blob/dfb84f04bcd786b6198ee375c25055a4ec47b0ae/CMake/vtkModuleWrapPython.cmake#L168-172)

---

<div class="post-metadata">

### Author: ![JohannesWilde](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@JohannesWilde](https://discourse.cmake.org/u/JohannesWilde)
#### Post date: [November 17, 2021, 2:14pm UTC](https://discourse.cmake.org/t/include-directories-target-property-not-reporting-indirect-ones/4493/3 "2021-11-17T14:14:16Z")

</div>

Hi,

I stumbled upon exactly the same problem recently and was sadly unable to solve this till now.

I created a simple MWI [see [https://github.com/JohannesWilde/TestingCmake](https://github.com/JohannesWilde/TestingCmake) - as I am unable to upload a file here], where the configure output is as follows:

> lib1\_include: TestingCMake/dir1/include  
> lib2\_include: TestingCMake/dir2/include  
> lib1\_interface\_include: TestingCMake/dir1/include  
> lib2\_interface\_include: TestingCMake/dir2/include  
> lib1\_link: lib1\_link-NOTFOUND  
> lib2\_link: lib1  
> – Configuring done  
> – Generating done

If I understand the CMake documentation for `INTERFACE_INCLUDE_DIRECTORIES` correctly [see [here](https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_INCLUDE_DIRECTORIES.html)]:

> When target dependencies are specified using `target\_link\_libraries(), CMake will read this property from all target dependencies to determine the build properties of the consumer.

, CMake does so somewhere at some point anyway. Is there a way to query those “build properties”? I.e. I want:

> lib2\_interface\_include: TestingCMake/dir2/include;TestingCMake/dir1/include

Thanks

Johannes

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 17, 2021, 2:27pm UTC](https://discourse.cmake.org/t/include-directories-target-property-not-reporting-indirect-ones/4493/4 "2021-11-17T14:27:12Z")

</div>

> [@JohannesWilde](#):
>
> , CMake does so somewhere at some point anyway. Is there a way to query those “build properties”? I.e. I want:

Not at configure time. Only generator expressions can access that information (because it is only then when everything is known to answer such questions).

---

<div class="post-metadata">

### Author: ![JohannesWilde](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@JohannesWilde](https://discourse.cmake.org/u/JohannesWilde)
#### Post date: [November 17, 2021, 7:43pm UTC](https://discourse.cmake.org/t/include-directories-target-property-not-reporting-indirect-ones/4493/5 "2021-11-17T19:43:36Z")

</div>

Hi Ben,

thanks a lot. Great support. This clears it up for me.

Cheers

Johannes
