mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-02 04:09:33 -05:00
cmake: Factor out default generator selection into helper
This commit is contained in:
+52
-48
@@ -1313,54 +1313,7 @@ int cmake::ActualConfigure()
|
||||
cmSystemTools::SetForceUnixPaths(
|
||||
this->GlobalGenerator->GetForceUnixPaths());
|
||||
} else {
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
|
||||
std::string installedCompiler;
|
||||
// Try to find the newest VS installed on the computer and
|
||||
// use that as a default if -G is not specified
|
||||
const std::string vsregBase =
|
||||
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\";
|
||||
std::vector<std::string> vsVerions;
|
||||
vsVerions.push_back("VisualStudio\\");
|
||||
vsVerions.push_back("VCExpress\\");
|
||||
vsVerions.push_back("WDExpress\\");
|
||||
struct VSRegistryEntryName
|
||||
{
|
||||
const char* MSVersion;
|
||||
const char* GeneratorName;
|
||||
};
|
||||
VSRegistryEntryName version[] = {
|
||||
/* clang-format needs this comment to break after the opening brace */
|
||||
{ "7.1", "Visual Studio 7 .NET 2003" },
|
||||
{ "8.0", "Visual Studio 8 2005" },
|
||||
{ "9.0", "Visual Studio 9 2008" },
|
||||
{ "10.0", "Visual Studio 10 2010" },
|
||||
{ "11.0", "Visual Studio 11 2012" },
|
||||
{ "12.0", "Visual Studio 12 2013" },
|
||||
{ "14.0", "Visual Studio 14 2015" },
|
||||
{ "15.0", "Visual Studio 15" },
|
||||
{ 0, 0 }
|
||||
};
|
||||
for (int i = 0; version[i].MSVersion != 0; i++) {
|
||||
for (size_t b = 0; b < vsVerions.size(); b++) {
|
||||
std::string reg = vsregBase + vsVerions[b] + version[i].MSVersion;
|
||||
reg += ";InstallDir]";
|
||||
cmSystemTools::ExpandRegistryValues(reg, cmSystemTools::KeyWOW64_32);
|
||||
if (!(reg == "/registry")) {
|
||||
installedCompiler = version[i].GeneratorName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
cmGlobalGenerator* gen =
|
||||
this->CreateGlobalGenerator(installedCompiler.c_str());
|
||||
if (!gen) {
|
||||
gen = new cmGlobalNMakeMakefileGenerator(this);
|
||||
}
|
||||
this->SetGlobalGenerator(gen);
|
||||
std::cout << "-- Building for: " << gen->GetName() << "\n";
|
||||
#else
|
||||
this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator3(this));
|
||||
#endif
|
||||
this->CreateDefaultGlobalGenerator();
|
||||
}
|
||||
if (!this->GlobalGenerator) {
|
||||
cmSystemTools::Error("Could not create generator");
|
||||
@@ -1488,6 +1441,57 @@ int cmake::ActualConfigure()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cmake::CreateDefaultGlobalGenerator()
|
||||
{
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
|
||||
std::string installedCompiler;
|
||||
// Try to find the newest VS installed on the computer and
|
||||
// use that as a default if -G is not specified
|
||||
const std::string vsregBase = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\";
|
||||
std::vector<std::string> vsVerions;
|
||||
vsVerions.push_back("VisualStudio\\");
|
||||
vsVerions.push_back("VCExpress\\");
|
||||
vsVerions.push_back("WDExpress\\");
|
||||
struct VSRegistryEntryName
|
||||
{
|
||||
const char* MSVersion;
|
||||
const char* GeneratorName;
|
||||
};
|
||||
VSRegistryEntryName version[] = {
|
||||
/* clang-format needs this comment to break after the opening brace */
|
||||
{ "7.1", "Visual Studio 7 .NET 2003" },
|
||||
{ "8.0", "Visual Studio 8 2005" },
|
||||
{ "9.0", "Visual Studio 9 2008" },
|
||||
{ "10.0", "Visual Studio 10 2010" },
|
||||
{ "11.0", "Visual Studio 11 2012" },
|
||||
{ "12.0", "Visual Studio 12 2013" },
|
||||
{ "14.0", "Visual Studio 14 2015" },
|
||||
{ "15.0", "Visual Studio 15" },
|
||||
{ 0, 0 }
|
||||
};
|
||||
for (int i = 0; version[i].MSVersion != 0; i++) {
|
||||
for (size_t b = 0; b < vsVerions.size(); b++) {
|
||||
std::string reg = vsregBase + vsVerions[b] + version[i].MSVersion;
|
||||
reg += ";InstallDir]";
|
||||
cmSystemTools::ExpandRegistryValues(reg, cmSystemTools::KeyWOW64_32);
|
||||
if (!(reg == "/registry")) {
|
||||
installedCompiler = version[i].GeneratorName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
cmGlobalGenerator* gen =
|
||||
this->CreateGlobalGenerator(installedCompiler.c_str());
|
||||
if (!gen) {
|
||||
gen = new cmGlobalNMakeMakefileGenerator(this);
|
||||
}
|
||||
this->SetGlobalGenerator(gen);
|
||||
std::cout << "-- Building for: " << gen->GetName() << "\n";
|
||||
#else
|
||||
this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator3(this));
|
||||
#endif
|
||||
}
|
||||
|
||||
void cmake::PreLoadCMakeFiles()
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
|
||||
@@ -500,6 +500,8 @@ private:
|
||||
// Print a list of valid generators to stderr.
|
||||
void PrintGeneratorList();
|
||||
|
||||
void CreateDefaultGlobalGenerator();
|
||||
|
||||
/**
|
||||
* Convert a message type between a warning and an error, based on the state
|
||||
* of the error output CMake variables, in the cache.
|
||||
|
||||
Reference in New Issue
Block a user