Browse Source

Congratulations to Tea Deliverers

pull/517/head 0.20180513.1
Fangrui Song 7 years ago
parent
commit
f9e1e8cbdc
  1. 5
      CMakeLists.txt
  2. 13
      cmake/FindClang.cmake
  3. 37
      src/filesystem.cc

5
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)

13
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()

37
src/filesystem.cc

@ -5,23 +5,20 @@ using namespace llvm;
#include <utility>
static void GetFilesInFolderHelper(
std::string folder,
bool recursive,
std::string output_prefix,
const std::function<void(const std::string&)>& handler) {
void GetFilesInFolder(std::string folder,
bool recursive,
bool dir_prefix,
const std::function<void(const std::string&)>& 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<void(const std::string&)>& handler) {
EnsureEndsInSlash(folder);
GetFilesInFolderHelper(folder, recursive, add_folder_to_path ? folder : "",
handler);
}

Loading…
Cancel
Save