diff --git a/implementations/Crafter.Build-Clang.cpp b/implementations/Crafter.Build-Clang.cpp index 5a0b343..6ff9c6a 100644 --- a/implementations/Crafter.Build-Clang.cpp +++ b/implementations/Crafter.Build-Clang.cpp @@ -380,12 +380,28 @@ CompileCommand Crafter::GetCompileCommand(const Configuration& config) { // -I propagation that's valid for both C and C++ compiles. Module-only // bits (-fprebuilt-module-path) stay on `command` only. { + // bin/ and build/ hold what builds write for the configuration whose + // path holds them: crafter-build's own outputs (BinDir(), BuildDir()) + // and whatever else a build leaves there, a CMake build tree or a + // flatpak-builder /app tree among it, whose include/ holds another + // library's or toolchain's headers and never the dependency's own. + // The walk leaves out every directory of those names, not only the + // graph's: a dependency's tree holds the outputs of configurations + // outside the graph too, a program in a directory below it or a + // project of its own beside it, as Crafter.Graphics' examples are. + // Walked, they would have every compile built on the dependency take + // those headers before the system's, and what compiled depend on + // which builds had run. std::unordered_set seen; std::function addFlags = [&](Configuration* dep) { if (!seen.insert(dep).second) return; - for (const auto& entry : fs::recursive_directory_iterator(dep->path)) { - if (entry.is_directory() && entry.path().filename() == "include") { - out.includeFlags += std::format(" -I{}", entry.path().string()); + for (auto it = fs::recursive_directory_iterator(dep->path); it != fs::recursive_directory_iterator(); ++it) { + if (!it->is_directory()) continue; + const fs::path name = it->path().filename(); + if (name == "bin" || name == "build") { + it.disable_recursion_pending(); + } else if (name == "include") { + out.includeFlags += std::format(" -I{}", it->path().string()); } } out.includeFlags += std::format(" -I{}", dep->path.string());