# propagation of include paths through targets

**URL:** <https://discourse.cmake.org/t/propagation-of-include-paths-through-targets/10692>\
**Category:** Code\
**Created:** [April 19, 2024, 1:01am UTC](https://discourse.cmake.org/t/propagation-of-include-paths-through-targets/10692 "2024-04-19T01:01:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwm](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jwm/32/654_2.png) [@jwm](https://discourse.cmake.org/u/jwm)\
**Post date:** [April 19, 2024, 1:01am UTC](https://discourse.cmake.org/t/propagation-of-include-paths-through-targets/10692/1 "2024-04-19T01:01:36Z")

</div>

I created a project (see [here](https://discourse.cmake.org/t/struggling-to-export-a-project/10491/6)) and am using it in another project through `FetchContent`.

In my new project, I create a base library that depends on one of my fetched targets, we’ll call it `fetchTarget`. Here I have

```cmake
add_library( myBase SHARED )

target_link_libraries( myBase PUBLIC fetchTarget )

```

This builds `myBase` just fine. However, when I try to use `myBase`

```cmake
add_executable( myProg )
target_link_libraries( myProg PRIVATE myBase )

```

I get compile errors from sources on `myProg` not finding include files from `fetchTarget` ( `myProg` includes `myBase` which includes `fetchTarget`).

In trying to debug, I added this:

```cmake
get_target_property(fetch_inc fetchTarget INCLUDE_DIRECTORIES)
message(" **** fetchTarget includes = ${fetch_inc}")

target_link_libraries( myBase PUBLIC fetchTarget)
get_target_property(myBase_inc myBase INCLUDE_DIRECTORIES)
message(" **** myBase includes = ${myBase_inc}")

```

Surprisingly, this prints

```auto
 *** fetchTarget includes = $<BUILD_INTERFACE:/usr/src/project/build-DEBUG/_deps/fetchTarget-src/src>;/usr/src/project/build-DEBUG/_deps/fetchTarget-src/src
 *** myBase includes = /usr/src/project/src/PUBLIC;/usr/src/project/src;$<BUILD_INTERFACE:/usr/src/project/src>

```

Why isn’t the `fetchTarget` include path being propagated to the `myBase` target? How can I fix that?

---

<div class="post-metadata">

**Author:** ![Mark](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@Mark](https://discourse.cmake.org/u/Mark)\
**Post date:** [April 19, 2024, 8:36pm UTC](https://discourse.cmake.org/t/propagation-of-include-paths-through-targets/10692/2 "2024-04-19T20:36:21Z")

</div>

You could check the INTERFACE\_INCLUDE\_DIRECTORIES properties and see if they are set as expected.

---

<div class="post-metadata">

**Author:** ![jwm](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jwm/32/654_2.png) [@jwm](https://discourse.cmake.org/u/jwm)\
**Post date:** [April 23, 2024, 12:46am UTC](https://discourse.cmake.org/t/propagation-of-include-paths-through-targets/10692/3 "2024-04-23T00:46:21Z")

</div>

The `INTERFACE_INCLUDE_DIRECTORIES` property was as you would expect.

It turns out that the issue was (surprise!) programmer error. `myProg` has most of its sources built in an `OBJECT` library to facilitate unit testing. When the sources were moved into the object library, `myBase` was left as a link library on the executable, rather than being moved to the object library. Consequently, the sources in the object library didn’t get the benefit of the `fetchTarget` includes when they compiled.

Thanks for looking; sorry for wasting everyone’s time.
