summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-07-22 15:34:14 -0400
committerBrad King <brad.king@kitware.com>2022-07-25 14:27:24 -0400
commitee047a68f27d9636d681d05252257da636b616a2 (patch)
tree6577a86cca6b947d63254e2d803ae550296b3c20
parent7ed8c2de6a755bc05d43ee1d5caf566b14c9209a (diff)
downloadcmake-ee047a68f27d9636d681d05252257da636b616a2.tar.gz
cmSystemTools: Factor out method to get Windows OS version
Factor the implementation out of `cmGlobalGenerator`.
-rw-r--r--Source/cmGlobalGenerator.cxx37
-rw-r--r--Source/cmSystemTools.cxx38
-rw-r--r--Source/cmSystemTools.h8
3 files changed, 52 insertions, 31 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 5113a46b74..ebb12f884c 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -49,6 +49,7 @@
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStateTypes.h"
+#include "cmSystemTools.h"
#include "cmValue.h"
#include "cmVersion.h"
#include "cmWorkingDirectory.h"
@@ -62,10 +63,6 @@
# include "cmQtAutoGenGlobalInitializer.h"
#endif
-#if defined(_MSC_VER) && _MSC_VER >= 1800
-# define KWSYS_WINDOWS_DEPRECATED_GetVersionEx
-#endif
-
const std::string kCMAKE_PLATFORM_INFO_INITIALIZED =
"CMAKE_PLATFORM_INFO_INITIALIZED";
@@ -616,34 +613,12 @@ void cmGlobalGenerator::EnableLanguage(
// what platform we are running on
if (!mf->GetDefinition("CMAKE_SYSTEM")) {
#if defined(_WIN32) && !defined(__CYGWIN__)
- /* Windows version number data. */
- OSVERSIONINFOEXW osviex;
- ZeroMemory(&osviex, sizeof(osviex));
- osviex.dwOSVersionInfoSize = sizeof(osviex);
-
-# ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
-# pragma warning(push)
-# ifdef __INTEL_COMPILER
-# pragma warning(disable : 1478)
-# elif defined __clang__
-# pragma clang diagnostic push
-# pragma clang diagnostic ignored "-Wdeprecated-declarations"
-# else
-# pragma warning(disable : 4996)
-# endif
-# endif
- GetVersionExW((OSVERSIONINFOW*)&osviex);
-# ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
-# ifdef __clang__
-# pragma clang diagnostic pop
-# else
-# pragma warning(pop)
-# endif
-# endif
+ cmSystemTools::WindowsVersion windowsVersion =
+ cmSystemTools::GetWindowsVersion();
std::ostringstream windowsVersionString;
- windowsVersionString << osviex.dwMajorVersion << "."
- << osviex.dwMinorVersion << "."
- << osviex.dwBuildNumber;
+ windowsVersionString << windowsVersion.dwMajorVersion << "."
+ << windowsVersion.dwMinorVersion << "."
+ << windowsVersion.dwBuildNumber;
mf->AddDefinition("CMAKE_HOST_SYSTEM_VERSION", windowsVersionString.str());
#endif
// Read the DetermineSystem file
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 351386a119..78d3ad98cc 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -107,6 +107,10 @@
# include <sys/utsname.h>
#endif
+#if defined(_MSC_VER) && _MSC_VER >= 1800
+# define CM_WINDOWS_DEPRECATED_GetVersionEx
+#endif
+
namespace {
cmSystemTools::InterruptCallback s_InterruptCallback;
@@ -904,6 +908,40 @@ cmSystemTools::WindowsFileRetry cmSystemTools::GetWindowsDirectoryRetry()
InitWindowsDirectoryRetry().Retry;
return retry;
}
+
+cmSystemTools::WindowsVersion cmSystemTools::GetWindowsVersion()
+{
+ /* Windows version number data. */
+ OSVERSIONINFOEXW osviex;
+ ZeroMemory(&osviex, sizeof(osviex));
+ osviex.dwOSVersionInfoSize = sizeof(osviex);
+
+# ifdef CM_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning(push)
+# ifdef __INTEL_COMPILER
+# pragma warning(disable : 1478)
+# elif defined __clang__
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdeprecated-declarations"
+# else
+# pragma warning(disable : 4996)
+# endif
+# endif
+ GetVersionExW((OSVERSIONINFOW*)&osviex);
+# ifdef CM_WINDOWS_DEPRECATED_GetVersionEx
+# ifdef __clang__
+# pragma clang diagnostic pop
+# else
+# pragma warning(pop)
+# endif
+# endif
+
+ WindowsVersion result;
+ result.dwMajorVersion = osviex.dwMajorVersion;
+ result.dwMinorVersion = osviex.dwMinorVersion;
+ result.dwBuildNumber = osviex.dwBuildNumber;
+ return result;
+}
#endif
std::string cmSystemTools::GetRealPathResolvingWindowsSubst(
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index 5f7a5ecbb0..ec650f7431 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -509,6 +509,14 @@ public:
};
static WindowsFileRetry GetWindowsFileRetry();
static WindowsFileRetry GetWindowsDirectoryRetry();
+
+ struct WindowsVersion
+ {
+ unsigned int dwMajorVersion;
+ unsigned int dwMinorVersion;
+ unsigned int dwBuildNumber;
+ };
+ static WindowsVersion GetWindowsVersion();
#endif
/** Get the real path for a given path, removing all symlinks.