Content #
CMake will try to evaluate unquoted arguments as if they are variable references. In other words, using a plain variable name inside a condition is equal to writing ${VAR}.
set(VAR1 FALSE)
set(VAR2 "VAR1")
if(${VAR2})
The if() condition works in a bit of a convoluted way here –
- it will evaluate ${VAR2} to VAR1, which is a recognized variable
- and this in turn is evaluated to the FALSE string.
Strings are considered Boolean true only if they equal any of the following constants (these comparisons are case insensitive):
- ON, Y, YES, or TRUE
- A non-zero number
Consider the following code example:
set(FOO BAR)
if(FOO)
Unlike with quoted arguments, FOO won’t be evaluated to BAR to produce an if(“BAR”) statement (which would be false). Instead, CMake will only evaluate if(FOO) to false if it is any of the following constants (these comparisons are case insensitive):
- OFF, NO, FALSE, N, IGNORE, NOTFOUND
- A string ending with -NOTFOUND
- An empty string
- Zero
Check if the variable is defined #
if(DEFINED <name>)
if(DEFINED CACHE{<name>})
if(DEFINED ENV{<name>})