# Property inheritance thru target\_link

**URL:** https://discourse.cmake.org/t/property-inheritance-thru-target-link/8426
**Category:** Usage
**Created:** [June 28, 2023, 7:49pm UTC](https://discourse.cmake.org/t/property-inheritance-thru-target-link/8426 "2023-06-28T19:49:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![kfsone](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kfsone/32/1880_2.png) [@kfsone](https://discourse.cmake.org/u/kfsone)
#### Post date: [June 28, 2023, 7:49pm UTC](https://discourse.cmake.org/t/property-inheritance-thru-target-link/8426/1 "2023-06-28T19:49:36Z")

</div>

I was attempting to validate my understanding of the inheritance of `PROPERTY`s through target link libraries. That is, I thought that if `target1` was given a property and `target2` linked that target, it would inherit that property, such that `$<TARGET_PROPERTY:target2,property_name>` would reveal that value.

Is this wrong, or is my test case simply wrong?

> **[GitHub - kfsone/cmake-genexp-prop: CMake Experiment on property inheritance /...](https://github.com/kfsone/cmake-genexp-prop)**
>
> CMake Experiment on property inheritance / visibility in generator expressions. - GitHub - kfsone/cmake-genexp-prop: CMake Experiment on property inheritance / visibility in generator expressions.

```auto
cmake_minimum_required (VERSION 3.17)
project (test LANGUAGES C)

add_library (l1 STATIC f1.c)
set_property (TARGET l1 PROPERTY FOO "FOO property from l1")
target_compile_definitions (l1 PUBLIC -DBAR="public Dbar from l1")
target_compile_definitions (l1 PRIVATE -DBAR="Dbar from l1")

add_library (l2 STATIC f2.c)
target_link_libraries (l2 PUBLIC l1)
target_compile_definitions (l2 PRIVATE -DFOO_L1="$<TARGET_PROPERTY:l1,FOO>")
target_compile_definitions (l2 PRIVATE -DFOO_L2="$<TARGET_PROPERTY:l2,FOO>")

add_executable (test main.c)
target_link_libraries (test l2)

```

what this finds is that `l1,FOO` resolves to a value, but `l2,FOO` is empty in this scenario.

```auto
f1BAR:[Dbar from l1] f2bar:[public Dbar from l1] f2foo1:[FOO property from l1] f2foo2:[]

```

Is this a limitation of `target_compile definitions` or a misunderstanding of properties?

---

<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: [July 1, 2023, 11:27pm UTC](https://discourse.cmake.org/t/property-inheritance-thru-target-link/8426/2 "2023-07-01T23:27:09Z")

</div>

Inheriting properties like that is not allowed. The other thing that cannot be asked is “what else has the end target used?”. These both run into the “this is false” paradox:

- target A says “set property P”
- target B says “link to A if property P is not set”

If target T links to B, should property P be set or not? If it is not set, it links to A and has P set. But then it should not link to A because only B said “if P is not set”.

Instead, what CMake provides are “usage requirements”: “if you link to _me_, here is what you must also do”. There is a post-resolution check via the `COMPATIBLE_INTERFACE` properties that can _check_ for consistency, but they cannot _fix_ an inconsistency.
