blob: 62a1d68f51f4fcb59e31ec3a066cbc6ba08857a0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
IF (ENABLE_CLANG_PLUGIN MATCHES "ON")
# Clang plugin for static analysis
if (NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
MESSAGE(FATAL_ERROR "Cannot build clang plugin when compiler is not clang")
endif ()
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
ENABLE_LANGUAGE(CXX)
FIND_PACKAGE(LLVM REQUIRED)
MESSAGE(STATUS "Trying to find libclang for llvm version ${LLVM_PACKAGE_VERSION}")
SET(libclang_llvm_header_search_paths
# LLVM Debian/Ubuntu nightly packages: http://llvm.org/apt/
"/usr/lib/llvm-${LLVM_PACKAGE_VERSION}/include/"
# LLVM MacPorts
"/opt/local/libexec/llvm-${LLVM_PACKAGE_VERSION}/include"
# LLVM Homebrew
"/usr/local/Cellar/llvm/${LLVM_PACKAGE_VERSION}/include"
# LLVM Homebrew/versions
"/usr/local/lib/llvm-${LLVM_PACKAGE_VERSION}/include"
# FreeBSD ports versions
"/usr/local/llvm${LLVM_PACKAGE_VERSION}/include"
"${LLVM_INCLUDE_DIRS}"
)
SET(libclang_llvm_lib_search_paths
# LLVM Debian/Ubuntu nightly packages: http://llvm.org/apt/
"/usr/lib/llvm-${LLVM_PACKAGE_VERSION}/lib/"
# LLVM MacPorts
"/opt/local/libexec/llvm-${LLVM_PACKAGE_VERSION}/lib"
# LLVM Homebrew
"/usr/local/Cellar/llvm/${LLVM_PACKAGE_VERSION}/lib"
# LLVM Homebrew/versions
"/usr/local/lib/llvm-${LLVM_PACKAGE_VERSION}/lib"
# FreeBSD ports versions
"/usr/local/llvm${LLVM_PACKAGE_VERSION}/lib"
"${LLVM_LIBRARY_DIRS}"
)
find_path(LIBCLANG_INCLUDE_DIR clang-c/Index.h
PATHS ${libclang_llvm_header_search_paths}
PATH_SUFFIXES LLVM/include #Windows package from http://llvm.org/releases/
DOC "The path to the directory that contains clang-c/Index.h")
find_library(LIBCLANG_LIBRARY NAMES libclang.imp libclang clang
PATHS ${libclang_llvm_lib_search_paths}
PATH_SUFFIXES LLVM/lib #Windows package from http://llvm.org/releases/
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})
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}
LINKER_LANGUAGE CXX)
TARGET_LINK_LIBRARIES(rspamd-clang ${LIBCLANG_LIBRARIES})
LINK_DIRECTORIES(${LLVM_LIBRARY_DIRS})
ENDIF()
|