Browse Source

Merge branch 'clang_resource_dir_fix' of https://gitlab.com/doe300/jucipp

merge-requests/413/merge
eidheim 2 years ago
parent
commit
546d5810be
  1. 30
      src/compile_commands.cpp

30
src/compile_commands.cpp

@ -83,6 +83,20 @@ std::vector<std::string> 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<std::string> 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/<version>
path = find_resource_path(boost::filesystem::path(LIBCLANG_LIBRARY_DIR) / ".." / "lib", version);
}
if(!path.empty()) {
return path;
}
}

Loading…
Cancel
Save