diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fe920cd..84334a9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,11 +85,12 @@ if(NOT SYSTEM_CLANG) if(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang AND CLANG_USE_BUNDLED_LIBC++) message(STATUS "Using bundled libc++") - target_compile_options(ccls PRIVATE -stdlib=libc++) - target_include_directories(ccls PRIVATE ${CLANG_ROOT}/include/c++/v1) - target_link_libraries(ccls PRIVATE ${CLANG_ROOT}/lib/libc++.a - ${CLANG_ROOT}/lib/libc++abi.a - ${CLANG_ROOT}/lib/libc++experimental.a) + target_compile_options(ccls PRIVATE -nostdinc++ -cxx-isystem ${CLANG_ROOT}/include/c++/v1) + target_link_libraries(ccls PRIVATE -stdlib=libc++ -L${CLANG_ROOT}/lib -lc++experimental) + if(${CMAKE_SYSTEM_NAME} STREQUAL Linux) + # FreeBSD uses system libcxxrt.a and does not need libc++abi. + target_link_libraries(ccls PRIVATE c++abi) + endif() endif() else() @@ -107,15 +108,13 @@ set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) target_link_libraries(ccls PRIVATE Threads::Threads) -if(${CMAKE_SYSTEM_NAME} STREQUAL Linux) - target_link_libraries(ccls PRIVATE -lstdc++fs) -elseif(MSVC) -else() - # e.g. Darwin, FreeBSD +if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin) target_link_libraries(ccls PRIVATE -lc++experimental) -endif() -if(${CMAKE_SYSTEM_NAME} STREQUAL Linux) +elseif(${CMAKE_SYSTEM_NAME} STREQUAL Linux) + if(NOT CLANG_USE_BUNDLED_LIBC++) + target_link_libraries(ccls PRIVATE -lstdc++fs) + endif() # loguru calls dladdr target_link_libraries(ccls PRIVATE ${CMAKE_DL_LIBS}) @@ -125,6 +124,9 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD) # src/platform_posix.cc uses libthr find_package(Backtrace REQUIRED) target_link_libraries(ccls PRIVATE ${Backtrace_LIBRARIES} kvm thr) + if(SYSTEM_CLANG) + target_link_libraries(ccls PRIVATE c++experimental) + endif() elseif(${CMAKE_SYSTEM_NAME} STREQUAL Windows) # sparsepp/spp_memory.h uses LibPsapi diff --git a/src/fuzzy_match.cc b/src/fuzzy_match.cc index 49b45de1..1d5d6058 100644 --- a/src/fuzzy_match.cc +++ b/src/fuzzy_match.cc @@ -121,7 +121,7 @@ int FuzzyMatcher::Match(std::string_view text) { pat[i] == text[j])) ? std::max(pre[j][0] + MatchScore(i, j, false), pre[j][1] + MatchScore(i, j, true)) - : cur[j + 1][1] = kMinScore * 2; + : kMinScore * 2; } } diff --git a/src/port.h b/src/port.h index d50e597b..da3da313 100644 --- a/src/port.h +++ b/src/port.h @@ -12,6 +12,8 @@ #ifdef __clang__ #define GUARDED_BY(x) __attribute__((guarded_by(x))) +#else +#define GUARDED_BY(x) #endif // TODO GCC diff --git a/src/project.cc b/src/project.cc index df568423..77a8273d 100644 --- a/src/project.cc +++ b/src/project.cc @@ -69,7 +69,7 @@ std::vector kBlacklist = { // Arguments which are followed by a potentially relative path. We need to make // all relative paths absolute, otherwise libclang will not resolve them. std::vector kPathArgs = { - "-I", "-iquote", "-isystem", "--sysroot=", + "-I", "-iquote", "-cxx-isystem", "-isystem", "--sysroot=", "-isysroot", "-gcc-toolchain", "-include-pch", "-iframework", "-F", "-imacros", "-include", "/I", "-idirafter"}; @@ -82,7 +82,7 @@ std::vector kNormalizePathArgs = {"--sysroot="}; // Arguments whose path arguments should be injected into include dir lookup // for #include completion. std::vector kQuoteIncludeArgs = {"-iquote", "-I", "/I"}; -std::vector kAngleIncludeArgs = {"-isystem", "-I", "/I"}; +std::vector kAngleIncludeArgs = {"-cxx-isystem", "-isystem", "-I", "/I"}; bool ShouldAddToQuoteIncludes(const std::string& arg) { return StartsWithAny(arg, kQuoteIncludeArgs); @@ -152,16 +152,6 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( for (; i < args.size(); ++i) { std::string arg = args[i]; - // If blacklist skip. - if (!next_flag_is_path) { - if (StartsWithAny(arg, kBlacklistMulti)) { - ++i; - continue; - } - if (StartsWithAny(arg, kBlacklist)) - continue; - } - // Finish processing path for the previous argument, which was a switch. // {"-I", "foo"} style. if (next_flag_is_path) { @@ -177,6 +167,12 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( add_next_flag_to_quote_dirs = false; add_next_flag_to_angle_dirs = false; } else { + // If blacklist skip. + if (StartsWithAny(arg, kBlacklistMulti)) { + i++; + continue; + } + // Check to see if arg is a path and needs to be updated. for (const std::string& flag_type : kPathArgs) { // {"-I", "foo"} style. @@ -184,7 +180,7 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( next_flag_is_path = true; add_next_flag_to_quote_dirs = ShouldAddToQuoteIncludes(arg); add_next_flag_to_angle_dirs = ShouldAddToAngleIncludes(arg); - break; + goto done; } // {"-Ifoo"} style. @@ -198,10 +194,13 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( config->quote_dirs.insert(path); if (ShouldAddToAngleIncludes(flag_type)) config->angle_dirs.insert(path); - break; + goto done; } } + if (StartsWithAny(arg, kBlacklist)) + continue; + // This is most likely the file path we will be passing to clang. The // path needs to be absolute, otherwise clang_codeCompleteAt is extremely // slow. See @@ -215,6 +214,7 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( continue; } + done: result.args.push_back(arg); } diff --git a/src/query.cc b/src/query.cc index 49b7a893..036f85e2 100644 --- a/src/query.cc +++ b/src/query.cc @@ -5,13 +5,12 @@ #include "serializers/json.h" #include -#include #include #include #include #include -#include +#include #include #include #include