Reputation: 1642
Variables like $<TARGET_OBJECTS:myTarget>
can contain a list. To pretty-print it I would like to transform like put a dash, or whatever. So the question is simple : can we call a function from a generator expression ?
I know generator expressions are evaluated at the end of the process, but for me it doesn't implies it can't call a function. However, it's not possible to return a value. If this is possible, is there a way to use it inside generator expressions ?
Upvotes: 1
Views: 394
Reputation: 66278
You cannot call a function for the result of a generator expression, because generator expressions are evaluated after the configuration stage, when all CMake functions are executed.
For pretty-printing a list you could use $<JOIN>
expression.
For example,
$<JOIN $<TARGET_OBJECTS:myTarget>,$<COMMA> >
will concatenate all objects and paste ,
between them.
Upvotes: 2
Reputation: 20026
I know generator expressions are evaluated at runtime, so the function should also be [evaluated] at runtime.
What do you mean by "runtime"? That's not a thing in CMake. There's configuration time and generation time, which are different. Functions run during configuration and generator expressions are expanded during generation, so you cannot call a CMake function from a generator expression.
Plus, it's not possible to return a value. If this is possible, is there a way to use it inside generator expressions?
Indeed, functions in CMake do not have return values.
Upvotes: 0