| 2807 | } |
| 2808 | |
| 2809 | std::unique_ptr<cmGlobalGenerator> cmake::EvaluateDefaultGlobalGenerator() |
| 2810 | { |
| 2811 | if (!this->EnvironmentGenerator.empty()) { |
| 2812 | auto gen = this->CreateGlobalGenerator(this->EnvironmentGenerator); |
| 2813 | if (!gen) { |
| 2814 | cmSystemTools::Error("CMAKE_GENERATOR was set but the specified " |
| 2815 | "generator doesn't exist. Using CMake default."); |
| 2816 | } else { |
| 2817 | return gen; |
| 2818 | } |
| 2819 | } |
| 2820 | #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW) |
| 2821 | std::string found; |
| 2822 | // Try to find the newest VS installed on the computer and |
| 2823 | // use that as a default if -G is not specified |
| 2824 | std::string const vsregBase = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"; |
| 2825 | static char const* const vsVariants[] = { |
| 2826 | /* clang-format needs this comment to break after the opening brace */ |
| 2827 | "VisualStudio\\", "VCExpress\\", "WDExpress\\" |
| 2828 | }; |
| 2829 | struct VSVersionedGenerator |
| 2830 | { |
| 2831 | char const* MSVersion; |
| 2832 | char const* GeneratorName; |
| 2833 | }; |
| 2834 | static VSVersionedGenerator const vsGenerators[] = { |
| 2835 | { "14.0", "Visual Studio 14 2015" }, // |
| 2836 | }; |
| 2837 | static char const* const vsEntries[] = { |
| 2838 | "\\Setup\\VC;ProductDir", // |
| 2839 | ";InstallDir" // |
| 2840 | }; |
| 2841 | if (cmVSSetupAPIHelper(18).IsVSInstalled()) { |
| 2842 | found = "Visual Studio 18 2026"; |
| 2843 | } else if (cmVSSetupAPIHelper(17).IsVSInstalled()) { |
| 2844 | found = "Visual Studio 17 2022"; |
| 2845 | } else if (cmVSSetupAPIHelper(16).IsVSInstalled()) { |
| 2846 | found = "Visual Studio 16 2019"; |
| 2847 | } else if (cmVSSetupAPIHelper(15).IsVSInstalled()) { |
| 2848 | found = "Visual Studio 15 2017"; |
| 2849 | } else { |
| 2850 | for (VSVersionedGenerator const* g = cm::cbegin(vsGenerators); |
| 2851 | found.empty() && g != cm::cend(vsGenerators); ++g) { |
| 2852 | for (char const* const* v = cm::cbegin(vsVariants); |
| 2853 | found.empty() && v != cm::cend(vsVariants); ++v) { |
| 2854 | for (char const* const* e = cm::cbegin(vsEntries); |
| 2855 | found.empty() && e != cm::cend(vsEntries); ++e) { |
| 2856 | std::string const reg = vsregBase + *v + g->MSVersion + *e; |
| 2857 | std::string dir; |
| 2858 | if (cmSystemTools::ReadRegistryValue(reg, dir, |
| 2859 | cmSystemTools::KeyWOW64_32) && |
| 2860 | cmSystemTools::PathExists(dir)) { |
| 2861 | found = g->GeneratorName; |
| 2862 | } |
| 2863 | } |
| 2864 | } |
| 2865 | } |
| 2866 | } |
no test coverage detected