Skip to content

Commit b1c9f8d

Browse files
committed
Fixed Clang build on Windows - needs the Ninja
1 parent 1fd3b78 commit b1c9f8d

3 files changed

Lines changed: 33 additions & 7 deletions

File tree

editor/Generator.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

editor/Generator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ namespace doriax::editor {
5656
std::string cCompiler; // e.g. "/usr/bin/gcc"
5757
std::string cxxCompiler; // e.g. "/usr/bin/g++"
5858
std::string generator; // e.g. "MinGW Makefiles" (Windows only, empty = CMake default)
59+
bool available = true; // false = detected but not usable (shown disabled in UI)
60+
std::string unavailableReason; // e.g. "requires Ninja on PATH"
5961
};
6062

6163
class Generator {

editor/window/dialog/ProjectSettingsWindow.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void ProjectSettingsWindow::open(Project* project) {
182182
std::string currentGen = project->getCMakeGenerator();
183183
if (!currentCxx.empty() || !currentGen.empty()) {
184184
for (size_t i = 0; i < m_availableKits.size(); i++) {
185-
if (m_availableKits[i].cxxCompiler == currentCxx && m_availableKits[i].generator == currentGen) {
185+
if (m_availableKits[i].available && m_availableKits[i].cxxCompiler == currentCxx && m_availableKits[i].generator == currentGen) {
186186
m_cmakeKitIndex = static_cast<int>(i + 1);
187187
break;
188188
}
@@ -384,8 +384,15 @@ void ProjectSettingsWindow::drawSettings() {
384384
ImGui::SetItemDefaultFocus();
385385
}
386386
for (size_t i = 0; i < m_availableKits.size(); i++) {
387+
const auto& kit = m_availableKits[i];
388+
if (!kit.available) {
389+
ImGui::BeginDisabled();
390+
ImGui::Selectable((kit.displayName + " (" + kit.unavailableReason + ")").c_str(), false);
391+
ImGui::EndDisabled();
392+
continue;
393+
}
387394
isSelected = (m_cmakeKitIndex == static_cast<int>(i + 1));
388-
if (ImGui::Selectable(m_availableKits[i].displayName.c_str(), isSelected)) {
395+
if (ImGui::Selectable(kit.displayName.c_str(), isSelected)) {
389396
m_cmakeKitIndex = static_cast<int>(i + 1);
390397
}
391398
if (isSelected) {

0 commit comments

Comments
 (0)