Merge bitcoin/bitcoin#30454: build: Introduce CMake-based build system

41051290ab cmake: Ignore build subdirectories within source directory (Hennadii Stepanov)
6ce50fd9d0 doc: Update for CMake-based build system (Hennadii Stepanov)
9730288a0c ci: Migrate CI scripts to CMake (Hennadii Stepanov)
c360837ca5 cmake, lint: Adjust `lint_includes_build_config` (Hennadii Stepanov)
3885441ee0 cmake: Add presets for native Windows builds (Hennadii Stepanov)
7681746b20 cmake: Add vcpkg manifest file (Hennadii Stepanov)
8b6f1c4353 cmake: Add `Coverage` and `CoverageFuzz` scripts (Hennadii Stepanov)
65bdbc1ff2 cmake: Add `docs` build target (Hennadii Stepanov)
fb75ebbc33 cmake: Add compiler diagnostic flags (Hennadii Stepanov)
e821f0a37a cmake: Migrate Guix build scripts to CMake (Hennadii Stepanov)
747adb6ffe cmake: Add `Maintenance` module (Hennadii Stepanov)
1f60b30df0 cmake: Add `APPEND_{CPP,C,CXX,LD}FLAGS` cache variables (Hennadii Stepanov)
2b43c45b13 cmake: Add `AddWindowsResources` module (Hennadii Stepanov)
973a3b0c5d cmake: Implement `install` build target (Hennadii Stepanov)
84ac35cfd4 cmake: Add cross-compiling support (Hennadii Stepanov)
0d01c228a7 build: Generate `toolchain.cmake` in depends (Hennadii Stepanov)
91a799247d depends: Add host-specific `cmake_system_version` variables (Hennadii Stepanov)
9b31209b4c depends: Rename `cmake_system` -> `cmake_system_name` (Hennadii Stepanov)
4a5208a81d Revert "build, qt: Do not install *.prl files" (Hennadii Stepanov)
6522af62af depends: Amend handling flags environment variables (Hennadii Stepanov)
90cec4d251 cmake: Add `MULTIPROCESS` option (Hennadii Stepanov)
bb1a450dcb cmake: Build `bitcoin-chainstate` executable (Hennadii Stepanov)
aed38ea58c cmake: Build `bitcoinkernel` library (Hennadii Stepanov)
975d67369b cmake: Build `test_bitcoin-qt` executable (Hennadii Stepanov)
10fcc668a3 cmake: Add `WITH_DBUS` option (Hennadii Stepanov)
5bb5a4bc75 cmake: Add `libqrencode` optional package support (Hennadii Stepanov)
57a6e2ef4a cmake: Build `bitcoin-qt` executable (Hennadii Stepanov)
30f642952c cmake: Add `WERROR` option (Hennadii Stepanov)
c98d4a4c34 cmake: Add `REDUCE_EXPORTS` option (Hennadii Stepanov)
a01cb6e63f cmake: Add `HARDENING` option (Hennadii Stepanov)
a8a2e364ac cmake: Add Python-based tests (Hennadii Stepanov)
3d85379570 cmake: Add fuzzing options (Hennadii Stepanov)
908530e312 cmake: Add `SANITIZERS` option (Hennadii Stepanov)
8bb0e85631 cmake: Build `bench_bitcoin` executable (Hennadii Stepanov)
801735163a cmake: Add external signer support (Hennadii Stepanov)
353e0c9e96 cmake: Add `systemtap-sdt` optional package support (Hennadii Stepanov)
d2fda82b49 cmake: Add `libzmq` optional package support (Hennadii Stepanov)
ae7b39a0e1 cmake: Add `libminiupnpc` optional package support (Hennadii Stepanov)
6480e1dcdb cmake: Add `libnatpmp` optional package support (Hennadii Stepanov)
e73e9304a1 cmake: Build `bitcoin-util` executable (Hennadii Stepanov)
027c6d7caa cmake: Build `bitcoin-tx` executable (Hennadii Stepanov)
d10c5c34c3 cmake: Add wallet functionality (Hennadii Stepanov)
ab2e99b0d9 cmake: Create test suite for `ctest` (Hennadii Stepanov)
959370bd76 cmake: Build `test_bitcoin` executable (Hennadii Stepanov)
b27bf9700d cmake: Build `bitcoin-cli` executable (Hennadii Stepanov)
a9813df826 cmake: Build `bitcoind` executable (Hennadii Stepanov)
97829ce2d5 cmake: Add `FindLibevent` module (Hennadii Stepanov)
3118e40c61 cmake: Build `bitcoin_consensus` library (Hennadii Stepanov)
809a2f1929 cmake: Build `bitcoin_util` static library (Hennadii Stepanov)
0a9a521a70 cmake: Build `bitcoin_crypto` library (Hennadii Stepanov)
958971f476 cmake: Build `univalue` static library (Hennadii Stepanov)
752747fda8 cmake: Generate `obj/build.h` header (Hennadii Stepanov)
1f0a78edf3 cmake: Build `minisketch` static library (Hennadii Stepanov)
12bfbc8154 cmake: Build `leveldb` static library (Hennadii Stepanov)
51985c5304 cmake: Build `crc32c` static library (Hennadii Stepanov)
db7a198f29 cmake: Build `secp256k1` subtree (Hennadii Stepanov)
dbb7ed14e8 cmake: Add `ccache` support (Hennadii Stepanov)
cedfdf6c72 cmake: Redefine/adjust per-configuration flags (Hennadii Stepanov)
b6b5e732c8 cmake: Add global compiler and linker flags (Hennadii Stepanov)
f98327931b cmake: Add `TryAppendLinkerFlag` module (Hennadii Stepanov)
4a0af29697 cmake: Add `TryAppendCXXFlags` module (Hennadii Stepanov)
35cffc497d cmake: Add POSIX threads support (Hennadii Stepanov)
fd72d00ffe cmake: Add position independent code support (Hennadii Stepanov)
07069e2bb0 cmake: Add introspection module (Hennadii Stepanov)
27d687fc1f cmake: Add `config/bitcoin-config.h` support (Hennadii Stepanov)
fe5cdace5f cmake: Print compiler and linker flags in summary (Hennadii Stepanov)
70683884c5 cmake: Introduce interface libraries to encapsulate common flags (Hennadii Stepanov)
a2317e27b7 cmake: Add root `CMakeLists.txt` file (Hennadii Stepanov)

Pull request description:

  This PR introduces a new CMake-based build system, which is a drop-in replacement for the current Autotools-based build system.

  ML announcement: https://groups.google.com/g/bitcoindev/c/hgKkfQWzrTo

  As discussed during the recent CoreDev meetup in April, the switch from Autotools to CMake is intended to happen as soon as possible after branching 28.x off, which means that 29.0 will be built using CMake.

  This PR branch is essentially the [staging branch](https://github.com/hebasto/bitcoin/tree/cmake-staging), with every change reviewed and tested by a group of contributors, including (in alphabetical order):
  - [**achow101**](https://github.com/achow101)
  - [**fanquake**](https://github.com/fanquake)
  - [**maflcko**](https://github.com/maflcko)
  - [**m3dwards**](https://github.com/m3dwards)
  - [**pablomartin4btc**](https://github.com/pablomartin4btc)
  - [**real-or-random**](https://github.com/real-or-random)
  - [**ryanofsky**](https://github.com/ryanofsky)
  - [**sipsorcery**](https://github.com/sipsorcery)
  - [**TheCharlatan**](https://github.com/TheCharlatan)
  - [**theStack**](https://github.com/theStack)
  - [**theuni**](https://github.com/theuni)
  - [**vasild**](https://github.com/vasild)

  Reviewing in a separate staging repo was suggested in https://github.com/bitcoin/bitcoin/pull/27060#issuecomment-1431798320.

  The accompanying changes to the OSS-Fuzz project are available in https://github.com/hebasto/oss-fuzz/pull/8.

  Please refer to the [build options parity table](https://gist.github.com/hebasto/2ef97d3a726bfce08ded9df07f7dab5e). The "auto" value is no longer available; non-default values must be specified explicitly. Additionally, the new default values have been chosen to suit the everyday build experience for the majority of developers.

  System requirements for using the CMake-based build system:
  - CMake >= 3.22 (if not available in your system's repository, it can be downloaded from https://cmake.org/download/)
  - a build tool of your choice:
  - any Make (GNU Make is no longer a requirement); GNU Make is still required to build depends
  - Ninja (https://ninja-build.org/)
  - MSBuild
  - Xcode

  A note for Windows users: The default installation of the latest version of MSVC 17.10.4 includes both CMake 3.28.3 and the vcpkg package manager).

  ---

  We, the build system developers, kindly ask reviewers to refrain from making suggestions that are not directly related to the migration process or can be implemented separately. Bugs in the scripts and errors in the updated documentation should be the focus of this PR. Please be advised that comments not aligned with this PR's goal may be ignored.

  Thank you all for your understanding.

ACKs for top commit:
  maflcko:
    review ACK 41051290ab 🐥
  sipsorcery:
    ACK 41051290ab.
  vasild:
    ACK 41051290ab
  TheCharlatan:
    ACK 41051290ab
  pablomartin4btc:
    tACK 41051290ab
  i-am-yuvi:
    tACK [`4105129`](41051290ab)
  theuni:
    ACK 41051290ab.
  fanquake:
    ACK 41051290ab

Tree-SHA512: 6c1445054436c6c00ad63bfa0f19d64091a2b25c9bd694f85bf2218ac358ffb774d6c000685b3ca1e9b50401babed989fa2a0694b774c211d226bfd1944c9b39
This commit is contained in:
merge-script
2024-08-28 10:51:24 +01:00
113 changed files with 5878 additions and 524 deletions

438
src/CMakeLists.txt Normal file
View File

@@ -0,0 +1,438 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
include(GNUInstallDirs)
include(AddWindowsResources)
configure_file(${PROJECT_SOURCE_DIR}/cmake/bitcoin-config.h.in config/bitcoin-config.h @ONLY)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
# TODO: After the transition from Autotools to CMake, the obj/ subdirectory
# could be dropped as its only purpose was to separate a generated header
# from source files.
add_custom_target(generate_build_info
BYPRODUCTS ${PROJECT_BINARY_DIR}/src/obj/build.h
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/src/obj
COMMAND ${CMAKE_COMMAND} -DBUILD_INFO_HEADER_PATH=${PROJECT_BINARY_DIR}/src/obj/build.h -DSOURCE_DIR=${PROJECT_SOURCE_DIR} -P ${PROJECT_SOURCE_DIR}/cmake/script/GenerateBuildInfo.cmake
COMMENT "Generating obj/build.h"
VERBATIM
)
add_library(bitcoin_clientversion OBJECT EXCLUDE_FROM_ALL
clientversion.cpp
)
target_compile_definitions(bitcoin_clientversion
PRIVATE
HAVE_BUILD_INFO
)
target_link_libraries(bitcoin_clientversion
PRIVATE
core_interface
)
add_dependencies(bitcoin_clientversion generate_build_info)
add_subdirectory(crypto)
add_subdirectory(univalue)
add_subdirectory(util)
if(WITH_MULTIPROCESS)
add_subdirectory(ipc)
endif()
#=============================
# secp256k1 subtree
#=============================
message("")
message("Configuring secp256k1 subtree...")
set(SECP256K1_DISABLE_SHARED ON CACHE BOOL "" FORCE)
set(SECP256K1_ENABLE_MODULE_ECDH OFF CACHE BOOL "" FORCE)
set(SECP256K1_ENABLE_MODULE_RECOVERY ON CACHE BOOL "" FORCE)
set(SECP256K1_BUILD_BENCHMARK OFF CACHE BOOL "" FORCE)
set(SECP256K1_BUILD_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE)
set(SECP256K1_BUILD_EXHAUSTIVE_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE)
set(SECP256K1_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
include(GetTargetInterface)
# -fsanitize and related flags apply to both C++ and C,
# so we can pass them down to libsecp256k1 as CFLAGS.
get_target_interface(core_sanitizer_cxx_flags "" sanitize_interface COMPILE_OPTIONS)
set(SECP256K1_LATE_CFLAGS ${core_sanitizer_cxx_flags} CACHE STRING "" FORCE)
unset(core_sanitizer_cxx_flags)
# We want to build libsecp256k1 with the most tested RelWithDebInfo configuration.
enable_language(C)
foreach(config IN LISTS CMAKE_BUILD_TYPE CMAKE_CONFIGURATION_TYPES)
if(config STREQUAL "")
continue()
endif()
string(TOUPPER "${config}" config)
set(CMAKE_C_FLAGS_${config} "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
endforeach()
# If the CFLAGS environment variable is defined during building depends
# and configuring this build system, its content might be duplicated.
if(DEFINED ENV{CFLAGS})
deduplicate_flags(CMAKE_C_FLAGS)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS OFF)
add_subdirectory(secp256k1)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
string(APPEND CMAKE_C_COMPILE_OBJECT " ${APPEND_CPPFLAGS} ${APPEND_CFLAGS}")
# Stable, backwards-compatible consensus functionality.
add_library(bitcoin_consensus STATIC EXCLUDE_FROM_ALL
arith_uint256.cpp
consensus/merkle.cpp
consensus/tx_check.cpp
hash.cpp
primitives/block.cpp
primitives/transaction.cpp
pubkey.cpp
script/interpreter.cpp
script/script.cpp
script/script_error.cpp
uint256.cpp
)
target_link_libraries(bitcoin_consensus
PRIVATE
core_interface
bitcoin_crypto
secp256k1
)
if(WITH_ZMQ)
add_subdirectory(zmq)
endif()
# Home for common functionality shared by different executables and libraries.
# Similar to `bitcoin_util` library, but higher-level.
add_library(bitcoin_common STATIC EXCLUDE_FROM_ALL
addresstype.cpp
base58.cpp
bech32.cpp
chainparams.cpp
chainparamsbase.cpp
coins.cpp
common/args.cpp
common/bloom.cpp
common/config.cpp
common/init.cpp
common/interfaces.cpp
common/messages.cpp
common/run_command.cpp
common/settings.cpp
common/signmessage.cpp
common/system.cpp
common/url.cpp
compressor.cpp
core_read.cpp
core_write.cpp
deploymentinfo.cpp
external_signer.cpp
init/common.cpp
kernel/chainparams.cpp
key.cpp
key_io.cpp
merkleblock.cpp
net_permissions.cpp
net_types.cpp
netaddress.cpp
netbase.cpp
outputtype.cpp
policy/feerate.cpp
policy/policy.cpp
protocol.cpp
psbt.cpp
rpc/external_signer.cpp
rpc/rawtransaction_util.cpp
rpc/request.cpp
rpc/util.cpp
scheduler.cpp
script/descriptor.cpp
script/miniscript.cpp
script/parsing.cpp
script/sign.cpp
script/signingprovider.cpp
script/solver.cpp
)
target_link_libraries(bitcoin_common
PRIVATE
core_interface
bitcoin_consensus
bitcoin_util
univalue
secp256k1
Boost::headers
$<TARGET_NAME_IF_EXISTS:USDT::headers>
$<$<PLATFORM_ID:Windows>:ws2_32>
)
set(installable_targets)
if(ENABLE_WALLET)
add_subdirectory(wallet)
if(BUILD_WALLET_TOOL)
add_executable(bitcoin-wallet
bitcoin-wallet.cpp
init/bitcoin-wallet.cpp
wallet/wallettool.cpp
)
add_windows_resources(bitcoin-wallet bitcoin-wallet-res.rc)
target_link_libraries(bitcoin-wallet
core_interface
bitcoin_wallet
bitcoin_common
bitcoin_util
Boost::headers
)
list(APPEND installable_targets bitcoin-wallet)
endif()
endif()
# P2P and RPC server functionality used by `bitcoind` and `bitcoin-qt` executables.
add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL
addrdb.cpp
addrman.cpp
banman.cpp
bip324.cpp
blockencodings.cpp
blockfilter.cpp
chain.cpp
consensus/tx_verify.cpp
dbwrapper.cpp
deploymentstatus.cpp
flatfile.cpp
headerssync.cpp
httprpc.cpp
httpserver.cpp
i2p.cpp
index/base.cpp
index/blockfilterindex.cpp
index/coinstatsindex.cpp
index/txindex.cpp
init.cpp
kernel/chain.cpp
kernel/checks.cpp
kernel/coinstats.cpp
kernel/context.cpp
kernel/cs_main.cpp
kernel/disconnected_transactions.cpp
kernel/mempool_removal_reason.cpp
mapport.cpp
net.cpp
net_processing.cpp
netgroup.cpp
node/abort.cpp
node/blockmanager_args.cpp
node/blockstorage.cpp
node/caches.cpp
node/chainstate.cpp
node/chainstatemanager_args.cpp
node/coin.cpp
node/coins_view_args.cpp
node/connection_types.cpp
node/context.cpp
node/database_args.cpp
node/eviction.cpp
node/interface_ui.cpp
node/interfaces.cpp
node/kernel_notifications.cpp
node/mempool_args.cpp
node/mempool_persist.cpp
node/mempool_persist_args.cpp
node/miner.cpp
node/mini_miner.cpp
node/minisketchwrapper.cpp
node/peerman_args.cpp
node/psbt.cpp
node/timeoffsets.cpp
node/transaction.cpp
node/txreconciliation.cpp
node/utxo_snapshot.cpp
node/warnings.cpp
noui.cpp
policy/fees.cpp
policy/fees_args.cpp
policy/packages.cpp
policy/rbf.cpp
policy/settings.cpp
policy/truc_policy.cpp
pow.cpp
rest.cpp
rpc/blockchain.cpp
rpc/fees.cpp
rpc/mempool.cpp
rpc/mining.cpp
rpc/net.cpp
rpc/node.cpp
rpc/output_script.cpp
rpc/rawtransaction.cpp
rpc/server.cpp
rpc/server_util.cpp
rpc/signmessage.cpp
rpc/txoutproof.cpp
script/sigcache.cpp
signet.cpp
torcontrol.cpp
txdb.cpp
txmempool.cpp
txorphanage.cpp
txrequest.cpp
validation.cpp
validationinterface.cpp
versionbits.cpp
$<$<TARGET_EXISTS:bitcoin_wallet>:wallet/init.cpp>
$<$<NOT:$<TARGET_EXISTS:bitcoin_wallet>>:dummywallet.cpp>
)
target_link_libraries(bitcoin_node
PRIVATE
core_interface
bitcoin_common
bitcoin_util
leveldb
minisketch
univalue
Boost::headers
$<TARGET_NAME_IF_EXISTS:libevent::libevent>
$<TARGET_NAME_IF_EXISTS:libevent::pthreads>
$<TARGET_NAME_IF_EXISTS:NATPMP::NATPMP>
$<TARGET_NAME_IF_EXISTS:MiniUPnPc::MiniUPnPc>
$<TARGET_NAME_IF_EXISTS:bitcoin_zmq>
$<TARGET_NAME_IF_EXISTS:USDT::headers>
)
# Bitcoin Core bitcoind.
if(BUILD_DAEMON)
add_executable(bitcoind
bitcoind.cpp
init/bitcoind.cpp
)
add_windows_resources(bitcoind bitcoind-res.rc)
target_link_libraries(bitcoind
core_interface
bitcoin_node
$<TARGET_NAME_IF_EXISTS:bitcoin_wallet>
)
list(APPEND installable_targets bitcoind)
endif()
if(WITH_MULTIPROCESS)
add_executable(bitcoin-node
bitcoind.cpp
init/bitcoin-node.cpp
)
target_link_libraries(bitcoin-node
core_interface
bitcoin_node
bitcoin_ipc
$<TARGET_NAME_IF_EXISTS:bitcoin_wallet>
)
list(APPEND installable_targets bitcoin-node)
endif()
add_library(bitcoin_cli STATIC EXCLUDE_FROM_ALL
compat/stdin.cpp
rpc/client.cpp
)
target_link_libraries(bitcoin_cli
PUBLIC
core_interface
univalue
)
# Bitcoin Core RPC client
if(BUILD_CLI)
add_executable(bitcoin-cli bitcoin-cli.cpp)
add_windows_resources(bitcoin-cli bitcoin-cli-res.rc)
target_link_libraries(bitcoin-cli
core_interface
bitcoin_cli
bitcoin_common
bitcoin_util
$<TARGET_NAME_IF_EXISTS:libevent::libevent>
)
list(APPEND installable_targets bitcoin-cli)
endif()
if(BUILD_TX)
add_executable(bitcoin-tx bitcoin-tx.cpp)
add_windows_resources(bitcoin-tx bitcoin-tx-res.rc)
target_link_libraries(bitcoin-tx
core_interface
bitcoin_common
bitcoin_util
univalue
)
list(APPEND installable_targets bitcoin-tx)
endif()
if(BUILD_UTIL)
add_executable(bitcoin-util bitcoin-util.cpp)
add_windows_resources(bitcoin-util bitcoin-util-res.rc)
target_link_libraries(bitcoin-util
core_interface
bitcoin_common
bitcoin_util
)
list(APPEND installable_targets bitcoin-util)
endif()
if(BUILD_GUI)
add_subdirectory(qt)
endif()
if(BUILD_KERNEL_LIB)
add_subdirectory(kernel)
endif()
if(BUILD_UTIL_CHAINSTATE)
add_executable(bitcoin-chainstate
bitcoin-chainstate.cpp
)
# TODO: The `SKIP_BUILD_RPATH` property setting can be deleted
# in the future after reordering Guix script commands to
# perform binary checks after the installation step.
# Relevant discussions:
# - https://github.com/hebasto/bitcoin/pull/236#issuecomment-2183120953
# - https://github.com/bitcoin/bitcoin/pull/30312#issuecomment-2191235833
set_target_properties(bitcoin-chainstate PROPERTIES
SKIP_BUILD_RPATH OFF
)
target_link_libraries(bitcoin-chainstate
PRIVATE
core_interface
bitcoinkernel
)
endif()
add_subdirectory(test/util)
if(BUILD_BENCH)
add_subdirectory(bench)
endif()
if(BUILD_TESTS)
add_subdirectory(test)
endif()
if(BUILD_FUZZ_BINARY)
add_subdirectory(test/fuzz)
endif()
install(TARGETS ${installable_targets}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
unset(installable_targets)
if(INSTALL_MAN)
# TODO: these stubs are no longer needed. man pages should be generated at install time.
install(DIRECTORY ../doc/man/
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
FILES_MATCHING PATTERN *.1
)
endif()

85
src/bench/CMakeLists.txt Normal file
View File

@@ -0,0 +1,85 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
include(GenerateHeaders)
generate_header_from_raw(data/block413567.raw)
add_executable(bench_bitcoin
bench_bitcoin.cpp
bench.cpp
data.cpp
nanobench.cpp
${CMAKE_CURRENT_BINARY_DIR}/data/block413567.raw.h
# Benchmarks:
addrman.cpp
base58.cpp
bech32.cpp
bip324_ecdh.cpp
block_assemble.cpp
ccoins_caching.cpp
chacha20.cpp
checkblock.cpp
checkblockindex.cpp
checkqueue.cpp
cluster_linearize.cpp
crypto_hash.cpp
descriptors.cpp
disconnected_transactions.cpp
duplicate_inputs.cpp
ellswift.cpp
examples.cpp
gcs_filter.cpp
hashpadding.cpp
index_blockfilter.cpp
load_external.cpp
lockedpool.cpp
logging.cpp
mempool_eviction.cpp
mempool_stress.cpp
merkle_root.cpp
parse_hex.cpp
peer_eviction.cpp
poly1305.cpp
pool.cpp
prevector.cpp
random.cpp
readblock.cpp
rollingbloom.cpp
rpc_blockchain.cpp
rpc_mempool.cpp
sign_transaction.cpp
streams_findbyte.cpp
strencodings.cpp
util_time.cpp
verify_script.cpp
xor.cpp
)
target_link_libraries(bench_bitcoin
core_interface
test_util
bitcoin_node
Boost::headers
)
if(ENABLE_WALLET)
target_sources(bench_bitcoin
PRIVATE
coin_selection.cpp
wallet_balance.cpp
wallet_create.cpp
wallet_create_tx.cpp
wallet_loading.cpp
wallet_ismine.cpp
)
target_link_libraries(bench_bitcoin bitcoin_wallet)
endif()
add_test(NAME bench_sanity_check_high_priority
COMMAND bench_bitcoin -sanity-check -priority-level=high
)
install(TARGETS bench_bitcoin
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

68
src/crypto/CMakeLists.txt Normal file
View File

@@ -0,0 +1,68 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
add_library(bitcoin_crypto STATIC EXCLUDE_FROM_ALL
aes.cpp
chacha20.cpp
chacha20poly1305.cpp
hex_base.cpp
hkdf_sha256_32.cpp
hmac_sha256.cpp
hmac_sha512.cpp
muhash.cpp
poly1305.cpp
ripemd160.cpp
sha1.cpp
sha256.cpp
sha256_sse4.cpp
sha3.cpp
sha512.cpp
siphash.cpp
../support/cleanse.cpp
)
target_link_libraries(bitcoin_crypto
PRIVATE
core_interface
)
if(HAVE_SSE41)
add_library(bitcoin_crypto_sse41 STATIC EXCLUDE_FROM_ALL
sha256_sse41.cpp
)
target_compile_definitions(bitcoin_crypto_sse41 PUBLIC ENABLE_SSE41)
target_compile_options(bitcoin_crypto_sse41 PRIVATE ${SSE41_CXXFLAGS})
target_link_libraries(bitcoin_crypto_sse41 PRIVATE core_interface)
target_link_libraries(bitcoin_crypto PRIVATE bitcoin_crypto_sse41)
endif()
if(HAVE_AVX2)
add_library(bitcoin_crypto_avx2 STATIC EXCLUDE_FROM_ALL
sha256_avx2.cpp
)
target_compile_definitions(bitcoin_crypto_avx2 PUBLIC ENABLE_AVX2)
target_compile_options(bitcoin_crypto_avx2 PRIVATE ${AVX2_CXXFLAGS})
target_link_libraries(bitcoin_crypto_avx2 PRIVATE core_interface)
target_link_libraries(bitcoin_crypto PRIVATE bitcoin_crypto_avx2)
endif()
if(HAVE_SSE41 AND HAVE_X86_SHANI)
add_library(bitcoin_crypto_x86_shani STATIC EXCLUDE_FROM_ALL
sha256_x86_shani.cpp
)
target_compile_definitions(bitcoin_crypto_x86_shani PUBLIC ENABLE_SSE41 ENABLE_X86_SHANI)
target_compile_options(bitcoin_crypto_x86_shani PRIVATE ${X86_SHANI_CXXFLAGS})
target_link_libraries(bitcoin_crypto_x86_shani PRIVATE core_interface)
target_link_libraries(bitcoin_crypto PRIVATE bitcoin_crypto_x86_shani)
endif()
if(HAVE_ARM_SHANI)
add_library(bitcoin_crypto_arm_shani STATIC EXCLUDE_FROM_ALL
sha256_arm_shani.cpp
)
target_compile_definitions(bitcoin_crypto_arm_shani PUBLIC ENABLE_ARM_SHANI)
target_compile_options(bitcoin_crypto_arm_shani PRIVATE ${ARM_SHANI_CXXFLAGS})
target_link_libraries(bitcoin_crypto_arm_shani PRIVATE core_interface)
target_link_libraries(bitcoin_crypto PRIVATE bitcoin_crypto_arm_shani)
endif()

18
src/ipc/CMakeLists.txt Normal file
View File

@@ -0,0 +1,18 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
add_library(bitcoin_ipc STATIC EXCLUDE_FROM_ALL
capnp/protocol.cpp
interfaces.cpp
process.cpp
)
target_capnp_sources(bitcoin_ipc ${PROJECT_SOURCE_DIR}
capnp/echo.capnp capnp/init.capnp
)
target_link_libraries(bitcoin_ipc
PRIVATE
core_interface
)

106
src/kernel/CMakeLists.txt Normal file
View File

@@ -0,0 +1,106 @@
# Copyright (c) 2024-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
# TODO: libbitcoinkernel is a work in progress consensus engine
# library, as more and more modules are decoupled from the
# consensus engine, this list will shrink to only those
# which are absolutely necessary.
add_library(bitcoinkernel
bitcoinkernel.cpp
chain.cpp
checks.cpp
chainparams.cpp
coinstats.cpp
context.cpp
cs_main.cpp
disconnected_transactions.cpp
mempool_removal_reason.cpp
../arith_uint256.cpp
../chain.cpp
../coins.cpp
../compressor.cpp
../consensus/merkle.cpp
../consensus/tx_check.cpp
../consensus/tx_verify.cpp
../core_read.cpp
../dbwrapper.cpp
../deploymentinfo.cpp
../deploymentstatus.cpp
../flatfile.cpp
../hash.cpp
../logging.cpp
../node/blockstorage.cpp
../node/chainstate.cpp
../node/utxo_snapshot.cpp
../policy/feerate.cpp
../policy/packages.cpp
../policy/policy.cpp
../policy/rbf.cpp
../policy/settings.cpp
../policy/truc_policy.cpp
../pow.cpp
../primitives/block.cpp
../primitives/transaction.cpp
../pubkey.cpp
../random.cpp
../randomenv.cpp
../script/interpreter.cpp
../script/script.cpp
../script/script_error.cpp
../script/sigcache.cpp
../script/solver.cpp
../signet.cpp
../streams.cpp
../support/lockedpool.cpp
../sync.cpp
../txdb.cpp
../txmempool.cpp
../uint256.cpp
../util/chaintype.cpp
../util/check.cpp
../util/feefrac.cpp
../util/fs.cpp
../util/fs_helpers.cpp
../util/hasher.cpp
../util/moneystr.cpp
../util/rbf.cpp
../util/serfloat.cpp
../util/signalinterrupt.cpp
../util/strencodings.cpp
../util/string.cpp
../util/syserror.cpp
../util/threadnames.cpp
../util/time.cpp
../util/tokenpipe.cpp
../validation.cpp
../validationinterface.cpp
../versionbits.cpp
)
target_link_libraries(bitcoinkernel
PRIVATE
core_interface
bitcoin_clientversion
bitcoin_crypto
leveldb
secp256k1
PUBLIC
Boost::headers
)
# libbitcoinkernel requires default symbol visibility, explicitly
# specify that here so that things still work even when user
# configures with -DREDUCE_EXPORTS=ON
#
# Note this is a quick hack that will be removed as we
# incrementally define what to export from the library.
set_target_properties(bitcoinkernel PROPERTIES
CXX_VISIBILITY_PRESET default
)
include(GNUInstallDirs)
install(TARGETS bitcoinkernel
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

334
src/qt/CMakeLists.txt Normal file
View File

@@ -0,0 +1,334 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
enable_language(OBJCXX)
set(CMAKE_OBJCXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
set(CMAKE_OBJCXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_OBJCXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_OBJCXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
string(APPEND CMAKE_OBJCXX_COMPILE_OBJECT " ${APPEND_CPPFLAGS} ${APPEND_CXXFLAGS}")
endif()
get_target_property(qt_lib_type Qt5::Core TYPE)
# TODO: After the transition from Autotools to CMake,
# all `Q_IMPORT_PLUGIN` macros can be deleted from the
# qt/bitcoin.cpp and qt/test/test_main.cpp source files.
function(import_plugins target)
if(qt_lib_type STREQUAL "STATIC_LIBRARY")
set(plugins Qt5::QMinimalIntegrationPlugin)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND plugins Qt5::QXcbIntegrationPlugin)
elseif(WIN32)
list(APPEND plugins Qt5::QWindowsIntegrationPlugin Qt5::QWindowsVistaStylePlugin)
elseif(APPLE)
list(APPEND plugins Qt5::QCocoaIntegrationPlugin Qt5::QMacStylePlugin)
endif()
qt5_import_plugins(${target}
INCLUDE ${plugins}
EXCLUDE_BY_TYPE imageformats iconengines
)
endif()
endfunction()
# For Qt-specific commands and variables, please consult:
# - https://cmake.org/cmake/help/latest/manual/cmake-qt.7.html
# - https://doc.qt.io/qt-5/cmake-manual.html
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOUIC_SEARCH_PATHS forms)
# TODO: The file(GLOB ...) command should be replaced with an explicit
# file list. Such a change must be synced with the corresponding change
# to https://github.com/bitcoin-core/bitcoin-maintainer-tools/blob/main/update-translations.py
file(GLOB ts_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} locale/*.ts)
set_source_files_properties(${ts_files} PROPERTIES OUTPUT_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/locale)
qt5_add_translation(qm_files ${ts_files})
configure_file(bitcoin_locale.qrc bitcoin_locale.qrc COPYONLY)
# The bitcoinqt sources have to include headers in
# order to parse them to collect translatable strings.
add_library(bitcoinqt STATIC EXCLUDE_FROM_ALL
bantablemodel.cpp
bantablemodel.h
bitcoin.cpp
bitcoin.h
bitcoinaddressvalidator.cpp
bitcoinaddressvalidator.h
bitcoinamountfield.cpp
bitcoinamountfield.h
bitcoingui.cpp
bitcoingui.h
bitcoinunits.cpp
bitcoinunits.h
clientmodel.cpp
clientmodel.h
csvmodelwriter.cpp
csvmodelwriter.h
guiutil.cpp
guiutil.h
initexecutor.cpp
initexecutor.h
intro.cpp
intro.h
$<$<PLATFORM_ID:Darwin>:macdockiconhandler.h>
$<$<PLATFORM_ID:Darwin>:macdockiconhandler.mm>
$<$<PLATFORM_ID:Darwin>:macnotificationhandler.h>
$<$<PLATFORM_ID:Darwin>:macnotificationhandler.mm>
$<$<PLATFORM_ID:Darwin>:macos_appnap.h>
$<$<PLATFORM_ID:Darwin>:macos_appnap.mm>
modaloverlay.cpp
modaloverlay.h
networkstyle.cpp
networkstyle.h
notificator.cpp
notificator.h
optionsdialog.cpp
optionsdialog.h
optionsmodel.cpp
optionsmodel.h
peertablemodel.cpp
peertablemodel.h
peertablesortproxy.cpp
peertablesortproxy.h
platformstyle.cpp
platformstyle.h
qvalidatedlineedit.cpp
qvalidatedlineedit.h
qvaluecombobox.cpp
qvaluecombobox.h
rpcconsole.cpp
rpcconsole.h
splashscreen.cpp
splashscreen.h
trafficgraphwidget.cpp
trafficgraphwidget.h
utilitydialog.cpp
utilitydialog.h
$<$<PLATFORM_ID:Windows>:winshutdownmonitor.cpp>
$<$<PLATFORM_ID:Windows>:winshutdownmonitor.h>
bitcoin.qrc
${CMAKE_CURRENT_BINARY_DIR}/bitcoin_locale.qrc
)
target_compile_definitions(bitcoinqt
PUBLIC
QT_NO_KEYWORDS
QT_USE_QSTRINGBUILDER
)
target_include_directories(bitcoinqt
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
)
set_property(SOURCE macnotificationhandler.mm
# Ignore warnings "'NSUserNotificationCenter' is deprecated: first deprecated in macOS 11.0".
APPEND PROPERTY COMPILE_OPTIONS -Wno-deprecated-declarations
)
target_link_libraries(bitcoinqt
PUBLIC
Qt5::Widgets
PRIVATE
core_interface
bitcoin_cli
leveldb
Boost::headers
$<TARGET_NAME_IF_EXISTS:NATPMP::NATPMP>
$<TARGET_NAME_IF_EXISTS:MiniUPnPc::MiniUPnPc>
$<TARGET_NAME_IF_EXISTS:PkgConfig::libqrencode>
$<$<PLATFORM_ID:Darwin>:-framework\ AppKit>
$<$<CXX_COMPILER_ID:MSVC>:shlwapi>
)
if(ENABLE_WALLET)
target_sources(bitcoinqt
PRIVATE
addressbookpage.cpp
addressbookpage.h
addresstablemodel.cpp
addresstablemodel.h
askpassphrasedialog.cpp
askpassphrasedialog.h
coincontroldialog.cpp
coincontroldialog.h
coincontroltreewidget.cpp
coincontroltreewidget.h
createwalletdialog.cpp
createwalletdialog.h
editaddressdialog.cpp
editaddressdialog.h
openuridialog.cpp
openuridialog.h
overviewpage.cpp
overviewpage.h
paymentserver.cpp
paymentserver.h
psbtoperationsdialog.cpp
psbtoperationsdialog.h
qrimagewidget.cpp
qrimagewidget.h
receivecoinsdialog.cpp
receivecoinsdialog.h
receiverequestdialog.cpp
receiverequestdialog.h
recentrequeststablemodel.cpp
recentrequeststablemodel.h
sendcoinsdialog.cpp
sendcoinsdialog.h
sendcoinsentry.cpp
sendcoinsentry.h
signverifymessagedialog.cpp
signverifymessagedialog.h
transactiondesc.cpp
transactiondesc.h
transactiondescdialog.cpp
transactiondescdialog.h
transactionfilterproxy.cpp
transactionfilterproxy.h
transactionoverviewwidget.cpp
transactionoverviewwidget.h
transactionrecord.cpp
transactionrecord.h
transactiontablemodel.cpp
transactiontablemodel.h
transactionview.cpp
transactionview.h
walletcontroller.cpp
walletcontroller.h
walletframe.cpp
walletframe.h
walletmodel.cpp
walletmodel.h
walletmodeltransaction.cpp
walletmodeltransaction.h
walletview.cpp
walletview.h
)
target_link_libraries(bitcoinqt
PRIVATE
bitcoin_wallet
Qt5::Network
)
endif()
if(WITH_DBUS)
target_link_libraries(bitcoinqt PRIVATE Qt5::DBus)
endif()
if(qt_lib_type STREQUAL "STATIC_LIBRARY")
# We want to define static plugins to link ourselves, thus preventing
# automatic linking against a "sane" set of default static plugins.
qt5_import_plugins(bitcoinqt
EXCLUDE_BY_TYPE bearer iconengines imageformats platforms styles
)
endif()
add_executable(bitcoin-qt
main.cpp
../init/bitcoin-qt.cpp
)
add_windows_resources(bitcoin-qt res/bitcoin-qt-res.rc)
target_link_libraries(bitcoin-qt
core_interface
bitcoinqt
bitcoin_node
)
import_plugins(bitcoin-qt)
set(installable_targets bitcoin-qt)
if(WIN32)
set_target_properties(bitcoin-qt PROPERTIES WIN32_EXECUTABLE TRUE)
endif()
if(WITH_MULTIPROCESS)
add_executable(bitcoin-gui
main.cpp
../init/bitcoin-gui.cpp
)
target_link_libraries(bitcoin-gui
core_interface
bitcoinqt
bitcoin_node
bitcoin_ipc
)
import_plugins(bitcoin-gui)
list(APPEND installable_targets bitcoin-gui)
if(WIN32)
set_target_properties(bitcoin-gui PROPERTIES WIN32_EXECUTABLE TRUE)
endif()
endif()
install(TARGETS ${installable_targets}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT GUI
)
if(BUILD_GUI_TESTS)
add_subdirectory(test)
endif()
# Gets sources to be parsed to gather translatable strings.
function(get_translatable_sources var)
set(result)
set(targets)
foreach(dir IN ITEMS ${ARGN})
get_directory_property(dir_targets DIRECTORY ${PROJECT_SOURCE_DIR}/${dir} BUILDSYSTEM_TARGETS)
list(APPEND targets ${dir_targets})
endforeach()
foreach(target IN LISTS targets)
get_target_property(target_sources ${target} SOURCES)
if(target_sources)
foreach(source IN LISTS target_sources)
# Get an expression from the generator expression, if any.
if(source MATCHES ":([^>]+)>$")
set(source ${CMAKE_MATCH_1})
endif()
cmake_path(GET source EXTENSION LAST_ONLY ext)
if(ext STREQUAL ".qrc")
continue()
endif()
if(NOT IS_ABSOLUTE source)
get_target_property(target_source_dir ${target} SOURCE_DIR)
cmake_path(APPEND target_source_dir ${source} OUTPUT_VARIABLE source)
endif()
list(APPEND result ${source})
endforeach()
endif()
endforeach()
set(${var} ${result} PARENT_SCOPE)
endfunction()
find_program(XGETTEXT_EXECUTABLE xgettext)
find_program(SED_EXECUTABLE sed)
if(NOT XGETTEXT_EXECUTABLE)
add_custom_target(translate
COMMAND ${CMAKE_COMMAND} -E echo "Error: GNU gettext-tools not found"
)
elseif(NOT SED_EXECUTABLE)
add_custom_target(translate
COMMAND ${CMAKE_COMMAND} -E echo "Error: GNU sed not found"
)
else()
set(translatable_sources_directories src src/qt src/util)
if(ENABLE_WALLET)
list(APPEND translatable_sources_directories src/wallet)
endif()
get_translatable_sources(translatable_sources ${translatable_sources_directories})
get_translatable_sources(qt_translatable_sources src/qt)
file(GLOB ui_files ${CMAKE_CURRENT_SOURCE_DIR}/forms/*.ui)
add_custom_target(translate
COMMAND ${CMAKE_COMMAND} -E env XGETTEXT=${XGETTEXT_EXECUTABLE} COPYRIGHT_HOLDERS=${COPYRIGHT_HOLDERS} ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/share/qt/extract_strings_qt.py ${translatable_sources}
COMMAND Qt5::lupdate -no-obsolete -I ${PROJECT_SOURCE_DIR}/src -locations relative ${CMAKE_CURRENT_SOURCE_DIR}/bitcoinstrings.cpp ${ui_files} ${qt_translatable_sources} -ts ${CMAKE_CURRENT_SOURCE_DIR}/locale/bitcoin_en.ts
COMMAND Qt5::lconvert -drop-translations -o ${CMAKE_CURRENT_SOURCE_DIR}/locale/bitcoin_en.xlf -i ${CMAKE_CURRENT_SOURCE_DIR}/locale/bitcoin_en.ts
COMMAND ${SED_EXECUTABLE} -i.old -e "s|source-language=\"en\" target-language=\"en\"|source-language=\"en\"|" -e "/<target xml:space=\"preserve\"><\\/target>/d" ${CMAKE_CURRENT_SOURCE_DIR}/locale/bitcoin_en.xlf
COMMAND ${CMAKE_COMMAND} -E rm ${CMAKE_CURRENT_SOURCE_DIR}/locale/bitcoin_en.xlf.old
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src
VERBATIM
)
endif()

View File

@@ -4,7 +4,7 @@ The current precise version for Qt 5 is specified in [qt.mk](/depends/packages/q
## Compile and run
See build instructions: [Unix](/doc/build-unix.md), [macOS](/doc/build-osx.md), [Windows](/doc/build-windows.md), [FreeBSD](/doc/build-freebsd.md), [NetBSD](/doc/build-netbsd.md), [OpenBSD](/doc/build-openbsd.md)
See build instructions: [Unix](/doc/build-unix.md), [macOS](/doc/build-osx.md), [Windows](/doc/build-windows-msvc.md), [FreeBSD](/doc/build-freebsd.md), [NetBSD](/doc/build-netbsd.md), [OpenBSD](/doc/build-openbsd.md)
When following your systems build instructions, make sure to install the `Qt` dependencies.

View File

@@ -0,0 +1,56 @@
# Copyright (c) 2024-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
add_executable(test_bitcoin-qt
apptests.cpp
optiontests.cpp
rpcnestedtests.cpp
test_main.cpp
uritests.cpp
util.cpp
../../init/bitcoin-qt.cpp
)
target_link_libraries(test_bitcoin-qt
core_interface
bitcoinqt
test_util
bitcoin_node
Boost::headers
Qt5::Test
)
import_plugins(test_bitcoin-qt)
if(ENABLE_WALLET)
target_sources(test_bitcoin-qt
PRIVATE
addressbooktests.cpp
wallettests.cpp
../../wallet/test/wallet_test_fixture.cpp
)
endif()
if(NOT QT_IS_STATIC)
add_custom_command(
TARGET test_bitcoin-qt POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_PROPERTY:Qt5::QMinimalIntegrationPlugin,LOCATION_$<UPPER_CASE:$<CONFIG>>> $<TARGET_FILE_DIR:test_bitcoin-qt>/plugins/platforms
VERBATIM
)
endif()
add_test(NAME test_bitcoin-qt
COMMAND test_bitcoin-qt
)
if(WIN32 AND VCPKG_TARGET_TRIPLET)
# On Windows, vcpkg configures Qt with `-opengl dynamic`, which makes
# the "minimal" platform plugin unusable due to internal Qt bugs.
set_tests_properties(test_bitcoin-qt PROPERTIES
ENVIRONMENT "QT_QPA_PLATFORM=windows"
)
endif()
install(TARGETS test_bitcoin-qt
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

223
src/test/CMakeLists.txt Normal file
View File

@@ -0,0 +1,223 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
include(GenerateHeaders)
generate_header_from_json(data/base58_encode_decode.json)
generate_header_from_json(data/bip341_wallet_vectors.json)
generate_header_from_json(data/blockfilters.json)
generate_header_from_json(data/key_io_invalid.json)
generate_header_from_json(data/key_io_valid.json)
generate_header_from_json(data/script_tests.json)
generate_header_from_json(data/sighash.json)
generate_header_from_json(data/tx_invalid.json)
generate_header_from_json(data/tx_valid.json)
generate_header_from_raw(data/asmap.raw)
# Do not use generator expressions in test sources because the
# SOURCES property is processed to gather test suite macros.
add_executable(test_bitcoin
main.cpp
$<TARGET_OBJECTS:bitcoin_consensus>
${CMAKE_CURRENT_BINARY_DIR}/data/asmap.raw.h
${CMAKE_CURRENT_BINARY_DIR}/data/base58_encode_decode.json.h
${CMAKE_CURRENT_BINARY_DIR}/data/bip341_wallet_vectors.json.h
${CMAKE_CURRENT_BINARY_DIR}/data/blockfilters.json.h
${CMAKE_CURRENT_BINARY_DIR}/data/key_io_invalid.json.h
${CMAKE_CURRENT_BINARY_DIR}/data/key_io_valid.json.h
${CMAKE_CURRENT_BINARY_DIR}/data/script_tests.json.h
${CMAKE_CURRENT_BINARY_DIR}/data/sighash.json.h
${CMAKE_CURRENT_BINARY_DIR}/data/tx_invalid.json.h
${CMAKE_CURRENT_BINARY_DIR}/data/tx_valid.json.h
addrman_tests.cpp
allocator_tests.cpp
amount_tests.cpp
argsman_tests.cpp
arith_uint256_tests.cpp
banman_tests.cpp
base32_tests.cpp
base58_tests.cpp
base64_tests.cpp
bech32_tests.cpp
bip32_tests.cpp
bip324_tests.cpp
blockchain_tests.cpp
blockencodings_tests.cpp
blockfilter_index_tests.cpp
blockfilter_tests.cpp
blockmanager_tests.cpp
bloom_tests.cpp
bswap_tests.cpp
checkqueue_tests.cpp
cluster_linearize_tests.cpp
coins_tests.cpp
coinscachepair_tests.cpp
coinstatsindex_tests.cpp
common_url_tests.cpp
compilerbug_tests.cpp
compress_tests.cpp
crypto_tests.cpp
cuckoocache_tests.cpp
dbwrapper_tests.cpp
denialofservice_tests.cpp
descriptor_tests.cpp
disconnected_transactions.cpp
feefrac_tests.cpp
flatfile_tests.cpp
fs_tests.cpp
getarg_tests.cpp
hash_tests.cpp
headers_sync_chainwork_tests.cpp
httpserver_tests.cpp
i2p_tests.cpp
interfaces_tests.cpp
key_io_tests.cpp
key_tests.cpp
logging_tests.cpp
mempool_tests.cpp
merkle_tests.cpp
merkleblock_tests.cpp
miner_tests.cpp
miniminer_tests.cpp
miniscript_tests.cpp
minisketch_tests.cpp
multisig_tests.cpp
net_peer_connection_tests.cpp
net_peer_eviction_tests.cpp
net_tests.cpp
netbase_tests.cpp
node_warnings_tests.cpp
orphanage_tests.cpp
peerman_tests.cpp
pmt_tests.cpp
policy_fee_tests.cpp
policyestimator_tests.cpp
pool_tests.cpp
pow_tests.cpp
prevector_tests.cpp
raii_event_tests.cpp
random_tests.cpp
rbf_tests.cpp
rest_tests.cpp
result_tests.cpp
reverselock_tests.cpp
rpc_tests.cpp
sanity_tests.cpp
scheduler_tests.cpp
script_p2sh_tests.cpp
script_parse_tests.cpp
script_segwit_tests.cpp
script_standard_tests.cpp
script_tests.cpp
scriptnum_tests.cpp
serfloat_tests.cpp
serialize_tests.cpp
settings_tests.cpp
sighash_tests.cpp
sigopcount_tests.cpp
skiplist_tests.cpp
sock_tests.cpp
span_tests.cpp
streams_tests.cpp
sync_tests.cpp
system_tests.cpp
timeoffsets_tests.cpp
torcontrol_tests.cpp
transaction_tests.cpp
translation_tests.cpp
txindex_tests.cpp
txpackage_tests.cpp
txreconciliation_tests.cpp
txrequest_tests.cpp
txvalidation_tests.cpp
txvalidationcache_tests.cpp
uint256_tests.cpp
util_tests.cpp
util_threadnames_tests.cpp
validation_block_tests.cpp
validation_chainstate_tests.cpp
validation_chainstatemanager_tests.cpp
validation_flush_tests.cpp
validation_tests.cpp
validationinterface_tests.cpp
versionbits_tests.cpp
)
target_link_libraries(test_bitcoin
core_interface
test_util
bitcoin_cli
bitcoin_node
minisketch
secp256k1
Boost::headers
$<TARGET_NAME_IF_EXISTS:libevent::libevent>
)
if(ENABLE_WALLET)
add_subdirectory(${PROJECT_SOURCE_DIR}/src/wallet/test wallet)
endif()
if(WITH_MULTIPROCESS)
add_library(bitcoin_ipc_test STATIC EXCLUDE_FROM_ALL
ipc_test.cpp
)
target_capnp_sources(bitcoin_ipc_test ${PROJECT_SOURCE_DIR}
ipc_test.capnp
)
target_link_libraries(bitcoin_ipc_test
PRIVATE
core_interface
univalue
)
target_sources(test_bitcoin
PRIVATE
ipc_tests.cpp
)
target_link_libraries(test_bitcoin bitcoin_ipc_test)
endif()
function(add_boost_test source_file)
if(NOT EXISTS ${source_file})
return()
endif()
file(READ "${source_file}" source_file_content)
string(REGEX
MATCH "(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\\(([A-Za-z0-9_]+)"
test_suite_macro "${source_file_content}"
)
string(REGEX
REPLACE "(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\\(" ""
test_suite_name "${test_suite_macro}"
)
if(test_suite_name)
add_test(NAME ${test_suite_name}
COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no
)
set_property(TEST ${test_suite_name} PROPERTY
SKIP_REGULAR_EXPRESSION "no test cases matching filter" "Skipping"
)
endif()
endfunction()
function(add_all_test_targets)
get_target_property(test_source_dir test_bitcoin SOURCE_DIR)
get_target_property(test_sources test_bitcoin SOURCES)
foreach(test_source ${test_sources})
cmake_path(IS_RELATIVE test_source result)
if(result)
cmake_path(APPEND test_source_dir ${test_source} OUTPUT_VARIABLE test_source)
endif()
add_boost_test(${test_source})
endforeach()
endfunction()
add_all_test_targets()
install(TARGETS test_bitcoin
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@@ -12,22 +12,23 @@ that runs all of the unit tests. The main source file for the test library is fo
### Compiling/running unit tests
Unit tests will be automatically compiled if dependencies were met in `./configure`
Unit tests will be automatically compiled if dependencies were met
during the generation of the Bitcoin Core build system
and tests weren't explicitly disabled.
After configuring, they can be run with `make check`, which includes unit tests from
subtrees, or `make && make -C src check-unit` for just the unit tests.
Assuming the build directory is named `build`, the unit tests can be run
with `ctests --test-dir build`, which includes unit tests from subtrees.
To run the unit tests manually, launch `src/test/test_bitcoin`. To recompile
after a test file was modified, run `make` and then run the test again. If you
modify a non-test file, use `make -C src/test` to recompile only what's needed
To run the unit tests manually, launch `build/src/test/test_bitcoin`. To recompile
after a test file was modified, run `cmake --build build` and then run the test again. If you
modify a non-test file, use `cmake --build build --target test_bitcoin` to recompile only what's needed
to run the unit tests.
To add more unit tests, add `BOOST_AUTO_TEST_CASE` functions to the existing
.cpp files in the `test/` directory or add new .cpp files that
implement new `BOOST_AUTO_TEST_SUITE` sections.
To run the GUI unit tests manually, launch `src/qt/test/test_bitcoin-qt`
To run the GUI unit tests manually, launch `build/src/qt/test/test_bitcoin-qt`
To add more GUI unit tests, add them to the `src/qt/test/` directory and
the `src/qt/test/test_main.cpp` file.
@@ -38,7 +39,7 @@ the `src/qt/test/test_main.cpp` file.
For example, to run just the `getarg_tests` suite of tests:
```bash
test_bitcoin --log_level=all --run_test=getarg_tests
build/src/test/test_bitcoin --log_level=all --run_test=getarg_tests
```
`log_level` controls the verbosity of the test framework, which logs when a
@@ -48,7 +49,7 @@ test case is entered, for example.
`bitcoind`. Use `--` to separate these sets of arguments:
```bash
test_bitcoin --log_level=all --run_test=getarg_tests -- -printtoconsole=1
build/src/test/test_bitcoin --log_level=all --run_test=getarg_tests -- -printtoconsole=1
```
The `-printtoconsole=1` after the two dashes sends debug logging, which
@@ -58,7 +59,7 @@ standard terminal output.
... or to run just the doubledash test:
```bash
test_bitcoin --run_test=getarg_tests/doubledash
build/src/test/test_bitcoin --run_test=getarg_tests/doubledash
```
`test_bitcoin` creates a temporary working (data) directory with a randomly
@@ -81,7 +82,7 @@ what the test wrote to `debug.log` after it completes, for example.
so no leftover state is used.)
```bash
$ test_bitcoin --run_test=getarg_tests/doubledash -- -testdatadir=/somewhere/mydatadir
$ build/src/test/test_bitcoin --run_test=getarg_tests/doubledash -- -testdatadir=/somewhere/mydatadir
Test directory (will not be deleted): "/somewhere/mydatadir/test_common_Bitcoin Core/getarg_tests/doubledash/datadir
Running 1 test case...
@@ -100,8 +101,9 @@ Run `test_bitcoin --help` for the full list of tests.
### Adding test cases
To add a new unit test file to our test suite you need
to add the file to `src/Makefile.test.include`. The pattern is to create
To add a new unit test file to our test suite, you need
to add the file to either `src/test/CMakeLists.txt` or
`src/wallet/test/CMakeLists.txt` for wallet-related tests. The pattern is to create
one test file for each class or source file for which you want to create
unit tests. The file naming convention is `<source_filename>_tests.cpp`
and such files should wrap their tests in a test suite
@@ -110,7 +112,8 @@ see `uint256_tests.cpp`.
### Logging and debugging in unit tests
`make check` will write to a log file `foo_tests.cpp.log` and display this file
`ctest --test-dir build` will write to a log file `build/Testing/Temporary/LastTest.log`. You can
additionaly use the `--output-on-failure` option to display logs of the failed tests automatically
on failure. For running individual tests verbosely, refer to the section
[above](#running-individual-tests).
@@ -121,13 +124,13 @@ For debugging you can launch the `test_bitcoin` executable with `gdb` or `lldb`
start debugging, just like you would with any other program:
```bash
gdb src/test/test_bitcoin
gdb build/src/test/test_bitcoin
```
#### Segmentation faults
If you hit a segmentation fault during a test run, you can diagnose where the fault
is happening by running `gdb ./src/test/test_bitcoin` and then using the `bt` command
is happening by running `gdb ./build/src/test/test_bitcoin` and then using the `bt` command
within gdb.
Another tool that can be used to resolve segmentation faults is
@@ -145,7 +148,7 @@ Running the tests and hitting a segmentation fault should now produce a file cal
You can then explore the core dump using
```bash
gdb src/test/test_bitcoin core
gdb build/src/test/test_bitcoin core
(gbd) bt # produce a backtrace for where a segfault occurred
```

View File

@@ -0,0 +1,144 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
add_subdirectory(util)
add_executable(fuzz
addition_overflow.cpp
addrman.cpp
asmap.cpp
asmap_direct.cpp
autofile.cpp
banman.cpp
base_encode_decode.cpp
bech32.cpp
bip324.cpp
bitdeque.cpp
bitset.cpp
block.cpp
block_header.cpp
block_index.cpp
blockfilter.cpp
bloom_filter.cpp
buffered_file.cpp
chain.cpp
checkqueue.cpp
cluster_linearize.cpp
coins_view.cpp
coinscache_sim.cpp
connman.cpp
crypto.cpp
crypto_aes256.cpp
crypto_aes256cbc.cpp
crypto_chacha20.cpp
crypto_chacha20poly1305.cpp
crypto_common.cpp
crypto_diff_fuzz_chacha20.cpp
crypto_hkdf_hmac_sha256_l32.cpp
crypto_poly1305.cpp
cuckoocache.cpp
decode_tx.cpp
descriptor_parse.cpp
deserialize.cpp
eval_script.cpp
feefrac.cpp
fee_rate.cpp
feeratediagram.cpp
fees.cpp
flatfile.cpp
float.cpp
golomb_rice.cpp
headerssync.cpp
hex.cpp
http_request.cpp
integer.cpp
key.cpp
key_io.cpp
kitchen_sink.cpp
load_external_block_file.cpp
locale.cpp
merkleblock.cpp
message.cpp
miniscript.cpp
minisketch.cpp
mini_miner.cpp
muhash.cpp
multiplication_overflow.cpp
net.cpp
net_permissions.cpp
netaddress.cpp
netbase_dns_lookup.cpp
node_eviction.cpp
p2p_handshake.cpp
p2p_transport_serialization.cpp
package_eval.cpp
parse_hd_keypath.cpp
parse_numbers.cpp
parse_script.cpp
parse_univalue.cpp
partially_downloaded_block.cpp
policy_estimator.cpp
policy_estimator_io.cpp
poolresource.cpp
pow.cpp
prevector.cpp
primitives_transaction.cpp
process_message.cpp
process_messages.cpp
protocol.cpp
psbt.cpp
random.cpp
rbf.cpp
rolling_bloom_filter.cpp
rpc.cpp
script.cpp
script_assets_test_minimizer.cpp
script_descriptor_cache.cpp
script_flags.cpp
script_format.cpp
script_interpreter.cpp
script_ops.cpp
script_parsing.cpp
script_sigcache.cpp
script_sign.cpp
scriptnum_ops.cpp
secp256k1_ec_seckey_import_export_der.cpp
secp256k1_ecdsa_signature_parse_der_lax.cpp
signature_checker.cpp
signet.cpp
socks5.cpp
span.cpp
string.cpp
strprintf.cpp
system.cpp
timeoffsets.cpp
torcontrol.cpp
transaction.cpp
tx_in.cpp
tx_out.cpp
tx_pool.cpp
txorphan.cpp
txrequest.cpp
utxo_snapshot.cpp
utxo_total_supply.cpp
validation_load_mempool.cpp
vecdeque.cpp
versionbits.cpp
)
target_link_libraries(fuzz
core_interface
test_fuzz
bitcoin_cli
bitcoin_common
minisketch
leveldb
univalue
secp256k1
Boost::headers
$<TARGET_NAME_IF_EXISTS:libevent::libevent>
)
if(ENABLE_WALLET)
add_subdirectory(${PROJECT_SOURCE_DIR}/src/wallet/test/fuzz wallet)
endif()

View File

@@ -0,0 +1,23 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
add_library(test_fuzz STATIC EXCLUDE_FROM_ALL
descriptor.cpp
mempool.cpp
net.cpp
../fuzz.cpp
../util.cpp
)
target_link_libraries(test_fuzz
PRIVATE
core_interface
test_util
bitcoin_node
Boost::headers
)
if(NOT FUZZ_BINARY_LINKS_WITHOUT_MAIN_FUNCTION)
target_compile_definitions(test_fuzz PRIVATE PROVIDE_FUZZ_MAIN_FUNCTION)
endif()

View File

@@ -0,0 +1,29 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
add_library(test_util STATIC EXCLUDE_FROM_ALL
blockfilter.cpp
coins.cpp
index.cpp
json.cpp
logging.cpp
mining.cpp
net.cpp
random.cpp
script.cpp
setup_common.cpp
str.cpp
transaction_utils.cpp
txmempool.cpp
validation.cpp
$<$<BOOL:${ENABLE_WALLET}>:${PROJECT_SOURCE_DIR}/src/wallet/test/util.cpp>
)
target_link_libraries(test_util
PRIVATE
core_interface
Boost::headers
PUBLIC
univalue
)

View File

@@ -0,0 +1,41 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
add_library(univalue STATIC EXCLUDE_FROM_ALL
lib/univalue.cpp
lib/univalue_get.cpp
lib/univalue_read.cpp
lib/univalue_write.cpp
)
target_include_directories(univalue
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
target_link_libraries(univalue PRIVATE core_interface)
if(BUILD_TESTS)
add_executable(unitester test/unitester.cpp)
target_compile_definitions(unitester
PRIVATE
JSON_TEST_SRC=\"${CMAKE_CURRENT_SOURCE_DIR}/test\"
)
target_link_libraries(unitester
PRIVATE
core_interface
univalue
)
add_test(NAME univalue_test
COMMAND unitester
)
add_executable(object test/object.cpp)
target_link_libraries(object
PRIVATE
core_interface
univalue
)
add_test(NAME univalue_object_test
COMMAND object
)
endif()

45
src/util/CMakeLists.txt Normal file
View File

@@ -0,0 +1,45 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
add_library(bitcoin_util STATIC EXCLUDE_FROM_ALL
asmap.cpp
batchpriority.cpp
bip32.cpp
bytevectorhash.cpp
chaintype.cpp
check.cpp
exception.cpp
feefrac.cpp
fs.cpp
fs_helpers.cpp
hasher.cpp
moneystr.cpp
rbf.cpp
readwritefile.cpp
serfloat.cpp
signalinterrupt.cpp
sock.cpp
strencodings.cpp
string.cpp
syserror.cpp
thread.cpp
threadinterrupt.cpp
threadnames.cpp
time.cpp
tokenpipe.cpp
../logging.cpp
../random.cpp
../randomenv.cpp
../streams.cpp
../support/lockedpool.cpp
../sync.cpp
)
target_link_libraries(bitcoin_util
PRIVATE
core_interface
bitcoin_clientversion
bitcoin_crypto
$<$<PLATFORM_ID:Windows>:ws2_32>
)

59
src/wallet/CMakeLists.txt Normal file
View File

@@ -0,0 +1,59 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
# 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
migrate.cpp
receive.cpp
rpc/addresses.cpp
rpc/backup.cpp
rpc/coins.cpp
rpc/encrypt.cpp
rpc/signmessage.cpp
rpc/spend.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
core_interface
bitcoin_common
univalue
Boost::headers
$<TARGET_NAME_IF_EXISTS:USDT::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
$<TARGET_NAME_IF_EXISTS:unofficial::sqlite3::sqlite3>
$<TARGET_NAME_IF_EXISTS:SQLite::SQLite3>
)
endif()
if(USE_BDB)
target_sources(bitcoin_wallet PRIVATE bdb.cpp salvage.cpp)
target_link_libraries(bitcoin_wallet PUBLIC BerkeleyDB::BerkeleyDB)
endif()

View File

@@ -0,0 +1,32 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
# Do not use generator expressions in test sources because the
# SOURCES property is processed to gather test suite macros.
target_sources(test_bitcoin
PRIVATE
init_test_fixture.cpp
wallet_test_fixture.cpp
coinselector_tests.cpp
feebumper_tests.cpp
group_outputs_tests.cpp
init_tests.cpp
ismine_tests.cpp
psbt_wallet_tests.cpp
rpc_util_tests.cpp
scriptpubkeyman_tests.cpp
spend_tests.cpp
wallet_crypto_tests.cpp
wallet_tests.cpp
wallet_transaction_tests.cpp
walletdb_tests.cpp
walletload_tests.cpp
)
if(USE_BDB)
target_sources(test_bitcoin
PRIVATE
db_tests.cpp
)
endif()
target_link_libraries(test_bitcoin bitcoin_wallet)

View File

@@ -0,0 +1,15 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
target_sources(fuzz
PRIVATE
coincontrol.cpp
coinselection.cpp
fees.cpp
$<$<BOOL:${USE_SQLITE}>:${CMAKE_CURRENT_LIST_DIR}/notifications.cpp>
parse_iso8601.cpp
$<$<BOOL:${USE_SQLITE}>:${CMAKE_CURRENT_LIST_DIR}/scriptpubkeyman.cpp>
wallet_bdb_parser.cpp
)
target_link_libraries(fuzz bitcoin_wallet)

24
src/zmq/CMakeLists.txt Normal file
View File

@@ -0,0 +1,24 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
add_library(bitcoin_zmq STATIC EXCLUDE_FROM_ALL
zmqabstractnotifier.cpp
zmqnotificationinterface.cpp
zmqpublishnotifier.cpp
zmqrpc.cpp
zmqutil.cpp
)
target_compile_definitions(bitcoin_zmq
INTERFACE
ENABLE_ZMQ=1
PRIVATE
$<$<AND:$<PLATFORM_ID:Windows>,$<CXX_COMPILER_ID:GNU>>:ZMQ_STATIC>
)
target_link_libraries(bitcoin_zmq
PRIVATE
core_interface
univalue
$<TARGET_NAME_IF_EXISTS:libzmq>
$<TARGET_NAME_IF_EXISTS:PkgConfig::libzmq>
)