jhol
October 24, 2024, 4:25pm
1
I would like to write a generator expression which takes a list of targets, and retrieves a target property for each one producing a list of values.
Is there a way to do this? I can’t see an obvious way.
I thought of one very tricky way to do this using $<GENEX_EVAL:expr>
:
$<GENEX_EVAL:$<LIST:TRANSFORM,${targets},REPLACE,(.+),$<DOLLAR>$<ANGLE-L>TARGET_PROPERTY:\\1$<COMMA>${prop}$<ANGLE-R>>>
…except it doesn’t work because there are no $<DOLLAR>
and $<ANGLE-L>
expressions, so how can I escape the inner expression?
Do things work if you replace $<DOLLAR>
with $<1:$>
, or $<ANGLE-L>
with $<1:<>
? I think the latter might be a bit problematic, but the former might work.
1 Like
jhol
October 25, 2024, 6:50pm
3
Ok, that works! Thank you. It even works recursively!:
set(targets picolibc::picolibc ZLIB::ZLIB)
function(escape_generator_expression var)
string(REPLACE ">" "__ANGLE_R__" ${var} "${${var}}")
string(REPLACE "$" "$<1:$>" ${var} "${${var}}")
string(REPLACE "," "$<COMMA>" ${var} "${${var}}")
string(REPLACE "__ANGLE_R__" "$<ANGLE-R>" ${var} "${${var}}")
return(PROPAGATE ${var})
endfunction()
set(prop "INTERFACE_INCLUDE_DIRECTORIES")
set(get_prop "$<TARGET_PROPERTY:\\1,${prop}>")
escape_generator_expression(get_prop)
escape_generator_expression(get_prop)
set(expr "$<GENEX_EVAL:$<GENEX_EVAL:$<LIST:TRANSFORM,${targets},REPLACE,(.+),${get_prop}>>>")
2 Likes