summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Edelev <alexey.edelev@qt.io>2024-08-19 19:10:18 (GMT)
committerAlexey Edelev <alexey.edelev@qt.io>2024-08-21 09:05:16 (GMT)
commit9ab270f47d68198dee29780a346294a728087105 (patch)
tree788a890f4c1bc06ea38d032f57e26bbfbe8bd7b8
parentb2b3c5825fae1c650086932149b81959573e867c (diff)
downloadCMake-9ab270f47d68198dee29780a346294a728087105.zip
CMake-9ab270f47d68198dee29780a346294a728087105.tar.gz
CMake-9ab270f47d68198dee29780a346294a728087105.tar.bz2
cmSystemTools: Add GetComspec method to get cmd on Windows
The function attempts to read the path to cmd executable from the COMSPEC environment variable. Falls back to cmd.exe if the respective environment variable is not set or path doesn't exist.
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx8
-rw-r--r--Source/cmSystemTools.cxx11
-rw-r--r--Source/cmSystemTools.h3
3 files changed, 15 insertions, 7 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 7d62fa8..b051d67 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -573,13 +573,7 @@ cmGlobalNinjaGenerator::cmGlobalNinjaGenerator(cmake* cm)
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";
- }
+ this->Comspec = cmSystemTools::GetComspec();
#endif
cm->GetState()->SetNinja(true);
this->FindMakeProgramFile = "CMakeNinjaFindMake.cmake";
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 8e59a35..05cc85a 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -970,6 +970,17 @@ cmSystemTools::WindowsVersion cmSystemTools::GetWindowsVersion()
result.dwBuildNumber = osviex.dwBuildNumber;
return result;
}
+
+std::string cmSystemTools::GetComspec()
+{
+ std::string comspec;
+ if (!cmSystemTools::GetEnv("COMSPEC", comspec) ||
+ !cmSystemTools::FileIsFullPath(comspec)) {
+ comspec = "cmd.exe";
+ }
+ return comspec;
+}
+
#endif
std::string cmSystemTools::GetRealPathResolvingWindowsSubst(
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index a07c749..d0b6046 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -585,6 +585,9 @@ public:
unsigned int dwBuildNumber;
};
static WindowsVersion GetWindowsVersion();
+
+ /** Attempt to get full path to COMSPEC, default "cmd.exe" */
+ static std::string GetComspec();
#endif
/** Get the real path for a given path, removing all symlinks.