From f9e1e8cbdc88a4be614c34a9a4b3ae097c890ad3 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 13 May 2018 19:09:26 -0700 Subject: [PATCH] Congratulations to Tea Deliverers --- CMakeLists.txt | 5 +---- cmake/FindClang.cmake | 13 +++++++++---- src/filesystem.cc | 37 +++++++++++-------------------------- 3 files changed, 21 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 010258ad..05aa3e0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ option(SYSTEM_CLANG "Use system installation of Clang instead of \ downloading Clang" OFF) option(ASAN "Compile with address sanitizers" OFF) option(CLANG_USE_BUNDLED_LIBC++ "Let Clang use bundled libc++" OFF) +option(USE_SHARED_LLVM "Link against libLLVM.so instead separate LLVM{Option,Support,...}" OFF) # Sources for the executable are specified at end of CMakeLists.txt add_executable(ccls "") @@ -105,11 +106,7 @@ endif() # See cmake/FindClang.cmake find_package(Clang ${CLANG_VERSION} REQUIRED) -find_package(Curses REQUIRED) target_link_libraries(ccls PRIVATE Clang::Clang) -if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL Windows) - target_link_libraries(ccls PRIVATE Clang::Clang ${CURSES_LIBRARIES}) -endif() # Enable threading support set(THREADS_PREFER_PTHREAD_FLAG ON) diff --git a/cmake/FindClang.cmake b/cmake/FindClang.cmake index 9524ca23..cc808ccc 100644 --- a/cmake/FindClang.cmake +++ b/cmake/FindClang.cmake @@ -71,9 +71,13 @@ set(_Clang_REQUIRED_VARS Clang_LIBRARY Clang_INCLUDE_DIR Clang_EXECUTABLE _Clang_find_library(Clang_LIBRARY clang) _Clang_find_add_library(clangDriver) _Clang_find_add_library(clangBasic) -_Clang_find_add_library(LLVMOption) -_Clang_find_add_library(LLVMSupport) -_Clang_find_add_library(LLVMDemangle) +if(USE_SHARED_LLVM) + _Clang_find_add_library(LLVM) +else() + _Clang_find_add_library(LLVMOption) + _Clang_find_add_library(LLVMSupport) + _Clang_find_add_library(LLVMDemangle) +endif() _Clang_find_path(Clang_INCLUDE_DIR clang-c/Index.h) _Clang_find_path(Clang_BUILD_INCLUDE_DIR clang/Driver/Options.inc) _Clang_find_path(LLVM_INCLUDE_DIR llvm/PassInfo.h) @@ -113,5 +117,6 @@ if(Clang_FOUND AND NOT TARGET Clang::Clang) IMPORTED_LOCATION ${Clang_LIBRARY} INTERFACE_INCLUDE_DIRECTORIES "${Clang_INCLUDE_DIR};${Clang_BUILD_INCLUDE_DIR};${LLVM_INCLUDE_DIR};${LLVM_BUILD_INCLUDE_DIR}") - set_property(TARGET Clang::Clang PROPERTY INTERFACE_LINK_LIBRARIES ${_Clang_LIBRARIES}) + find_package(Curses REQUIRED) + set_property(TARGET Clang::Clang PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES "${_Clang_LIBRARIES};${CURSES_LIBRARIES}") endif() diff --git a/src/filesystem.cc b/src/filesystem.cc index f9d31004..1b343b14 100644 --- a/src/filesystem.cc +++ b/src/filesystem.cc @@ -5,23 +5,20 @@ using namespace llvm; #include -static void GetFilesInFolderHelper( - std::string folder, - bool recursive, - std::string output_prefix, - const std::function& handler) { +void GetFilesInFolder(std::string folder, + bool recursive, + bool dir_prefix, + const std::function& handler) { + EnsureEndsInSlash(folder); std::error_code ec; if (recursive) for (sys::fs::recursive_directory_iterator I(folder, ec), E; I != E && !ec; I.increment(ec)) { std::string path = I->path(), filename = sys::path::filename(path); if (filename[0] != '.' || filename == ".ccls") { - SmallString<256> Path; - if (output_prefix.size()) { - sys::path::append(Path, output_prefix, path); - handler(Path.str()); - } else - handler(path); + if (!dir_prefix) + path = path.substr(folder.size()); + handler(path); } } else @@ -29,21 +26,9 @@ static void GetFilesInFolderHelper( I.increment(ec)) { std::string path = I->path(), filename = sys::path::filename(path); if (filename[0] != '.' || filename == ".ccls") { - SmallString<256> Path; - if (output_prefix.size()) { - sys::path::append(Path, output_prefix, path); - handler(Path.str()); - } else - handler(path); + if (!dir_prefix) + path = path.substr(folder.size()); + handler(path); } } } - -void GetFilesInFolder(std::string folder, - bool recursive, - bool add_folder_to_path, - const std::function& handler) { - EnsureEndsInSlash(folder); - GetFilesInFolderHelper(folder, recursive, add_folder_to_path ? folder : "", - handler); -}