From 68d316e0cf278021d9fa4553471d29803d09a394 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 9 Jan 2019 10:26:49 -0500 Subject: VS: Rename VS 2017 generator sources to be version-independent Rename `cmGlobalVisualStudio{15 => Versioned}Generator`. Rename `Factory` to `Factory15` since that part still needs to be version-specific. --- Source/CMakeLists.txt | 4 +- Source/cmCMakeHostSystemInformationCommand.cxx | 6 +- Source/cmGlobalVisualStudio15Generator.cxx | 286 --------------------- Source/cmGlobalVisualStudio15Generator.h | 60 ----- Source/cmGlobalVisualStudioVersionedGenerator.cxx | 291 ++++++++++++++++++++++ Source/cmGlobalVisualStudioVersionedGenerator.h | 62 +++++ Source/cmake.cxx | 5 +- 7 files changed, 361 insertions(+), 353 deletions(-) delete mode 100644 Source/cmGlobalVisualStudio15Generator.cxx delete mode 100644 Source/cmGlobalVisualStudio15Generator.h create mode 100644 Source/cmGlobalVisualStudioVersionedGenerator.cxx create mode 100644 Source/cmGlobalVisualStudioVersionedGenerator.h diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 91c45bc..c87ceba 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -696,10 +696,10 @@ if (WIN32) cmGlobalVisualStudio12Generator.cxx cmGlobalVisualStudio14Generator.h cmGlobalVisualStudio14Generator.cxx - cmGlobalVisualStudio15Generator.h - cmGlobalVisualStudio15Generator.cxx cmGlobalVisualStudioGenerator.cxx cmGlobalVisualStudioGenerator.h + cmGlobalVisualStudioVersionedGenerator.h + cmGlobalVisualStudioVersionedGenerator.cxx cmIDEFlagTable.h cmIDEOptions.cxx cmIDEOptions.h diff --git a/Source/cmCMakeHostSystemInformationCommand.cxx b/Source/cmCMakeHostSystemInformationCommand.cxx index a2423ac..ddc32c0 100644 --- a/Source/cmCMakeHostSystemInformationCommand.cxx +++ b/Source/cmCMakeHostSystemInformationCommand.cxx @@ -10,7 +10,7 @@ #if defined(_WIN32) # include "cmAlgorithms.h" # include "cmGlobalGenerator.h" -# include "cmGlobalVisualStudio15Generator.h" +# include "cmGlobalVisualStudioVersionedGenerator.h" # include "cmSystemTools.h" # include "cmVSSetupHelper.h" # define HAVE_VS_SETUP_HELPER @@ -133,8 +133,8 @@ bool cmCMakeHostSystemInformationCommand::GetValue( // If generating for the VS 15 IDE, use the same instance. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator(); if (cmHasLiteralPrefix(gg->GetName(), "Visual Studio 15 ")) { - cmGlobalVisualStudio15Generator* vs15gen = - static_cast(gg); + cmGlobalVisualStudioVersionedGenerator* vs15gen = + static_cast(gg); if (vs15gen->GetVSInstance(value)) { return true; } diff --git a/Source/cmGlobalVisualStudio15Generator.cxx b/Source/cmGlobalVisualStudio15Generator.cxx deleted file mode 100644 index f9fcbdf..0000000 --- a/Source/cmGlobalVisualStudio15Generator.cxx +++ /dev/null @@ -1,286 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#include "cmGlobalVisualStudio15Generator.h" - -#include "cmAlgorithms.h" -#include "cmDocumentationEntry.h" -#include "cmLocalVisualStudio10Generator.h" -#include "cmMakefile.h" -#include "cmVSSetupHelper.h" - -static const char vs15generatorName[] = "Visual Studio 15 2017"; - -// Map generator name without year to name with year. -static const char* cmVS15GenName(const std::string& name, std::string& genName) -{ - if (strncmp(name.c_str(), vs15generatorName, - sizeof(vs15generatorName) - 6) != 0) { - return 0; - } - const char* p = name.c_str() + sizeof(vs15generatorName) - 6; - if (cmHasLiteralPrefix(p, " 2017")) { - p += 5; - } - genName = std::string(vs15generatorName) + p; - return p; -} - -class cmGlobalVisualStudio15Generator::Factory - : public cmGlobalGeneratorFactory -{ -public: - cmGlobalGenerator* CreateGlobalGenerator(const std::string& name, - cmake* cm) const override - { - std::string genName; - const char* p = cmVS15GenName(name, genName); - if (!p) { - return 0; - } - if (!*p) { - return new cmGlobalVisualStudio15Generator(cm, genName, ""); - } - if (*p++ != ' ') { - return 0; - } - if (strcmp(p, "Win64") == 0) { - return new cmGlobalVisualStudio15Generator(cm, genName, "x64"); - } - if (strcmp(p, "ARM") == 0) { - return new cmGlobalVisualStudio15Generator(cm, genName, "ARM"); - } - return 0; - } - - void GetDocumentation(cmDocumentationEntry& entry) const override - { - entry.Name = std::string(vs15generatorName) + " [arch]"; - entry.Brief = "Generates Visual Studio 2017 project files. " - "Optional [arch] can be \"Win64\" or \"ARM\"."; - } - - void GetGenerators(std::vector& names) const override - { - names.push_back(vs15generatorName); - names.push_back(vs15generatorName + std::string(" ARM")); - names.push_back(vs15generatorName + std::string(" Win64")); - } - - bool SupportsToolset() const override { return true; } - bool SupportsPlatform() const override { return true; } -}; - -cmGlobalGeneratorFactory* cmGlobalVisualStudio15Generator::NewFactory() -{ - return new Factory; -} - -cmGlobalVisualStudio15Generator::cmGlobalVisualStudio15Generator( - cmake* cm, const std::string& name, - std::string const& platformInGeneratorName) - : cmGlobalVisualStudio14Generator(cm, name, platformInGeneratorName) - , vsSetupAPIHelper(15) -{ - this->ExpressEdition = false; - this->DefaultPlatformToolset = "v141"; - this->DefaultCLFlagTableName = "v141"; - this->DefaultCSharpFlagTableName = "v141"; - this->DefaultLinkFlagTableName = "v141"; - this->Version = VS15; -} - -bool cmGlobalVisualStudio15Generator::MatchesGeneratorName( - const std::string& name) const -{ - std::string genName; - if (cmVS15GenName(name, genName)) { - return genName == this->GetName(); - } - return false; -} - -bool cmGlobalVisualStudio15Generator::SetGeneratorInstance( - std::string const& i, cmMakefile* mf) -{ - if (!i.empty()) { - if (!this->vsSetupAPIHelper.SetVSInstance(i)) { - std::ostringstream e; - /* clang-format off */ - e << - "Generator\n" - " " << this->GetName() << "\n" - "could not find specified instance of Visual Studio:\n" - " " << i; - /* clang-format on */ - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); - return false; - } - } - - std::string vsInstance; - if (!this->vsSetupAPIHelper.GetVSInstanceInfo(vsInstance)) { - std::ostringstream e; - /* clang-format off */ - e << - "Generator\n" - " " << this->GetName() << "\n" - "could not find any instance of Visual Studio.\n"; - /* clang-format on */ - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); - return false; - } - - // Save the selected instance persistently. - std::string genInstance = mf->GetSafeDefinition("CMAKE_GENERATOR_INSTANCE"); - if (vsInstance != genInstance) { - this->CMakeInstance->AddCacheEntry( - "CMAKE_GENERATOR_INSTANCE", vsInstance.c_str(), - "Generator instance identifier.", cmStateEnums::INTERNAL); - } - - return true; -} - -bool cmGlobalVisualStudio15Generator::GetVSInstance(std::string& dir) const -{ - return vsSetupAPIHelper.GetVSInstanceInfo(dir); -} - -bool cmGlobalVisualStudio15Generator::IsDefaultToolset( - const std::string& version) const -{ - if (version.empty()) { - return true; - } - - std::string vcToolsetVersion; - if (this->vsSetupAPIHelper.GetVCToolsetVersion(vcToolsetVersion)) { - - cmsys::RegularExpression regex("[0-9][0-9]\\.[0-9]+"); - if (regex.find(version) && regex.find(vcToolsetVersion)) { - const auto majorMinorEnd = vcToolsetVersion.find('.', 3); - const auto majorMinor = vcToolsetVersion.substr(0, majorMinorEnd); - return version == majorMinor; - } - } - - return false; -} - -std::string cmGlobalVisualStudio15Generator::GetAuxiliaryToolset() const -{ - const char* version = this->GetPlatformToolsetVersion(); - if (version) { - std::string instancePath; - GetVSInstance(instancePath); - std::stringstream path; - path << instancePath; - path << "/VC/Auxiliary/Build/"; - path << version; - path << "/Microsoft.VCToolsVersion." << version << ".props"; - - std::string toolsetPath = path.str(); - cmSystemTools::ConvertToUnixSlashes(toolsetPath); - return toolsetPath; - } - return {}; -} - -bool cmGlobalVisualStudio15Generator::InitializeWindows(cmMakefile* mf) -{ - // If the Win 8.1 SDK is installed then we can select a SDK matching - // the target Windows version. - if (this->IsWin81SDKInstalled()) { - return cmGlobalVisualStudio14Generator::InitializeWindows(mf); - } - // Otherwise we must choose a Win 10 SDK even if we are not targeting - // Windows 10. - return this->SelectWindows10SDK(mf, false); -} - -bool cmGlobalVisualStudio15Generator::SelectWindowsStoreToolset( - std::string& toolset) const -{ - if (cmHasLiteralPrefix(this->SystemVersion, "10.0")) { - if (this->IsWindowsStoreToolsetInstalled() && - this->IsWindowsDesktopToolsetInstalled()) { - toolset = "v141"; // VS 15 uses v141 toolset - return true; - } else { - return false; - } - } - return this->cmGlobalVisualStudio14Generator::SelectWindowsStoreToolset( - toolset); -} - -bool cmGlobalVisualStudio15Generator::IsWindowsDesktopToolsetInstalled() const -{ - return vsSetupAPIHelper.IsVSInstalled(); -} - -bool cmGlobalVisualStudio15Generator::IsWindowsStoreToolsetInstalled() const -{ - return vsSetupAPIHelper.IsWin10SDKInstalled(); -} - -bool cmGlobalVisualStudio15Generator::IsWin81SDKInstalled() const -{ - // Does the VS installer tool know about one? - if (vsSetupAPIHelper.IsWin81SDKInstalled()) { - return true; - } - - // Does the registry know about one (e.g. from VS 2015)? - std::string win81Root; - if (cmSystemTools::ReadRegistryValue( - "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" - "Windows Kits\\Installed Roots;KitsRoot81", - win81Root, cmSystemTools::KeyWOW64_32) || - cmSystemTools::ReadRegistryValue( - "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\" - "Windows Kits\\Installed Roots;KitsRoot81", - win81Root, cmSystemTools::KeyWOW64_32)) { - return cmSystemTools::FileExists(win81Root + "/um/windows.h", true); - } - return false; -} - -std::string cmGlobalVisualStudio15Generator::GetWindows10SDKMaxVersion() const -{ - return std::string(); -} - -std::string cmGlobalVisualStudio15Generator::FindMSBuildCommand() -{ - std::string msbuild; - - // Ask Visual Studio Installer tool. - std::string vs; - if (vsSetupAPIHelper.GetVSInstanceInfo(vs)) { - msbuild = vs + "/MSBuild/15.0/Bin/MSBuild.exe"; - if (cmSystemTools::FileExists(msbuild)) { - return msbuild; - } - } - - msbuild = "MSBuild.exe"; - return msbuild; -} - -std::string cmGlobalVisualStudio15Generator::FindDevEnvCommand() -{ - std::string devenv; - - // Ask Visual Studio Installer tool. - std::string vs; - if (vsSetupAPIHelper.GetVSInstanceInfo(vs)) { - devenv = vs + "/Common7/IDE/devenv.com"; - if (cmSystemTools::FileExists(devenv)) { - return devenv; - } - } - - devenv = "devenv.com"; - return devenv; -} diff --git a/Source/cmGlobalVisualStudio15Generator.h b/Source/cmGlobalVisualStudio15Generator.h deleted file mode 100644 index da85d23..0000000 --- a/Source/cmGlobalVisualStudio15Generator.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#ifndef cmGlobalVisualStudio15Generator_h -#define cmGlobalVisualStudio15Generator_h - -#include "cmConfigure.h" // IWYU pragma: keep - -#include -#include - -#include "cmGlobalVisualStudio14Generator.h" -#include "cmVSSetupHelper.h" - -class cmGlobalGeneratorFactory; -class cmake; - -/** \class cmGlobalVisualStudio15Generator */ -class cmGlobalVisualStudio15Generator : public cmGlobalVisualStudio14Generator -{ -public: - static cmGlobalGeneratorFactory* NewFactory(); - - bool MatchesGeneratorName(const std::string& name) const override; - - bool SetGeneratorInstance(std::string const& i, cmMakefile* mf) override; - - bool GetVSInstance(std::string& dir) const; - - bool IsDefaultToolset(const std::string& version) const override; - std::string GetAuxiliaryToolset() const override; - -protected: - cmGlobalVisualStudio15Generator(cmake* cm, const std::string& name, - std::string const& platformInGeneratorName); - - bool InitializeWindows(cmMakefile* mf) override; - bool SelectWindowsStoreToolset(std::string& toolset) const override; - - // Used to verify that the Desktop toolset for the current generator is - // installed on the machine. - bool IsWindowsDesktopToolsetInstalled() const override; - - // These aren't virtual because we need to check if the selected version - // of the toolset is installed - bool IsWindowsStoreToolsetInstalled() const; - - // Check for a Win 8 SDK known to the registry or VS installer tool. - bool IsWin81SDKInstalled() const; - - std::string GetWindows10SDKMaxVersion() const override; - - std::string FindMSBuildCommand() override; - std::string FindDevEnvCommand() override; - -private: - class Factory; - friend class Factory; - mutable cmVSSetupAPIHelper vsSetupAPIHelper; -}; -#endif diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx new file mode 100644 index 0000000..354af72 --- /dev/null +++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx @@ -0,0 +1,291 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmGlobalVisualStudioVersionedGenerator.h" + +#include "cmAlgorithms.h" +#include "cmDocumentationEntry.h" +#include "cmLocalVisualStudio10Generator.h" +#include "cmMakefile.h" +#include "cmVSSetupHelper.h" + +static const char vs15generatorName[] = "Visual Studio 15 2017"; + +// Map generator name without year to name with year. +static const char* cmVS15GenName(const std::string& name, std::string& genName) +{ + if (strncmp(name.c_str(), vs15generatorName, + sizeof(vs15generatorName) - 6) != 0) { + return 0; + } + const char* p = name.c_str() + sizeof(vs15generatorName) - 6; + if (cmHasLiteralPrefix(p, " 2017")) { + p += 5; + } + genName = std::string(vs15generatorName) + p; + return p; +} + +class cmGlobalVisualStudioVersionedGenerator::Factory15 + : public cmGlobalGeneratorFactory +{ +public: + cmGlobalGenerator* CreateGlobalGenerator(const std::string& name, + cmake* cm) const override + { + std::string genName; + const char* p = cmVS15GenName(name, genName); + if (!p) { + return 0; + } + if (!*p) { + return new cmGlobalVisualStudioVersionedGenerator(cm, genName, ""); + } + if (*p++ != ' ') { + return 0; + } + if (strcmp(p, "Win64") == 0) { + return new cmGlobalVisualStudioVersionedGenerator(cm, genName, "x64"); + } + if (strcmp(p, "ARM") == 0) { + return new cmGlobalVisualStudioVersionedGenerator(cm, genName, "ARM"); + } + return 0; + } + + void GetDocumentation(cmDocumentationEntry& entry) const override + { + entry.Name = std::string(vs15generatorName) + " [arch]"; + entry.Brief = "Generates Visual Studio 2017 project files. " + "Optional [arch] can be \"Win64\" or \"ARM\"."; + } + + void GetGenerators(std::vector& names) const override + { + names.push_back(vs15generatorName); + names.push_back(vs15generatorName + std::string(" ARM")); + names.push_back(vs15generatorName + std::string(" Win64")); + } + + bool SupportsToolset() const override { return true; } + bool SupportsPlatform() const override { return true; } +}; + +cmGlobalGeneratorFactory* +cmGlobalVisualStudioVersionedGenerator::NewFactory15() +{ + return new Factory15; +} + +cmGlobalVisualStudioVersionedGenerator::cmGlobalVisualStudioVersionedGenerator( + cmake* cm, const std::string& name, + std::string const& platformInGeneratorName) + : cmGlobalVisualStudio14Generator(cm, name, platformInGeneratorName) + , vsSetupAPIHelper(15) +{ + this->ExpressEdition = false; + this->DefaultPlatformToolset = "v141"; + this->DefaultCLFlagTableName = "v141"; + this->DefaultCSharpFlagTableName = "v141"; + this->DefaultLinkFlagTableName = "v141"; + this->Version = VS15; +} + +bool cmGlobalVisualStudioVersionedGenerator::MatchesGeneratorName( + const std::string& name) const +{ + std::string genName; + if (cmVS15GenName(name, genName)) { + return genName == this->GetName(); + } + return false; +} + +bool cmGlobalVisualStudioVersionedGenerator::SetGeneratorInstance( + std::string const& i, cmMakefile* mf) +{ + if (!i.empty()) { + if (!this->vsSetupAPIHelper.SetVSInstance(i)) { + std::ostringstream e; + /* clang-format off */ + e << + "Generator\n" + " " << this->GetName() << "\n" + "could not find specified instance of Visual Studio:\n" + " " << i; + /* clang-format on */ + mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + return false; + } + } + + std::string vsInstance; + if (!this->vsSetupAPIHelper.GetVSInstanceInfo(vsInstance)) { + std::ostringstream e; + /* clang-format off */ + e << + "Generator\n" + " " << this->GetName() << "\n" + "could not find any instance of Visual Studio.\n"; + /* clang-format on */ + mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + return false; + } + + // Save the selected instance persistently. + std::string genInstance = mf->GetSafeDefinition("CMAKE_GENERATOR_INSTANCE"); + if (vsInstance != genInstance) { + this->CMakeInstance->AddCacheEntry( + "CMAKE_GENERATOR_INSTANCE", vsInstance.c_str(), + "Generator instance identifier.", cmStateEnums::INTERNAL); + } + + return true; +} + +bool cmGlobalVisualStudioVersionedGenerator::GetVSInstance( + std::string& dir) const +{ + return vsSetupAPIHelper.GetVSInstanceInfo(dir); +} + +bool cmGlobalVisualStudioVersionedGenerator::IsDefaultToolset( + const std::string& version) const +{ + if (version.empty()) { + return true; + } + + std::string vcToolsetVersion; + if (this->vsSetupAPIHelper.GetVCToolsetVersion(vcToolsetVersion)) { + + cmsys::RegularExpression regex("[0-9][0-9]\\.[0-9]+"); + if (regex.find(version) && regex.find(vcToolsetVersion)) { + const auto majorMinorEnd = vcToolsetVersion.find('.', 3); + const auto majorMinor = vcToolsetVersion.substr(0, majorMinorEnd); + return version == majorMinor; + } + } + + return false; +} + +std::string cmGlobalVisualStudioVersionedGenerator::GetAuxiliaryToolset() const +{ + const char* version = this->GetPlatformToolsetVersion(); + if (version) { + std::string instancePath; + GetVSInstance(instancePath); + std::stringstream path; + path << instancePath; + path << "/VC/Auxiliary/Build/"; + path << version; + path << "/Microsoft.VCToolsVersion." << version << ".props"; + + std::string toolsetPath = path.str(); + cmSystemTools::ConvertToUnixSlashes(toolsetPath); + return toolsetPath; + } + return {}; +} + +bool cmGlobalVisualStudioVersionedGenerator::InitializeWindows(cmMakefile* mf) +{ + // If the Win 8.1 SDK is installed then we can select a SDK matching + // the target Windows version. + if (this->IsWin81SDKInstalled()) { + return cmGlobalVisualStudio14Generator::InitializeWindows(mf); + } + // Otherwise we must choose a Win 10 SDK even if we are not targeting + // Windows 10. + return this->SelectWindows10SDK(mf, false); +} + +bool cmGlobalVisualStudioVersionedGenerator::SelectWindowsStoreToolset( + std::string& toolset) const +{ + if (cmHasLiteralPrefix(this->SystemVersion, "10.0")) { + if (this->IsWindowsStoreToolsetInstalled() && + this->IsWindowsDesktopToolsetInstalled()) { + toolset = "v141"; // VS 15 uses v141 toolset + return true; + } else { + return false; + } + } + return this->cmGlobalVisualStudio14Generator::SelectWindowsStoreToolset( + toolset); +} + +bool cmGlobalVisualStudioVersionedGenerator::IsWindowsDesktopToolsetInstalled() + const +{ + return vsSetupAPIHelper.IsVSInstalled(); +} + +bool cmGlobalVisualStudioVersionedGenerator::IsWindowsStoreToolsetInstalled() + const +{ + return vsSetupAPIHelper.IsWin10SDKInstalled(); +} + +bool cmGlobalVisualStudioVersionedGenerator::IsWin81SDKInstalled() const +{ + // Does the VS installer tool know about one? + if (vsSetupAPIHelper.IsWin81SDKInstalled()) { + return true; + } + + // Does the registry know about one (e.g. from VS 2015)? + std::string win81Root; + if (cmSystemTools::ReadRegistryValue( + "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" + "Windows Kits\\Installed Roots;KitsRoot81", + win81Root, cmSystemTools::KeyWOW64_32) || + cmSystemTools::ReadRegistryValue( + "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\" + "Windows Kits\\Installed Roots;KitsRoot81", + win81Root, cmSystemTools::KeyWOW64_32)) { + return cmSystemTools::FileExists(win81Root + "/um/windows.h", true); + } + return false; +} + +std::string cmGlobalVisualStudioVersionedGenerator::GetWindows10SDKMaxVersion() + const +{ + return std::string(); +} + +std::string cmGlobalVisualStudioVersionedGenerator::FindMSBuildCommand() +{ + std::string msbuild; + + // Ask Visual Studio Installer tool. + std::string vs; + if (vsSetupAPIHelper.GetVSInstanceInfo(vs)) { + msbuild = vs + "/MSBuild/15.0/Bin/MSBuild.exe"; + if (cmSystemTools::FileExists(msbuild)) { + return msbuild; + } + } + + msbuild = "MSBuild.exe"; + return msbuild; +} + +std::string cmGlobalVisualStudioVersionedGenerator::FindDevEnvCommand() +{ + std::string devenv; + + // Ask Visual Studio Installer tool. + std::string vs; + if (vsSetupAPIHelper.GetVSInstanceInfo(vs)) { + devenv = vs + "/Common7/IDE/devenv.com"; + if (cmSystemTools::FileExists(devenv)) { + return devenv; + } + } + + devenv = "devenv.com"; + return devenv; +} diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.h b/Source/cmGlobalVisualStudioVersionedGenerator.h new file mode 100644 index 0000000..2ffd568 --- /dev/null +++ b/Source/cmGlobalVisualStudioVersionedGenerator.h @@ -0,0 +1,62 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmGlobalVisualStudioVersionedGenerator_h +#define cmGlobalVisualStudioVersionedGenerator_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include +#include + +#include "cmGlobalVisualStudio14Generator.h" +#include "cmVSSetupHelper.h" + +class cmGlobalGeneratorFactory; +class cmake; + +/** \class cmGlobalVisualStudioVersionedGenerator */ +class cmGlobalVisualStudioVersionedGenerator + : public cmGlobalVisualStudio14Generator +{ +public: + static cmGlobalGeneratorFactory* NewFactory15(); + + bool MatchesGeneratorName(const std::string& name) const override; + + bool SetGeneratorInstance(std::string const& i, cmMakefile* mf) override; + + bool GetVSInstance(std::string& dir) const; + + bool IsDefaultToolset(const std::string& version) const override; + std::string GetAuxiliaryToolset() const override; + +protected: + cmGlobalVisualStudioVersionedGenerator( + cmake* cm, const std::string& name, + std::string const& platformInGeneratorName); + + bool InitializeWindows(cmMakefile* mf) override; + bool SelectWindowsStoreToolset(std::string& toolset) const override; + + // Used to verify that the Desktop toolset for the current generator is + // installed on the machine. + bool IsWindowsDesktopToolsetInstalled() const override; + + // These aren't virtual because we need to check if the selected version + // of the toolset is installed + bool IsWindowsStoreToolsetInstalled() const; + + // Check for a Win 8 SDK known to the registry or VS installer tool. + bool IsWin81SDKInstalled() const; + + std::string GetWindows10SDKMaxVersion() const override; + + std::string FindMSBuildCommand() override; + std::string FindDevEnvCommand() override; + +private: + class Factory15; + friend class Factory15; + mutable cmVSSetupAPIHelper vsSetupAPIHelper; +}; +#endif diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 195956b..1d062f4 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -55,8 +55,8 @@ # include "cmGlobalVisualStudio11Generator.h" # include "cmGlobalVisualStudio12Generator.h" # include "cmGlobalVisualStudio14Generator.h" -# include "cmGlobalVisualStudio15Generator.h" # include "cmGlobalVisualStudio9Generator.h" +# include "cmGlobalVisualStudioVersionedGenerator.h" # include "cmVSSetupHelper.h" # define CMAKE_HAVE_VS_GENERATORS @@ -1792,7 +1792,8 @@ void cmake::AddDefaultGenerators() { #if defined(_WIN32) && !defined(__CYGWIN__) # if !defined(CMAKE_BOOT_MINGW) - this->Generators.push_back(cmGlobalVisualStudio15Generator::NewFactory()); + this->Generators.push_back( + cmGlobalVisualStudioVersionedGenerator::NewFactory15()); this->Generators.push_back(cmGlobalVisualStudio14Generator::NewFactory()); this->Generators.push_back(cmGlobalVisualStudio12Generator::NewFactory()); this->Generators.push_back(cmGlobalVisualStudio11Generator::NewFactory()); -- cgit v0.12