Is there a way to alleviate or possibly use true/falseor on/offor yes/noin CMake generator expressions, and 1/0?
Context
As for the documentation , only 1and are recognized in the expressions of the generator 0.
However, as the team the if , 1, ON, YES, TRUE, Yall are considered to be logical values.
It scares some things; for example, you can use the command optionto get input from the user at the configuration stage, and then try to use its value in the generator expression; however, in this case, cmake will complain if the value is not equal to 1or 0. The same applies to boolean variables stored in the CMake cache.
cmake_minimum_required(VERSION 2.8.12)
add_custom_target(print
${CMAKE_COMMAND} -E echo $<1:hello> $<0:world>
)
Create a file CMakeLists.txtwith the above contents, run it cmake .and then make(generator expressions are evaluated only during build). It will print helloas expected.
However, the following example will not even work with the command itself cmake:
cmake_minimum_required(VERSION 2.8.12)
add_custom_target(print2
${CMAKE_COMMAND} -E echo $<true:hello> $<false:world>
)
Here is its output (during setup):
-- Configuring done
CMake Error at CMakeLists.txt:3 (add_custom_target):
Error evaluating generator expression:
$<true:hello>
Expression did not evaluate to a known generator expression
CMake Error at CMakeLists.txt:3 (add_custom_target):
Error evaluating generator expression:
$<false:world>
Expression did not evaluate to a known generator expression
-- Generating done
-- Build files have been written to: /tmp/cmake
Yet again:
true/false on/off yes/no CMake, 1/0?
, , 1/0, ?