From 3fd65f5ca601d38c7b2ee8c99b148df31cea1acd Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 17 Jun 2021 07:30:48 -0400 Subject: VS: Compare VS instance versions as strings This makes the values more readable. --- Source/cmGlobalVisualStudio10Generator.cxx | 13 +++++++------ Source/cmGlobalVisualStudio10Generator.h | 5 +---- Source/cmGlobalVisualStudioVersionedGenerator.cxx | 14 +++++++------- Source/cmGlobalVisualStudioVersionedGenerator.h | 2 +- Source/cmVSSetupHelper.cxx | 8 +++----- Source/cmVSSetupHelper.h | 4 ++-- 6 files changed, 21 insertions(+), 25 deletions(-) diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index fa51092..6ce82f4 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -1361,10 +1361,10 @@ static unsigned int cmLoadFlagTableSpecial(Json::Value entry, namespace { -unsigned long long const vsVer16_10_0 = 4503644629696790; +std::string const vsVer16_10_0 = "16.10.31321.278"; -cmIDEFlagTable const* cmLoadFlagTableJson( - std::string const& flagJsonPath, cm::optional vsver) +cmIDEFlagTable const* cmLoadFlagTableJson(std::string const& flagJsonPath, + cm::optional vsVer) { cmIDEFlagTable* ret = nullptr; auto savedFlagIterator = loadedFlagJsonFiles.find(flagJsonPath); @@ -1387,7 +1387,8 @@ cmIDEFlagTable const* cmLoadFlagTableJson( flagEntry.value = cmLoadFlagTableString(flag, "value"); flagEntry.special = cmLoadFlagTableSpecial(flag, "flags"); // FIXME: Port this version check to a Json field. - if (vsver && *vsver < vsVer16_10_0 && + if (vsVer && + !cmSystemTools::VersionCompareGreaterEq(*vsVer, vsVer16_10_0) && flagEntry.IDEName == "ExternalWarningLevel") { continue; } @@ -1466,8 +1467,8 @@ cmIDEFlagTable const* cmGlobalVisualStudio10Generator::LoadFlagTable( } } - cm::optional vsver = this->GetVSInstanceVersion(); - if (cmIDEFlagTable const* ret = cmLoadFlagTableJson(filename, vsver)) { + cm::optional vsVer = this->GetVSInstanceVersion(); + if (cmIDEFlagTable const* ret = cmLoadFlagTableJson(filename, vsVer)) { return ret; } diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index 48fe465..646dbe2 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -128,10 +128,7 @@ public: std::string Encoding() override; const char* GetToolsVersion() const; - virtual cm::optional GetVSInstanceVersion() const - { - return {}; - } + virtual cm::optional GetVSInstanceVersion() const { return {}; } bool GetSupportsUnityBuilds() const { return this->SupportsUnityBuilds; } diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx index 50dc30b..384aa66 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx +++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx @@ -391,11 +391,11 @@ bool cmGlobalVisualStudioVersionedGenerator::GetVSInstance( return vsSetupAPIHelper.GetVSInstanceInfo(dir); } -cm::optional +cm::optional cmGlobalVisualStudioVersionedGenerator::GetVSInstanceVersion() const { - cm::optional result; - unsigned long long vsInstanceVersion; + cm::optional result; + std::string vsInstanceVersion; if (vsSetupAPIHelper.GetVSInstanceVersion(vsInstanceVersion)) { result = vsInstanceVersion; } @@ -411,10 +411,10 @@ bool cmGlobalVisualStudioVersionedGenerator::IsStdOutEncodingSupported() const if (this->Version < cmGlobalVisualStudioGenerator::VSVersion::VS16) { return false; } - unsigned long long const vsInstanceVersion16_7_P2 = 4503631666610212; - cm::optional vsInstanceVersion = - this->GetVSInstanceVersion(); - return (vsInstanceVersion && *vsInstanceVersion > vsInstanceVersion16_7_P2); + static std::string const vsVer16_7_P2 = "16.7.30128.36"; + cm::optional vsVer = this->GetVSInstanceVersion(); + return (vsVer && + cmSystemTools::VersionCompareGreaterEq(*vsVer, vsVer16_7_P2)); } const char* diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.h b/Source/cmGlobalVisualStudioVersionedGenerator.h index 105e495..db4a0ba 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.h +++ b/Source/cmGlobalVisualStudioVersionedGenerator.h @@ -28,7 +28,7 @@ public: bool GetVSInstance(std::string& dir) const; - cm::optional GetVSInstanceVersion() const override; + cm::optional GetVSInstanceVersion() const override; AuxToolset FindAuxToolset(std::string& version, std::string& props) const override; diff --git a/Source/cmVSSetupHelper.cxx b/Source/cmVSSetupHelper.cxx index 9626599..969a2c2 100644 --- a/Source/cmVSSetupHelper.cxx +++ b/Source/cmVSSetupHelper.cxx @@ -258,15 +258,13 @@ bool cmVSSetupAPIHelper::GetVSInstanceInfo(std::string& vsInstallLocation) return isInstalled; } -bool cmVSSetupAPIHelper::GetVSInstanceVersion( - unsigned long long& vsInstanceVersion) +bool cmVSSetupAPIHelper::GetVSInstanceVersion(std::string& vsInstanceVersion) { - vsInstanceVersion = 0; + vsInstanceVersion.clear(); bool isInstalled = this->EnumerateAndChooseVSInstance(); if (isInstalled) { - vsInstanceVersion = - static_cast(chosenInstanceInfo.ullVersion); + vsInstanceVersion = cmsys::Encoding::ToNarrow(chosenInstanceInfo.Version); } return isInstalled; diff --git a/Source/cmVSSetupHelper.h b/Source/cmVSSetupHelper.h index 04ea46d..61a3ac7 100644 --- a/Source/cmVSSetupHelper.h +++ b/Source/cmVSSetupHelper.h @@ -88,7 +88,7 @@ struct VSInstanceInfo std::wstring VSInstallLocation; std::wstring Version; std::string VCToolsetVersion; - ULONGLONG ullVersion = 0; + ULONGLONG ullVersion = 0; // A.B.C.D = (A<<48)|(B<<32)|(C<<16)|D bool IsWin10SDKInstalled = false; bool IsWin81SDKInstalled = false; @@ -105,7 +105,7 @@ public: bool IsVSInstalled(); bool GetVSInstanceInfo(std::string& vsInstallLocation); - bool GetVSInstanceVersion(unsigned long long& vsInstanceVersion); + bool GetVSInstanceVersion(std::string& vsInstanceVersion); bool GetVCToolsetVersion(std::string& vsToolsetVersion); bool IsWin10SDKInstalled(); bool IsWin81SDKInstalled(); -- cgit v0.12