forked from pwang200/xbridge_witness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
265 lines (231 loc) · 8.6 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
cmake_minimum_required (VERSION 3.20)
project (xbridge_witnessd)
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11))
message(FATAL_ERROR "Use gcc >= 11.0")
elseif((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13))
message(FATAL_ERROR "Use clang >= 13.0")
endif()
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE OR "${CMAKE_TOOLCHAIN_FILE} " STREQUAL " ")
set(conan_toolchain ${CMAKE_CURRENT_BINARY_DIR}/build/generators/conan_toolchain.cmake)
if(NOT EXISTS "${conan_toolchain}")
message(FATAL_ERROR "${conan_toolchain} not found")
endif()
include(${conan_toolchain})
endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_VERBOSE_MAKEFILE 1)
#[===========================================[
The tool depends on the xrpl_core
library which is defined by the rippled
project. This looks for installed rippled
libs and, if not found, pulls them in with
FetchContent.
#]===========================================]
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Builds/CMake")
#include(deps/Boost)
find_package(SOCI REQUIRED)
find_package(fmt REQUIRED)
find_package(date REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(Threads)
include(XBridgeWitnessNIH)
get_directory_property(has_parent PARENT_DIRECTORY)
if(coverage)
# Rippled also responds to the "coverage" flag, so clear it if it's set until
# the dependency is set up.
set(xbridge_witness_coverage ${coverage})
set(coverage OFF CACHE BOOL "gcc/clang only" FORCE)
endif()
add_compile_definitions(
BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT
BOOST_CONTAINER_FWD_BAD_DEQUE
HAS_UNCAUGHT_EXCEPTIONS=1
)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_definitions(_DEBUG)
endif()
if (NOT has_parent)
find_package(Ripple QUIET)
if (NOT TARGET Ripple::xrpl_core)
include(deps/FindRipple)
if (NOT TARGET Ripple::xrpl_core)
find_package(Git)
if (NOT GIT_FOUND)
message (FATAL_ERROR "git is required to determine branch name")
endif ()
execute_process (COMMAND ${GIT_EXECUTABLE} "rev-parse" "--abbrev-ref" "HEAD"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE _git_exit_code
OUTPUT_VARIABLE _branch
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
if (NOT _git_exit_code EQUAL 0)
message (WARNING "git command failed - deduced branch might be incorrect")
endif ()
# rippled_tag is cache string and can be overriden when configuring
# with -Drippled_tag=commit_or_tag in order to pick a specific
# rippled version to download. Default tag is develop/master/release as
# determined by the branch of this project
if (NOT (_branch STREQUAL "master" OR _branch STREQUAL "release"))
set (rippled_tag "develop" CACHE STRING
"tag/commit of rippled to fetch from if a local install is not found")
else ()
set (rippled_tag "${_branch}" CACHE STRING
"tag/commit of rippled to fetch from if a local install is not found")
endif ()
message(STATUS "Installed rippled not found... \
using local copy from tag/commit [${rippled_tag}]")
include (FetchContent)
FetchContent_Declare(
rippled_src
GIT_REPOSITORY https://github.com/XRPLF/rippled.git
GIT_TAG ${rippled_tag}
)
FetchContent_GetProperties(rippled_src)
if(NOT rippled_src_POPULATED)
message (STATUS "Pausing to download rippled source...")
FetchContent_Populate(rippled_src)
set (conan_build_type "Release")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set (conan_build_type "Debug")
endif()
set (conan_profile "default")
if(NOT "${CONAN_PROFILE} " STREQUAL " ")
set (conan_profile ${CONAN_PROFILE})
endif()
execute_process (COMMAND conan install ${rippled_src_SOURCE_DIR} --build missing --output-folder . -s build_type=${conan_build_type} -pr=${conan_profile}
WORKING_DIRECTORY ${rippled_src_BINARY_DIR}
RESULT_VARIABLE _git_exit_code
OUTPUT_STRIP_TRAILING_WHITESPACE
ECHO_OUTPUT_VARIABLE
ECHO_ERROR_VARIABLE
)
if (NOT _git_exit_code EQUAL 0)
message (WARNING "conan exit_code: ${_git_exit_code}\n conan command failed - build might be incorrect")
endif ()
option (tests "Build tests" OFF)
add_subdirectory(${rippled_src_SOURCE_DIR} ${rippled_src_BINARY_DIR})
endif()
endif()
endif ()
endif ()
if(xbridge_witness_coverage)
set(coverage ${xbridge_witness_coverage} CACHE BOOL "gcc/clang only" FORCE)
endif()
# this one is a string and therefore can't be an option
set (san "" CACHE STRING "On gcc & clang, add sanitizer instrumentation")
set_property (CACHE san PROPERTY STRINGS ";undefined;memory;address;thread")
if (san)
string (TOLOWER ${san} san)
set (SAN_FLAG "-fsanitize=${san}")
set (SAN_LIB "")
if (is_gcc)
if (san STREQUAL "address")
set (SAN_LIB "asan")
elseif (san STREQUAL "thread")
set (SAN_LIB "tsan")
elseif (san STREQUAL "memory")
set (SAN_LIB "msan")
elseif (san STREQUAL "undefined")
set (SAN_LIB "ubsan")
endif ()
endif ()
set (_saved_CRL ${CMAKE_REQUIRED_LIBRARIES})
set (CMAKE_REQUIRED_LIBRARIES "${SAN_FLAG};${SAN_LIB}")
check_cxx_compiler_flag (${SAN_FLAG} COMPILER_SUPPORTS_SAN)
set (CMAKE_REQUIRED_LIBRARIES ${_saved_CRL})
if (NOT COMPILER_SUPPORTS_SAN)
message (FATAL_ERROR "${san} sanitizer does not seem to be supported by your compiler")
endif ()
endif ()
include(XBridgeWitnessSanity)
include(XBridgeWitnessCov)
include(XBridgeWitnessInterface)
set(HEADERS
src/xbwd/app/App.h
src/xbwd/app/BuildInfo.h
src/xbwd/app/Config.h
src/xbwd/app/DBInit.h
src/xbwd/basics/ChainTypes.h
src/xbwd/basics/StructuredLog.h
src/xbwd/basics/ThreadSaftyAnalysis.h
src/xbwd/client/WebsocketClient.h
src/xbwd/client/ChainListener.h
src/xbwd/client/RpcResultParse.h
src/xbwd/core/DatabaseCon.h
src/xbwd/core/SociDB.h
src/xbwd/federator/Federator.h
src/xbwd/federator/FederatorEvents.cpp
src/xbwd/federator/TxnSupport.h
src/xbwd/rpc/fromJSON.h
src/xbwd/rpc/RPCCall.h
src/xbwd/rpc/RPCClient.h
src/xbwd/rpc/RPCHandler.h
src/xbwd/rpc/ServerHandler.h
)
set(SOURCES
src/xbwd/app/App.cpp
src/xbwd/app/BuildInfo.cpp
src/xbwd/app/Config.cpp
src/xbwd/app/DBInit.cpp
src/xbwd/app/main.cpp
src/xbwd/client/WebsocketClient.cpp
src/xbwd/client/ChainListener.cpp
src/xbwd/client/RpcResultParse.cpp
src/xbwd/core/DatabaseCon.cpp
src/xbwd/core/SociDB.cpp
src/xbwd/federator/Federator.cpp
src/xbwd/federator/FederatorEvents.cpp
src/xbwd/rpc/RPCClient.cpp
src/xbwd/rpc/RPCHandler.cpp
src/xbwd/rpc/ServerHandler.cpp
)
option(tests "Enable unit tests" ON)
if (tests)
set(UNIT_TESTS
src/test/Config_test.cpp
src/test/DB_test.cpp
src/test/main_test.cpp
src/test/RPCClient_test.cpp
src/test/RPCParse_test.cpp
src/test/WS_test.cpp
)
endif () #tests
add_executable (${PROJECT_NAME}
${SOURCES}
${HEADERS}
${UNIT_TESTS}
)
install (TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
target_compile_options(${PROJECT_NAME} PUBLIC "-fstack-protector-strong")
if (is_linux)
target_link_options(${PROJECT_NAME} PUBLIC "LINKER:-z,relro,-z,now")
endif()
target_include_directories (${PROJECT_NAME} PRIVATE src ${date_INCLUDE_DIR})
target_link_libraries (${PROJECT_NAME} PUBLIC Ripple::xrpl_core XBridgeWitness::opts
SOCI::soci_core_static SOCI::soci_sqlite3_static fmt::fmt OpenSSL::Crypto OpenSSL::SSL)
if (san)
target_compile_options (${PROJECT_NAME}
INTERFACE
# sanitizers recommend minimum of -O1 for reasonable performance
$<$<CONFIG:Debug>:-O1>
${SAN_FLAG}
-fno-omit-frame-pointer)
target_compile_definitions (${PROJECT_NAME}
INTERFACE
$<$<STREQUAL:${san},address>:SANITIZER=ASAN>
$<$<STREQUAL:${san},thread>:SANITIZER=TSAN>
$<$<STREQUAL:${san},memory>:SANITIZER=MSAN>
$<$<STREQUAL:${san},undefined>:SANITIZER=UBSAN>)
target_link_libraries (${PROJECT_NAME} INTERFACE ${SAN_FLAG} ${SAN_LIB})
endif ()
if (has_parent)
set_target_properties (${PROJECT_NAME} PROPERTIES EXCLUDE_FROM_ALL ON)
set_target_properties (${PROJECT_NAME} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON)
endif ()
#fix for MAC
get_target_property(FMT_INC_DIRS fmt::fmt INTERFACE_INCLUDE_DIRECTORIES)
list (GET FMT_INC_DIRS 0 FMT_INC_DIR)
target_include_directories(${PROJECT_NAME} BEFORE PRIVATE ${FMT_INC_DIR})
include(packaging/package)