|
|
@@ -1,6 +1,6 @@
|
|
|
/* 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 "cmGlobalVisualStudioVersionedGenerator.h"
|
|
|
|
|
|
#include "cmAlgorithms.h"
|
|
|
#include "cmDocumentationEntry.h"
|
|
|
@@ -8,6 +8,61 @@
|
|
|
#include "cmMakefile.h"
|
|
|
#include "cmVSSetupHelper.h"
|
|
|
|
|
|
+#if defined(_M_ARM64)
|
|
|
+# define HOST_PLATFORM_NAME "ARM64";
|
|
|
+#elif defined(_M_ARM)
|
|
|
+# define HOST_PLATFORM_NAME "ARM";
|
|
|
+#elif defined(_M_IA64)
|
|
|
+# define HOST_PLATFORM_NAME "Itanium";
|
|
|
+#else
|
|
|
+# include "cmsys/SystemInformation.hxx"
|
|
|
+#endif
|
|
|
+
|
|
|
+static unsigned int VSVersionToMajor(
|
|
|
+ cmGlobalVisualStudioGenerator::VSVersion v)
|
|
|
+{
|
|
|
+ switch (v) {
|
|
|
+ case cmGlobalVisualStudioGenerator::VS9:
|
|
|
+ return 9;
|
|
|
+ case cmGlobalVisualStudioGenerator::VS10:
|
|
|
+ return 10;
|
|
|
+ case cmGlobalVisualStudioGenerator::VS11:
|
|
|
+ return 11;
|
|
|
+ case cmGlobalVisualStudioGenerator::VS12:
|
|
|
+ return 12;
|
|
|
+ case cmGlobalVisualStudioGenerator::VS14:
|
|
|
+ return 14;
|
|
|
+ case cmGlobalVisualStudioGenerator::VS15:
|
|
|
+ return 15;
|
|
|
+ case cmGlobalVisualStudioGenerator::VS16:
|
|
|
+ return 16;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+static const char* VSVersionToToolset(
|
|
|
+ cmGlobalVisualStudioGenerator::VSVersion v)
|
|
|
+{
|
|
|
+ switch (v) {
|
|
|
+ case cmGlobalVisualStudioGenerator::VS9:
|
|
|
+ return "v90";
|
|
|
+ case cmGlobalVisualStudioGenerator::VS10:
|
|
|
+ return "v100";
|
|
|
+ case cmGlobalVisualStudioGenerator::VS11:
|
|
|
+ return "v110";
|
|
|
+ case cmGlobalVisualStudioGenerator::VS12:
|
|
|
+ return "v120";
|
|
|
+ case cmGlobalVisualStudioGenerator::VS14:
|
|
|
+ return "v140";
|
|
|
+ case cmGlobalVisualStudioGenerator::VS15:
|
|
|
+ return "v141";
|
|
|
+ case cmGlobalVisualStudioGenerator::VS16:
|
|
|
+ // FIXME: VS 2019 Preview 1.1 uses v141 but preview 2 will use v142.
|
|
|
+ return "v141";
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+}
|
|
|
+
|
|
|
static const char vs15generatorName[] = "Visual Studio 15 2017";
|
|
|
|
|
|
// Map generator name without year to name with year.
|
|
|
@@ -25,7 +80,7 @@ static const char* cmVS15GenName(const std::string& name, std::string& genName)
|
|
|
return p;
|
|
|
}
|
|
|
|
|
|
-class cmGlobalVisualStudio15Generator::Factory
|
|
|
+class cmGlobalVisualStudioVersionedGenerator::Factory15
|
|
|
: public cmGlobalGeneratorFactory
|
|
|
{
|
|
|
public:
|
|
|
@@ -38,16 +93,19 @@ public:
|
|
|
return 0;
|
|
|
}
|
|
|
if (!*p) {
|
|
|
- return new cmGlobalVisualStudio15Generator(cm, genName, "");
|
|
|
+ return new cmGlobalVisualStudioVersionedGenerator(
|
|
|
+ cmGlobalVisualStudioGenerator::VS15, cm, genName, "");
|
|
|
}
|
|
|
if (*p++ != ' ') {
|
|
|
return 0;
|
|
|
}
|
|
|
if (strcmp(p, "Win64") == 0) {
|
|
|
- return new cmGlobalVisualStudio15Generator(cm, genName, "x64");
|
|
|
+ return new cmGlobalVisualStudioVersionedGenerator(
|
|
|
+ cmGlobalVisualStudioGenerator::VS15, cm, genName, "x64");
|
|
|
}
|
|
|
if (strcmp(p, "ARM") == 0) {
|
|
|
- return new cmGlobalVisualStudio15Generator(cm, genName, "ARM");
|
|
|
+ return new cmGlobalVisualStudioVersionedGenerator(
|
|
|
+ cmGlobalVisualStudioGenerator::VS15, cm, genName, "ARM");
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -70,35 +128,122 @@ public:
|
|
|
bool SupportsPlatform() const override { return true; }
|
|
|
};
|
|
|
|
|
|
-cmGlobalGeneratorFactory* cmGlobalVisualStudio15Generator::NewFactory()
|
|
|
+cmGlobalGeneratorFactory*
|
|
|
+cmGlobalVisualStudioVersionedGenerator::NewFactory15()
|
|
|
+{
|
|
|
+ return new Factory15;
|
|
|
+}
|
|
|
+
|
|
|
+static const char vs16generatorName[] = "Visual Studio 16 2019";
|
|
|
+
|
|
|
+// Map generator name without year to name with year.
|
|
|
+static const char* cmVS16GenName(const std::string& name, std::string& genName)
|
|
|
+{
|
|
|
+ if (strncmp(name.c_str(), vs16generatorName,
|
|
|
+ sizeof(vs16generatorName) - 6) != 0) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ const char* p = name.c_str() + sizeof(vs16generatorName) - 6;
|
|
|
+ if (cmHasLiteralPrefix(p, " 2019")) {
|
|
|
+ p += 5;
|
|
|
+ }
|
|
|
+ genName = std::string(vs16generatorName) + p;
|
|
|
+ return p;
|
|
|
+}
|
|
|
+
|
|
|
+class cmGlobalVisualStudioVersionedGenerator::Factory16
|
|
|
+ : public cmGlobalGeneratorFactory
|
|
|
+{
|
|
|
+public:
|
|
|
+ virtual cmGlobalGenerator* CreateGlobalGenerator(const std::string& name,
|
|
|
+ cmake* cm) const
|
|
|
+ {
|
|
|
+ std::string genName;
|
|
|
+ const char* p = cmVS16GenName(name, genName);
|
|
|
+ if (!p) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ if (!*p) {
|
|
|
+ return new cmGlobalVisualStudioVersionedGenerator(
|
|
|
+ cmGlobalVisualStudioGenerator::VS16, cm, genName, "");
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ virtual void GetDocumentation(cmDocumentationEntry& entry) const
|
|
|
+ {
|
|
|
+ entry.Name = std::string(vs16generatorName);
|
|
|
+ entry.Brief = "Generates Visual Studio 2019 project files. "
|
|
|
+ "Use -A option to specify architecture.";
|
|
|
+ }
|
|
|
+
|
|
|
+ virtual void GetGenerators(std::vector<std::string>& names) const
|
|
|
+ {
|
|
|
+ names.push_back(vs16generatorName);
|
|
|
+ }
|
|
|
+
|
|
|
+ bool SupportsToolset() const override { return true; }
|
|
|
+ bool SupportsPlatform() const override { return true; }
|
|
|
+};
|
|
|
+
|
|
|
+cmGlobalGeneratorFactory*
|
|
|
+cmGlobalVisualStudioVersionedGenerator::NewFactory16()
|
|
|
{
|
|
|
- return new Factory;
|
|
|
+ return new Factory16;
|
|
|
}
|
|
|
|
|
|
-cmGlobalVisualStudio15Generator::cmGlobalVisualStudio15Generator(
|
|
|
- cmake* cm, const std::string& name,
|
|
|
+cmGlobalVisualStudioVersionedGenerator::cmGlobalVisualStudioVersionedGenerator(
|
|
|
+ VSVersion version, cmake* cm, const std::string& name,
|
|
|
std::string const& platformInGeneratorName)
|
|
|
: cmGlobalVisualStudio14Generator(cm, name, platformInGeneratorName)
|
|
|
+ , vsSetupAPIHelper(VSVersionToMajor(version))
|
|
|
{
|
|
|
+ this->Version = version;
|
|
|
this->ExpressEdition = false;
|
|
|
- this->DefaultPlatformToolset = "v141";
|
|
|
- this->DefaultCLFlagTableName = "v141";
|
|
|
- this->DefaultCSharpFlagTableName = "v141";
|
|
|
- this->DefaultLinkFlagTableName = "v141";
|
|
|
- this->Version = VS15;
|
|
|
+ this->DefaultPlatformToolset = VSVersionToToolset(this->Version);
|
|
|
+ this->DefaultCLFlagTableName = VSVersionToToolset(this->Version);
|
|
|
+ this->DefaultCSharpFlagTableName = VSVersionToToolset(this->Version);
|
|
|
+ this->DefaultLinkFlagTableName = VSVersionToToolset(this->Version);
|
|
|
+ if (this->Version >= cmGlobalVisualStudioGenerator::VS16) {
|
|
|
+#ifdef HOST_PLATFORM_NAME
|
|
|
+ this->DefaultPlatformName = HOST_PLATFORM_NAME;
|
|
|
+#else
|
|
|
+ cmsys::SystemInformation info;
|
|
|
+ if (info.Is64Bits()) {
|
|
|
+ this->DefaultPlatformName = "x64";
|
|
|
+ } else {
|
|
|
+ this->DefaultPlatformName = "Win32";
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-bool cmGlobalVisualStudio15Generator::MatchesGeneratorName(
|
|
|
+bool cmGlobalVisualStudioVersionedGenerator::MatchesGeneratorName(
|
|
|
const std::string& name) const
|
|
|
{
|
|
|
std::string genName;
|
|
|
- if (cmVS15GenName(name, genName)) {
|
|
|
- return genName == this->GetName();
|
|
|
+ switch (this->Version) {
|
|
|
+ case cmGlobalVisualStudioGenerator::VS9:
|
|
|
+ case cmGlobalVisualStudioGenerator::VS10:
|
|
|
+ case cmGlobalVisualStudioGenerator::VS11:
|
|
|
+ case cmGlobalVisualStudioGenerator::VS12:
|
|
|
+ case cmGlobalVisualStudioGenerator::VS14:
|
|
|
+ break;
|
|
|
+ case cmGlobalVisualStudioGenerator::VS15:
|
|
|
+ if (cmVS15GenName(name, genName)) {
|
|
|
+ return genName == this->GetName();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case cmGlobalVisualStudioGenerator::VS16:
|
|
|
+ if (cmVS16GenName(name, genName)) {
|
|
|
+ return genName == this->GetName();
|
|
|
+ }
|
|
|
+ break;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-bool cmGlobalVisualStudio15Generator::SetGeneratorInstance(
|
|
|
+bool cmGlobalVisualStudioVersionedGenerator::SetGeneratorInstance(
|
|
|
std::string const& i, cmMakefile* mf)
|
|
|
{
|
|
|
if (!i.empty()) {
|
|
|
@@ -140,12 +285,13 @@ bool cmGlobalVisualStudio15Generator::SetGeneratorInstance(
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-bool cmGlobalVisualStudio15Generator::GetVSInstance(std::string& dir) const
|
|
|
+bool cmGlobalVisualStudioVersionedGenerator::GetVSInstance(
|
|
|
+ std::string& dir) const
|
|
|
{
|
|
|
return vsSetupAPIHelper.GetVSInstanceInfo(dir);
|
|
|
}
|
|
|
|
|
|
-bool cmGlobalVisualStudio15Generator::IsDefaultToolset(
|
|
|
+bool cmGlobalVisualStudioVersionedGenerator::IsDefaultToolset(
|
|
|
const std::string& version) const
|
|
|
{
|
|
|
if (version.empty()) {
|
|
|
@@ -166,7 +312,7 @@ bool cmGlobalVisualStudio15Generator::IsDefaultToolset(
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-std::string cmGlobalVisualStudio15Generator::GetAuxiliaryToolset() const
|
|
|
+std::string cmGlobalVisualStudioVersionedGenerator::GetAuxiliaryToolset() const
|
|
|
{
|
|
|
const char* version = this->GetPlatformToolsetVersion();
|
|
|
if (version) {
|
|
|
@@ -185,7 +331,7 @@ std::string cmGlobalVisualStudio15Generator::GetAuxiliaryToolset() const
|
|
|
return {};
|
|
|
}
|
|
|
|
|
|
-bool cmGlobalVisualStudio15Generator::InitializeWindows(cmMakefile* mf)
|
|
|
+bool cmGlobalVisualStudioVersionedGenerator::InitializeWindows(cmMakefile* mf)
|
|
|
{
|
|
|
// If the Win 8.1 SDK is installed then we can select a SDK matching
|
|
|
// the target Windows version.
|
|
|
@@ -197,13 +343,13 @@ bool cmGlobalVisualStudio15Generator::InitializeWindows(cmMakefile* mf)
|
|
|
return this->SelectWindows10SDK(mf, false);
|
|
|
}
|
|
|
|
|
|
-bool cmGlobalVisualStudio15Generator::SelectWindowsStoreToolset(
|
|
|
+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
|
|
|
+ toolset = VSVersionToToolset(this->Version);
|
|
|
return true;
|
|
|
} else {
|
|
|
return false;
|
|
|
@@ -213,17 +359,19 @@ bool cmGlobalVisualStudio15Generator::SelectWindowsStoreToolset(
|
|
|
toolset);
|
|
|
}
|
|
|
|
|
|
-bool cmGlobalVisualStudio15Generator::IsWindowsDesktopToolsetInstalled() const
|
|
|
+bool cmGlobalVisualStudioVersionedGenerator::IsWindowsDesktopToolsetInstalled()
|
|
|
+ const
|
|
|
{
|
|
|
- return vsSetupAPIHelper.IsVS2017Installed();
|
|
|
+ return vsSetupAPIHelper.IsVSInstalled();
|
|
|
}
|
|
|
|
|
|
-bool cmGlobalVisualStudio15Generator::IsWindowsStoreToolsetInstalled() const
|
|
|
+bool cmGlobalVisualStudioVersionedGenerator::IsWindowsStoreToolsetInstalled()
|
|
|
+ const
|
|
|
{
|
|
|
return vsSetupAPIHelper.IsWin10SDKInstalled();
|
|
|
}
|
|
|
|
|
|
-bool cmGlobalVisualStudio15Generator::IsWin81SDKInstalled() const
|
|
|
+bool cmGlobalVisualStudioVersionedGenerator::IsWin81SDKInstalled() const
|
|
|
{
|
|
|
// Does the VS installer tool know about one?
|
|
|
if (vsSetupAPIHelper.IsWin81SDKInstalled()) {
|
|
|
@@ -245,18 +393,23 @@ bool cmGlobalVisualStudio15Generator::IsWin81SDKInstalled() const
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-std::string cmGlobalVisualStudio15Generator::GetWindows10SDKMaxVersion() const
|
|
|
+std::string cmGlobalVisualStudioVersionedGenerator::GetWindows10SDKMaxVersion()
|
|
|
+ const
|
|
|
{
|
|
|
return std::string();
|
|
|
}
|
|
|
|
|
|
-std::string cmGlobalVisualStudio15Generator::FindMSBuildCommand()
|
|
|
+std::string cmGlobalVisualStudioVersionedGenerator::FindMSBuildCommand()
|
|
|
{
|
|
|
std::string msbuild;
|
|
|
|
|
|
// Ask Visual Studio Installer tool.
|
|
|
std::string vs;
|
|
|
if (vsSetupAPIHelper.GetVSInstanceInfo(vs)) {
|
|
|
+ msbuild = vs + "/MSBuild/Current/Bin/MSBuild.exe";
|
|
|
+ if (cmSystemTools::FileExists(msbuild)) {
|
|
|
+ return msbuild;
|
|
|
+ }
|
|
|
msbuild = vs + "/MSBuild/15.0/Bin/MSBuild.exe";
|
|
|
if (cmSystemTools::FileExists(msbuild)) {
|
|
|
return msbuild;
|
|
|
@@ -267,7 +420,7 @@ std::string cmGlobalVisualStudio15Generator::FindMSBuildCommand()
|
|
|
return msbuild;
|
|
|
}
|
|
|
|
|
|
-std::string cmGlobalVisualStudio15Generator::FindDevEnvCommand()
|
|
|
+std::string cmGlobalVisualStudioVersionedGenerator::FindDevEnvCommand()
|
|
|
{
|
|
|
std::string devenv;
|
|
|
|