From b454aaaba7d85b4d770c28dcb1445f4b664f4648 Mon Sep 17 00:00:00 2001 From: Max Ferger Date: Fri, 2 Feb 2024 10:21:08 +0100 Subject: [PATCH] Feat: assert() macro --- CMakeEssential.cmake | 1 + CMakeEssentialConfig.cmake | 2 +- CMakeEssentialConfigVersion.cmake | 6 +++--- CMakeLists.txt | 3 ++- README.adoc | 2 +- include/Assert.cmake | 10 ++++++++++ tools/CMakeLists.in.cmake | 1 + 7 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 include/Assert.cmake diff --git a/CMakeEssential.cmake b/CMakeEssential.cmake index 0c3f797..2724d9d 100644 --- a/CMakeEssential.cmake +++ b/CMakeEssential.cmake @@ -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") diff --git a/CMakeEssentialConfig.cmake b/CMakeEssentialConfig.cmake index 5ebe88d..3f3b054 100644 --- a/CMakeEssentialConfig.cmake +++ b/CMakeEssentialConfig.cmake @@ -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() ####### diff --git a/CMakeEssentialConfigVersion.cmake b/CMakeEssentialConfigVersion.cmake index ebc45e9..0fad911 100644 --- a/CMakeEssentialConfigVersion.cmake +++ b/CMakeEssentialConfigVersion.cmake @@ -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) diff --git a/CMakeLists.txt b/CMakeLists.txt index f883e72..9eb7bfe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -15,6 +15,7 @@ project( project_message_context() set(provided_snippets + "Assert.cmake" "Ccache.cmake" "Git.cmake" "MessageContext.cmake" diff --git a/README.adoc b/README.adoc index 61ae575..c0ad7e1 100644 --- a/README.adoc +++ b/README.adoc @@ -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 diff --git a/include/Assert.cmake b/include/Assert.cmake new file mode 100644 index 0000000..5f269cb --- /dev/null +++ b/include/Assert.cmake @@ -0,0 +1,10 @@ +# assert( [...]) +# +# 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() diff --git a/tools/CMakeLists.in.cmake b/tools/CMakeLists.in.cmake index 9ae2777..0d02846 100644 --- a/tools/CMakeLists.in.cmake +++ b/tools/CMakeLists.in.cmake @@ -15,6 +15,7 @@ project( project_message_context() set(provided_snippets + "Assert.cmake" "Ccache.cmake" "Git.cmake" "MessageContext.cmake"