-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
63 lines (46 loc) · 2.04 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
54
55
56
57
58
59
60
61
62
63
cmake_minimum_required(VERSION 3.2)
project("ub-tester-tool")
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(UB_EXE ub-tester)
set(UB_INCLUDE include)
set(UB_SRC src)
set_property(GLOBAL PROPERTY GET_TOGETHER)
function(ADD_SOURCE)
get_property(tmp GLOBAL PROPERTY GET_TOGETHER)
list(APPEND tmp ${ARGV})
set_property(GLOBAL PROPERTY GET_TOGETHER ${tmp})
endfunction(ADD_SOURCE)
add_subdirectory(${UB_SRC})
get_property(ALL_SOURCES GLOBAL PROPERTY GET_TOGETHER)
add_executable(${UB_EXE} ${ALL_SOURCES})
target_link_libraries(${UB_EXE}
LLVMSupport
clangTooling
clangBasic
)
target_link_libraries(${UB_EXE} stdc++fs pthread z dl)
endif()