forked from JonathanSalwan/Triton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
196 lines (166 loc) · 5.91 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
##
## Copyright (C) - Triton
##
## This program is under the terms of the BSD License.
##
##################################################################################### CMake libtriton
cmake_minimum_required(VERSION 2.8)
project(triton)
# Define cmake options
option(ASAN "Enable the ASAN linking" OFF)
option(GCOV "Enable code coverage" OFF)
option(KERNEL4 "Pin will run on a Linux's kernel v4" ON)
option(PINTOOL "Build Triton with the Pin tool as tracer" OFF)
option(PYTHON36 "Python 36" ON)
option(PYTHON_BINDINGS "Enable Python bindings into the libtriton" ON)
option(PYTHON_BINDINGS_AUTOCOMPLETE "Enable the generation of a triton_autocomplete module for IDE autocompletion" OFF)
option(STATICLIB "Build a static library" OFF)
option(Z3_INTERFACE "Use Z3 as SMT solver" ON)
if(STATICLIB)
# We can't use Python bindings with a static library
set(PYTHON_BINDINGS OFF)
endif()
if(PINTOOL AND NOT PYTHON_BINDINGS)
MESSAGE(FATAL_ERROR "You can't have pintools without python binding.")
endif()
if(PINTOOL AND PYTHON36)
MESSAGE(FATAL_ERROR "The Pin tracer needs Python 2.7.")
endif()
set(TRITON_ROOT "${CMAKE_CURRENT_LIST_DIR}")
#Enable ctest
include(CTest)
set(PYTHONPATH_CMD ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/src/libtriton/${CMAKE_CFG_INTDIR}/)
if(PYTHON_BINDINGS)
if(PYTHON36)
set(PYTHON_VERSION 3.6)
else()
set(PYTHON_VERSION 2.7)
endif()
find_package(PythonInterp ${PYTHON_VERSION} REQUIRED)
add_custom_target(test-python
COMMAND ${PYTHONPATH_CMD} ${PYTHON_EXECUTABLE} -m unittest discover ${TRITON_ROOT}/src/testers/unittests
DEPENDS python-triton
)
else()
add_custom_target(test-python
COMMAND echo "No python test as python support is disabled"
)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(GCOV)
add_custom_target(check
COMMAND lcov --zerocounters --directory ${CMAKE_BINARY_DIR}/src/libtriton
COMMAND lcov --capture --initial --directory ${CMAKE_BINARY_DIR}/src/libtriton --output-file app
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target test-python
COMMAND ${PYTHONPATH_CMD} ${TRITON_ROOT}/src/scripts/run_linux_test.sh
COMMAND lcov --no-checksum --directory ${CMAKE_BINARY_DIR}/src/libtriton --capture --output-file coverage.info
COMMAND lcov --remove coverage.info '/usr*' --remove coverage.info 'pintools*' --remove coverage.info 'examples*' -o coverage.info
COMMAND genhtml coverage.info -o coverage
COMMAND ${CMAKE_COMMAND} -E echo "-- Report generated in ${CMAKE_CURRENT_BINARY_DIR}/coverage/index.html"
)
else()
# Special handling of Linux test to check if pin can be attached on other binaries.
add_custom_target(check
COMMAND ${PYTHONPATH_CMD} ${TRITON_ROOT}/src/scripts/run_linux_test.sh
DEPENDS test-python
)
endif()
else()
add_custom_target(check
COMMAND ${PYTHONPATH_CMD} ctest --output-on-failure
DEPENDS test-python
)
endif()
# Defaut build type as Release
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release)
endif()
if(GCOV)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 --coverage")
endif()
# Specific OSX POLICY
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if(POLICY CMP0025)
cmake_policy(SET CMP0025 OLD) # report Apple's Clang as just Clang
endif()
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW) # MACOSX_RPATH
endif()
endif()
# Get architecture
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCHITECTURE amd64)
else()
set(ARCHITECTURE i386)
endif()
if(${TARGET} MATCHES "ia32")
set(ARCHITECTURE i386)
endif()
# Read the build version
file(READ ${TRITON_ROOT}/.build_number BUILD_NUMBER)
set(VERSION_MAJOR 0)
set(VERSION_MINOR 8)
set(VERSION_BUILD ${BUILD_NUMBER})
# Custom cmake search
list(APPEND CMAKE_MODULE_PATH "${TRITON_ROOT}/CMakeModules/")
# Find Python
if(PYTHON_BINDINGS)
find_package(PythonInterp ${PYTHON_VERSION} REQUIRED)
if(NOT PYTHON_INCLUDE_DIRS)
set(PYTHON_INCLUDE_DIRS "$ENV{PYTHON_INCLUDE_DIRS}")
endif()
if(NOT PYTHON_LIBRARIES)
set(PYTHON_LIBRARIES "$ENV{PYTHON_LIBRARIES}")
endif()
if(NOT PYTHON_INCLUDE_DIRS AND NOT PYTHON_LIBRARIES)
find_package(PythonLibs ${PYTHON_VERSION} REQUIRED)
elseif(NOT (PYTHON_INCLUDE_DIRS AND PYTHON_LIBRARIES))
message(FATAL_ERROR "Inconsistent PYTHON_INCLUDE_DIRS and PYTHON_LIBRARIES")
endif()
include_directories(${PYTHON_INCLUDE_DIRS})
add_definitions("-DPYTHON_LIBRARIES=\"${PYTHON_LIBRARIES}\"")
endif()
# Find Z3
if(Z3_INTERFACE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DZ3_INTERFACE")
if(NOT Z3_INCLUDE_DIRS)
set(Z3_INCLUDE_DIRS "$ENV{Z3_INCLUDE_DIRS}")
endif()
if(NOT Z3_LIBRARIES)
set(Z3_LIBRARIES "$ENV{Z3_LIBRARIES}")
endif()
if(NOT Z3_INCLUDE_DIRS AND NOT Z3_LIBRARIES)
find_package(Z3 REQUIRED)
if(NOT Z3_FOUND)
message(FATAL_ERROR "Z3 not found")
endif()
endif()
include_directories(${Z3_INCLUDE_DIRS})
set(TRITON_Z3_INTERFACE ON)
endif()
# Find Capstone
if(NOT CAPSTONE_INCLUDE_DIRS)
set(CAPSTONE_INCLUDE_DIRS "$ENV{CAPSTONE_INCLUDE_DIRS}")
endif()
if(NOT CAPSTONE_LIBRARIES)
set(CAPSTONE_LIBRARIES "$ENV{CAPSTONE_LIBRARIES}")
endif()
if(NOT CAPSTONE_INCLUDE_DIRS AND NOT CAPSTONE_LIBRARIES)
find_package(CAPSTONE REQUIRED)
if(NOT CAPSTONE_FOUND)
message(FATAL_ERROR "Capstone not found")
endif()
endif()
include_directories(${CAPSTONE_INCLUDE_DIRS})
# Find boost
find_package(Boost 1.55.0 REQUIRED)
include_directories("${Boost_INCLUDE_DIRS}")
# Use the same ABI as pin
if(PINTOOL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
endif()
# Add triton includes for every project
include_directories("${TRITON_ROOT}/src/libtriton/includes")
set(PROJECT_LIBTRITON "triton")
add_subdirectory(src)
add_subdirectory(doc)