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:
+,-,*,/, and%modulo division - Bitwise:
|or,&and,^xor,~not,<<shift left, and>>shift right - Parenthesis (...)
Constant values can be provided in decimal or hexadecimal format.