From: Vsevolod Stakhov Date: Mon, 21 Oct 2019 14:35:20 +0000 (+0100) Subject: [Minor] Clang-Plugin: Fix linking with clang X-Git-Tag: 2.1~53 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ee7bbf1c3d84d61e75504608b4b489cc1cc3afee;p=rspamd.git [Minor] Clang-Plugin: Fix linking with clang Submitted by: @citrin --- diff --git a/clang-plugin/CMakeLists.txt b/clang-plugin/CMakeLists.txt index 5b81a7dc5..3a0b8ab8b 100644 --- a/clang-plugin/CMakeLists.txt +++ b/clang-plugin/CMakeLists.txt @@ -1,4 +1,6 @@ + IF (ENABLE_CLANG_PLUGIN MATCHES "ON") + cmake_minimum_required(VERSION 3.9) # Clang plugin for static analysis PROJECT(RspamdClangPlugin) if (NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") @@ -11,39 +13,29 @@ IF (ENABLE_CLANG_PLUGIN MATCHES "ON") INCLUDE_DIRECTORIES(${LLVM_INCLUDE_DIRS}) ADD_DEFINITIONS(${LLVM_DEFINITIONS}) - find_path(LIBCLANG_INCLUDE_DIR clang-c/Index.h - PATHS ${LLVM_INCLUDE_DIRS} - DOC "The path to the directory that contains clang-c/Index.h") - - find_library(LIBCLANG_LIBRARY - NAMES - libclang - clang - PATHS ${LLVM_LIBRARY_DIRS} - DOC "The file that corresponds to the libclang library.") - - get_filename_component(LIBCLANG_LIBRARY_DIR ${LIBCLANG_LIBRARY} PATH) - - set(LIBCLANG_LIBRARIES ${LIBCLANG_LIBRARY}) - set(LIBCLANG_INCLUDE_DIRS ${LIBCLANG_INCLUDE_DIR}) - - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(LibClang DEFAULT_MSG - LIBCLANG_LIBRARY LIBCLANG_INCLUDE_DIR) - - mark_as_advanced(LIBCLANG_INCLUDE_DIR LIBCLANG_LIBRARY) - - if (NOT LIBCLANG_FOUND) - MESSAGE(FATAL_ERROR "Libclang is required to build clang plugin") - endif() + find_package(Clang REQUIRED) + include_directories(${CLANG_INCLUDE_DIRS}) SET(CLANGPLUGINSRC plugin.cc printf_check.cc) ADD_LIBRARY(rspamd-clang SHARED ${CLANGPLUGINSRC}) SET_TARGET_PROPERTIES(rspamd-clang PROPERTIES - COMPILE_FLAGS "${LLVM_CPP_FLAGS} -O2 -Wall -Wextra -Wno-unused-parameter -Werror" - INCLUDE_DIRECTORIES ${LIBCLANG_INCLUDE_DIR} + COMPILE_FLAGS "-O2 -Wall -Wextra -Wno-unused-parameter -Werror" LINKER_LANGUAGE CXX) - TARGET_LINK_LIBRARIES(rspamd-clang ${LIBCLANG_LIBRARIES}) - LINK_DIRECTORIES(${LLVM_LIBRARY_DIRS}) + set_property(TARGET rspamd-clang APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--no-undefined -Wl,--as-needed") + + find_library(found_LLVM LLVM HINTS ${LLVM_LIBRARY_DIRS}) + if(found_LLVM) + target_link_libraries(rspamd-clang PRIVATE LLVM) + else() + # XXX not tested yet + llvm_map_components_to_libnames(llvm_libs support core) + target_link_libraries(rspamd-clang PRIVATE ${llvm_libs}) + endif() + + set(clang_libs + clangAST + clangBasic + clangFrontend) + target_link_libraries(rspamd-clang PRIVATE ${clang_libs}) ENDIF()