Browse Source

Added another attempt to find libclang resource path

merge-requests/413/head
eidheim 3 years ago
parent
commit
ba3ee99d11
  1. 16
      src/compile_commands.cpp

16
src/compile_commands.cpp

@ -85,6 +85,22 @@ std::vector<std::string> CompileCommands::get_arguments(const boost::filesystem:
} }
static auto resource_path = []() -> std::string { 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; boost::system::error_code ec;
for(boost::filesystem::directory_iterator it(boost::filesystem::path(LIBCLANG_LIBRARY_DIR) / "clang", ec), end; it != end; ++it) { 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)) if(boost::filesystem::is_directory(it->path() / "include", ec))

Loading…
Cancel
Save