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 b454aaa
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 6 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
2 changes: 1 addition & 1 deletion CMakeEssentialConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(CMakeEssential_VERSION 1.0.3.2)
set(CMakeEssential_VERSION 1.0.4.0)


####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
Expand Down
6 changes: 3 additions & 3 deletions CMakeEssentialConfigVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
# The variable CVF_VERSION must be set before calling configure_file().


set(PACKAGE_VERSION "1.0.3.2")
set(PACKAGE_VERSION "1.0.4.0")

if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()

if("1.0.3.2" MATCHES "^([0-9]+)\\.")
if("1.0.4.0" MATCHES "^([0-9]+)\\.")
set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}")
if(NOT CVF_VERSION_MAJOR VERSION_EQUAL 0)
string(REGEX REPLACE "^0+" "" CVF_VERSION_MAJOR "${CVF_VERSION_MAJOR}")
endif()
else()
set(CVF_VERSION_MAJOR "1.0.3.2")
set(CVF_VERSION_MAJOR "1.0.4.0")
endif()

if(PACKAGE_FIND_VERSION_RANGE)
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include("include/Policies.cmake")
include("include/Project.cmake")

# This project can be used via 'git subtree' or copy&paste, where git cannot provide the version number.
set(PROJECT_VERSION "1.0.3.2")
set(PROJECT_VERSION "1.0.4.0")

project(
CMakeEssential
Expand All @@ -15,6 +15,7 @@ project(
project_message_context()

set(provided_snippets
"Assert.cmake"
"Ccache.cmake"
"Git.cmake"
"MessageContext.cmake"
Expand Down
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:author: Max FERGER
// Metadata:
:description: Essential CMake snippets for software development with modern CMake
:revnumber: 1.0.3.2
:revnumber: 1.0.4.0
// References:
:url-repo: https://github.com/UnePierre/cmake-essential
:url-issues: {url-repo}/-/issues
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 b454aaa

Please sign in to comment.