$<AND:...> does not short-circuit
Starting with CMake 3.28, the $<AND:...>
generator expression is meant to short-circuit. Once it knows the result after processing some items (i.e. once it encounters an item that evaluates to 0), it should skip evaluating the rest of the items. The following example demonstrates that this isn't being done, at least not for the case shown:
add_executable(genex main.cpp
$<$<AND:1,0,$<NOT_A_VALID_GENEX>>:>
)
Instead of skipping the $<NOT_A_VALID_GENEX>
, it still gets processed, even though the preceding item is 0, and therefore all later items should be skipped. The error generated with CMake 3.28.0-rc4 is the following (note the extra spurious error message at the end about no sources, which is also wrong):
CMake Error at CMakeLists.txt:6 (add_executable):
Error evaluating generator expression:
$<NOT_A_VALID_GENEX>
Expression did not evaluate to a known generator expression
CMake Error at CMakeLists.txt:6 (add_executable):
Error evaluating generator expression:
$<NOT_A_VALID_GENEX>
Expression did not evaluate to a known generator expression
CMake Error at CMakeLists.txt:6 (add_executable):
Error evaluating generator expression:
$<NOT_A_VALID_GENEX>
Expression did not evaluate to a known generator expression
CMake Error at CMakeLists.txt:6 (add_executable):
No SOURCES given to target: genex
The $<IF:...>
, $<OR:...>
and $<0:...>
generator expressions do not have this weakness, it only seems to be $<AND:...>
which doesn't short-circuit in the expected way.