# custom properties for target

**URL:** <https://discourse.cmake.org/t/custom-properties-for-target/9486>\
**Category:** Code\
**Created:** [November 22, 2023, 4:26pm UTC](https://discourse.cmake.org/t/custom-properties-for-target/9486 "2023-11-22T16:26:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KSergeyP](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/8baadc/32.png) [@KSergeyP](https://discourse.cmake.org/u/KSergeyP)\
**Post date:** [November 22, 2023, 4:26pm UTC](https://discourse.cmake.org/t/custom-properties-for-target/9486/1 "2023-11-22T16:26:37Z")

</div>

I’m adding an external library (subdirectory). In this case, it is necessary to specify some configuration properties for this library. Now I do this by setting the values of global variables, because these properties are not in “CMAKE Properties on Targets”. This doesn’t seem like a very good solution. Can I add my custom properties to the CMakeList of the library, which will have to set targets that use this library, for example using set\_target\_properties? And is it possible to specify valid values for these properties so that CMAKE checks them during script execution.

---

<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 22, 2023, 9:39pm UTC](https://discourse.cmake.org/t/custom-properties-for-target/9486/2 "2023-11-22T21:39:13Z")

</div>

> [@KSergeyP](#):
>
> Can I add my custom properties to the CMakeList of the library, which will have to set targets that use this library, for example using set\_target\_properties?

You can define whatever properties you want on targets, but only CMake-defined ones will be initialized from a `CMAKE_` variable value. You’re probably best off with some `add_library` wrapper that does the variable to property forwarding for the properties you care about.

> [@KSergeyP](#):
>
> And is it possible to specify valid values for these properties so that CMAKE checks them during script execution.

I don’t think CMake has validation for custom properties at all.

---

<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 22, 2023, 9:40pm UTC](https://discourse.cmake.org/t/custom-properties-for-target/9486/3 "2023-11-22T21:40:16Z")

</div>

Oh, it looks like [`define_property`](https://cmake.org/cmake/help/latest/command/define_property.html) can do it actually.
