summaryrefslogtreecommitdiffstats
path: root/Source/cmLocalNinjaGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-03-21 12:58:16 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-03-21 12:58:43 (GMT)
commitca8c171021369f535fa18013796cc0b8f9cbd4fc (patch)
treefe86b75fd9f168720d40c29d0763af751ddba1ab /Source/cmLocalNinjaGenerator.cxx
parent5f8929f721966f7560d18811126d74553af3df5f (diff)
parent1b7c26da49e7e1a337f66951424bda8d3f4067fc (diff)
downloadCMake-ca8c171021369f535fa18013796cc0b8f9cbd4fc.zip
CMake-ca8c171021369f535fa18013796cc0b8f9cbd4fc.tar.gz
CMake-ca8c171021369f535fa18013796cc0b8f9cbd4fc.tar.bz2
Merge topic 'clang-windows-cxx-modules'
1b7c26da49 Ninja: Wrap rules using '>' shell redirection with 'cmd /C' on Windows ffd8537acf Clang: Record Clang 16.0 C++ modules flags only for GNU-like front-end 6013227230 cmGlobalNinjaGenerator: Use forward slashes in clang modmap format on Windows d9d74b5e8a cmDyndepCollation: Drop outdated mentions of CXX_MODULE_INTERNAL_PARTITIONS edab56d29a cmLocalNinjaGenerator: De-duplicate condition for using 'cmd /C' on Windows 8ebe3f92b3 cmGlobalNinjaGenerator: Detect GNU-like command-line for dyndep collator f3ca199c9b cmGlobalNinjaGenerator: Factor out GNU-like command-line detection on Windows f79817fcf0 cmCxxModuleMapper: Use value semantics in path conversion callback ... Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !8346
Diffstat (limited to 'Source/cmLocalNinjaGenerator.cxx')
-rw-r--r--Source/cmLocalNinjaGenerator.cxx27
1 files changed, 22 insertions, 5 deletions
diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx
index f8027c0..305dab3 100644
--- a/Source/cmLocalNinjaGenerator.cxx
+++ b/Source/cmLocalNinjaGenerator.cxx
@@ -456,6 +456,22 @@ std::string cmLocalNinjaGenerator::WriteCommandScript(
return scriptPath;
}
+#ifdef _WIN32
+namespace {
+bool RuleNeedsCMD(std::string const& cmd)
+{
+ std::vector<std::string> args;
+ cmSystemTools::ParseWindowsCommandLine(cmd.c_str(), args);
+ auto it = std::find_if(args.cbegin(), args.cend(),
+ [](std::string const& arg) -> bool {
+ // FIXME: Detect more windows shell operators.
+ return cmHasLiteralPrefix(arg, ">");
+ });
+ return it != args.cend();
+}
+}
+#endif
+
std::string cmLocalNinjaGenerator::BuildCommandLine(
std::vector<std::string> const& cmdLines, std::string const& outputConfig,
std::string const& commandConfig, std::string const& customStep,
@@ -498,12 +514,13 @@ std::string cmLocalNinjaGenerator::BuildCommandLine(
}
std::ostringstream cmd;
- for (auto li = cmdLines.begin(); li != cmdLines.end(); ++li)
#ifdef _WIN32
- {
+ bool const needCMD =
+ cmdLines.size() > 1 || (customStep.empty() && RuleNeedsCMD(cmdLines[0]));
+ for (auto li = cmdLines.begin(); li != cmdLines.end(); ++li) {
if (li != cmdLines.begin()) {
cmd << " && ";
- } else if (cmdLines.size() > 1) {
+ } else if (needCMD) {
cmd << "cmd.exe /C \"";
}
// Put current cmdLine in brackets if it contains "||" because it has
@@ -514,11 +531,11 @@ std::string cmLocalNinjaGenerator::BuildCommandLine(
cmd << *li;
}
}
- if (cmdLines.size() > 1) {
+ if (needCMD) {
cmd << "\"";
}
#else
- {
+ for (auto li = cmdLines.begin(); li != cmdLines.end(); ++li) {
if (li != cmdLines.begin()) {
cmd << " && ";
}