forked from Zilliqa/Zilliqa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
314 lines (257 loc) · 9.55 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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
cmake_minimum_required(VERSION 3.19)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
message(STATUS "Found ccache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()
project(Zilliqa)
# detect operating system
message(STATUS "We are on a ${CMAKE_SYSTEM_NAME} system")
# Workaround: there's a bug related to protobuf 3.9.1 on vcpkg when compiled with
# x64-osx-dynamic (see https://github.com/microsoft/vcpkg/issues/8421).
# This is a simple workaround against this issue.
if (APPLE)
file(CREATE_LINK
${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/lib
${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/tools/lib
SYMBOLIC)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
#
# check dependencies
#
find_package(Libevent REQUIRED)
find_package(jsoncpp REQUIRED)
find_package(mongocxx REQUIRED)
find_package(bsoncxx REQUIRED)
find_package(websocketpp REQUIRED)
find_package(leveldb REQUIRED)
find_package(g3log REQUIRED)
find_package(g3sinks REQUIRED)
#TODO: upgrade to OpenSSL 1.1.1a
find_package(OpenSSL REQUIRED)
# Temporary workarounds for Python3:
#
# 1. Make sure PATH points to the python3 in the vcpkg tools sub-directory; otherwise on some systems find_package
# will fail (e.g. if libpython3-dev is installed on Ubuntu 20.04).
# 2. For some reason it only finds debug library upon a second call to find_package. Otherwise, the release
# library will be used and if it's a debug build linkage could fail.
set(PREV_PATH $ENV{PATH})
set(ENV{PATH} "${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/tools/python3:$ENV{PATH}")
find_package(Python3 COMPONENTS Development REQUIRED)
find_package(Python3 COMPONENTS Development REQUIRED)
set(ENV{PATH} "${PREV_PATH}")
include(FindProtobuf)
set(protobuf_MODULE_COMPATIBLE TRUE)
find_package(Protobuf REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(Boost COMPONENTS filesystem system unit_test_framework program_options REQUIRED)
find_package(Schnorr REQUIRED)
find_package(CryptoUtils REQUIRED)
include_directories(${SCHNORR_INCLUDE_DIR}/include)
include_directories(${OPENSSL_INCLUDE_DIR})
if(OPENCL_MINE)
message(STATUS "OpenCL enabled")
find_package(OpenCL REQUIRED)
add_definitions(-DOPENCL_MINE)
endif()
# VC related test scenario
# For DS Block Consensus
if(VC_TEST_DS_SUSPEND_1)
message(STATUS "VC 1 test enabled")
add_definitions(-DVC_TEST_DS_SUSPEND_1)
endif()
if(VC_TEST_DS_SUSPEND_3)
message(STATUS "VC 2 test enabled")
add_definitions(-DVC_TEST_DS_SUSPEND_3)
endif()
if(GOVVC_TEST_DS_SUSPEND_3)
message(STATUS "GOVVC 2 test enabled")
add_definitions(-DGOVVC_TEST_DS_SUSPEND_3)
endif()
# For Final Block Consensus
if(VC_TEST_FB_SUSPEND_1)
message(STATUS "VC 3 test enabled")
add_definitions(-DVC_TEST_FB_SUSPEND_1)
endif()
if(VC_TEST_FB_SUSPEND_3)
message(STATUS "VC 4 test enabled")
add_definitions(-DVC_TEST_FB_SUSPEND_3)
endif()
# For View change Block Consensus
if(VC_TEST_VC_SUSPEND_1)
message(STATUS "VC 5 test enabled")
add_definitions(-DVC_TEST_VC_SUSPEND_1)
endif()
if(VC_TEST_VC_SUSPEND_3)
message(STATUS "VC 6 test enabled")
add_definitions(-DVC_TEST_VC_SUSPEND_3)
endif()
if(VC_TEST_VC_PRECHECK_1)
message(STATUS "VC 7 test enabled")
add_definitions(-DVC_TEST_VC_PRECHECK_1)
endif()
if(VC_TEST_VC_PRECHECK_2)
message(STATUS "VC 8 test enabled")
add_definitions(-DVC_TEST_VC_PRECHECK_2)
endif()
if(VC_TEST_FB_SUSPEND_RESPONSE)
message(STATUS "VC 9 test enabled")
add_definitions(-DVC_TEST_FB_SUSPEND_RESPONSE)
endif()
# For Merging DSMB into FINALBLOCK
if(DM_TEST_DM_LESSTXN_ONE)
message(STATUS "DM 1 test enabled")
add_definitions(-DDM_TEST_DM_LESSTXN_ONE)
endif()
if(DM_TEST_DM_LESSTXN_ALL)
message(STATUS "DM 2 test enabled")
add_definitions(-DDM_TEST_DM_LESSTXN_ALL)
endif()
if(DM_TEST_DM_LESSMB_ONE)
message(STATUS "DM 3 test enabled")
add_definitions(-DDM_TEST_DM_LESSMB_ONE)
endif()
if(DM_TEST_DM_LESSMB_ALL)
message(STATUS "DM 4 test enabled")
add_definitions(-DDM_TEST_DM_LESSMB_ALL)
endif()
if(DM_TEST_DM_BAD_ANNOUNCE)
message(STATUS "DM 5 test enabled")
add_definitions(-DDM_TEST_DM_BAD_ANNOUNCE)
endif()
if(DM_TEST_DM_BAD_MB_ANNOUNCE)
message(STATUS "DM 6 test enabled")
add_definitions(-DDM_TEST_DM_BAD_MB_ANNOUNCE)
endif()
if(DM_TEST_DM_MORETXN_LEADER)
message(STATUS "DM 7 test enabled")
add_definitions(-DDM_TEST_DM_MORETXN_LEADER)
endif()
if(DM_TEST_DM_MORETXN_HALF)
message(STATUS "DM 8 test enabled")
add_definitions(-DDM_TEST_DM_MORETXN_HALF)
endif()
if(DM_TEST_DM_MOREMB_HALF)
message(STATUS "DM 9 test enabled")
add_definitions(-DDM_TEST_DM_MOREMB_HALF)
endif()
if(SJ_TEST_SJ_TXNBLKS_PROCESS_SLOW)
message(STATUS "SJ 1 test enabled")
add_definitions(-DSJ_TEST_SJ_TXNBLKS_PROCESS_SLOW)
endif()
if(SJ_TEST_SJ_MISSING_MBTXNS)
message(STATUS "SJ 2 test enabled")
add_definitions(-DSJ_TEST_SJ_MISSING_MBTXNS)
endif()
include_directories(${PROTOBUF_INCLUDE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src/depends/cryptoutils/include/)
include_directories(${G3LOG_INCLUDE_DIR})
# export compile commands
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# customize the flags for RELWITHDEBINFO
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -ggdb -DNDEBUG")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# pack related variables
set(CPACK_GENERATOR "DEB")
set(CPACK_PACKAGE_VERSION $ENV{ZIL_VER})
set(CPACK_PACKAGE_NAME $ENV{ZIL_PACK_NAME})
set(CPACK_DEBIAN_PACKAGE_NAME "zilliqa")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libboost-system-dev, libboost-filesystem-dev, libboost-test-dev, libssl-dev, libleveldb-dev, libjsoncpp-dev, libsnappy-dev, cmake, libmicrohttpd-dev, libjsonrpccpp-dev, build-essential, pkg-config, libevent-dev, libminiupnpc-dev, libprotobuf-dev, protobuf-compiler, libboost-program-options-dev")
set(CPACK_PACKAGE_CONTACT "maintainers@zilliqa.com")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Members of maintainers@zilliqa.com")
# compiler and linker options
add_compile_options(-Wall)
add_compile_options(-Werror)
add_compile_options(-pedantic)
add_compile_options(-Wextra)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
add_compile_options(-Wno-error=deprecated-declarations)
add_compile_options(-Wno-unused-parameter)
endif()
if (THREAD_SANITIZER AND ADDRESS_SANITIZER)
message(FATAL_ERROR "Cannot use ThreadSanitizer (THREAD_SANITIZER=ON) and AddressSanitizer (ADDRESS_SANITIZER=ON) at the same time")
endif()
if (THREAD_SANITIZER)
add_compile_options(-fsanitize=thread)
link_libraries(-fsanitize=thread)
message(STATUS "THREAD SANITIZER enabled")
endif()
if (ADDRESS_SANITIZER)
add_compile_options(-fsanitize=address)
add_compile_options(-fno-omit-frame-pointer)
link_libraries(-fsanitize=address)
message(STATUS "ADDRESS SANITIZER enabled")
endif()
if (UNDEF_BEHAVIOR_SANITIZER)
add_compile_options(-fsanitize=undefined)
link_libraries(-fsanitize=undefined)
message(STATUS "UNDEFINED BEHAVIOR SANITIZER enabled")
endif()
if (LIBFUZZER_SANITIZER)
include(CodeCoverage)
link_libraries(--coverage)
link_libraries(-lgcov)
add_compile_options(-fsanitize=fuzzer,address,undefined)
add_compile_options(-fno-omit-frame-pointer)
link_libraries(-fsanitize=fuzzer,address,undefined)
message(STATUS "Libfuzzer with address and undefined behavior sanitizer enabled")
endif()
# FIXME: This following
#
# add_custom_target(ctest COMMAND ${CMAKE_CTEST_COMMAND})
#
# needs to be fixed. The same chunk of CMake code (as below:
# if (ENABLE_COVERAGE AND CMAKE_COMPILER_IS_GNUCXX) ....
# exists here, in cryptoutils & Schnorr.
#
# Once fixed, the following if-case for allowing duplciate targets
# (which isn't supported in Xcode) can be removed.
if (NOT ${CMAKE_GENERATOR} STREQUAL "Xcode")
set_property(GLOBAL PROPERTY ALLOW_DUPLICATE_CUSTOM_TARGETS 1)
endif()
if (ENABLE_COVERAGE AND CMAKE_COMPILER_IS_GNUCXX)
if (NOT TESTS)
message(FATAL_ERROR "TESTS is not ON")
endif()
include(CodeCoverage)
add_compile_options(--coverage)
link_libraries(--coverage)
add_custom_target(ctest COMMAND ${CMAKE_CTEST_COMMAND})
# TODO: remove the hardcoded number in -j option
setup_target_for_coverage(${PROJECT_NAME}_coverage ctest coverage "--output-on-failure;--timeout;90")
endif()
# using internal jsonrpc variant
include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src/depends)
add_subdirectory(src)
add_subdirectory(daemon)
if (TESTS)
enable_testing()
add_subdirectory(tests)
endif()
# installation
set_target_properties(buildTxBlockHashesToNums genaccounts genkeypair genTxnBodiesFromS3
getpub getaddr gentxn signmultisig verifymultisig gensigninitialds getnetworkhistory grepperf
getrewardhistory isolatedServer restore sendcmd validateDB zilliqa zilliqad
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set_target_properties(Common Trie NAT
PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
if(OPENCL_MINE)
set_target_properties(ethash-cl PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
endif()
install(
DIRECTORY ${CMAKE_BINARY_DIR}/bin ${CMAKE_BINARY_DIR}/lib
DESTINATION ${CMAKE_INSTALL_PREFIX}
USE_SOURCE_PERMISSIONS
)
# add clang-format and clang-tidy targets lastly
if(LLVM_EXTRA_TOOLS)
include(LLVMExtraTools)
else()
message(STATUS "LLVM extra tools NOT found (for clang format/tidy)")
endif()
include(CPack)