diff --git a/src/compile_commands.cpp b/src/compile_commands.cpp index e8ccbff..da5d565 100644 --- a/src/compile_commands.cpp +++ b/src/compile_commands.cpp @@ -85,6 +85,22 @@ std::vector CompileCommands::get_arguments(const boost::filesystem: } static auto resource_path = []() -> std::string { + // Try based on clang_getClangVersion first, even though its format is not guaranteed to be stable. + auto clang_version = clangmm::to_string(clang_getClangVersion()); + std::string version; + for(auto it = clang_version.rbegin(); it != clang_version.rend() && ((*it >= '0' && *it <= '9') || *it == '.'); ++it) + version.insert(version.begin(), *it); + while(!version.empty() && version.front() != '.' && version.back() != '.') { + auto path = boost::filesystem::path(LIBCLANG_LIBRARY_DIR) / "clang" / version; + boost::system::error_code ec; + if(boost::filesystem::is_directory(path / "include", ec)) + return path.string(); + auto pos = version.rfind('.'); + if(pos == std::string::npos) + break; + version.erase(pos); + } + boost::system::error_code ec; for(boost::filesystem::directory_iterator it(boost::filesystem::path(LIBCLANG_LIBRARY_DIR) / "clang", ec), end; it != end; ++it) { if(boost::filesystem::is_directory(it->path() / "include", ec))