[CMake] Iterating over a generator expression list, specifically $<TARGET_OBJECTS:objlib> of an OBJECT library

Eric Noulard eric.noulard at gmail.com
Tue Aug 28 10:39:59 EDT 2018


I cc the list because I think you drop it inadvertently.

Le mar. 28 août 2018 à 16:18, George PF <george.p.f at mail.com> a écrit :

> > Because generator expressions are not handled in every cmake construct:
> >
> https://cmake.org/cmake/help/v3.12/manual/cmake-generator-expressions.7.html
> >
> > genex is probably not handled in foreach.
>
> That is a harsh limitation, set() or list() also does not expand this
> expression.
>

genex are evaluated during "Generation time" i.e. when CMake
produces/generates the specific build system
files (makefile, [build|rules].ninja, MSVC solution etc...). This is
convenient because some (most of) genex informations
may be generator specific (library file name, build artefact location,
etc...)

https://stackoverflow.com/questions/46206495/cmake-generator-expressions

set() , list(), foreach() are "running" at "CMake time" i.e. when cmake
runs and processes CMakeLists.txt and other cmake scripts
that is before "Generation time".


And the variable XYZ, when set via this indirection to TARGET_OBJECTS,
>
>     add_library(lib12 SHARED $<TARGET_OBJECTS:objlib12>)
>     get_property(XYZ TARGET lib12 PROPERTY SOURCES)
>
> is also not expanded yet. Is there a workaround regarding the generator
> expressions, or
> another way to get the TARGET_OBJECTS of an object library (and why is
> this hidden
> behind a generator and not available as a property)?
>

My opinion (but I may be proven wrong by others) is that genex contains
generator specific bits that cannot be **evaluated**
until the build system is generated.  Properties (on target, or directory,
or files) contains informations that is available as soon
as the corresponding CMakeLists.txt part defining the object has been
processed.


-- 
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180828/79f78c74/attachment.html>


More information about the CMake mailing list