[CMake] target_link_libraries and Custom Properties

Robert Maynard robert.maynard at kitware.com
Tue May 15 13:22:28 EDT 2018


>  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.

This isn't currently possible.

> The executable targets need to collect the shader files and headers of
only the libraries they depend on in order to compile them

Have you looked at using `target_sources`? In general target_sources are
transitive and allow you to include source files for compilation for your
consumers, when you combine them generator expressions you make the
inclusion conditional. A great example would be how Qt5 conditionally
includes sources when it encounters an executable on windows (
https://github.com/qt/qtbase/blob/17b73b0d2b8e0d643bdf13b543cc23d657a4b330/src/corelib/Qt5CoreConfigExtras.cmake.in#L160
).

On Wed, May 9, 2018 at 11:55 AM Marek Vojtko (Firaxis) <
Marek.Vojtko at firaxis.com> wrote:

> 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
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180515/a3ef9490/attachment.html>


More information about the CMake mailing list