From 1bb17692359d675eee12996c43446fa9c9fe5175 Mon Sep 17 00:00:00 2001 From: leha-bot Date: Fri, 5 Jan 2024 19:12:22 +0300 Subject: cmake_language: Add EXIT subcommand Add tests to cover these cases: * run as regular CMake module, in NORMAL_MODE (expected to fail); * run as CMake script in SCRIPT_MODE (expected to exit with given code); * run as CMake script that `include()`-s another script with EXIT subcommand; * run as CMake script which EVAL-uates EXIT subcommand via `cmake_language(EVAL CODE "")`. Fixes: #23162 --- Help/command/cmake_language.rst | 23 +++++++++++++++++++ Help/release/dev/cmake-language-exit.rst | 5 +++++ Source/cmCMakeLanguageCommand.cxx | 26 ++++++++++++++++++++++ Tests/RunCMake/cmake_language/RunCMakeTest.cmake | 7 ++++++ Tests/RunCMake/cmake_language/exit_0-result.txt | 1 + Tests/RunCMake/cmake_language/exit_0-stderr.txt | 2 ++ Tests/RunCMake/cmake_language/exit_0.cmake | 1 + .../cmake_language/exit_0_script-result.txt | 1 + .../cmake_language/exit_0_script-stderr.txt | 0 Tests/RunCMake/cmake_language/exit_0_script.cmake | 1 + .../exit_0_script_with_command-result.txt | 1 + .../exit_0_script_with_command-stderr.txt | 0 .../exit_0_script_with_command.cmake | 3 +++ Tests/RunCMake/cmake_language/exit_5-result.txt | 1 + Tests/RunCMake/cmake_language/exit_5-stderr.txt | 2 ++ Tests/RunCMake/cmake_language/exit_5.cmake | 1 + .../cmake_language/exit_5_script-result.txt | 1 + .../cmake_language/exit_5_script-stderr.txt | 0 Tests/RunCMake/cmake_language/exit_5_script.cmake | 1 + .../exit_5_script_with_command-result.txt | 1 + .../exit_5_script_with_command-stderr.txt | 0 .../exit_5_script_with_command.cmake | 3 +++ .../exit_7_script_in_include-result.txt | 1 + .../exit_7_script_in_include-stderr.txt | 0 .../cmake_language/exit_7_script_in_include.cmake | 3 +++ .../exit_7_script_included_with_exit.cmake | 3 +++ ...8_script_in_recursive_cmake_language-result.txt | 1 + ...8_script_in_recursive_cmake_language-stderr.txt | 1 + ...exit_8_script_in_recursive_cmake_language.cmake | 3 +++ 29 files changed, 93 insertions(+) create mode 100644 Help/release/dev/cmake-language-exit.rst create mode 100644 Tests/RunCMake/cmake_language/exit_0-result.txt create mode 100644 Tests/RunCMake/cmake_language/exit_0-stderr.txt create mode 100644 Tests/RunCMake/cmake_language/exit_0.cmake create mode 100644 Tests/RunCMake/cmake_language/exit_0_script-result.txt create mode 100644 Tests/RunCMake/cmake_language/exit_0_script-stderr.txt create mode 100644 Tests/RunCMake/cmake_language/exit_0_script.cmake create mode 100644 Tests/RunCMake/cmake_language/exit_0_script_with_command-result.txt create mode 100644 Tests/RunCMake/cmake_language/exit_0_script_with_command-stderr.txt create mode 100644 Tests/RunCMake/cmake_language/exit_0_script_with_command.cmake create mode 100644 Tests/RunCMake/cmake_language/exit_5-result.txt create mode 100644 Tests/RunCMake/cmake_language/exit_5-stderr.txt create mode 100644 Tests/RunCMake/cmake_language/exit_5.cmake create mode 100644 Tests/RunCMake/cmake_language/exit_5_script-result.txt create mode 100644 Tests/RunCMake/cmake_language/exit_5_script-stderr.txt create mode 100644 Tests/RunCMake/cmake_language/exit_5_script.cmake create mode 100644 Tests/RunCMake/cmake_language/exit_5_script_with_command-result.txt create mode 100644 Tests/RunCMake/cmake_language/exit_5_script_with_command-stderr.txt create mode 100644 Tests/RunCMake/cmake_language/exit_5_script_with_command.cmake create mode 100644 Tests/RunCMake/cmake_language/exit_7_script_in_include-result.txt create mode 100644 Tests/RunCMake/cmake_language/exit_7_script_in_include-stderr.txt create mode 100644 Tests/RunCMake/cmake_language/exit_7_script_in_include.cmake create mode 100644 Tests/RunCMake/cmake_language/exit_7_script_included_with_exit.cmake create mode 100644 Tests/RunCMake/cmake_language/exit_8_script_in_recursive_cmake_language-result.txt create mode 100644 Tests/RunCMake/cmake_language/exit_8_script_in_recursive_cmake_language-stderr.txt create mode 100644 Tests/RunCMake/cmake_language/exit_8_script_in_recursive_cmake_language.cmake diff --git a/Help/command/cmake_language.rst b/Help/command/cmake_language.rst index 4b64eb6..45ac569 100644 --- a/Help/command/cmake_language.rst +++ b/Help/command/cmake_language.rst @@ -15,6 +15,7 @@ Synopsis cmake_language(`DEFER`_ ... CALL [...]) cmake_language(`SET_DEPENDENCY_PROVIDER`_ SUPPORTED_METHODS ...) cmake_language(`GET_MESSAGE_LOG_LEVEL`_ ) + cmake_language(`EXIT`_ ) Introduction ^^^^^^^^^^^^ @@ -506,3 +507,25 @@ Getting current message log level If both the command line option and the variable are set, the command line option takes precedence. If neither are set, the default logging level is returned. + +Terminating Scripts +^^^^^^^^^^^^^^^^^^^ + +.. versionadded:: 3.29 + +.. _EXIT: +.. _exit-code: + +.. code-block:: cmake + +.. signature:: + cmake_language(EXIT ) + + Terminate the current :option:`cmake -P` script and exit with ````. + + This command works only in :ref:`script mode