diff options
author | Robert Maynard <rmaynard@nvidia.com> | 2022-02-14 15:23:46 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-02-16 17:11:33 (GMT) |
commit | f73457ca2ecb7abe66050910d74a37f80d10de2e (patch) | |
tree | e629aff9fdbe7956852b94746d22c690ed21597c /Source/cmake.cxx | |
parent | 67f97f54789413f47a0f03a36c3bb32518a2e922 (diff) | |
download | CMake-f73457ca2ecb7abe66050910d74a37f80d10de2e.zip CMake-f73457ca2ecb7abe66050910d74a37f80d10de2e.tar.gz CMake-f73457ca2ecb7abe66050910d74a37f80d10de2e.tar.bz2 |
cmake: Ignore any empty "" command line arguments
Don't treat empty quote arguments("") as the current working
directory but instead ignore them.
Fixes #23217
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r-- | Source/cmake.cxx | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx index ef4e37b..8d27eb0 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -544,6 +544,10 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args) "-C", "-C must be followed by a file name.", CommandArgument::Values::One, CommandArgument::RequiresSeparator::No, [&](std::string const& value, cmake* state) -> bool { + if (value.empty()) { + cmSystemTools::Error("No file name specified for -C"); + return false; + } cmSystemTools::Stdout("loading initial cache file " + value + "\n"); // Resolve script path specified on command line // relative to $PWD. @@ -800,7 +804,18 @@ void cmake::SetArgs(const std::vector<std::string>& args) ListPresets listPresets = ListPresets::None; #endif + auto EmptyStringArgLambda = [](std::string const&, cmake* state) -> bool { + state->IssueMessage( + MessageType::WARNING, + "Ignoring empty string (\"\") provided on the command line."); + return true; + }; + auto SourceArgLambda = [](std::string const& value, cmake* state) -> bool { + if (value.empty()) { + cmSystemTools::Error("No source directory specified for -S"); + return false; + } std::string path = cmSystemTools::CollapseFullPath(value); cmSystemTools::ConvertToUnixSlashes(path); state->SetHomeDirectory(path); @@ -808,6 +823,10 @@ void cmake::SetArgs(const std::vector<std::string>& args) }; auto BuildArgLambda = [&](std::string const& value, cmake* state) -> bool { + if (value.empty()) { + cmSystemTools::Error("No build directory specified for -B"); + return false; + } std::string path = cmSystemTools::CollapseFullPath(value); cmSystemTools::ConvertToUnixSlashes(path); state->SetHomeOutputDirectory(path); @@ -836,6 +855,7 @@ void cmake::SetArgs(const std::vector<std::string>& args) }; std::vector<CommandArgument> arguments = { + CommandArgument{ "", CommandArgument::Values::Zero, EmptyStringArgLambda }, CommandArgument{ "-S", "No source directory specified for -S", CommandArgument::Values::One, CommandArgument::RequiresSeparator::No, SourceArgLambda }, @@ -1179,8 +1199,8 @@ void cmake::SetArgs(const std::vector<std::string>& args) if (!extraProvidedPath.empty() && !scriptMode) { this->IssueMessage(MessageType::WARNING, - cmStrCat("Ignoring extra path from command line:\n ", - extraProvidedPath)); + cmStrCat("Ignoring extra path from command line:\n \"", + extraProvidedPath, "\"")); } if (!possibleUnknownArg.empty() && !scriptMode) { cmSystemTools::Error(cmStrCat("Unknown argument ", possibleUnknownArg)); |