summaryrefslogtreecommitdiff
path: root/Source/cmake.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-02-17 13:45:45 +0000
committerKitware Robot <kwrobot@kitware.com>2022-02-17 08:45:52 -0500
commit9c81f2cb8bcb5f4ad96f2ad527035649bd70d5fc (patch)
treedb1cd55736b9bcdd96ba70016cee8028cc0e9085 /Source/cmake.cxx
parented9e7a27324ec54cc1a0ae9397ae5b49f0c9bab3 (diff)
parentf73457ca2ecb7abe66050910d74a37f80d10de2e (diff)
downloadcmake-9c81f2cb8bcb5f4ad96f2ad527035649bd70d5fc.tar.gz
Merge topic 'cmake-empty-cmd-line-arg' into release-3.23
f73457ca2e cmake: Ignore any empty "" command line arguments 67f97f5478 Tests: Add RunCMake helper to run cmake with raw execute_process args Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6980
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r--Source/cmake.cxx24
1 files changed, 22 insertions, 2 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index e1ba12c210..d80c4bc6e7 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));