4

In CMake, I want to get all property names that are set for a target.

In How to print all the properties of a target in cmake? they use cmake --help-property-list to list a predefined set. But if you have a target that defines other properties, how can I know which are they? For example:

set_target_properties(some_target PROPERTIES some_custom_property prop_val)

How can I get all such properties? I am looking for something like

get_target_property_names(some_target property_names)
starball
  • 20,030
  • 7
  • 43
  • 238
Sogartar
  • 2,035
  • 2
  • 19
  • 35

1 Answers1

2

At the time of this writing, the latest CMake version is v3.25. I am not aware of any commands or functions which directly implement what you are looking for.

I tried looking to see if there was any special target property which lists names of all other target properties on a target, but didn't see such a property in the list of target properties in the reference documentation.

I tried to see if there was any internal/undocumented functionality that tracked the names of all properties on a target. You can see the source code in the cmTarget::SetProperty and cmTarget::StoreProperty member functions in KitWare/CMake/Source/cmTarget.cxx. There technically is, but not in a way that is simple, or that I can see any way to access from a CMake script. I say it isn't simple because when you look at cmTarget::StoreProperty, you'll see that many properties are handled and stored in custom ways other than the more general storage (this->impl->Properties).

Perhaps you could try to come up with a way to override the set_target_properties and set_property commands to track changes to them to know what custom properties are being added, and combine that knowledge with what can be gotten from How to print all the properties of a target in cmake?, but redefining CMake commands is generally not a good idea / difficult to do right.

At this point, you might want to think more about why you want to be able to do this and whether there are different ways to achieve what you want (Ie. this could be an XY Problem). You could ask your "Y"-Question as a separate question on Stack Overflow, or you could ask on the CMake Discourse. If you talk with the CMake maintainers in an issue ticket and agree that there's a good case for such functionality for general users of CMake, then (who knows!) it could become a feature in a later CMake version.

starball
  • 20,030
  • 7
  • 43
  • 238