The math() command
CMake also supports some simple arithmetical operations. See the online documentation for full details:
https://cmake.org/cmake/help/latest/command/math.html
To evaluate a mathematical expression and store it in the <out>
variable as the string in an optional <format>
(HEXADECIMAL
or DECIMAL
), use the following signature:
math(EXPR <out> "<expression>" [OUTPUT_FORMAT <format>])
The <expression>
value is a string that supports operators present in C code (they have the same meaning here):
- Arithmetical:
+
,-
,*
,/
,%
modulo division - Bitwise:
|
or,&
and,^
xor,~
not,<<
shift left,>>
shift right - Parenthesis (...)
Constant values can be provided in decimal or hexadecimal format.