# set target property project-wide

**URL:** <https://discourse.cmake.org/t/set-target-property-project-wide/2798>\
**Category:** Code\
**Created:** [February 19, 2021, 12:33am UTC](https://discourse.cmake.org/t/set-target-property-project-wide/2798 "2021-02-19T00:33:47Z")\
**Posts on this page:** 5\
**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:** [February 19, 2021, 12:33am UTC](https://discourse.cmake.org/t/set-target-property-project-wide/2798/1 "2021-02-19T00:33:47Z")

</div>

I lifted my C++ backtrace utility from another project. There was even a note in the source code about requiring `-rdynamic` to use. Originally, we were using CMake 3.3. When I upgraded to 3.17, I was silently bitten by CMP0065. I now see that I need to set the [ENABLE\_EXPORTS](https://cmake.org/cmake/help/v3.17/prop_tgt/ENABLE_EXPORTS.html#prop_tgt:ENABLE_EXPORTS) target property, in order to get the appropriate linker flag.

I’ve looked at [How to share common cmake properties between exes?](https://discourse.cmake.org/t/how-to-share-common-cmake-properties-between-exes/1120). @marc.chevrier had a [response](https://discourse.cmake.org/t/how-to-share-common-cmake-properties-between-exes/1120/4) that hints at the solution I want, but I don’t want to set compile/link options directly; I want to use the abstraction of the `ENABLE_EXPORTS` property. Unfortunately, setting it on my utility library doesn’t translate into an inherited link flag for targets that use it.

I’d like to think that I could set a global-scope property that would apply to all targets, but it doesn’t appear that global-scope properties work that way.

I think it’s too much to ask of users of a library to know that if you call function `backtrace` in library `util` that you need to set the `ENABLE_EXPORTS` property on your executable. It’s even worse if some intervening library makes the call, the the executable writer has no idea.

Am I totally off base, or is there a better way?

---

<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:** [February 19, 2021, 1:50pm UTC](https://discourse.cmake.org/t/set-target-property-project-wide/2798/2 "2021-02-19T13:50:45Z")

</div>

Unfortunately, not really. CMake won’t propagate usage requirements across a `PRIVATE` boundary, so there’s no way for a “buried” library to communicate with an executable. You could create an `INTERFACE` library that you document that one should link to publicly when linking to your other library via `PRIVATE` (alas, they’ll need the same instructions for _their_ consumers). This `INTERFACE` library can at least bring along the flag guarded by a `$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>` genex conditional, but there’s no way to say “must set this property to X”. Though maybe the [`COMPATIBLE_INTERFACE_BOOL`](https://cmake.org/cmake/help/latest/prop_tgt/COMPATIBLE_INTERFACE_BOOL.html) property could be used to at least get CMake to error if the property isn’t set properly?

---

<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:** [February 20, 2021, 7:22am UTC](https://discourse.cmake.org/t/set-target-property-project-wide/2798/3 "2021-02-20T07:22:52Z")

</div>

But the variable [CMAKE\_ENABLE\_EXPORTS](https://cmake.org/cmake/help/latest/variable/CMAKE_ENABLE_EXPORTS.html) can be used to set, for a whole project, property `ENABLE_EXPORTS`.

---

<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:** [February 20, 2021, 1:53pm UTC](https://discourse.cmake.org/t/set-target-property-project-wide/2798/4 "2021-02-20T13:53:47Z")

</div>

Yes, but that only works within a single project. If there’s no exported SDK for such a project, that solution is probably sufficient.

---

<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:** [February 22, 2021, 6:50pm UTC](https://discourse.cmake.org/t/set-target-property-project-wide/2798/5 "2021-02-22T18:50:01Z")

</div>

@ben.boeckel makes a valid point, and it would be nice for a library to be able to export this type of requirement for use in other projects. However, my near-term need is for a single project, and @marc.chevrier had just the ticket I needed.

Thanks all!
