From 7381df3bdd9e1f654fa424e19b285de7922c1a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Fri, 1 Nov 2019 10:02:57 +0100 Subject: [PATCH] Fix builds for LLVM 9 (for LLVM build without BUILD_SHARED_LIBS=ON) LLVM 9 officially ships the C++ libraries as a single library libclang-cpp.so. This makes ccls fail to link as the individual libraries libclangIndex, libclangFormat, etc. are no longer present. We use clang-cpp if it is available and fallback to the previously used behavior if clang-cpp is not available. --- CMakeLists.txt | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 278e0735..fe6f8f70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,23 +68,33 @@ endif() ### Libraries +# LLVM >= 9 ships the C++ libraries by default in a single library libclang-cpp, +# but this is not universally enabled on all distributions. +# If clang-cpp is available, then link against it, otherwise link against the +# individual clang libraries. find_package(Clang REQUIRED) -target_link_libraries(ccls PRIVATE - clangIndex - clangFormat - clangTooling - clangToolingInclusions - clangToolingCore - clangFrontend - clangParse - clangSerialization - clangSema - clangAST - clangLex - clangDriver - clangBasic -) +if(TARGET clang-cpp AND NOT TARGET clangBasic) + target_link_libraries(ccls PRIVATE + clang-cpp + ) +else() + target_link_libraries(ccls PRIVATE + clangIndex + clangFormat + clangTooling + clangToolingInclusions + clangToolingCore + clangFrontend + clangParse + clangSerialization + clangSema + clangAST + clangLex + clangDriver + clangBasic + ) +endif() if(LLVM_LINK_LLVM_DYLIB) target_link_libraries(ccls PRIVATE LLVM)