# INTERFACE\_INCLUDE\_DIRECTORIES not transitive for target\_link\_libraries

**URL:** https://discourse.cmake.org/t/interface-include-directories-not-transitive-for-target-link-libraries/4028
**Category:** Usage
**Created:** [September 3, 2021, 11:54am UTC](https://discourse.cmake.org/t/interface-include-directories-not-transitive-for-target-link-libraries/4028 "2021-09-03T11:54:49Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Ronald](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@Ronald](https://discourse.cmake.org/u/Ronald)
#### Post date: [September 3, 2021, 11:54am UTC](https://discourse.cmake.org/t/interface-include-directories-not-transitive-for-target-link-libraries/4028/1 "2021-09-03T11:54:49Z")

</div>

# Env

- OS: Linux
- cmake: 3.21.1

# Test Code

```cmake
cmake_minimum_required(VERSION 3.20)

project(test_cmake_transitive_deps LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

macro(dump_target_includes TARGET_NAME)
    message("=====================dump_target_includes begin (${TARGET_NAME})=====================")
    get_target_property(PROP_TMP
                        ${TARGET_NAME}
                        INCLUDE_DIRECTORIES)
    message(----INCLUDE_DIRECTORIES----)
    foreach(PATH_TMP ${PROP_TMP})
        message("* " ${PATH_TMP})
    endforeach()

    get_target_property(PROP_TMP
                        ${TARGET_NAME}
                        INTERFACE_INCLUDE_DIRECTORIES)
    message(----INTERFACE_INCLUDE_DIRECTORIES----)
    foreach(PATH_TMP ${PROP_TMP})
        message("* " ${PATH_TMP})
    endforeach()
    message("=====================dump_target_includes end (${TARGET_NAME})=====================")
endmacro()

add_library(a a/a.cpp)
target_include_directories(a PUBLIC a)
dump_target_includes(a)

add_library(b b/b.cpp)
target_link_libraries(b PUBLIC a)
dump_target_includes(b)

```

project file structure

```auto
CMakeLists.txt
a/a.h
a/a.cpp
b/b.h
b/b.cpp

```

# Problem

for

- target\_include\_directories(a PUBLIC a)
- `target_link_libraries(b PUBLIC a)`

`dump_target_includes` for `b` is as below, why no inlucde paths for `b`?

```auto
=====================dump_target_includes begin (b)=====================
----INCLUDE_DIRECTORIES----
* PROP_TMP-NOTFOUND
----INTERFACE_INCLUDE_DIRECTORIES----
* PROP_TMP-NOTFOUND
=====================dump_target_includes end (b)=====================

```

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [September 3, 2021, 12:16pm UTC](https://discourse.cmake.org/t/interface-include-directories-not-transitive-for-target-link-libraries/4028/2 "2021-09-03T12:16:17Z")

</div>

This property is computed at generation time. Requesting it at configuration time will not give you the expected value.

If you need the final information, you have to use [generator expression](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html)`$<TARGET_PROPERTY:...>` which is evaluated at generation time.

---

<div class="post-metadata">

### Author: ![Ronald](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@Ronald](https://discourse.cmake.org/u/Ronald)
#### Post date: [September 3, 2021, 12:39pm UTC](https://discourse.cmake.org/t/interface-include-directories-not-transitive-for-target-link-libraries/4028/4 "2021-09-03T12:39:23Z")

</div>

> [@marc.chevrier](#):
>
> This property is computed at generation time. Requesting it at configuration time will not give you the expected value.
> 
> If you need the final information, you have to use [generator expression](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html) `$<TARGET_PROPERTY:...>` which is evaluated at generation time.

What does `generation time` mean?  
Does it mean buid time?  
How to check `*_INCLUDE_DIRECTORIES` for `b` here?

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [September 3, 2021, 12:55pm UTC](https://discourse.cmake.org/t/interface-include-directories-not-transitive-for-target-link-libraries/4028/5 "2021-09-03T12:55:46Z")

</div>

`generation time` is the step where build system files (Makefiles, ninja or whatever depending on what you specify with option `-G`) are generated by `CMake`.

To manipulate target properties with the right information, use [generator expressions](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html). See also [file(GENERATE)](https://cmake.org/cmake/help/latest/command/file.html#generate).

---

<div class="post-metadata">

### Author: ![Ronald](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@Ronald](https://discourse.cmake.org/u/Ronald)
#### Post date: [September 3, 2021, 1:44pm UTC](https://discourse.cmake.org/t/interface-include-directories-not-transitive-for-target-link-libraries/4028/6 "2021-09-03T13:44:26Z")

</div>

> [@marc.chevrier](#):
>
> To manipulate target properties with the right information, use [generator expressions](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html). See also [file(GENERATE)](https://cmake.org/cmake/help/latest/command/file.html#generate).

```cmake
file(GENERATE OUTPUT test_debug_genex.log
     CONTENT $<TARGET_PROPERTY:b, INCLUDE_DIRECTORIES>)

```

The code above failed, logs as below

```auto
file Unknown argument to GENERATE subcommand.

```

BTW, does it have to save the output to a file, or anyway to output to stdout/stderr?

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [September 3, 2021, 2:55pm UTC](https://discourse.cmake.org/t/interface-include-directories-not-transitive-for-target-link-libraries/4028/7 "2021-09-03T14:55:53Z")

</div>

Use quotes for `CONTENT`:

```cmake
file(GENERATE OUTPUT test_debug_genex.log
     CONTENT "$<TARGET_PROPERTY:b,INCLUDE_DIRECTORIES>")

```

---

<div class="post-metadata">

### Author: ![Ronald](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@Ronald](https://discourse.cmake.org/u/Ronald)
#### Post date: [September 3, 2021, 3:06pm UTC](https://discourse.cmake.org/t/interface-include-directories-not-transitive-for-target-link-libraries/4028/8 "2021-09-03T15:06:08Z")

</div>

It works, thanks very much.  
BTW space after comma in genex is not allowed.
