# COMPILE\_DEFINITIONS directory property not propagated to targets?

**URL:** https://discourse.cmake.org/t/compile-definitions-directory-property-not-propagated-to-targets/4555
**Category:** Usage
**Created:** [November 26, 2021, 1:54pm UTC](https://discourse.cmake.org/t/compile-definitions-directory-property-not-propagated-to-targets/4555 "2021-11-26T13:54:58Z")
**Posts on this page:** 3
**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 26, 2021, 1:54pm UTC](https://discourse.cmake.org/t/compile-definitions-directory-property-not-propagated-to-targets/4555/1 "2021-11-26T13:54:59Z")

</div>

Hi,

apparently, the `COMPILE_DEFINITIONS` directory property is not (always) propagated to the targets defined in that directory. Is that on purpose? Do I miss something?

In my situation, there is an `add_definitions(-Dsomething)` in the toplevel `CMakeLists.txt`. This is correctly propagated to the `COMPILE_DEFINITIONS` property of subdirectories: `get_directory_property(_defines COMPILE_DEFINITIONS)` in a subdirectory yields the expected definition.

However, when asking for `get_target_property(_defines ${target} COMPILE_DEFINITIONS)` with a `${target}` defined in that subdirectory, there is nothing.

Is this again something which can only be addressed via generator expressions?

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 26, 2021, 2:12pm UTC](https://discourse.cmake.org/t/compile-definitions-directory-property-not-propagated-to-targets/4555/2 "2021-11-26T14:12:39Z")

</div>

This is expected. The target, at generation time, looks up its `COMPILE_DEFINITIONS` _and_ its owning directory’s `COMPILE_DEFINITIONS` and uses the combination. The genex should be able to see this combination, but I’m not 100% sure (in any case, changing it would likely be a policy or need to be a new genex).

---

<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 29, 2021, 8:18am UTC](https://discourse.cmake.org/t/compile-definitions-directory-property-not-propagated-to-targets/4555/3 "2021-11-29T08:18:22Z")

</div>

> The genex should be able to see this combination

Apparently, it does. Thanks; works with generator expressions. Slowly but surely, I am getting used to them 😉.

Kind regards  
Ingolf
