@@ -206,6 +206,21 @@ bool editor::Generator::configureCMake(const fs::path& projectPath, const fs::pa
206206 }
207207 }
208208
209+ #ifdef _WIN32
210+ // A compiler override without an explicit generator makes CMake fall back
211+ // to the Visual Studio generator, which ignores CMAKE_C/CXX_COMPILER
212+ // (MSBuild always drives cl.exe) and fails at link time. Fail early with
213+ // an actionable message instead. Honor CMAKE_GENERATOR if the user set it.
214+ if (generator.empty () && (!cCompiler.empty () || !cxxCompiler.empty ())) {
215+ const char * envGenerator = std::getenv (" CMAKE_GENERATOR" );
216+ if (!envGenerator || !*envGenerator) {
217+ Out::error (" The selected compiler '%s' cannot be used with the default Visual Studio generator. Install Ninja (https://ninja-build.org), add it to PATH and re-select the compiler in Project Settings, or switch to the MSVC compiler." ,
218+ (!cxxCompiler.empty () ? cxxCompiler : cCompiler).c_str ());
219+ return false ;
220+ }
221+ }
222+ #endif
223+
209224 const fs::path exePath = FileUtils::getExecutableDir ();
210225
211226 // CMake stores path values (e.g. CMAKE_C_COMPILER) into generated .cmake
@@ -1526,14 +1541,16 @@ std::vector<editor::CMakeKit> editor::Generator::detectAvailableKits() {
15261541#ifdef _WIN32
15271542 // Determine generator from the target triple.
15281543 // MinGW-targeting Clang uses MinGW Makefiles;
1529- // MSVC-targeting Clang works best with Ninja (or VS generator as fallback).
1544+ // MSVC-targeting Clang requires Ninja: the Visual Studio
1545+ // generator ignores CMAKE_C/CXX_COMPILER (MSBuild always drives
1546+ // cl.exe), so without Ninja this kit has no usable generator.
15301547 if (machine.find (" mingw" ) != std::string::npos) {
15311548 kit.generator = " MinGW Makefiles" ;
1549+ } else if (!findCompiler (" ninja" ).empty ()) {
1550+ kit.generator = " Ninja" ;
15321551 } else {
1533- if (!findCompiler (" ninja" ).empty ()) {
1534- kit.generator = " Ninja" ;
1535- }
1536- // Otherwise leave empty; CMake will pick the VS generator.
1552+ kit.available = false ;
1553+ kit.unavailableReason = " requires Ninja on PATH (https://ninja-build.org)" ;
15371554 }
15381555#endif
15391556 kits.push_back (kit);
0 commit comments