summaryrefslogtreecommitdiffstats
path: root/Source/cmake.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-10-11 15:25:28 (GMT)
committerBrad King <brad.king@kitware.com>2016-10-11 15:30:46 (GMT)
commit8f33de92ba4fc152b0e2b63008732ce0ad4ba18c (patch)
treefa200da421cea0d95b892f83c99e9cdd2a119b36 /Source/cmake.cxx
parent2fb8e5b1c46ea586233b19e612ba174aa74d004c (diff)
downloadCMake-8f33de92ba4fc152b0e2b63008732ce0ad4ba18c.zip
CMake-8f33de92ba4fc152b0e2b63008732ce0ad4ba18c.tar.gz
CMake-8f33de92ba4fc152b0e2b63008732ce0ad4ba18c.tar.bz2
cmake: Factor out default generator selection into helper
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r--Source/cmake.cxx100
1 files changed, 52 insertions, 48 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index e0f4000..3bf7f38 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -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;