-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
345 lines (270 loc) · 12.2 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
# 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(database 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_TOOLS "Compile with tools." OFF)
option(WITH_MEASUREMENTS "Measurements enabled." OFF)
option(DB_READONLY_MODE "Readonly DB mode enabled." OFF)
option(JUST_KTH_SOURCES "Just Knuth source code to be linted." OFF)
option(USE_LIBMDBX "Uses libmdbx DB library." OFF)
option(GLOBAL_BUILD "" OFF)
set(MARCH_ID "" CACHE STRING "Specify the Microarchitecture ID (x86_64|...).")
message( STATUS "Knuth: Compiling for Microarchitecture ID ${MARCH_ID}")
if (WITH_MEASUREMENTS)
message(STATUS "Knuth: MEASUREMENTS enabled")
add_definitions(-DWITH_MEASUREMENTS)
endif()
if (DB_READONLY_MODE)
message(STATUS "Knuth: Readonly DB mode enabled")
add_definitions(-DKTH_DB_READONLY)
endif()
if (JUST_KTH_SOURCES)
message(STATUS "Knuth: Just Knuth source code to be linted: enabled")
endif()
if (USE_LIBMDBX)
add_definitions(-DKTH_USE_LIBMDBX)
endif()
set(LOG_LIBRARY "boost" CACHE STRING "Setting for the logging library (boost|spdlog|binlog).")
if (${LOG_LIBRARY} STREQUAL "boost")
add_definitions(-DKTH_LOG_LIBRARY_BOOST)
elseif (${LOG_LIBRARY} STREQUAL "spdlog")
add_definitions(-DKTH_LOG_LIBRARY_SPDLOG)
elseif (${LOG_LIBRARY} STREQUAL "binlog")
add_definitions(-DKTH_LOG_LIBRARY_BINLOG)
else()
message(FATAL_ERROR "Invalid Logging Library: ${LOG_LIBRARY}")
endif()
message(STATUS "Knuth: Logging Library: ${LOG_LIBRARY}")
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}")
if (NOT GLOBAL_BUILD)
find_package(domain REQUIRED)
endif()
find_package(lmdb 0.9.29 REQUIRED)
include(CheckCXXCompilerFlag)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/ci_utils/cmake)
include(KnuthTools)
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()
# Build
#==============================================================================
set(MODE STATIC)
if (ENABLE_SHARED)
set(MODE SHARED)
endif()
set(kth_sources_just_kth
${kth_sources_just_kth}
src/data_base.cpp
src/settings.cpp
src/store.cpp
src/version.cpp
src/databases/header_abla_entry.cpp
src/databases/utxo_entry.cpp
src/databases/history_entry.cpp
src/databases/transaction_entry.cpp
src/databases/transaction_unconfirmed_entry.cpp
)
set(kth_sources
${kth_sources}
${kth_sources_just_kth}
)
set(kth_headers
include/kth/database/store.hpp
include/kth/database/currency_config.hpp
include/kth/database/define.hpp
include/kth/database/data_base.hpp
include/kth/database/databases/block_database.ipp
include/kth/database/databases/property_code.hpp
include/kth/database/databases/internal_database.ipp
include/kth/database/databases/reorg_database.ipp
include/kth/database/databases/internal_database.hpp
include/kth/database/databases/transaction_unconfirmed_database.ipp
include/kth/database/databases/transaction_entry.hpp
include/kth/database/databases/history_database.ipp
include/kth/database/databases/history_entry.hpp
include/kth/database/databases/transaction_database.ipp
include/kth/database/databases/generic_db.hpp
include/kth/database/databases/tools.hpp
include/kth/database/databases/lmdb_helper.hpp
include/kth/database/databases/result_code.hpp
include/kth/database/databases/transaction_unconfirmed_entry.hpp
include/kth/database/databases/header_abla_entry.hpp
include/kth/database/databases/utxo_entry.hpp
include/kth/database/databases/spend_database.ipp
include/kth/database/databases/utxo_database.ipp
include/kth/database/databases/header_database.ipp
include/kth/database/settings.hpp
# include/kth/database/unspent_outputs.hpp
# include/kth/database/unspent_transaction.hpp
include/kth/database/version.hpp
include/kth/database.hpp
)
add_library(${PROJECT_NAME} ${MODE} ${kth_sources} ${kth_headers})
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 -DKD_STATIC -DBC_STATIC)
endif()
target_link_libraries(${PROJECT_NAME} PUBLIC domain::domain)
target_link_libraries(${PROJECT_NAME} PUBLIC lmdb::lmdb)
if (MINGW)
target_link_libraries(${PROJECT_NAME} PUBLIC ws2_32 wsock32)
endif()
_group_sources(${PROJECT_NAME} "${CMAKE_CURRENT_LIST_DIR}")
# Tests
#==============================================================================
if (WITH_TESTS)
enable_testing()
find_package(Catch2 3 REQUIRED)
add_executable(kth_database_test
test/main.cpp
test/internal_database.cpp
)
target_include_directories(kth_database_test PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/test>)
target_link_libraries(kth_database_test PUBLIC ${PROJECT_NAME})
target_link_libraries(kth_database_test PRIVATE Catch2::Catch2WithMain)
_group_sources(kth_database_test "${CMAKE_CURRENT_LIST_DIR}/test")
include(CTest)
include(Catch)
catch_discover_tests(kth_database_test)
endif()
# Tools
#------------------------------------------------------------------------------
if (WITH_TOOLS)
add_executable(tools.block_db
tools/block_db/block_db.cpp)
target_link_libraries(tools.block_db ${PROJECT_NAME})
_group_sources(tools.block_db "${CMAKE_CURRENT_LIST_DIR}/tools/block_db")
add_executable(tools.count_records
tools/count_records/count_records.cpp)
target_link_libraries(tools.count_records ${PROJECT_NAME})
_group_sources(tools.count_records "${CMAKE_CURRENT_LIST_DIR}/tools/count_records")
add_executable(tools.history_db
tools/history_db/history_db.cpp)
target_link_libraries(tools.history_db ${PROJECT_NAME})
_group_sources(tools.history_db "${CMAKE_CURRENT_LIST_DIR}/tools/history_db")
add_executable(tools.initchain_db
tools/initchain/initchain.cpp)
target_link_libraries(tools.initchain_db ${PROJECT_NAME})
_group_sources(tools.initchain_db "${CMAKE_CURRENT_LIST_DIR}/tools/initchain")
add_executable(tools.mmr_add_row
tools/mmr_add_row/mmr_add_row.cpp)
target_link_libraries(tools.mmr_add_row ${PROJECT_NAME})
_group_sources(tools.mmr_add_row "${CMAKE_CURRENT_LIST_DIR}/tools/mmr_add_row")
add_executable(tools.mmr_create
tools/mmr_create/mmr_create.cpp)
target_link_libraries(tools.mmr_create ${PROJECT_NAME})
_group_sources(tools.mmr_create "${CMAKE_CURRENT_LIST_DIR}/tools/mmr_create")
add_executable(tools.mmr_delete_last_row
tools/mmr_delete_last_row/mmr_delete_last_row.cpp)
target_link_libraries(tools.mmr_delete_last_row ${PROJECT_NAME})
_group_sources(tools.mmr_delete_last_row "${CMAKE_CURRENT_LIST_DIR}/tools/mmr_delete_last_row")
add_executable(tools.mmr_lookup
tools/mmr_lookup/mmr_lookup.cpp)
target_link_libraries(tools.mmr_lookup ${PROJECT_NAME})
_group_sources(tools.mmr_lookup "${CMAKE_CURRENT_LIST_DIR}/tools/mmr_lookup")
add_executable(tools.read_htdb_record_value
tools/read_htdb_record_value/read_htdb_record_value.cpp)
target_link_libraries(tools.read_htdb_record_value ${PROJECT_NAME})
_group_sources(tools.read_htdb_record_value "${CMAKE_CURRENT_LIST_DIR}/tools/read_htdb_record_value")
add_executable(tools.read_htdb_slab_value
tools/read_htdb_slab_value/read_htdb_slab_value.cpp)
target_link_libraries(tools.read_htdb_slab_value ${PROJECT_NAME})
_group_sources(tools.read_htdb_slab_value "${CMAKE_CURRENT_LIST_DIR}/tools/read_htdb_slab_value")
add_executable(tools.show_array
tools/show_array/show_array.cpp)
target_link_libraries(tools.show_array ${PROJECT_NAME})
_group_sources(tools.show_array "${CMAKE_CURRENT_LIST_DIR}/tools/show_array")
add_executable(tools.show_linked_records
tools/show_linked_records/show_linked_records.cpp)
target_link_libraries(tools.show_linked_records ${PROJECT_NAME})
_group_sources(tools.show_linked_records "${CMAKE_CURRENT_LIST_DIR}/tools/initchain")
add_executable(tools.show_records
tools/show_records/show_records.cpp)
target_link_libraries(tools.show_records ${PROJECT_NAME})
_group_sources(tools.show_records "${CMAKE_CURRENT_LIST_DIR}/tools/show_records")
add_executable(tools.spend_db
tools/spend_db/spend_db.cpp)
target_link_libraries(tools.spend_db ${PROJECT_NAME})
_group_sources(tools.spend_db "${CMAKE_CURRENT_LIST_DIR}/tools/spend_db")
add_executable(tools.stealth_db
tools/stealth_db/stealth_db.cpp)
target_link_libraries(tools.stealth_db ${PROJECT_NAME})
_group_sources(tools.stealth_db "${CMAKE_CURRENT_LIST_DIR}/tools/stealth_db")
add_executable(tools.transaction_db
tools/transaction_db/transaction_db.cpp)
target_link_libraries(tools.transaction_db ${PROJECT_NAME})
_group_sources(tools.transaction_db "${CMAKE_CURRENT_LIST_DIR}/tools/transaction_db")
# add_executable(tools.unspent_db
# tools/unspent_db/unspent_db.cpp)
# target_link_libraries(tools.unspent_db ${PROJECT_NAME})
# add_executable(tools.build_utxo
# tools/build_utxo/build_utxo.cpp)
# target_link_libraries(tools.build_utxo ${PROJECT_NAME})
# _group_sources(tools.transaction_db "${CMAKE_CURRENT_LIST_DIR}/tools/build_utxo")
# add_executable(tools.check_scripts
# tools/check_scripts/check_scripts.cpp)
# target_link_libraries(tools.check_scripts ${PROJECT_NAME})
# _group_sources(tools.transaction_db "${CMAKE_CURRENT_LIST_DIR}/tools/check_scripts")
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}
)