Skip to content

Commit

Permalink
Feat: assert() macro
Browse files Browse the repository at this point in the history
  • Loading branch information
UnePierre committed Feb 2, 2024
1 parent a923618 commit 7efd75c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeEssential.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set_package_properties(
TYPE RECOMMENDED)

# Provided snippets:
include("${CMAKE_CURRENT_LIST_DIR}/include/Assert.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/include/Ccache.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/include/Git.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/include/MessageContext.cmake")
Expand Down
10 changes: 10 additions & 0 deletions include/Assert.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# assert(<test> [...])
#
# Output a SEND_ERROR message, iff the test fails, including the test and all other arguments.
#
macro(assert test)
if(NOT ${test})
string(JOIN " " arguments ${ARGV})
message(SEND_ERROR "Assertion failed: ${arguments}")
endif()
endmacro()
1 change: 1 addition & 0 deletions tools/CMakeLists.in.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ project(
project_message_context()

set(provided_snippets
"Assert.cmake"
"Ccache.cmake"
"Git.cmake"
"MessageContext.cmake"
Expand Down

0 comments on commit 7efd75c

Please sign in to comment.