This repository was archived by the owner on Jul 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
215 lines (183 loc) · 6.95 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
##
## Project: retdec-cpp
## Copyright: (c) 2015 by Petr Zemek <[email protected]>
## License: MIT, see the LICENSE file for more details
##
## The project's main CMake configuration file.
##
cmake_minimum_required(VERSION 2.8)
project(retdec-cpp CXX C)
##
## Options.
##
option(RETDEC_DOC "Build public API documentation (requires Doxygen)." OFF)
option(RETDEC_INTERNAL_DOC "Build also the internal parts of the API documentation." OFF)
option(RETDEC_TOOLS "Build tools." OFF)
option(RETDEC_COVERAGE "Build with code coverage support (requires GCC and lcov)." OFF)
option(RETDEC_TESTS "Build tests." OFF)
if(${RETDEC_INTERNAL_DOC})
set(RETDEC_DOC ON)
endif()
if(${RETDEC_COVERAGE})
set(RETDEC_TESTS ON)
# The coverage currently works only for GCC builds.
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message(FATAL_ERROR "Code coverage support requires GCC to be used.")
endif()
endif()
##
## Paths.
##
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install" CACHE PATH "default install path" FORCE)
endif()
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin")
set(INSTALL_DOC_DIR "${CMAKE_INSTALL_PREFIX}/doc")
set(INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include")
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
set(INSTALL_LIB_CMAKE_DIR "${INSTALL_LIB_DIR}/cmake")
##
## Dependencies.
##
include(ExternalProject)
# The default root directory for external projects.
set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/third_party)
# Threads
find_package(Threads REQUIRED)
# Boost
find_package(Boost 1.55 COMPONENTS "filesystem" "system" "thread" REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
# A workaround to link error "undefined reference to
# `boost::filesystem::detail::copy_file()" when using Boost < 1.57
# (https://www.robertnitsch.de/notes/cpp/cpp11_boost_filesystem_undefined_reference_copy_file).
add_definitions(-DBOOST_NO_CXX11_SCOPED_ENUMS)
# OpenSSL
find_package(OpenSSL REQUIRED)
include_directories(SYSTEM ${OPENSSL_INCLUDE_DIR})
# cpp-netlib
find_package(CPP-NETLIB COMPONENTS "uri" "client-connections")
if(NOT CPPNETLIB_FOUND)
message(STATUS " --> cppnetlib will be built as an external project")
ExternalProject_Add(cpp-netlib
URL http://downloads.cpp-netlib.org/0.11.2/cpp-netlib-0.11.2-final.zip
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCPP-NETLIB_BUILD_TESTS:BOOL=OFF
-DCPP-NETLIB_BUILD_EXAMPLES:BOOL=OFF
# Disable the install step.
INSTALL_COMMAND ""
# Wrap the download, configure and build steps in a script to log the
# output.
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
)
ExternalProject_Get_Property(cpp-netlib source_dir)
ExternalProject_Get_Property(cpp-netlib binary_dir)
set(CPPNETLIB_INCLUDE_DIR "${source_dir}")
set(CPPNETLIB_LIBRARY_DIR "${binary_dir}/libs/network/src")
set(CPPNETLIB_LIBRARIES "cppnetlib-uri" "cppnetlib-client-connections")
link_directories(${CPPNETLIB_LIBRARY_DIR})
endif()
include_directories(SYSTEM ${CPPNETLIB_INCLUDE_DIR})
# Enable HTTPS. The following symbol has to be defined prior to including
# cpp-netlib headers.
add_definitions(-DBOOST_NETWORK_ENABLE_HTTPS)
# json-cpp
find_package(JsonCpp)
if(NOT JsonCpp_FOUND)
message(STATUS " --> JsonCpp will be built as an external project")
ExternalProject_Add(json-cpp
URL https://github.com/open-source-parsers/jsoncpp/archive/1.6.5.zip
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DJSONCPP_WITH_TESTS:BOOL=OFF
# Disable the install step.
INSTALL_COMMAND ""
# Wrap the download, configure and build steps in a script to log the
# output.
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
)
ExternalProject_Get_Property(json-cpp source_dir)
ExternalProject_Get_Property(json-cpp binary_dir)
set(JsonCpp_INCLUDE_DIR "${source_dir}/include")
set(JsonCpp_LIBRARY_DIR "${binary_dir}/src/json_lib")
set(JsonCpp_LIBRARY "jsoncpp")
link_directories(${JsonCpp_LIBRARY_DIR})
endif()
include_directories(SYSTEM ${JsonCpp_INCLUDE_DIR})
##
## Includes.
##
include_directories(include)
##
## Compiler options.
##
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# C++14 is required.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pedantic")
# Abort compilation upon the first error.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wfatal-errors")
# Standard warning parameters.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
# Enable additional warnings that are not included in -Wall and -Wextra
# (according to `man gcc`).
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-qual")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wfloat-equal")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wswitch-default")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wuninitialized")
# Compiler-specific warnings.
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wuseless-cast")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wconditional-uninitialized")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wheader-hygiene")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-literal-null-conversion")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wreserved-id-macro")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsometimes-uninitialized")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunreachable-code")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-exception-parameter")
endif()
endif()
##
## Code coverage.
##
if(RETDEC_COVERAGE)
# Enable code coverage.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
# Build with debugging information to make the output meaningful.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
# Disable optimizations to get the most accurate results.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
# Add a custom target to generate the code coverage.
add_custom_target(coverage
COMMENT "Running the tests and generating code coverage"
COMMAND "${PROJECT_BINARY_DIR}/tests/retdec/retdec_tests"
COMMAND mkdir -p "${PROJECT_BINARY_DIR}/coverage"
COMMAND lcov --capture --no-external
--directory include --directory "${PROJECT_BINARY_DIR}/include"
--directory src --directory "${PROJECT_BINARY_DIR}/src"
# Comment out the next line if you want to omit test code from the
# coverage.
--directory tests --directory "${PROJECT_BINARY_DIR}/tests"
--output-file "${PROJECT_BINARY_DIR}/coverage/coverage.info"
COMMAND genhtml --show-details --num-spaces 4 --demangle-cpp
--legend --title "retdec-cpp code coverage"
--output-directory "${PROJECT_BINARY_DIR}/coverage"
"${PROJECT_BINARY_DIR}/coverage/coverage.info"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
)
endif()
##
## Subdirectories.
##
add_subdirectory(doc)
add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(tests)