aboutsummaryrefslogtreecommitdiffstats
path: root/clang-plugin
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-10-21 15:35:20 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-10-21 15:35:20 +0100
commitee7bbf1c3d84d61e75504608b4b489cc1cc3afee (patch)
treec1ec022666b231221feac0a3e373380dc44110b4 /clang-plugin
parent66468690e6caa0ada83d1d6707d3c58b1487ea87 (diff)
downloadrspamd-ee7bbf1c3d84d61e75504608b4b489cc1cc3afee.tar.gz
rspamd-ee7bbf1c3d84d61e75504608b4b489cc1cc3afee.zip
[Minor] Clang-Plugin: Fix linking with clang
Submitted by: @citrin
Diffstat (limited to 'clang-plugin')
-rw-r--r--clang-plugin/CMakeLists.txt50
1 files changed, 21 insertions, 29 deletions
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()