From ddd53d98fb400b43186652729db152e5399e1c04 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 19 Jun 2023 16:17:36 +0200 Subject: [PATCH] Improved resource path detection on systems without clang/clang++ installed --- CMakeLists.txt | 4 +--- src/compile_commands.cpp | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85d7af1..a45fc95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,9 +100,7 @@ else() find_package(LibClang REQUIRED) endif() -if(APPLE) - add_definitions(-DLIBCLANG_LIBRARY_DIR="${LIBCLANG_LIBRARY_DIR}") -endif() +add_definitions(-DLIBCLANG_LIBRARY_DIR="${LIBCLANG_LIBRARY_DIR}") set(BUILD_TESTING_SAVED ${BUILD_TESTING}) set(BUILD_TESTING OFF CACHE BOOL "Disable sub-project tests" FORCE) diff --git a/src/compile_commands.cpp b/src/compile_commands.cpp index b597012..0c3adc4 100644 --- a/src/compile_commands.cpp +++ b/src/compile_commands.cpp @@ -107,14 +107,22 @@ std::vector CompileCommands::get_arguments(const boost::filesystem: } #else static auto resource_path = []() -> std::string { - std::stringstream stdin_stream, stdout_stream; - auto exit_status = Terminal::get().process(stdin_stream, stdout_stream, "clang++ -print-resource-dir"); - if(exit_status != 0) - return {}; - auto path = stdout_stream.str(); - if(!path.empty()) - path.pop_back(); - return path; + if(!filesystem::find_executable("clang++").empty()) { + std::stringstream stdin_stream, stdout_stream; + auto exit_status = Terminal::get().process(stdin_stream, stdout_stream, "clang++ -print-resource-dir"); + if(exit_status != 0) + return {}; + auto path = stdout_stream.str(); + if(!path.empty()) + path.pop_back(); + return path; + } + else { + boost::system::error_code ec; + for(boost::filesystem::directory_iterator it(boost::filesystem::path(LIBCLANG_LIBRARY_DIR) / "clang", ec), end; it != end; ++it) + return it->path().string(); + } + return {}; }(); if(!resource_path.empty()) { arguments.emplace_back("-resource-dir");