diff --git a/src/compile_commands.cpp b/src/compile_commands.cpp index b50223ac410aee0464c54c819c039c1ffeea7589..e4d773cf3c73fdd0736b5a89d2ec4fe27c7086c6 100644 --- a/src/compile_commands.cpp +++ b/src/compile_commands.cpp @@ -83,6 +83,20 @@ std::vector CompileCommands::get_arguments(const boost::filesystem: } } + static auto find_resource_path = [](const boost::filesystem::path &base_path, std::string version) -> std::string { + while(!version.empty() && version.front() != '.' && version.back() != '.') { + auto path = base_path / "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); + } + return ""; + }; + static std::string 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()); @@ -90,15 +104,13 @@ std::vector CompileCommands::get_arguments(const boost::filesystem: std::smatch sm; if(std::regex_search(clang_version, sm, clang_version_regex)) { auto version = sm[1].str(); - 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); + auto path = find_resource_path(boost::filesystem::path(LIBCLANG_LIBRARY_DIR), version); + if(path.empty()) { + // For e.g. Fedora the LibClang is located in /usr/lib64/libclang.so while the resource dir is in /usr/lib/clang/ + path = find_resource_path(boost::filesystem::path(LIBCLANG_LIBRARY_DIR) / ".." / "lib", version); + } + if(!path.empty()) { + return path; } }