To put it shortly: Everything inside the if parentheses is evaluated as an expression, this is the semantic of the if
keyword. So if you put APPLE
there, it gets evaluated as a variable name and yields the correct result.
Now if you put ${APPLE}
there, ${}
will evaluate its contents before if
evaluates the expression. Therefore, it's the same as if you'd written
if (1 AND )
(in the case that the variable APPLE
isn't set, which is the case on non-OSX systems). This is invalid syntax and yields the error you get. You should write:
if (FOO AND APPLE)
Quoting from the CMake Documentation:
The if command was written very early in CMake’s history, predating the ${} variable evaluation syntax, and for convenience evaluates variables named by its arguments as shown in the above signatures. Note that normal variable evaluation with ${} applies before the if command even receives the arguments. Therefore code like:
set(var1 OFF)
set(var2 "var1")
if(${var2})
appears to the if command as:
if(var1)
and is evaluated according to the if() case documented above. The result is OFF which is false. However, if we remove the ${} from the example then the command sees:
if(var2)
which is true because var2 is defined to “var1” which is not a false constant.