diff options
author | leha-bot <leha-bot@yandex.ru> | 2024-01-05 16:12:22 (GMT) |
---|---|---|
committer | leha-bot <leha-bot@yandex.ru> | 2024-01-16 07:41:31 (GMT) |
commit | 1bb17692359d675eee12996c43446fa9c9fe5175 (patch) | |
tree | 4b303b56a54fd9c22bfbfc57d49feaa5f4feac34 /Source | |
parent | 4f160f7906ef8075dad54b9bf2e0ba204a1c41fc (diff) | |
download | CMake-1bb17692359d675eee12996c43446fa9c9fe5175.zip CMake-1bb17692359d675eee12996c43446fa9c9fe5175.tar.gz CMake-1bb17692359d675eee12996c43446fa9c9fe5175.tar.bz2 |
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 "<cmake code>")`.
Fixes: #23162
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCMakeLanguageCommand.cxx | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Source/cmCMakeLanguageCommand.cxx b/Source/cmCMakeLanguageCommand.cxx index 329427c..9ffc363 100644 --- a/Source/cmCMakeLanguageCommand.cxx +++ b/Source/cmCMakeLanguageCommand.cxx @@ -398,6 +398,32 @@ bool cmCMakeLanguageCommand(std::vector<cmListFileArgument> const& args, if (!moreArgs()) { return FatalError(status, "called with incorrect number of arguments"); } + if (expArgs[expArg] == "EXIT"_s) { + ++expArg; // consume "EXIT". + + if (!moreArgs()) { + return FatalError(status, "EXIT requires one argument"); + } + + auto workingMode = + status.GetMakefile().GetCMakeInstance()->GetWorkingMode(); + if (workingMode != cmake::SCRIPT_MODE) { + return FatalError(status, "EXIT can be used only in SCRIPT mode"); + } + + long retCode = 0; + + if (!cmStrToLong(expArgs[expArg], &retCode)) { + return FatalError(status, + cmStrCat("EXIT requires one integral argument, got \"", + expArgs[expArg], '\"')); + } + + if (workingMode == cmake::SCRIPT_MODE) { + status.SetExitCode(static_cast<int>(retCode)); + } + return true; + } if (expArgs[expArg] == "SET_DEPENDENCY_PROVIDER"_s) { finishArgs(); |