[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 09:48:12 EDT 2018


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

> Hello,
>
> how can e.g. $<TARGET_OBJECTS:objlib> be iterated over in cmake?
>
> This builds the lib, but the loop is never run:
>
>     add_library(objlib12 OBJECT lib1.c lib2.c)
>     foreach(o IN LISTS $<TARGET_OBJECTS:objlib12>)
>         message("obj ${o}")
>     endforeach()
>
> But the $<TARGET_OBJECTS:objlib12> variable is set correctly, as this
> builds a shared library:
>
>     add_library(lib12 SHARED $<TARGET_OBJECTS:objlib12>)
>
> And the ;-separated list is visible when running this custom command via
> the 'test12' target:
>
>     add_custom_command(OUTPUT libtest.cc
>         COMMAND bash -c "echo '$<TARGET_OBJECTS:objlib12>'; echo >
> libtest.cc"
>         VERBATIM)
>     add_library(test12 SHARED libtest.cc)
>
>
> Why does the for loop completely ignore this variable?
>

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.


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


More information about the CMake mailing list