Skip to content

Commit

Permalink
cmake: Add wallet functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed May 13, 2023
1 parent f944ccd commit 2e3721e
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 4 deletions.
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,19 @@ option(BUILD_CLI "Build bitcoin-cli executable." ON)
option(BUILD_TX "Build bitcoin-tx executable." ON)
option(BUILD_UTIL "Build bitcoin-util executable." ON)
option(ASM "Use assembly routines." ON)
cmake_dependent_option(CXX20 "Enable compilation in C++20 mode." OFF "NOT MSVC" ON)
option(THREADLOCAL "Enable features that depend on the C++ thread_local keyword (currently just thread names in debug logs)." ON)

option(ENABLE_WALLET "Enable wallet." ON)
# TODO: These tri-state options will be removed and most features
# will become opt-in by default before merging into master.
include(TristateOption)
tristate_option(WITH_SQLITE "Enable SQLite wallet support." "if libsqlite3 is found." AUTO)
tristate_option(WITH_BDB "Enable Berkeley DB (BDB) wallet support." "if libdb_cxx is found." AUTO)
option(WARN_INCOMPATIBLE_BDB "Warn when using a Berkeley DB (BDB) version other than 4.8." ON)
cmake_dependent_option(BUILD_WALLET_TOOL "Build bitcoin-wallet tool." ON "ENABLE_WALLET" OFF)

cmake_dependent_option(CXX20 "Enable compilation in C++20 mode." OFF "NOT MSVC" ON)
option(THREADLOCAL "Enable features that depend on the C++ thread_local keyword (currently just thread names in debug logs)." ON)

tristate_option(CCACHE "Use ccache for compiling." "if ccache is found." AUTO)
tristate_option(WITH_NATPMP "Enable NAT-PMP." "if libnatpmp is found." AUTO)
tristate_option(WITH_MINIUPNPC "Enable UPnP." "if libminiupnpc is found." AUTO)
Expand Down Expand Up @@ -154,6 +161,10 @@ message(" bitcoind ............................ ${BUILD_DAEMON}")
message(" bitcoin-cli ......................... ${BUILD_CLI}")
message(" bitcoin-tx .......................... ${BUILD_TX}")
message(" bitcoin-util ........................ ${BUILD_UTIL}")
message(" bitcoin-wallet ...................... ${BUILD_WALLET_TOOL}")
message("Wallet support:")
message(" SQLite, descriptor wallets .......... ${WITH_SQLITE}")
message(" Berkeley DB, legacy wallets ......... ${WITH_BDB}")
message("Optional packages:")
message(" NAT-PMP ............................. ${WITH_NATPMP}")
message(" UPnP ................................ ${WITH_MINIUPNPC}")
Expand Down
9 changes: 9 additions & 0 deletions cmake/bitcoin-config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,13 @@
significant byte first (like Motorola and SPARC, unlike Intel). */
#cmakedefine WORDS_BIGENDIAN 1

/* Define to 1 to enable wallet functions. */
#cmakedefine ENABLE_WALLET 1

/* Define if SQLite support should be compiled in. */
#cmakedefine USE_SQLITE

/* Define if Berkeley DB (BDB) support should be compiled in. */
#cmakedefine USE_BDB

#endif //BITCOIN_CONFIG_H
87 changes: 87 additions & 0 deletions cmake/module/FindBerkeleyDB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright (c) 2023 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

if(CMAKE_HOST_APPLE)
execute_process(
COMMAND brew --prefix berkeley-db@4
OUTPUT_VARIABLE bdb4_brew_prefix
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()

find_path(BerkeleyDB_INCLUDE_DIR
NAMES db.h
HINTS ${bdb4_brew_prefix}/include
PATH_SUFFIXES 4.8 48 4 db4 5 5.3 db5
)

if(BerkeleyDB_INCLUDE_DIR)
file(
STRINGS "${BerkeleyDB_INCLUDE_DIR}/db.h" version_strings
REGEX ".*DB_VERSION_(MAJOR|MINOR)[ \t]+[0-9]+.*"
)
string(REGEX REPLACE ".*DB_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" BerkeleyDB_VERSION_MAJOR "${version_strings}")
string(REGEX REPLACE ".*DB_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" BerkeleyDB_VERSION_MINOR "${version_strings}")
set(BerkeleyDB_VERSION ${BerkeleyDB_VERSION_MAJOR}.${BerkeleyDB_VERSION_MINOR})
endif()

if(MSVC)
cmake_path(GET BerkeleyDB_INCLUDE_DIR PARENT_PATH BerkeleyDB_IMPORTED_PATH)
find_library(BerkeleyDB_LIBRARY_DEBUG
NAMES libdb48 PATHS ${BerkeleyDB_IMPORTED_PATH}/debug/lib
NO_DEFAULT_PATH
)
find_library(BerkeleyDB_LIBRARY_RELEASE
NAMES libdb48 PATHS ${BerkeleyDB_IMPORTED_PATH}/lib
NO_DEFAULT_PATH
)
if(BerkeleyDB_LIBRARY_DEBUG OR BerkeleyDB_LIBRARY_RELEASE)
set(BerkeleyDB_required BerkeleyDB_IMPORTED_PATH)
endif()
else()
find_library(BerkeleyDB_LIBRARY
NAMES db_cxx-4.8 libdb48 db4_cxx db_cxx db_cxx-5
HINTS ${bdb4_brew_prefix}/lib
)
set(BerkeleyDB_required BerkeleyDB_LIBRARY)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(BerkeleyDB
REQUIRED_VARS ${BerkeleyDB_required} BerkeleyDB_INCLUDE_DIR
VERSION_VAR BerkeleyDB_VERSION
)

if(BerkeleyDB_FOUND AND NOT TARGET BerkeleyDB::BerkeleyDB)
add_library(BerkeleyDB::BerkeleyDB UNKNOWN IMPORTED)
set_target_properties(BerkeleyDB::BerkeleyDB PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${BerkeleyDB_INCLUDE_DIR}"
)
if(MSVC)
if(BerkeleyDB_LIBRARY_DEBUG)
set_property(TARGET BerkeleyDB::BerkeleyDB APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(BerkeleyDB::BerkeleyDB PROPERTIES
IMPORTED_LOCATION_DEBUG "${BerkeleyDB_LIBRARY_DEBUG}"
)
endif()
if(BerkeleyDB_LIBRARY_RELEASE)
set_property(TARGET BerkeleyDB::BerkeleyDB APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(BerkeleyDB::BerkeleyDB PROPERTIES
IMPORTED_LOCATION_RELEASE "${BerkeleyDB_LIBRARY_RELEASE}"
)
endif()
else()
set_target_properties(BerkeleyDB::BerkeleyDB PROPERTIES
IMPORTED_LOCATION "${BerkeleyDB_LIBRARY}"
)
endif()
endif()

mark_as_advanced(
BerkeleyDB_INCLUDE_DIR
BerkeleyDB_LIBRARY
BerkeleyDB_LIBRARY_DEBUG
BerkeleyDB_LIBRARY_RELEASE
)
40 changes: 40 additions & 0 deletions cmake/optional.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,43 @@ if(WITH_USDT)
message(FATAL_ERROR "sys/sdt.h requested, but not found.")
endif()
endif()

if(ENABLE_WALLET)
if(WITH_SQLITE)
include(CrossPkgConfig)
cross_pkg_check_modules(sqlite sqlite3>=3.7.17 IMPORTED_TARGET)
if(sqlite_FOUND)
set(WITH_SQLITE ON)
set(USE_SQLITE ON)
elseif(WITH_SQLITE STREQUAL "AUTO")
set(WITH_SQLITE OFF)
else()
message(FATAL_ERROR "SQLite requested, but not found.")
endif()
endif()

if(WITH_BDB)
find_package(BerkeleyDB 4.8 MODULE)
if(BerkeleyDB_FOUND)
set(WITH_BDB ON)
set(USE_BDB ON)
if(NOT BerkeleyDB_VERSION VERSION_EQUAL 4.8)
message(WARNING "Found Berkeley DB (BDB) other than 4.8.")
if(WARN_INCOMPATIBLE_BDB)
message(WARNING "BDB (legacy) wallets opened by this build would not be portable!\n"
"If this is intended, pass \"-DWARN_INCOMPATIBLE_BDB=OFF\".\n"
"Passing \"-DWITH_BDB=OFF\" will suppress this warning.\n")
else()
message(WARNING "BDB (legacy) wallets opened by this build will not be portable!")
endif()
endif()
else()
message(WARNING "Berkeley DB (BDB) required for legacy wallet support, but not found.\n"
"Passing \"-DWITH_BDB=OFF\" will suppress this warning.\n")
set(WITH_BDB OFF)
endif()
endif()
else()
set(WITH_SQLITE OFF)
set(WITH_BDB OFF)
endif()
27 changes: 25 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,25 @@ target_link_libraries(bitcoin_common
)


if(ENABLE_WALLET)
add_subdirectory(wallet)

if(BUILD_WALLET_TOOL)
add_executable(bitcoin-wallet
bitcoin-wallet.cpp
init/bitcoin-wallet.cpp
wallet/wallettool.cpp
)
target_link_libraries(bitcoin-wallet
bitcoin_wallet
bitcoin_common
bitcoin_util
Boost::headers
)
endif()
endif()


# P2P and RPC server functionality used by `bitcoind` and `bitcoin-qt` executables.
add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL
addrdb.cpp
Expand Down Expand Up @@ -178,9 +197,13 @@ add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL
validation.cpp
validationinterface.cpp
versionbits.cpp

dummywallet.cpp
)
if(ENABLE_WALLET)
target_sources(bitcoin_node PRIVATE wallet/init.cpp)
target_link_libraries(bitcoin_node PRIVATE bitcoin_wallet)
else()
target_sources(bitcoin_node PRIVATE dummywallet.cpp)
endif()
target_link_libraries(bitcoin_node
PRIVATE
bitcoin_common
Expand Down
52 changes: 52 additions & 0 deletions src/wallet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright (c) 2023 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

# Wallet functionality used by bitcoind and bitcoin-wallet executables.
add_library(bitcoin_wallet STATIC EXCLUDE_FROM_ALL
coincontrol.cpp
coinselection.cpp
context.cpp
crypter.cpp
db.cpp
dump.cpp
external_signer_scriptpubkeyman.cpp
feebumper.cpp
fees.cpp
interfaces.cpp
load.cpp
receive.cpp
rpc/addresses.cpp
rpc/backup.cpp
rpc/coins.cpp
rpc/encrypt.cpp
rpc/spend.cpp
rpc/signmessage.cpp
rpc/transactions.cpp
rpc/util.cpp
rpc/wallet.cpp
scriptpubkeyman.cpp
spend.cpp
transaction.cpp
wallet.cpp
walletdb.cpp
walletutil.cpp
)
target_link_libraries(bitcoin_wallet
PRIVATE
bitcoin_common
univalue
Boost::headers
)

if(NOT USE_SQLITE AND NOT USE_BDB)
message(FATAL_ERROR "Wallet functionality requested but no BDB or SQLite support available.")
endif()
if(USE_SQLITE)
target_sources(bitcoin_wallet PRIVATE sqlite.cpp)
target_link_libraries(bitcoin_wallet PRIVATE PkgConfig::sqlite)
endif()
if(USE_BDB)
target_sources(bitcoin_wallet PRIVATE bdb.cpp salvage.cpp)
target_link_libraries(bitcoin_wallet PUBLIC BerkeleyDB::BerkeleyDB)
endif()

0 comments on commit 2e3721e

Please sign in to comment.