diff options
author | Brad King <brad.king@kitware.com> | 2023-09-12 11:57:55 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2023-09-12 11:58:09 (GMT) |
commit | 5477afd920f323ff0f0aab55e89cb258f2c1d5c2 (patch) | |
tree | 57267ac941e1f432675cef607832b8be231eab47 /Source | |
parent | c6e07514a1bb8534dc3d2ab0018e7f9aaa56866b (diff) | |
parent | 6ebf0e1a46ddc3a93421b33af7ffc99f2c89c282 (diff) | |
download | CMake-5477afd920f323ff0f0aab55e89cb258f2c1d5c2.zip CMake-5477afd920f323ff0f0aab55e89cb258f2c1d5c2.tar.gz CMake-5477afd920f323ff0f0aab55e89cb258f2c1d5c2.tar.bz2 |
Merge topic 'ninja-cmd'
6ebf0e1a46 Ninja: Use absolute path to COMSPEC if possible
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !8747
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 9 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.h | 9 | ||||
-rw-r--r-- | Source/cmLocalNinjaGenerator.cxx | 3 |
3 files changed, 20 insertions, 1 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 54c3737..30305a1 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -554,6 +554,15 @@ cmGlobalNinjaGenerator::cmGlobalNinjaGenerator(cmake* cm) { #ifdef _WIN32 cm->GetState()->SetWindowsShell(true); + + // Attempt to use full path to COMSPEC, default "cmd.exe" + std::string comspec; + if (cmSystemTools::GetEnv("COMSPEC", comspec) && + cmSystemTools::FileIsFullPath(comspec)) { + this->Comspec = comspec; + } else { + this->Comspec = "cmd.exe"; + } #endif this->FindMakeProgramFile = "CMakeNinjaFindMake.cmake"; } diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 4b026eb..c43e27c 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -282,6 +282,10 @@ public: }; MapToNinjaPathImpl MapToNinjaPath() { return { this }; } +#ifdef _WIN32 + std::string const& GetComspec() const { return this->Comspec; } +#endif + // -- Additional clean files void AddAdditionalCleanFile(std::string fileName, const std::string& config); const char* GetAdditionalCleanTargetName() const @@ -592,6 +596,11 @@ private: codecvt_Encoding NinjaExpectedEncoding = codecvt_Encoding::None; +#ifdef _WIN32 + // Windows Command shell. + std::string Comspec; +#endif + bool DiagnosedCxxModuleNinjaSupport = false; void InitOutputPathPrefix(); diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 2316fb3..bc3da6e 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -538,13 +538,14 @@ std::string cmLocalNinjaGenerator::BuildCommandLine( std::ostringstream cmd; #ifdef _WIN32 + cmGlobalNinjaGenerator const* gg = this->GetGlobalNinjaGenerator(); 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 (needCMD) { - cmd << "cmd.exe /C \""; + cmd << gg->GetComspec() << " /C \""; } // Put current cmdLine in brackets if it contains "||" because it has // higher precedence than "&&" in cmd.exe |