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. 28
      src/compile_commands.cpp

28
src/compile_commands.cpp

@ -83,15 +83,9 @@ std::vector<std::string> CompileCommands::get_arguments(const boost::filesystem:
} }
} }
static std::string resource_path = []() -> std::string { static auto find_resource_path = [](const boost::filesystem::path &base_path, std::string version) -> 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::regex clang_version_regex("([0-9]+\\.[0-9]+\\.[0-9]+)");
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() != '.') { while(!version.empty() && version.front() != '.' && version.back() != '.') {
auto path = boost::filesystem::path(LIBCLANG_LIBRARY_DIR) / "clang" / version; auto path = base_path / "clang" / version;
boost::system::error_code ec; boost::system::error_code ec;
if(boost::filesystem::is_directory(path / "include", ec)) if(boost::filesystem::is_directory(path / "include", ec))
return path.string(); return path.string();
@ -100,6 +94,24 @@ std::vector<std::string> CompileCommands::get_arguments(const boost::filesystem:
break; break;
version.erase(pos); 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());
std::regex clang_version_regex("([0-9]+\\.[0-9]+\\.[0-9]+)");
std::smatch sm;
if(std::regex_search(clang_version, sm, clang_version_regex)) {
auto version = sm[1].str();
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;
}
} }
boost::system::error_code ec; boost::system::error_code ec;

Loading…
Cancel
Save