CMake has a math command to assign a variable with the evaluation of a mathematical expression. For example the following cmake code sets the variable v to the value "7"
math(EXPR v "2 * 3 + 1")
The following prints the numbers from 0 to 9
set(i "0")
while(i LESS "10")
math(EXPR i "${i} + 1")
message("i = ${i}")
endwhile()
The cmake documentation on the if command provides information on the syntax for performing numerical comparisons.
Operation | Keyword |
---|---|
< | LESS |
> | GREATER |
= | EQUAL |
≤ | LESS_EQUAL |
≥ | GREATER_EQUAL |
The boolean operators are: AND, OR and NOT.