# define\_property on target has no effect?

**URL:** https://discourse.cmake.org/t/define-property-on-target-has-no-effect/7425
**Category:** Usage
**Created:** [February 7, 2023, 8:29pm UTC](https://discourse.cmake.org/t/define-property-on-target-has-no-effect/7425 "2023-02-07T20:29:14Z")
**Posts on this page:** 6
**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: [February 7, 2023, 8:29pm UTC](https://discourse.cmake.org/t/define-property-on-target-has-no-effect/7425/1 "2023-02-07T20:29:14Z")

</div>

[kfsone/cmake-defprop: Cmake “define-property” validation (github.com)](https://github.com/kfsone/cmake-defprop)

Am I misusing/misunderstanding `define_property`?

CMake documentation suggests that using `define_property` will cause `get_target_property` to return no value if the property is defined as a `TARGET` property and `INHERITED` .

I wanted to use target properties on INTERFACE libraries to allow me to forward runtime file requirements on INTERFACE libraries so that post-build functions can be called naively and simply consume the list of runtime requirements if they are inherited up to a target.

```auto
# (wow, I really botched this line in the description originally)
define_property (TARGET PROPERTY runtime_stuff INHERITED)
if (complex-conditional)
  set_target_properties (libsoandso PROPERTIES runtime_stuff strings.bundle config.ini)
endif ()

function (post_build_soandso TARGET)
    get_property (runtimes ${TARGET} runtime_stuff)
    if (runtimes)
        add_custom_command ...
    endif ()
endfunction ()

```

This doesn’t work, because `runtimes` gets set to `runtimes-NOTFOUND`.

While not the worst thing in the world, it’s a weird case to try and teach.

```auto
    get_property (runtimes ${TARGET} runtime_stuff)
    if (runtimes AND NOT ${runtimes} STREQUAL "runtimes-NOTFOUND")

```

this is not something I expect developers who aren’t living in CMake to get right, so `define_property` promises to give me a better behavior.

It doesn’t appear to work, though.

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [February 8, 2023, 1:53pm UTC](https://discourse.cmake.org/t/define-property-on-target-has-no-effect/7425/2 "2023-02-08T13:53:54Z")

</div>

CMake treats a variable whose value ends in `-NOTFOUND` as false (this is documented in the [docs of the `if()` command](https://cmake.org/cmake/help/latest/command/if.html#basic-expressions)). So if you do this:

```auto
set(var var-NOTFOUND)
if(var)
  message(FATAL_ERROR "")
endif()

```

you will _not_ get an error. So if your actual code contains the `if` as you described, it should work. If it doesn’t, the problem is somewhere else.

---

<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: [February 9, 2023, 10:11am UTC](https://discourse.cmake.org/t/define-property-on-target-has-no-effect/7425/3 "2023-02-09T10:11:29Z")

</div>

It gets treated as false, but it also expands out to a string. My reading of ‘define\_property’ documentation is that it would cause the get\_property outvar to have no value, not a value that will be inconvenient in anything but a boolean context.

```auto
get_property(runtimes ${TARGET} runtime_stuff)
add_custom_command (${TARGET} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${runtime_stuff} $<TARGET_FILE_DIR:${TARGET}> COMMAND_EXPAND_LISTS)

```

is not happy when this expands to

```auto
cmake -E copy_if_different runtimes-NOTFOUND .../build/.../target.dir

```

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [February 10, 2023, 1:37am UTC](https://discourse.cmake.org/t/define-property-on-target-has-no-effect/7425/4 "2023-02-10T01:37:30Z")

</div>

> [@kfsone](#):
>
> `get_property(runtimes ${TARGET} runtime_stuff)`

This command is not well-formed. It should be one of the following alternatives:

```cmake
get_property(runtimes TARGET ${TARGET} PROPERTY runtime_stuff)
get_target_property(runtimes ${TARGET} runtime_stuff)

```

If the property is not defined, `get_property()` returns an empty string, but `get_target_property()` returns `runtimes-NOTFOUND`. Use the former if you want an empty string in this scenario.

---

<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: [February 15, 2023, 1:09am UTC](https://discourse.cmake.org/t/define-property-on-target-has-no-effect/7425/5 "2023-02-15T01:09:08Z")

</div>

Oh, heck; thanks.

Is there a reason that `define` doesn’t affect get\_target\_property? (I’m guessing scope)

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [February 15, 2023, 3:57am UTC](https://discourse.cmake.org/t/define-property-on-target-has-no-effect/7425/6 "2023-02-15T03:57:30Z")

</div>

I assume you mean `define_property()`, not `define()`. There’s no difference in what `get_property()` and `get_target_property()` see as target properties. Both commands see the property as not defined. The difference is in what they give back when the property isn’t defined, and that difference has nothing to do with the `define_property()` command.
