mirror of
https://github.com/reactos/CMake.git
synced 2025-04-02 15:21:41 +00:00
VS: Use Visual Studio Installer to locate VS 2017
VS 2017 and later may no longer populate the Windows Registry entries CMake has traditionally used to find the VS installations. This is because VS now supports having multiple installations of the same version. The Visual Studio Installer tool provides a COM interface we can query to locate installations.
This commit is contained in:
parent
18c8278b62
commit
c93e85d87e
@ -425,20 +425,6 @@ std::string cmGlobalVisualStudio10Generator::FindMSBuildCommand()
|
||||
}
|
||||
}
|
||||
|
||||
// Search where VS15Preview places it.
|
||||
mskey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;";
|
||||
mskey += this->GetIDEVersion();
|
||||
if (cmSystemTools::ReadRegistryValue(mskey.c_str(), msbuild,
|
||||
cmSystemTools::KeyWOW64_32)) {
|
||||
cmSystemTools::ConvertToUnixSlashes(msbuild);
|
||||
msbuild += "/MSBuild/";
|
||||
msbuild += this->GetIDEVersion();
|
||||
msbuild += "/Bin/MSBuild.exe";
|
||||
if (cmSystemTools::FileExists(msbuild, true)) {
|
||||
return msbuild;
|
||||
}
|
||||
}
|
||||
|
||||
msbuild = "MSBuild.exe";
|
||||
return msbuild;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "cmMakefile.h"
|
||||
#include "cmVS141CLFlagTable.h"
|
||||
#include "cmVS141CSharpFlagTable.h"
|
||||
#include "cmVSSetupHelper.h"
|
||||
|
||||
static const char vs15generatorName[] = "Visual Studio 15 2017";
|
||||
|
||||
@ -126,21 +127,44 @@ bool cmGlobalVisualStudio15Generator::SelectWindowsStoreToolset(
|
||||
|
||||
bool cmGlobalVisualStudio15Generator::IsWindowsDesktopToolsetInstalled() const
|
||||
{
|
||||
const char desktop10Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
|
||||
"VisualStudio\\15.0\\VC\\Runtimes";
|
||||
|
||||
std::vector<std::string> vc15;
|
||||
return cmSystemTools::GetRegistrySubKeys(desktop10Key, vc15,
|
||||
cmSystemTools::KeyWOW64_32);
|
||||
return vsSetupAPIHelper.IsVS2017Installed();
|
||||
}
|
||||
|
||||
bool cmGlobalVisualStudio15Generator::IsWindowsStoreToolsetInstalled() const
|
||||
{
|
||||
const char universal10Key[] =
|
||||
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
|
||||
"VisualStudio\\15.0\\Setup\\Build Tools for Windows 10;SrcPath";
|
||||
|
||||
std::string win10SDK;
|
||||
return cmSystemTools::ReadRegistryValue(universal10Key, win10SDK,
|
||||
cmSystemTools::KeyWOW64_32);
|
||||
return vsSetupAPIHelper.IsWin10SDKInstalled();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "cmGlobalVisualStudio14Generator.h"
|
||||
#include "cmVSSetupHelper.h"
|
||||
|
||||
class cmGlobalGeneratorFactory;
|
||||
class cmake;
|
||||
@ -39,7 +40,11 @@ protected:
|
||||
// of the toolset is installed
|
||||
bool IsWindowsStoreToolsetInstalled() const;
|
||||
|
||||
std::string FindMSBuildCommand() CM_OVERRIDE;
|
||||
std::string FindDevEnvCommand() CM_OVERRIDE;
|
||||
|
||||
private:
|
||||
class Factory;
|
||||
mutable cmVSSetupAPIHelper vsSetupAPIHelper;
|
||||
};
|
||||
#endif
|
||||
|
@ -64,6 +64,7 @@
|
||||
#include "cmGlobalVisualStudio71Generator.h"
|
||||
#include "cmGlobalVisualStudio8Generator.h"
|
||||
#include "cmGlobalVisualStudio9Generator.h"
|
||||
#include "cmVSSetupHelper.h"
|
||||
|
||||
#define CMAKE_HAVE_VS_GENERATORS
|
||||
#endif
|
||||
@ -1470,18 +1471,23 @@ void cmake::CreateDefaultGlobalGenerator()
|
||||
"\\Setup\\VC;ProductDir", //
|
||||
";InstallDir" //
|
||||
};
|
||||
for (VSVersionedGenerator const* g = cmArrayBegin(vsGenerators);
|
||||
found.empty() && g != cmArrayEnd(vsGenerators); ++g) {
|
||||
for (const char* const* v = cmArrayBegin(vsVariants);
|
||||
found.empty() && v != cmArrayEnd(vsVariants); ++v) {
|
||||
for (const char* const* e = cmArrayBegin(vsEntries);
|
||||
found.empty() && e != cmArrayEnd(vsEntries); ++e) {
|
||||
std::string const reg = vsregBase + *v + g->MSVersion + *e;
|
||||
std::string dir;
|
||||
if (cmSystemTools::ReadRegistryValue(reg, dir,
|
||||
cmSystemTools::KeyWOW64_32) &&
|
||||
cmSystemTools::PathExists(dir)) {
|
||||
found = g->GeneratorName;
|
||||
cmVSSetupAPIHelper vsSetupAPIHelper;
|
||||
if (vsSetupAPIHelper.IsVS2017Installed()) {
|
||||
found = "Visual Studio 15 2017";
|
||||
} else {
|
||||
for (VSVersionedGenerator const* g = cmArrayBegin(vsGenerators);
|
||||
found.empty() && g != cmArrayEnd(vsGenerators); ++g) {
|
||||
for (const char* const* v = cmArrayBegin(vsVariants);
|
||||
found.empty() && v != cmArrayEnd(vsVariants); ++v) {
|
||||
for (const char* const* e = cmArrayBegin(vsEntries);
|
||||
found.empty() && e != cmArrayEnd(vsEntries); ++e) {
|
||||
std::string const reg = vsregBase + *v + g->MSVersion + *e;
|
||||
std::string dir;
|
||||
if (cmSystemTools::ReadRegistryValue(reg, dir,
|
||||
cmSystemTools::KeyWOW64_32) &&
|
||||
cmSystemTools::PathExists(dir)) {
|
||||
found = g->GeneratorName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user