From 6cff79d377b4dc5e914873f008d3c6f1ec74ddf2 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Wed, 2 Sep 2020 10:30:37 +0200 Subject: [PATCH] CMake build: Support building clang tooling without static libs Create a FindClang.cmake and move all Clang configuration there. Find Clang and choose static libraries if available, otherwise use clang-cpp if available. Add option to link to clang-cpp even if static libraries are available. Fixes: QTCREATORBUG-23172 Change-Id: If40304d174469df0c786259e724cbee8de0e2d0e Reviewed-by: Cristian Adam --- CMakeLists.txt | 14 ++------------ cmake/FindClang.cmake | 14 ++++++++++++++ src/tools/clangpchmanagerbackend/CMakeLists.txt | 3 ++- .../clangrefactoringbackend/source/CMakeLists.txt | 5 +---- 4 files changed, 19 insertions(+), 17 deletions(-) create mode 100644 cmake/FindClang.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index d4cd30b44e1..48770a54831 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,12 +43,11 @@ find_package(Qt5 QuickWidgets Sql Widgets Xml ${QT_TEST_COMPONENT} REQUIRED ) - find_package(Qt5 COMPONENTS LinguistTools) +find_package(Qt5 COMPONENTS Designer DesignerComponents Help SerialPort Svg QUIET) find_package(Threads) - -find_package(Qt5 COMPONENTS Designer DesignerComponents Help SerialPort Svg QUIET) +find_package(Clang QUIET) function (set_if_target var target) if (TARGET "${target}") @@ -75,15 +74,6 @@ else() endif() install(TARGETS OptionalSvg EXPORT QtCreator) -find_package(Clang COMPONENTS libclang QUIET) -# silence a lot of warnings from building against llvm -# this would better fit inside a central libclang detection/include cmake file, but since we do not -# have one put it temporary here -if(MSVC AND TARGET libclang) - target_compile_options(libclang INTERFACE /wd4100 /wd4141 /wd4146 /wd4244 /wd4267 /wd4291) -endif() -find_package(LLVM QUIET) - if (APPLE) find_library(FWCoreFoundation CoreFoundation) find_library(FWCoreServices CoreServices) diff --git a/cmake/FindClang.cmake b/cmake/FindClang.cmake new file mode 100644 index 00000000000..0e1f5db36c6 --- /dev/null +++ b/cmake/FindClang.cmake @@ -0,0 +1,14 @@ +find_package(Clang CONFIG) + +# silence a lot of warnings from building against llvm +if(MSVC AND TARGET libclang) + target_compile_options(libclang INTERFACE /wd4100 /wd4141 /wd4146 /wd4244 /wd4267 /wd4291) +endif() + +option(CLANGTOOLING_LINK_CLANG_DYLIB "Force linking of Clang tooling against clang-cpp" NO) + +if (TARGET clangTooling AND NOT CLANGTOOLING_LINK_CLANG_DYLIB) + set(CLANG_TOOLING_LIBS libclang clangTooling clangQuery clangIndex) +elseif (TARGET clang-cpp) + set(CLANG_TOOLING_LIBS libclang clang-cpp) +endif() diff --git a/src/tools/clangpchmanagerbackend/CMakeLists.txt b/src/tools/clangpchmanagerbackend/CMakeLists.txt index 965ef441bdb..cdbc111bab1 100644 --- a/src/tools/clangpchmanagerbackend/CMakeLists.txt +++ b/src/tools/clangpchmanagerbackend/CMakeLists.txt @@ -3,7 +3,8 @@ add_subdirectory(source) add_qtc_executable(clangpchmanagerbackend DEPENDS clangrefactoringbackend_lib clangpchmanagerbackend_lib - clangTooling libclang Sqlite ClangSupport clangQuery clangIndex + Sqlite ClangSupport + ${CLANG_TOOLING_LIBS} SOURCES clangpchmanagerbackendmain.cpp ) diff --git a/src/tools/clangrefactoringbackend/source/CMakeLists.txt b/src/tools/clangrefactoringbackend/source/CMakeLists.txt index f06ddee1cc6..06d606cae82 100644 --- a/src/tools/clangrefactoringbackend/source/CMakeLists.txt +++ b/src/tools/clangrefactoringbackend/source/CMakeLists.txt @@ -1,10 +1,7 @@ add_qtc_library(clangrefactoringbackend_lib STATIC PUBLIC_DEPENDS Threads::Threads - LLVMCore libclang - clangAST clangASTMatchers clangBasic clangDynamicASTMatchers clangFrontend - clangHandleCXX clangIndex clangLex - clangSerialization clangTooling clangQuery + ${CLANG_TOOLING_LIBS} ClangSupport PUBLIC_DEFINES CLANGSUPPORT_BUILD_LIB PUBLIC_INCLUDES