[CMake] target_link_libraries and Custom Properties

Marek Vojtko (Firaxis) Marek.Vojtko at firaxis.com
Wed May 9 11:49:10 EDT 2018


Hi,

I have multiple library targets that each provide shader files and headers. I also have multiple executable targets that each depend on a different set of these library targets. The executable targets need to collect the shader files and headers of only the libraries they depend on in order to compile them.

The ideal solution would be to reproduce the transitive dependency behavior controlled by target_link_libraries on a custom target property [0], but as far as I can tell define_property does not do that - it just creates a property on a target that can be queried but is not part of the dependency chain. I also wasn't able to find a way to get a list of targets a given target depends on, so that I could run through it and query each dependent target's custom property manually.

Variables do not solve this problem, because different executables depend on different libraries. Each library would need to know a) about all executables, and b) whether a particular executable depended on said library in order to be able to add the shader files and headers to a per-executable variable.

Is there a way to achieve this in CMake?

[0] CMake has a set of properties that get propagated according to the transitive dependency rules (PRIVATE, INTERFACE, PUBLIC) using target_link_libraries (e.g. COMPILE_DEFINITIONS, COMPILE_OPTIONS, INCLUDE_DIRECTORIES, etc.). I would like to add a custom property, for example SHADER_SOURCES, and have it propagate the same way, i.e. target A that depends on targets B, C, and D would have the INTERFACE_SHADER_SOURCES of targets B, C, and D in its SHADER_SOURCES property.
--
Marek Vojtko
mail: marek.vojtko at firaxis.com
phone: (+1) 410-229-2519



More information about the CMake mailing list