CMake syntax: how to negate if(<constant>) and if(<variable|string>)

2.7k Views Asked by At

CMake's if command [1] supports several signatures, starting with

if(<constant>)
if(<variable|string>)
if(NOT <expression>)

How to negate the first two?

If the CMake documentation is correct (which in my experience is far from certain), then my question boils down to:

How to convert a constant, a variable, or a string X into an expression, with the additional requirement that X is to be evaluated as a boolean?

[1] https://cmake.org/cmake/help/latest/command/if.html

1

There are 1 best solutions below

0
On BEST ANSWER

Actually, <expression> is just a placeholder for any parameter, which can be passed to if. Even the list of possible if constructions is titled as "Possible expressions are".

if(NOT <constant>) # Revert 'if(<constant>)'
if(NOT <variable|string>) # Revert 'if(NOT <variable|string>)'