]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Clang-Plugin: Fix linking with clang
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 21 Oct 2019 14:35:20 +0000 (15:35 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 21 Oct 2019 14:35:20 +0000 (15:35 +0100)
Submitted by: @citrin

clang-plugin/CMakeLists.txt

index 5b81a7dc5e54eaf2e6030a2d4e5aa070db279ef7..3a0b8ab8b794d6df0b91531a765f0214873bc388 100644 (file)
@@ -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()