forked from binrats/ddisasm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
248 lines (200 loc) · 7.78 KB
/
CMakeLists.txt
File metadata and controls
248 lines (200 loc) · 7.78 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#
# Cmake Configuration
#
# Need 3.9 to support CXX_STANDARD=17 and protobuf
cmake_minimum_required(VERSION 3.9.0)
project(DDISASM)
#
# Global Options (CMake)
#
option(DDISASM_ENABLE_TESTS "Enable building and running unit tests." ON)
# This just sets the builtin BUILD_SHARED_LIBS, but if defaults to ON instead of
# OFF.
option(DDISASM_BUILD_SHARED_LIBS "Build shared libraries." ON)
option(DDISASM_USE_SYSTEM_BOOST "Use system-wide installation of Boost." OFF)
if(DDISASM_BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON)
else()
set(BUILD_SHARED_LIBS OFF)
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
if(WIN32)
set(CMAKE_DEBUG_POSTFIX
"d"
CACHE STRING "add a postfix, usually d on windows")
endif()
set(CMAKE_RELEASE_POSTFIX
""
CACHE STRING "add a postfix, usually empty on windows")
set(CMAKE_RELWITHDEBINFO_POSTFIX
""
CACHE STRING "add a postfix, usually empty on windows")
set(CMAKE_MINSIZEREL_POSTFIX
""
CACHE STRING "add a postfix, usually empty on windows")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_CXX_EXTENSIONS OFF)
# Use C++17
set(CMAKE_CXX_STANDARD 17)
# Error if it's not available
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Specifically check for gcc-7 or later. gcc-5 is installed on many systems and
# will accept -std=c++17, but does not fully support the standard.
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "7.0.0")
message(FATAL_ERROR "gcc 7 or later is required to build gtirb")
endif()
endif()
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
# If we're using libc++, we need to manually include libc++abi (unlike with
# using libstdc++, which automatically does this)
include(CheckCXXSourceCompiles)
check_cxx_source_compiles(
"
#include <ciso646>
int main() {
return _LIBCPP_VERSION;
}
"
USING_LIBCPP)
if(USING_LIBCPP)
if(BUILD_SHARED_LIBS)
find_library(LIBCPP_ABI NAMES c++abi)
else()
find_library(LIBCPP_ABI NAMES libc++abi.a)
endif()
if(NOT LIBCPP_ABI)
message(FATAL_ERROR "libc++abi not found")
endif()
endif()
# ---------------------------------------------------------------------------
# gtirb
# ---------------------------------------------------------------------------
find_package(gtirb REQUIRED)
# ---------------------------------------------------------------------------
# pretty-printer
# ---------------------------------------------------------------------------
find_package(gtirb_pprinter REQUIRED)
# ---------------------------------------------------------------------------
# libehp
# ---------------------------------------------------------------------------
find_package(ehp REQUIRED)
# ---------------------------------------------------------------------------
# DWARF
# ---------------------------------------------------------------------------
if (BUILD_SHARED_LIBS)
find_library(DWARF NAMES dwarf)
endif()
if(NOT DWARF)
message(FATAL_ERROR
" No DWARF installation found.\n")
endif()
# ---------------------------------------------------------------------------
# Boost
# ---------------------------------------------------------------------------
set(BOOST_COMPONENTS filesystem program_options system)
find_package(Boost 1.67 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
# Boost versions 1.70.0+ may use Boost's provided CMake support rather than
# CMake's internal Boost support. The former uses "Boost::boost" and so on,
# while the latter uses "Boost_BOOST" and so on. This normalizes the two cases
# to use Boost_INCLUDE_DIRS and Boost_LIBRARIES.
if(TARGET Boost::headers)
get_target_property(Boost_INCLUDE_DIRS Boost::headers
INTERFACE_INCLUDE_DIRECTORIES)
foreach(BOOST_COMPONENT ${BOOST_COMPONENTS})
list(APPEND Boost_LIBRARIES Boost::${BOOST_COMPONENT})
endforeach()
endif()
include_directories(${Boost_INCLUDE_DIRS})
# ---------------------------------------------------------------------------
# capstone
# ---------------------------------------------------------------------------
if(BUILD_SHARED_LIBS)
find_library(CAPSTONE NAMES capstone)
else()
find_library(CAPSTONE NAMES libcapstone.a)
endif()
if(NOT CAPSTONE)
message(
FATAL_ERROR
" No Capstone installation found.\n"
" - If Capstone is not installed, install it from souce.\n"
" You can get the latest version of Capstone at:\n"
" http://www.capstone-engine.org/\n"
" - If Capstone is installed, make sure the installation location is in your PATH,\n"
" and it is at least version 4.0.1.\n")
endif()
# Use LIEF with 'find_package()'
# ==============================
# Custom path to the LIEF install directory
set(LIEF_ROOT CACHE PATH ${CMAKE_INSTALL_PREFIX})
# Directory to 'FindLIEF.cmake'
list(APPEND CMAKE_MODULE_PATH ${LIEF_ROOT}/share/LIEF/cmake)
# include 'FindLIEF.cmake'
include(FindLIEF)
# Find LIEF
find_package(LIEF REQUIRED COMPONENTS STATIC)
# ---------------------------------------------------------------------------
# Google Test Application
# ---------------------------------------------------------------------------
if(DDISASM_ENABLE_TESTS)
enable_testing()
# Pull in Google Test
# https://github.com/google/googletest/tree/master/googletest#incorporating-
# into-an-existing-cmake-project
# Download and unpack googletest at configure time
configure_file(CMakeLists.googletest googletest-download/CMakeLists.txt)
execute_process(
COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download")
if(result)
message(WARNING "CMake step for googletest failed: ${result}")
endif()
execute_process(
COMMAND "${CMAKE_COMMAND}" --build .
RESULT_VARIABLE result
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download")
if(result)
message(WARNING "Build step for googletest failed: ${result}")
endif()
# Prevent overriding the parent project's compiler/linker settings on Windows
set(gtest_force_shared_crt
ON
CACHE BOOL "" FORCE)
# Add googletest directly to our build. This defines the gtest and gtest_main
# targets.
add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src"
"${CMAKE_BINARY_DIR}/googletest-build" EXCLUDE_FROM_ALL)
include_directories("${gtest_SOURCE_DIR}/include")
endif()
# ---------------------------------------------------------------------------
# source files
# ---------------------------------------------------------------------------
add_subdirectory(src)
add_subdirectory(doc)
if(DDISASM_ENABLE_TESTS)
find_program(PYTHON "python3")
add_test(
NAME python_tests
COMMAND ${PYTHON} -m unittest discover tests "*_test.py"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/")
endif()
# ---------------------------------------------------------------------------
# Package generation with cpack
# ---------------------------------------------------------------------------
set(CMAKE_PROJECT_HOMEPAGE_URL https://github.com/grammatech/ddisasm)
# set(CPACK_PACKAGE_VERSION_MAJOR ${DDISASM_MAJOR_VERSION})
# set(CPACK_PACKAGE_VERSION_MINOR ${DDISASM_MINOR_VERSION})
# set(CPACK_PACKAGE_VERSION_PATCH ${DDISASM_PATCH_VERSION})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"A fast disassembler which is accurate enough for the resulting assembly code to be reassembled. The disassembler implemented using the datalog (souffle) declarative logic programming language to compile disassembly rules and heuristics."
)
set(CPACK_PACKAGE_VEDOR "GrammaTech Inc.")
set(CPACK_PACKAGE_CONTACT gtirb@grammatech.com)
set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
set(CPACK_PACKAGE_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt)
set(CPACK_DEBIAN_PACKAGE_SECTION devel)
include(CPack)