diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2020-11-30 17:34:19 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-12-01 14:04:08 (GMT) |
commit | 1b6c5333a0b4a56eaf8b010084e18a40e473c2e3 (patch) | |
tree | 432b467bda279cb7508cddbc9831adf6ed6a6966 /Source/cmake.cxx | |
parent | 7137dff083a1868bcc9d22fe6fe7d052abb06513 (diff) | |
download | CMake-1b6c5333a0b4a56eaf8b010084e18a40e473c2e3.zip CMake-1b6c5333a0b4a56eaf8b010084e18a40e473c2e3.tar.gz CMake-1b6c5333a0b4a56eaf8b010084e18a40e473c2e3.tar.bz2 |
cmake: Error out on unknown arguments starting with `-`.
Fixes: #21521
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r-- | Source/cmake.cxx | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 5524d4e..cfd724b 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -846,6 +846,8 @@ void cmake::SetArgs(const std::vector<std::string>& args) bool haveToolset = false; bool havePlatform = false; bool haveBArg = false; + bool scriptMode = false; + std::string possibleUnknownArg; #if !defined(CMAKE_BOOTSTRAP) std::string profilingFormat; std::string profilingOutput; @@ -898,7 +900,11 @@ void cmake::SetArgs(const std::vector<std::string>& args) CommandArgument{ "-B", "No build directory specified for -B", CommandArgument::Values::One, BuildArgLambda }, CommandArgument{ "-P", "-P must be followed by a file name.", - CommandArgument::Values::One, IgnoreAndTrueLambda }, + CommandArgument::Values::One, + [&](std::string const&, cmake*) -> bool { + scriptMode = true; + return true; + } }, CommandArgument{ "-D", "-D must be followed with VAR=VALUE.", CommandArgument::Values::One, IgnoreAndTrueLambda }, CommandArgument{ "-C", "-C must be followed by a file name.", @@ -1145,14 +1151,28 @@ void cmake::SetArgs(const std::vector<std::string>& args) break; } } + + // We have an issue where arguments to a "-P" script mode + // can be provided before the "-P" argument. This means + // that we need to lazily check this argument after checking + // all args. + // Additionally it can't be the source/binary tree location if (!parsedCorrectly) { cmSystemTools::Error("Run 'cmake --help' for all supported options."); exit(1); + } else if (!matched && cmHasLiteralPrefix(arg, "-")) { + possibleUnknownArg = arg; } else if (!matched) { this->SetDirectoriesFromFile(arg); } } + if (!possibleUnknownArg.empty() && !scriptMode) { + cmSystemTools::Error(cmStrCat("Unknown argument ", possibleUnknownArg)); + cmSystemTools::Error("Run 'cmake --help' for all supported options."); + exit(1); + } + // Empty instance, platform and toolset if only a generator is specified if (this->GlobalGenerator) { this->GeneratorInstance = ""; |