-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
53 lines (39 loc) · 1.9 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.2)
project("clang-tool-out-of-tree")
if ( NOT DEFINED ENV{LLVM_HOME})
message(FATAL_ERROR "$LLVM_HOME is not defined")
else()
message(STATUS "$LLVM_HOME found: $ENV{LLVM_HOME}")
set(LLVM_HOME $ENV{LLVM_HOME} CACHE PATH "Root of LLVM installation")
set(LLVM_INC ${LLVM_HOME}/include)
set(LLVM_LIB ${LLVM_HOME}/lib)
set(LLVM_BIN ${LLVM_HOME}/bin)
set(LLVM_CMAKE ${LLVM_LIB}/cmake/llvm)
find_package(LLVM REQUIRED CONFIG)
find_package(Clang REQUIRED CONFIG)
set(CMAKE_C_COMPILER ${LLVM_BIN}/clang)
set(CMAKE_CXX_COMPILER ${LLVM_BIN}/clang++)
# Generate compile_commands.json for our tool (need to run the tool with -p compile_commands.json)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
add_definitions(-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS)
# Get the Clang version within the current LLVM installation
EXECUTE_PROCESS( COMMAND ${LLVM_BIN}/clang++ --version OUTPUT_VARIABLE clang_full_version_string )
# Extract the numeric value to a string e.g 10.0.0
string (REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION_STRING ${clang_full_version_string})
# Include clang builtins they are added in compile_commands.json and thus included by our tool
include_directories(${LLVM_LIB}/clang/${CLANG_VERSION_STRING}/include)
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
set(SOURCE_FILES src/SimpleClangCheck.cpp)
add_executable(simple-clang-check ${SOURCE_FILES})
set_target_properties(simple-clang-check PROPERTIES COMPILE_FLAGS "-fno-rtti")
add_definitions(${LLVM_CXXFLAGS})
target_compile_options(simple-clang-check PUBLIC "-fPIC")
target_link_libraries(simple-clang-check
LLVMSupport
clangTooling
clangBasic
clangASTMatchers
)
target_link_libraries(simple-clang-check pthread z dl)
endif()