Skip to content

Commit 20f6d18

Browse files
committed
cmake: Add wallet functionality
1 parent 210693e commit 20f6d18

File tree

6 files changed

+226
-4
lines changed

6 files changed

+226
-4
lines changed

CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,19 @@ option(BUILD_CLI "Build bitcoin-cli executable." ON)
4343
option(BUILD_TX "Build bitcoin-tx executable." ON)
4444
option(BUILD_UTIL "Build bitcoin-util executable." ON)
4545
option(ASM "Use assembly routines." ON)
46-
cmake_dependent_option(CXX20 "Enable compilation in C++20 mode." OFF "NOT MSVC" ON)
47-
option(THREADLOCAL "Enable features that depend on the C++ thread_local keyword (currently just thread names in debug logs)." ON)
4846

47+
option(ENABLE_WALLET "Enable wallet." ON)
4948
# TODO: These tri-state options will be removed and most features
5049
# will become opt-in by default before merging into master.
5150
include(TristateOption)
51+
tristate_option(WITH_SQLITE "Enable SQLite wallet support." "if libsqlite3 is found." AUTO)
52+
tristate_option(WITH_BDB "Enable Berkeley DB (BDB) wallet support." "if libdb_cxx is found." AUTO)
53+
option(WARN_INCOMPATIBLE_BDB "Warn when using a Berkeley DB (BDB) version other than 4.8." ON)
54+
cmake_dependent_option(BUILD_WALLET_TOOL "Build bitcoin-wallet tool." ON "ENABLE_WALLET" OFF)
55+
56+
cmake_dependent_option(CXX20 "Enable compilation in C++20 mode." OFF "NOT MSVC" ON)
57+
option(THREADLOCAL "Enable features that depend on the C++ thread_local keyword (currently just thread names in debug logs)." ON)
58+
5259
tristate_option(CCACHE "Use ccache for compiling." "if ccache is found." AUTO)
5360
tristate_option(WITH_NATPMP "Enable NAT-PMP." "if libnatpmp is found." AUTO)
5461
tristate_option(WITH_MINIUPNPC "Enable UPnP." "if libminiupnpc is found." AUTO)
@@ -151,6 +158,10 @@ message(" bitcoind ............................ ${BUILD_DAEMON}")
151158
message(" bitcoin-cli ......................... ${BUILD_CLI}")
152159
message(" bitcoin-tx .......................... ${BUILD_TX}")
153160
message(" bitcoin-util ........................ ${BUILD_UTIL}")
161+
message(" bitcoin-wallet ...................... ${BUILD_WALLET_TOOL}")
162+
message("Wallet support:")
163+
message(" SQLite, descriptor wallets .......... ${WITH_SQLITE}")
164+
message(" Berkeley DB, legacy wallets ......... ${WITH_BDB}")
154165
message("Optional packages:")
155166
message(" NAT-PMP ............................. ${WITH_NATPMP}")
156167
message(" UPnP ................................ ${WITH_MINIUPNPC}")

cmake/bitcoin-config.h.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,13 @@
206206
significant byte first (like Motorola and SPARC, unlike Intel). */
207207
#cmakedefine WORDS_BIGENDIAN 1
208208

209+
/* Define to 1 to enable wallet functions. */
210+
#cmakedefine ENABLE_WALLET 1
211+
212+
/* Define if SQLite support should be compiled in. */
213+
#cmakedefine USE_SQLITE
214+
215+
/* Define if Berkeley DB (BDB) support should be compiled in. */
216+
#cmakedefine USE_BDB
217+
209218
#endif //BITCOIN_CONFIG_H

cmake/module/FindBerkeleyDB.cmake

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Copyright (c) 2023 The Bitcoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
if(CMAKE_HOST_APPLE)
6+
execute_process(
7+
COMMAND brew --prefix berkeley-db@4
8+
OUTPUT_VARIABLE bdb4_brew_prefix
9+
ERROR_QUIET
10+
OUTPUT_STRIP_TRAILING_WHITESPACE
11+
)
12+
endif()
13+
14+
find_path(BerkeleyDB_INCLUDE_DIR
15+
NAMES db.h
16+
HINTS ${bdb4_brew_prefix}/include
17+
PATH_SUFFIXES 4.8 48 4 db4 5 5.3 db5
18+
)
19+
20+
if(BerkeleyDB_INCLUDE_DIR)
21+
file(
22+
STRINGS "${BerkeleyDB_INCLUDE_DIR}/db.h" version_strings
23+
REGEX ".*DB_VERSION_(MAJOR|MINOR)[ \t]+[0-9]+.*"
24+
)
25+
string(REGEX REPLACE ".*DB_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" BerkeleyDB_VERSION_MAJOR "${version_strings}")
26+
string(REGEX REPLACE ".*DB_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" BerkeleyDB_VERSION_MINOR "${version_strings}")
27+
set(BerkeleyDB_VERSION ${BerkeleyDB_VERSION_MAJOR}.${BerkeleyDB_VERSION_MINOR})
28+
endif()
29+
30+
if(MSVC)
31+
cmake_path(GET BerkeleyDB_INCLUDE_DIR PARENT_PATH BerkeleyDB_IMPORTED_PATH)
32+
find_library(BerkeleyDB_LIBRARY_DEBUG
33+
NAMES libdb48 PATHS ${BerkeleyDB_IMPORTED_PATH}/debug/lib
34+
NO_DEFAULT_PATH
35+
)
36+
find_library(BerkeleyDB_LIBRARY_RELEASE
37+
NAMES libdb48 PATHS ${BerkeleyDB_IMPORTED_PATH}/lib
38+
NO_DEFAULT_PATH
39+
)
40+
if(BerkeleyDB_LIBRARY_DEBUG OR BerkeleyDB_LIBRARY_RELEASE)
41+
set(BerkeleyDB_required BerkeleyDB_IMPORTED_PATH)
42+
endif()
43+
else()
44+
find_library(BerkeleyDB_LIBRARY
45+
NAMES db_cxx-4.8 libdb48 db4_cxx db_cxx db_cxx-5
46+
HINTS ${bdb4_brew_prefix}/lib
47+
)
48+
set(BerkeleyDB_required BerkeleyDB_LIBRARY)
49+
endif()
50+
51+
include(FindPackageHandleStandardArgs)
52+
find_package_handle_standard_args(BerkeleyDB
53+
REQUIRED_VARS ${BerkeleyDB_required} BerkeleyDB_INCLUDE_DIR
54+
VERSION_VAR BerkeleyDB_VERSION
55+
)
56+
57+
if(BerkeleyDB_FOUND AND NOT TARGET BerkeleyDB::BerkeleyDB)
58+
add_library(BerkeleyDB::BerkeleyDB UNKNOWN IMPORTED)
59+
set_target_properties(BerkeleyDB::BerkeleyDB PROPERTIES
60+
INTERFACE_INCLUDE_DIRECTORIES "${BerkeleyDB_INCLUDE_DIR}"
61+
)
62+
if(MSVC)
63+
if(BerkeleyDB_LIBRARY_DEBUG)
64+
set_property(TARGET BerkeleyDB::BerkeleyDB APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
65+
set_target_properties(BerkeleyDB::BerkeleyDB PROPERTIES
66+
IMPORTED_LOCATION_DEBUG "${BerkeleyDB_LIBRARY_DEBUG}"
67+
)
68+
endif()
69+
if(BerkeleyDB_LIBRARY_RELEASE)
70+
set_property(TARGET BerkeleyDB::BerkeleyDB APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
71+
set_target_properties(BerkeleyDB::BerkeleyDB PROPERTIES
72+
IMPORTED_LOCATION_RELEASE "${BerkeleyDB_LIBRARY_RELEASE}"
73+
)
74+
endif()
75+
else()
76+
set_target_properties(BerkeleyDB::BerkeleyDB PROPERTIES
77+
IMPORTED_LOCATION "${BerkeleyDB_LIBRARY}"
78+
)
79+
endif()
80+
endif()
81+
82+
mark_as_advanced(
83+
BerkeleyDB_INCLUDE_DIR
84+
BerkeleyDB_LIBRARY
85+
BerkeleyDB_LIBRARY_DEBUG
86+
BerkeleyDB_LIBRARY_RELEASE
87+
)

cmake/optional.cmake

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,43 @@ if(WITH_USDT)
108108
message(FATAL_ERROR "sys/sdt.h requested, but not found.")
109109
endif()
110110
endif()
111+
112+
if(ENABLE_WALLET)
113+
if(WITH_SQLITE)
114+
include(CrossPkgConfig)
115+
cross_pkg_check_modules(sqlite sqlite3>=3.7.17 IMPORTED_TARGET)
116+
if(sqlite_FOUND)
117+
set(WITH_SQLITE ON)
118+
set(USE_SQLITE ON)
119+
elseif(WITH_SQLITE STREQUAL "AUTO")
120+
set(WITH_SQLITE OFF)
121+
else()
122+
message(FATAL_ERROR "SQLite requested, but not found.")
123+
endif()
124+
endif()
125+
126+
if(WITH_BDB)
127+
find_package(BerkeleyDB 4.8 MODULE)
128+
if(BerkeleyDB_FOUND)
129+
set(WITH_BDB ON)
130+
set(USE_BDB ON)
131+
if(NOT BerkeleyDB_VERSION VERSION_EQUAL 4.8)
132+
message(WARNING "Found Berkeley DB (BDB) other than 4.8.")
133+
if(WARN_INCOMPATIBLE_BDB)
134+
message(WARNING "BDB (legacy) wallets opened by this build would not be portable!\n"
135+
"If this is intended, pass \"-DWARN_INCOMPATIBLE_BDB=OFF\".\n"
136+
"Passing \"-DWITH_BDB=OFF\" will suppress this warning.\n")
137+
else()
138+
message(WARNING "BDB (legacy) wallets opened by this build will not be portable!")
139+
endif()
140+
endif()
141+
else()
142+
message(WARNING "Berkeley DB (BDB) required for legacy wallet support, but not found.\n"
143+
"Passing \"-DWITH_BDB=OFF\" will suppress this warning.\n")
144+
set(WITH_BDB OFF)
145+
endif()
146+
endif()
147+
else()
148+
set(WITH_SQLITE OFF)
149+
set(WITH_BDB OFF)
150+
endif()

src/CMakeLists.txt

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,25 @@ target_link_libraries(bitcoin_common
9595
)
9696

9797

98+
if(ENABLE_WALLET)
99+
add_subdirectory(wallet)
100+
101+
if(BUILD_WALLET_TOOL)
102+
add_executable(bitcoin-wallet
103+
bitcoin-wallet.cpp
104+
init/bitcoin-wallet.cpp
105+
wallet/wallettool.cpp
106+
)
107+
target_link_libraries(bitcoin-wallet
108+
bitcoin_wallet
109+
bitcoin_common
110+
bitcoin_util
111+
Boost::headers
112+
)
113+
endif()
114+
endif()
115+
116+
98117
# P2P and RPC server functionality used by `bitcoind` and `bitcoin-qt` executables.
99118
add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL
100119
addrdb.cpp
@@ -183,9 +202,13 @@ add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL
183202
validation.cpp
184203
validationinterface.cpp
185204
versionbits.cpp
186-
187-
dummywallet.cpp
188205
)
206+
if(ENABLE_WALLET)
207+
target_sources(bitcoin_node PRIVATE wallet/init.cpp)
208+
target_link_libraries(bitcoin_node PRIVATE bitcoin_wallet)
209+
else()
210+
target_sources(bitcoin_node PRIVATE dummywallet.cpp)
211+
endif()
189212
target_link_libraries(bitcoin_node
190213
PRIVATE
191214
bitcoin_common

src/wallet/CMakeLists.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (c) 2023 The Bitcoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
# Wallet functionality used by bitcoind and bitcoin-wallet executables.
6+
add_library(bitcoin_wallet STATIC EXCLUDE_FROM_ALL
7+
coincontrol.cpp
8+
coinselection.cpp
9+
context.cpp
10+
crypter.cpp
11+
db.cpp
12+
dump.cpp
13+
external_signer_scriptpubkeyman.cpp
14+
feebumper.cpp
15+
fees.cpp
16+
interfaces.cpp
17+
load.cpp
18+
receive.cpp
19+
rpc/addresses.cpp
20+
rpc/backup.cpp
21+
rpc/coins.cpp
22+
rpc/encrypt.cpp
23+
rpc/spend.cpp
24+
rpc/signmessage.cpp
25+
rpc/transactions.cpp
26+
rpc/util.cpp
27+
rpc/wallet.cpp
28+
scriptpubkeyman.cpp
29+
spend.cpp
30+
transaction.cpp
31+
wallet.cpp
32+
walletdb.cpp
33+
walletutil.cpp
34+
)
35+
target_link_libraries(bitcoin_wallet
36+
PRIVATE
37+
bitcoin_common
38+
univalue
39+
Boost::headers
40+
)
41+
42+
if(NOT USE_SQLITE AND NOT USE_BDB)
43+
message(FATAL_ERROR "Wallet functionality requested but no BDB or SQLite support available.")
44+
endif()
45+
if(USE_SQLITE)
46+
target_sources(bitcoin_wallet PRIVATE sqlite.cpp)
47+
target_link_libraries(bitcoin_wallet PRIVATE PkgConfig::sqlite)
48+
endif()
49+
if(USE_BDB)
50+
target_sources(bitcoin_wallet PRIVATE bdb.cpp salvage.cpp)
51+
target_link_libraries(bitcoin_wallet PUBLIC BerkeleyDB::BerkeleyDB)
52+
endif()

0 commit comments

Comments
 (0)