-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
354 lines (293 loc) · 12.3 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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# Copyright (c) 2016-2024 Knuth Project developers.
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
cmake_minimum_required(VERSION 3.20)
project(consensus VERSION 0 LANGUAGES CXX C)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(ENABLE_SHARED "" OFF)
option(ENABLE_POSITION_INDEPENDENT_CODE "Enable POSITION_INDEPENDENT_CODE property" ON)
option(WITH_TESTS "Compile with unit tests." ON)
option(WITH_JAVA "Compile the Java bindings." OFF)
option(WITH_PYTHON "Compile the Python bindings." OFF)
if (WITH_JAVA)
message(FATAL_ERROR "WITH_JAVA not yet implemented")
endif()
if (WITH_PYTHON)
message(FATAL_ERROR "WITH_PYTHON not yet implemented")
endif()
set(MARCH_ID "" CACHE STRING "Specify the Microarchitecture ID (x86_64|...).")
message( STATUS "Knuth: Compiling for Microarchitecture ID ${MARCH_ID}")
message( STATUS "Knuth: CONAN_CXX_FLAGS ${CONAN_CXX_FLAGS}")
message( STATUS "Knuth: CONAN_C_FLAGS ${CONAN_C_FLAGS}")
set(CURRENCY "BCH" CACHE STRING "Specify the Cryptocurrency (BCH|BTC|LTC).")
if (${CURRENCY} STREQUAL "BCH")
add_definitions(-DKTH_CURRENCY_BCH)
elseif (${CURRENCY} STREQUAL "BTC")
add_definitions(-DKTH_CURRENCY_BTC)
elseif (${CURRENCY} STREQUAL "LTC")
add_definitions(-DKTH_CURRENCY_LTC)
else()
message(FATAL_ERROR "Invalid Cryptocurrency: ${CURRENCY}")
endif()
message(STATUS "Knuth: Cryptocurrency: ${CURRENCY}")
# Set preprocessor defines.
include(CheckIncludeFile)
include(CheckCXXSymbolExists)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/ci_utils/cmake)
include(KnuthTools)
_check_has_decl(byteswap.h HAVE_BYTESWAP_H bswap_16 HAVE_DECL_BSWAP_16)
_check_has_decl(byteswap.h HAVE_BYTESWAP_H bswap_32 HAVE_DECL_BSWAP_32)
_check_has_decl(byteswap.h HAVE_BYTESWAP_H bswap_64 HAVE_DECL_BSWAP_64)
_check_has_decl(endian.h HAVE_ENDIAN_H le16toh HAVE_DECL_LE16TOH)
_check_has_decl(endian.h HAVE_ENDIAN_H le32toh HAVE_DECL_LE32TOH)
_check_has_decl(endian.h HAVE_ENDIAN_H le64toh HAVE_DECL_LE64TOH)
_check_has_decl(endian.h HAVE_ENDIAN_H htole16 HAVE_DECL_HTOLE16)
_check_has_decl(endian.h HAVE_ENDIAN_H htole32 HAVE_DECL_HTOLE32)
_check_has_decl(endian.h HAVE_ENDIAN_H htole64 HAVE_DECL_HTOLE64)
_check_has_decl(endian.h HAVE_ENDIAN_H be16toh HAVE_DECL_BE16TOH)
_check_has_decl(endian.h HAVE_ENDIAN_H be32toh HAVE_DECL_BE32TOH)
_check_has_decl(endian.h HAVE_ENDIAN_H be64toh HAVE_DECL_BE64TOH)
_check_has_decl(endian.h HAVE_ENDIAN_H htobe16 HAVE_DECL_HTOBE16)
_check_has_decl(endian.h HAVE_ENDIAN_H htobe32 HAVE_DECL_HTOBE32)
_check_has_decl(endian.h HAVE_ENDIAN_H htobe64 HAVE_DECL_HTOBE64)
_check_has_decl(sys/endian.h HAVE_SYS_ENDIAN_H le16toh HAVE_DECL_LE16TOH)
_check_has_decl(sys/endian.h HAVE_SYS_ENDIAN_H le32toh HAVE_DECL_LE32TOH)
_check_has_decl(sys/endian.h HAVE_SYS_ENDIAN_H le64toh HAVE_DECL_LE64TOH)
_check_has_decl(sys/endian.h HAVE_SYS_ENDIAN_H htole16 HAVE_DECL_HTOLE16)
_check_has_decl(sys/endian.h HAVE_SYS_ENDIAN_H htole32 HAVE_DECL_HTOLE32)
_check_has_decl(sys/endian.h HAVE_SYS_ENDIAN_H htole64 HAVE_DECL_HTOLE64)
_check_has_decl(sys/endian.h HAVE_SYS_ENDIAN_H be16toh HAVE_DECL_BE16TOH)
_check_has_decl(sys/endian.h HAVE_SYS_ENDIAN_H be32toh HAVE_DECL_BE32TOH)
_check_has_decl(sys/endian.h HAVE_SYS_ENDIAN_H be64toh HAVE_DECL_BE64TOH)
_check_has_decl(sys/endian.h HAVE_SYS_ENDIAN_H htobe16 HAVE_DECL_HTOBE16)
_check_has_decl(sys/endian.h HAVE_SYS_ENDIAN_H htobe32 HAVE_DECL_HTOBE32)
_check_has_decl(sys/endian.h HAVE_SYS_ENDIAN_H htobe64 HAVE_DECL_HTOBE64)
if (NOT GLOBAL_BUILD)
find_package(secp256k1 REQUIRED)
endif()
find_package(Boost COMPONENTS boost REQUIRED)
include(CheckCXXCompilerFlag)
if (NOT MSVC)
_add_c_compile_flag(-Wall _has_all_warning_flag)
else()
_add_c_compile_flag(-W4 _has_all_warning_flag)
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
if (NOT MSVC)
_add_c_compile_flag(-Wextra _has_extra_warning_flag)
endif()
_add_c_compile_flag(-Wpedantic _has_pedantic_warning_flag)
if (_has_pedantic_warning_flag)
_add_c_compile_flag(-pedantic _has_pedantic_flag)
endif()
_add_cxx_compile_flag(-Wno-missing-braces _has_no_missing_braces_warning_flag)
_add_cxx_compile_flag(-Wno-mismatched-tags _has_no_mismatched_tags_warning_flag)
_add_c_compile_flag(-Wno-deprecated-declarations _has_no_deprecated_declarations_warning_flag)
_add_link_flag(-fstack-protector _has_stack_protector_flag)
_add_link_flag(-fstack-protector-all _has_stack_protector_all_flag)
_add_cxx_compile_flag(-fvisibility-hidden _has_visibility_hidden_flag)
_add_cxx_compile_flag(-fvisibility-inlines-hidden _has_visibility_inlines_hidden_flag)
if (MSVC)
add_definitions(-D_WIN32_WINNT=0x0600)
endif()
#------------------------------------------------------------------------------
if (${CURRENCY} STREQUAL "BCH")
set(kth_sources_clone
src/bch-rules/amount.h
src/bch-rules/amount.cpp
src/bch-rules/coins.cpp
src/bch-rules/hash.cpp
src/bch-rules/hash.h
src/bch-rules/prevector.h
src/bch-rules/pubkey.cpp
src/bch-rules/pubkey.h
src/bch-rules/feerate.cpp
src/bch-rules/feerate.h
src/bch-rules/serialize.h
src/bch-rules/tinyformat.h
src/bch-rules/uint256.cpp
src/bch-rules/uint256.h
src/bch-rules/version.h
src/bch-rules/compat/byteswap.h
src/bch-rules/compat/endian.h
src/bch-rules/crypto/common.h
src/bch-rules/crypto/hmac_sha512.cpp
src/bch-rules/crypto/hmac_sha512.h
src/bch-rules/crypto/ripemd160.cpp
src/bch-rules/crypto/ripemd160.h
src/bch-rules/crypto/sha1.cpp
src/bch-rules/crypto/sha1.h
src/bch-rules/crypto/sha256.cpp
src/bch-rules/crypto/sha256.h
src/bch-rules/crypto/sha512.cpp
src/bch-rules/crypto/sha512.h
src/bch-rules/crypto/siphash.h
src/bch-rules/primitives/token.h
src/bch-rules/primitives/token.cpp
src/bch-rules/primitives/transaction.cpp
src/bch-rules/primitives/transaction.h
src/bch-rules/primitives/txid.h
src/bch-rules/script/bitfield.cpp
src/bch-rules/script/bitfield.h
src/bch-rules/script/interpreter.cpp
src/bch-rules/script/interpreter.h
src/bch-rules/script/script.cpp
src/bch-rules/script/script.h
src/bch-rules/script/script_flags.h
src/bch-rules/script/script_error.h
src/bch-rules/script/script_execution_context.cpp
src/bch-rules/script/sigencoding.h
src/bch-rules/script/sigencoding.cpp
src/bch-rules/support/cleanse.h
src/bch-rules/support/cleanse.cpp
src/bch-rules/util/strencodings.cpp
src/bch-rules/util/strencodings.h
src/bch-rules/util/string.cpp
src/bch-rules/util/string.h
)
else()
set(kth_sources_clone
src/btc-rules/amount.h
src/btc-rules/hash.cpp
src/btc-rules/hash.h
src/btc-rules/prevector.h
src/btc-rules/pubkey.cpp
src/btc-rules/pubkey.h
src/btc-rules/serialize.h
src/btc-rules/tinyformat.h
src/btc-rules/uint256.cpp
src/btc-rules/uint256.h
src/btc-rules/version.h
src/btc-rules/compat/byteswap.h
src/btc-rules/compat/endian.h
src/btc-rules/crypto/common.h
src/btc-rules/crypto/hmac_sha512.cpp
src/btc-rules/crypto/hmac_sha512.h
src/btc-rules/crypto/ripemd160.cpp
src/btc-rules/crypto/ripemd160.h
src/btc-rules/crypto/sha1.cpp
src/btc-rules/crypto/sha1.h
src/btc-rules/crypto/sha256.cpp
src/btc-rules/crypto/sha256.h
src/btc-rules/crypto/sha512.cpp
src/btc-rules/crypto/sha512.h
src/btc-rules/primitives/transaction.cpp
src/btc-rules/primitives/transaction.h
src/btc-rules/script/interpreter.cpp
src/btc-rules/script/interpreter.h
src/btc-rules/script/script.cpp
src/btc-rules/script/script.h
src/btc-rules/script/script_error.h
src/btc-rules/util/strencodings.cpp
src/btc-rules/util/strencodings.h
)
endif()
# add_library(${PROJECT_NAME}-clone OBJECT)
add_library(${PROJECT_NAME}-clone ${MODE} ${kth_sources_clone})
add_library(${PROJECT_NAME}-clone::${PROJECT_NAME}-clone ALIAS ${PROJECT_NAME}-clone)
set_target_properties(${PROJECT_NAME}-clone PROPERTIES LINKER_LANGUAGE CXX CXX_STANDARD 23 CXX_STANDARD_REQUIRED TRUE)
if (ENABLE_POSITION_INDEPENDENT_CODE)
set_property(TARGET ${PROJECT_NAME}-clone PROPERTY POSITION_INDEPENDENT_CODE ON)
endif(ENABLE_POSITION_INDEPENDENT_CODE)
if (${CURRENCY} STREQUAL "BCH")
target_include_directories(${PROJECT_NAME}-clone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/bch-rules)
else()
target_include_directories(${PROJECT_NAME}-clone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/btc-rules)
endif()
target_compile_definitions(${PROJECT_NAME}-clone PRIVATE $<TARGET_PROPERTY:secp256k1::secp256k1,INTERFACE_COMPILE_DEFINITIONS>)
target_include_directories(${PROJECT_NAME}-clone PRIVATE $<TARGET_PROPERTY:secp256k1::secp256k1,INTERFACE_INCLUDE_DIRECTORIES>)
target_link_libraries(${PROJECT_NAME}-clone PUBLIC Boost::boost)
if (${CURRENCY} STREQUAL "BCH")
_group_sources(${PROJECT_NAME}-clone "${CMAKE_CURRENT_SOURCE_DIR}/src/bch-rules")
else()
_group_sources(${PROJECT_NAME}-clone "${CMAKE_CURRENT_SOURCE_DIR}/src/btc-rules")
endif()
set(MODE STATIC)
if (ENABLE_SHARED)
set(MODE SHARED)
endif()
set(kth_sources
src/consensus/consensus.cpp
src/consensus/consensus.hpp
)
set(kth_headers
include/kth/consensus.hpp
include/kth/consensus/define.hpp
include/kth/consensus/export.hpp
include/kth/consensus/version.hpp
)
add_library(${PROJECT_NAME} ${MODE} ${kth_sources} ${kth_headers} $<TARGET_OBJECTS:${PROJECT_NAME}-clone>)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX CXX_STANDARD 23 CXX_STANDARD_REQUIRED TRUE)
if (ENABLE_POSITION_INDEPENDENT_CODE)
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)
endif(ENABLE_POSITION_INDEPENDENT_CODE)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
if (NOT ENABLE_SHARED)
target_compile_definitions(${PROJECT_NAME} PUBLIC -DBCK_STATIC)
endif()
if (${CURRENCY} STREQUAL "BCH")
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/bch-rules)
else()
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/btc-rules)
endif()
target_link_libraries(${PROJECT_NAME} PUBLIC secp256k1::secp256k1)
target_link_libraries(${PROJECT_NAME} PUBLIC Boost::boost)
if (MINGW)
target_link_libraries(${PROJECT_NAME} PUBLIC ws2_32 wsock32) #TODO(fernando): manage with Conan
endif()
_group_sources(${PROJECT_NAME} "${CMAKE_CURRENT_LIST_DIR}")
# Tests
#==============================================================================
if (WITH_TESTS)
enable_testing()
find_package(Catch2 3 REQUIRED)
add_executable(kth_consensus_test
test/consensus__script_error_to_verify_result.cpp
test/consensus__script_verify.cpp
test/consensus__verify_flags_to_script_flags.cpp
test/main.cpp
test/script.hpp)
if (${CURRENCY} STREQUAL "BCH")
target_include_directories(kth_consensus_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/bch-rules)
else()
target_include_directories(kth_consensus_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/btc-rules)
endif()
target_include_directories(kth_consensus_test PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/test>)
target_link_libraries(kth_consensus_test PUBLIC ${PROJECT_NAME})
target_link_libraries(kth_consensus_test PRIVATE Catch2::Catch2WithMain)
_group_sources(kth_consensus_test "${CMAKE_CURRENT_LIST_DIR}/test")
include(CTest)
include(Catch)
catch_discover_tests(kth_consensus_test)
endif()
# Install
# ------------------------------------------------------------------------------
include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Generate and install a CMake package configuration file
install(EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}-config.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)