From 712f9d15908534a1c328a52f5e44574fe821b958 Mon Sep 17 00:00:00 2001 From: zachcran Date: Sun, 27 Jul 2025 15:58:01 -0600 Subject: [PATCH 1/3] Add fix of message fix from #116 with some extra documentation --- cmake/cmake_test/overrides.cmake | 47 +++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/cmake/cmake_test/overrides.cmake b/cmake/cmake_test/overrides.cmake index 396ed86..7acd607 100644 --- a/cmake/cmake_test/overrides.cmake +++ b/cmake/cmake_test/overrides.cmake @@ -42,26 +42,59 @@ function(message) cpp_get_global(_m_exception_handlers "_CPP_EXCEPTION_HANDLERS_") cpp_map(GET "${_m_exception_handlers}" _m_handlers_list "GENERIC_ERROR") cpp_map(GET "${_m_exception_handlers}" _m_all_handlers_list "ALL_EXCEPTIONS") + if("${_m_handlers_list}" STREQUAL "" AND "${_m_all_handlers_list}" STREQUAL "" ) - #No handlers set, will cause infinite recursion if we raise error - #so force terminate + # No handlers set, this will cause infinite recursion if we raise an error + # because cpp_raise() invokes message(FATAL_ERROR ...), so just terminate CMake here ct_exit("Uncaught exception: ${ARGN}") - else() cpp_raise(GENERIC_ERROR "${ARGV1}") set(CMAKEPP_LANG_DEBUG_MODE "${_m_temp_debug_mode}") return() endif() endif() - else() cpp_set_global(CT_LAST_MESSAGE "${ARGV}") endif() - if("${ARGV}" STREQUAL "") - _message("") + if (${ARGC} EQUAL 0) + _message("") + elseif (${ARGC} EQUAL 1) + _message("${ARGV0}") else() - _message(${ARGV}) + # For a list of valid message modes, see + # https://cmake.org/cmake/help/latest/command/message.html + set(valid_message_modes + # Log Levels + # "FATAL_ERROR" # Handled above + "SEND_ERROR" + "WARNING" + "AUTHOR_WARNING" + "DEPRECATION" + "NOTICE" # Added in 3.15 + "STATUS" + "VERBOSE" # Added in 3.15 + "DEBUG" # Added in 3.15 + "TRACE" # Added in 3.15 + # Reporting Checks + "CHECK_START" # Added in 3.17 + "CHECK_PASS" # Added in 3.17 + "CHECK_FAIL" # Added in 3.17 + # Configure Log + "CONFIGURE_LOG" # Added in 3.26 + ) + set(first_arg "${ARGV0}") + if ("${first_arg}" IN_LIST valid_message_modes) + list(REMOVE_AT ARGV 0) + if(${ARGC} EQUAL 2) + _message("${first_arg}" "${ARGV}") + else() + string(JOIN "" msg ${ARGV}) + _message("${first_arg}" "${msg}") + endif() + else() + _message(${ARGV}) + endif() endif() set(CMAKEPP_LANG_DEBUG_MODE "${_m_temp_debug_mode}") From 9b31c1bafdadae6a5c64c9765978b01e034a52b3 Mon Sep 17 00:00:00 2001 From: zachcran Date: Sun, 27 Jul 2025 16:02:58 -0600 Subject: [PATCH 2/3] Update documentation of message override function --- cmake/cmake_test/overrides.cmake | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cmake/cmake_test/overrides.cmake b/cmake/cmake_test/overrides.cmake index 7acd607..bdf8895 100644 --- a/cmake/cmake_test/overrides.cmake +++ b/cmake/cmake_test/overrides.cmake @@ -25,9 +25,20 @@ include_guard(GLOBAL) #[[[ -# This function overrides the standard message() function to convert fatal_errors into CMakePP GENERIC_ERROR exceptions. -# This is useful for executing tests which are expected to fail without requiring subprocesses. -# If the first argument is not FATAL_ERROR, this function will behave exactly as the original message(). +# Overrides the standard ``message()`` to handle errors as CMakePP exceptions. +# +# This function overrides the standard ``message()`` function to convert +# fatal_errors into CMakePP ``GENERIC_ERROR`` exceptions. This is useful for +# executing tests which are expected to fail without requiring subprocesses. +# If the first argument is not ``FATAL_ERROR``, this function will behave exactly +# as the original ``message()``. +# +# It should be noted that redefining CMake commands is `highly discouraged +# https://crascit.com/2018/09/14/do-not-redefine-cmake-commands/`__. +# +# :param *args: A variadiac list of arguments intended for the ``message()`` +# function. +# :type *args: str #]] function(message) # Set debug mode to what it should be for cmaketest, in case the test changed it From 2e3a7569d75bd445367a6b217964aead92d7d8b6 Mon Sep 17 00:00:00 2001 From: zachcran Date: Sun, 27 Jul 2025 16:07:05 -0600 Subject: [PATCH 3/3] Formatting and a few more comments explaining things more --- cmake/cmake_test/overrides.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/cmake_test/overrides.cmake b/cmake/cmake_test/overrides.cmake index bdf8895..90dd96b 100644 --- a/cmake/cmake_test/overrides.cmake +++ b/cmake/cmake_test/overrides.cmake @@ -45,11 +45,15 @@ function(message) set(_m_temp_debug_mode "${CMAKEPP_LANG_DEBUG_MODE}") cpp_get_global(_m_ct_debug_mode "CT_DEBUG_MODE") set(CMAKEPP_LANG_DEBUG_MODE "${_m_ct_debug_mode}") + if(ARGC GREATER 1) set(_msg_message_with_level "${ARGV}") list(REMOVE_AT _msg_message_with_level 0) cpp_set_global(CT_LAST_MESSAGE "${_msg_message_with_level}") + + # Our override turns the FATAL_ERROR level into a CMakePPLang GENERIC_ERROR if(ARGV0 STREQUAL "FATAL_ERROR") + # Check if any exception handlers are active cpp_get_global(_m_exception_handlers "_CPP_EXCEPTION_HANDLERS_") cpp_map(GET "${_m_exception_handlers}" _m_handlers_list "GENERIC_ERROR") cpp_map(GET "${_m_exception_handlers}" _m_all_handlers_list "ALL_EXCEPTIONS")