cmakepp_lang/asserts/assert

cmakepp_lang/asserts/assert.cpp_assert(cond desc)

Asserts that provided value is true.

The cpp_assert function is code factorization for the very common scenario where we want to crash the program if a condition is not met.

Parameters:
  • cond (bool or str or list(str)) – The condition which should be true. This can be anything that can be passed to CMake’s if statement; however, if the condition is not a single argument it must be provided as a list, e.g., x STREQUAL x becomes x;STREQUAL;x.

  • desc (str) – Human-readable description of the assertion.

Example Usage

This first example shows how to use cpp_assert to ensure that an object is a particular type (in this case an integer). It should be noted that this same functionality is provided by the cpp_assert_int function and does not need to be reimplemented.

include(cmakepp_lang/asserts/assert)
include(cmakepp_lang/types/integer)
cpp_is_int(is_int 3)
cpp_assert("${_is_int}" "3 is an integer")

This second example shows how to pass an actual condition as opposed to a result:

include(cmakepp_lang/asserts/assert)
set(x 4)
cpp_assert("${x};GREATER;3" "x is > 3")