-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
126 lines (106 loc) · 4.26 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
cmake_minimum_required(VERSION 2.8)
project(cheritrace)
set(cheritrace_VERSION 0.1)
file(GLOB cheritrace_CXX_SRCS "*.cc")
file(GLOB cheritrace_HDRS "*.hh")
set(LLVM_LIBS
Mips debuginfodwarf mc mcparser mcdisassembler object
)
# Define the cheritrace program that we will build
add_library(cheritrace SHARED ${cheritrace_CXX_SRCS})
add_library(cheritrace-static STATIC ${cheritrace_CXX_SRCS})
set_target_properties(cheritrace-static PROPERTIES
POSITION_INDEPENDENT_CODE true
OUTPUT_NAME cheritrace)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-zero-length-array")
find_program(LLVM_CONFIG NAMES llvm-config DOC "Path to llvm-config utility")
if (${LLVM_CONFIG} STREQUAL "LLVM_CONFIG-NOTFOUND")
message(SEND_ERROR "llvm-config not found, please manually set path with -DLLVM_CONFIG")
endif()
message(STATUS "Using llvm-config: ${LLVM_CONFIG}")
# Define LLVM version macros so that we can support multiple versions in the source.
execute_process(COMMAND ${LLVM_CONFIG} --version
OUTPUT_VARIABLE LLVM_VER
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVM_CONFIG} --cxxflags
OUTPUT_VARIABLE LLVM_CXXFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVM_CONFIG} --libs ${LLVM_LIBS}
OUTPUT_VARIABLE LLVM_LIBS_FLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVM_CONFIG} --ldflags
OUTPUT_VARIABLE LLVM_LDFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVM_CONFIG} --system-libs
OUTPUT_VARIABLE LLVM_SYSTEMLIBS
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX REPLACE "([0-9]*).([0-9]*).*" "-DLLVM_MAJOR=\\1 -DLLVM_MINOR=\\2" LLVM_VERSION "${LLVM_VER}")
string(REGEX REPLACE "-l/usr/lib/libexecinfo.so" "-lexecinfo" LLVM_SYSTEMLIBS "${LLVM_SYSTEMLIBS}")
# Ensure that all system-libs are prefixed by -l correctly
separate_arguments(LLVM_SYSTEMLIBS)
set(LLVM_SYSTEMLIBS_NORMALIZED "")
set(LLVM_EXTRA_LINK_DIRECTORIES)
foreach (lib ${LLVM_SYSTEMLIBS})
# if the argument does not start with -l and is an absolute path we have to fix it
if (NOT lib MATCHES "^-l" AND lib MATCHES "^/")
# extract libXXX.so name
string(REGEX MATCH "lib[a-zA-Z0-9]+.so" libname ${lib})
# extract name without lib or .so
string(REGEX REPLACE "lib([a-zA-Z09]+).so" "\\1" name ${libname})
# extract base path
string(REGEX REPLACE "/${libname}" "" libpath ${lib})
list(APPEND LLVM_EXTRA_LINK_DIRECTORIES ${libpath})
list(APPEND LLVM_SYSTEMLIBS_NORMALIZED "-l${name}")
else ()
list(APPEND LLVM_SYSTEMLIBS_NORMALIZED "${lib}")
endif ()
endforeach ()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
string(REPLACE "-DNDEBUG" "" LLVM_CXXFLAGS "${LLVM_CXXFLAGS}")
endif ()
FIND_PACKAGE(LibLZMA REQUIRED)
include_directories(SYSTEM ${LibLZMA_INCLUDE_DIRS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CXXFLAGS} ${LLVM_VERSION} ${BOOST_CXX_FLAGS}")
target_link_directories(cheritrace PUBLIC
${LLVM_EXTRA_LINK_DIRECTORIES})
target_link_libraries(cheritrace
${LLVM_LDFLAGS}
${LLVM_LIBS_FLAGS}
${LLVM_SYSTEMLIBS_NORMALIZED}
${LIBLZMA_LIBRARIES})
set(CMAKE_SKIP_RPATH true)
option(BUILD_DOCUMENTATION "Use Doxygen to create the HTML based API documentation" OFF)
if(BUILD_DOCUMENTATION)
FIND_PACKAGE(Doxygen)
if (NOT DOXYGEN_FOUND)
message(FATAL_ERROR
"Doxygen is needed to build the documentation. Please install it correctly")
endif()
#-- Configure the Template Doxyfile for our specific project
configure_file(Doxyfile.in
${PROJECT_BINARY_DIR}/Doxyfile @ONLY IMMEDIATE)
#-- Add a custom target to run Doxygen when ever the project is built
add_custom_target (Docs ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
endif()
set(TESTS TRUE CACHE BOOL "Enable building the tests")
if (TESTS)
enable_testing()
add_subdirectory(Tests)
endif ()
add_subdirectory(Tools)
option(PYTHON_BINDINGS "Build python bindings" ON)
if (PYTHON_BINDINGS)
add_subdirectory(Python)
endif ()
if (NOT CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR lib)
endif ()
set(INSTALL_TARGETS cheritrace)
list(APPEND INSTALL_TARGETS cheritrace-static)
install(TARGETS ${INSTALL_TARGETS}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${cheritrace_HDRS}
DESTINATION "include/cheritrace")