CForgeAssert¶
This module provides functions for working with assertions.
- cforge_assert¶
Ensure that an expression evaluates to true. If it evaluates to false, a fatal error is emitted with a customizable message.
cforge_assert( CONDITION <expr> [MESSAGE <message>] )
The expression passed to the CONDITION
argument is evaluated using the
same logic as the if()
CMake command.
In case of assertion failure, a fatal error is generated with the message
"Assertion failed!"
. If the MESSAGE
argument is provided, it is appended
to the message of the fatal error.
Usage example
cforge_assert(CONDITION CMAKE_COMMAND AND CMAKE_VERSION MESSAGE "Ouch")Assert that both variables
CMAKE_COMMAND
andCMAKE_VERSION
are defined. Print “Ouch” in case of failure.cforge_assert(CONDITION VAR STREQUAL "value")Assert that the variable
VAR
is equal to the string"value"
.cforge_assert(CONDITION INDEX LESS 100)Assert that the variable
INDEX
is less than100
.