Generator Expression to evaluate whether the input is a target which does not result in error
We have run into an issue regarding conditional evaluation of generator expressions. We are trying to extract property information form dependent targets specified in the LINK_LIBRARIES property.
We have generator expressions that do not result in valid CMake targets (e.g: TARGET_OBJECTS). We tried to filter these out using the BOOL generator expression coupled with TARGET_EXISTS. Sadly TARGET_EXISTS expects the input to be a valid target name.
We'd like to see a generator expression, e.g: $<IS_TARGET:...>, which would be able to evaluate whether the result in ... evaluates to a target and does not error out if the input can't be used with TARGET_EXISTS, for instance. Alternatively, if possible, extending TARGET_EXISTS, to accept inputs which are not valid target names would also work.
For example we would like to be able to write expressions such as:
set(target $<TARGET_OBJECTS:Foo>)
file(GENERATE
OUTPUT ${CMAKE_BINARY_DIR}/test.txt
CONTENT "$<$<BOOL:$<IS_TARGET:${target}>:$<TARGET_PROPERTY:${target},BAR>>"
)
That being said, it may be required to tweak the evaluation of generator expressions. Consider the following expression:
set(target $<TARGET_OBJECTS:Foo>)
...
"$<0:$<TARGET_PROPERTY:${target},BAR>>"
While this generator expression should never be evaluated due to the false condition, it is still it and results in an error:
Error evaluating generator expression:
$<TARGET_PROPERTY:$<TARGET_OBJECTS:Foo>, BAR>
Target name and property name not supported.
Taking this into account, it doesn't seem possible to implement the above suggested expression if we also evaluate/validate non valid conditions.
Would it be possible in the current state to not evaluate the contents of the expression when the conditions are false?