mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 13:20:47 -06:00
VS: Parameterize cmVSSetupAPIHelper instances with VS version
This commit is contained in:
@@ -141,7 +141,7 @@ bool cmCMakeHostSystemInformationCommand::GetValue(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, find a VS 15 instance ourselves.
|
// Otherwise, find a VS 15 instance ourselves.
|
||||||
cmVSSetupAPIHelper vsSetupAPIHelper;
|
cmVSSetupAPIHelper vsSetupAPIHelper(15);
|
||||||
if (vsSetupAPIHelper.GetVSInstanceInfo(value)) {
|
if (vsSetupAPIHelper.GetVSInstanceInfo(value)) {
|
||||||
cmSystemTools::ConvertToUnixSlashes(value);
|
cmSystemTools::ConvertToUnixSlashes(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ cmGlobalVisualStudio15Generator::cmGlobalVisualStudio15Generator(
|
|||||||
cmake* cm, const std::string& name,
|
cmake* cm, const std::string& name,
|
||||||
std::string const& platformInGeneratorName)
|
std::string const& platformInGeneratorName)
|
||||||
: cmGlobalVisualStudio14Generator(cm, name, platformInGeneratorName)
|
: cmGlobalVisualStudio14Generator(cm, name, platformInGeneratorName)
|
||||||
|
, vsSetupAPIHelper(15)
|
||||||
{
|
{
|
||||||
this->ExpressEdition = false;
|
this->ExpressEdition = false;
|
||||||
this->DefaultPlatformToolset = "v141";
|
this->DefaultPlatformToolset = "v141";
|
||||||
@@ -215,7 +216,7 @@ bool cmGlobalVisualStudio15Generator::SelectWindowsStoreToolset(
|
|||||||
|
|
||||||
bool cmGlobalVisualStudio15Generator::IsWindowsDesktopToolsetInstalled() const
|
bool cmGlobalVisualStudio15Generator::IsWindowsDesktopToolsetInstalled() const
|
||||||
{
|
{
|
||||||
return vsSetupAPIHelper.IsVS2017Installed();
|
return vsSetupAPIHelper.IsVSInstalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmGlobalVisualStudio15Generator::IsWindowsStoreToolsetInstalled() const
|
bool cmGlobalVisualStudio15Generator::IsWindowsStoreToolsetInstalled() const
|
||||||
|
|||||||
@@ -57,8 +57,9 @@ std::string VSInstanceInfo::GetInstallLocation() const
|
|||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmVSSetupAPIHelper::cmVSSetupAPIHelper()
|
cmVSSetupAPIHelper::cmVSSetupAPIHelper(unsigned int version)
|
||||||
: setupConfig(NULL)
|
: Version(version)
|
||||||
|
, setupConfig(NULL)
|
||||||
, setupConfig2(NULL)
|
, setupConfig2(NULL)
|
||||||
, setupHelper(NULL)
|
, setupHelper(NULL)
|
||||||
, initializationFailure(false)
|
, initializationFailure(false)
|
||||||
@@ -88,7 +89,7 @@ bool cmVSSetupAPIHelper::SetVSInstance(std::string const& vsInstallLocation)
|
|||||||
return this->EnumerateAndChooseVSInstance();
|
return this->EnumerateAndChooseVSInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmVSSetupAPIHelper::IsVS2017Installed()
|
bool cmVSSetupAPIHelper::IsVSInstalled()
|
||||||
{
|
{
|
||||||
return this->EnumerateAndChooseVSInstance();
|
return this->EnumerateAndChooseVSInstance();
|
||||||
}
|
}
|
||||||
@@ -312,11 +313,11 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance()
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::string envVSCommonToolsDir;
|
std::string envVSCommonToolsDir;
|
||||||
|
std::string envVSCommonToolsDirEnvName =
|
||||||
|
"VS" + std::to_string(this->Version) + "0COMNTOOLS";
|
||||||
|
|
||||||
// FIXME: When we support VS versions beyond 2017, the version
|
if (cmSystemTools::GetEnv(envVSCommonToolsDirEnvName.c_str(),
|
||||||
// to choose will be passed in by the caller. We need to map that
|
envVSCommonToolsDir)) {
|
||||||
// to a per-version name of this environment variable.
|
|
||||||
if (cmSystemTools::GetEnv("VS150COMNTOOLS", envVSCommonToolsDir)) {
|
|
||||||
cmSystemTools::ConvertToUnixSlashes(envVSCommonToolsDir);
|
cmSystemTools::ConvertToUnixSlashes(envVSCommonToolsDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,8 +329,7 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Add a way for caller to specify other versions.
|
std::wstring const wantVersion = std::to_wstring(this->Version) + L'.';
|
||||||
std::wstring wantVersion = std::to_wstring(15) + L'.';
|
|
||||||
|
|
||||||
SmartCOMPtr<ISetupInstance> instance;
|
SmartCOMPtr<ISetupInstance> instance;
|
||||||
while (SUCCEEDED(enumInstances->Next(1, &instance, NULL)) && instance) {
|
while (SUCCEEDED(enumInstances->Next(1, &instance, NULL)) && instance) {
|
||||||
|
|||||||
@@ -120,12 +120,12 @@ struct VSInstanceInfo
|
|||||||
class cmVSSetupAPIHelper
|
class cmVSSetupAPIHelper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cmVSSetupAPIHelper();
|
cmVSSetupAPIHelper(unsigned int version);
|
||||||
~cmVSSetupAPIHelper();
|
~cmVSSetupAPIHelper();
|
||||||
|
|
||||||
bool SetVSInstance(std::string const& vsInstallLocation);
|
bool SetVSInstance(std::string const& vsInstallLocation);
|
||||||
|
|
||||||
bool IsVS2017Installed();
|
bool IsVSInstalled();
|
||||||
bool GetVSInstanceInfo(std::string& vsInstallLocation);
|
bool GetVSInstanceInfo(std::string& vsInstallLocation);
|
||||||
bool GetVCToolsetVersion(std::string& vsToolsetVersion);
|
bool GetVCToolsetVersion(std::string& vsToolsetVersion);
|
||||||
bool IsWin10SDKInstalled();
|
bool IsWin10SDKInstalled();
|
||||||
@@ -140,6 +140,8 @@ private:
|
|||||||
int ChooseVSInstance(const std::vector<VSInstanceInfo>& vecVSInstances);
|
int ChooseVSInstance(const std::vector<VSInstanceInfo>& vecVSInstances);
|
||||||
bool EnumerateAndChooseVSInstance();
|
bool EnumerateAndChooseVSInstance();
|
||||||
|
|
||||||
|
unsigned int Version;
|
||||||
|
|
||||||
// COM ptrs to query about VS instances
|
// COM ptrs to query about VS instances
|
||||||
SmartCOMPtr<ISetupConfiguration> setupConfig;
|
SmartCOMPtr<ISetupConfiguration> setupConfig;
|
||||||
SmartCOMPtr<ISetupConfiguration2> setupConfig2;
|
SmartCOMPtr<ISetupConfiguration2> setupConfig2;
|
||||||
|
|||||||
@@ -1538,8 +1538,7 @@ void cmake::CreateDefaultGlobalGenerator()
|
|||||||
"\\Setup\\VC;ProductDir", //
|
"\\Setup\\VC;ProductDir", //
|
||||||
";InstallDir" //
|
";InstallDir" //
|
||||||
};
|
};
|
||||||
cmVSSetupAPIHelper vsSetupAPIHelper;
|
if (cmVSSetupAPIHelper(15).IsVSInstalled()) {
|
||||||
if (vsSetupAPIHelper.IsVS2017Installed()) {
|
|
||||||
found = "Visual Studio 15 2017";
|
found = "Visual Studio 15 2017";
|
||||||
} else {
|
} else {
|
||||||
for (VSVersionedGenerator const* g = cm::cbegin(vsGenerators);
|
for (VSVersionedGenerator const* g = cm::cbegin(vsGenerators);
|
||||||
|
|||||||
Reference in New Issue
Block a user