Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
fa01d51
cmake: Add root `CMakeLists.txt` file
hebasto Sep 17, 2023
60423ee
cmake: Warn about not encapsulated build properties
hebasto Sep 2, 2023
dc8810d
cmake: Add `config/bitcoin-config.h` support
hebasto Feb 15, 2023
3bc406d
cmake: Add `cmake/introspection.cmake` file
hebasto Mar 31, 2023
5091fbc
cmake: Check system headers
hebasto Feb 21, 2023
ce87cbc
cmake: Check system symbols
hebasto Jul 10, 2023
82decc2
cmake: Check compiler features
hebasto Sep 17, 2023
ace12e4
cmake: Add position independent code support
hebasto Sep 17, 2023
dad4d7d
cmake: Build `crc32c` static library
hebasto Sep 13, 2023
e4bd403
cmake: Build `leveldb` static library
hebasto Sep 13, 2023
cbb978a
cmake: Add platform-specific definitions and properties
hebasto Sep 13, 2023
667fbea
cmake: Build `minisketch` static library
hebasto Sep 17, 2023
7e2143a
cmake: Build `secp256k1` static library
hebasto Sep 16, 2023
60135b9
cmake: Build `univalue` static library
hebasto Sep 17, 2023
59b404e
cmake: Build `bitcoin_crypto` library
hebasto Sep 13, 2023
6b8120e
cmake: Build `bitcoin_util` static library
hebasto Sep 13, 2023
a8fdf47
cmake: Build `bitcoin_consensus` library
hebasto Sep 13, 2023
6bf981a
cmake: Build `bitcoind` executable
hebasto Sep 17, 2023
5e352f2
build: Generate `share/toolchain.cmake` in depends
hebasto Sep 17, 2023
d68d9fc
cmake: Add cross-compiling support
hebasto Sep 13, 2023
be6ec09
cmake: Add `TristateOption` module
hebasto Apr 13, 2023
8444b4f
cmake: Add `ccache` support
hebasto Sep 13, 2023
09f7a91
cmake: Add `libnatpmp` optional package support
hebasto Apr 6, 2023
8002c68
cmake: Add `libminiupnpc` optional package support
hebasto Apr 6, 2023
223c393
cmake: Add `libzmq` optional package support
hebasto Sep 16, 2023
17fa954
cmake: Add `systemtap-sdt` optional package support
hebasto Jul 10, 2023
604a21d
cmake: Build `bitcoin-cli` executable
hebasto Sep 13, 2023
ed36791
cmake: Build `bitcoin-tx` executable
hebasto Sep 13, 2023
f08381f
cmake: Build `bitcoin-util` executable
hebasto Sep 13, 2023
5425fd0
cmake: Add wallet functionality
hebasto Sep 13, 2023
8c90135
cmake: Add test config and runners
hebasto Jul 10, 2023
5e000d1
cmake: Build `bench_bitcoin` executable
hebasto Sep 13, 2023
85f96f4
cmake: Build `test_bitcoin` executable
hebasto Sep 13, 2023
241fc3f
cmake: Include CTest
hebasto May 13, 2023
72dbc2e
cmake: Add `TryAppendCXXFlags` module
hebasto Sep 2, 2023
c381343
cmake: Add `TryAppendLinkerFlag` module
hebasto Sep 2, 2023
57705bd
cmake: Add platform-specific linker flags
hebasto Sep 2, 2023
c20de96
cmake: Redefine configuration flags
hebasto Sep 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/module)
# Configurable options.
# When adding a new option, end the <help_text> with a full stop for consistency.
include(CMakeDependentOption)
option(BUILD_DAEMON "Build bitcoind 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)
Expand Down Expand Up @@ -117,6 +118,9 @@ endif()
include(AddThreadsIfNeeded)
add_threads_if_needed()

include(AddBoostIfNeeded)
add_boost_if_needed()

include(CheckSourceCompilesAndLinks)

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
Expand All @@ -133,6 +137,9 @@ else()
endif()
endif()

include(AddLibeventIfNeeded)
add_libevent_if_needed()

include(cmake/introspection.cmake)

include(cmake/crc32c.cmake)
Expand All @@ -145,6 +152,9 @@ add_subdirectory(src)
message("\n")
message("Configure summary")
message("=================")
message("Executables:")
message(" bitcoind ............................ ${BUILD_DAEMON}")
message("")
get_directory_property(definitions COMPILE_DEFINITIONS)
string(REPLACE ";" " " definitions "${definitions}")
message("Preprocessor defined macros ........... ${definitions}")
Expand Down
4 changes: 4 additions & 0 deletions cmake/introspection.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,7 @@ check_cxx_source_compiles("
int main(){}
" HAVE_DLLEXPORT_ATTRIBUTE
)

if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
find_program(BREW_COMMAND brew)
endif()
32 changes: 32 additions & 0 deletions cmake/module/AddBoostIfNeeded.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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.

function(add_boost_if_needed)
#[=[
TODO: Not all targets, which will be added in the future, require
Boost. Therefore, a proper check will be appropriate here.

Implementation notes:
Although only Boost headers are used to build Bitcoin Core,
we still leverage a standard CMake's approach to handle
dependencies, i.e., the Boost::headers "library".
A command target_link_libraries(target PRIVATE Boost::headers)
will propagate Boost::headers usage requirements to the target.
For Boost::headers such usage requirements is an include
directory and other added INTERFACE properties.
]=]

set(Boost_NO_BOOST_CMAKE ON)
find_package(Boost 1.64.0 REQUIRED)
set_target_properties(Boost::boost PROPERTIES IMPORTED_GLOBAL TRUE)
target_compile_definitions(Boost::boost INTERFACE
# We don't use multi_index serialization.
BOOST_MULTI_INDEX_DISABLE_SERIALIZATION
)
if(CMAKE_VERSION VERSION_LESS 3.15)
add_library(Boost::headers ALIAS Boost::boost)
endif()

mark_as_advanced(Boost_INCLUDE_DIR)
endfunction()
60 changes: 60 additions & 0 deletions cmake/module/AddLibeventIfNeeded.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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.

# Check whether evhttp_connection_get_peer expects const char**.
# See https://github.com/libevent/libevent/commit/a18301a2bb160ff7c3ffaf5b7653c39ffe27b385
macro(check_evhttp_connection_get_peer target)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_LIBRARIES ${target})
check_cxx_source_compiles("
#include <cstdint>
#include <event2/http.h>

int main()
{
evhttp_connection* conn = (evhttp_connection*)1;
const char* host;
uint16_t port;
evhttp_connection_get_peer(conn, &host, &port);
}
" HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR
)
cmake_pop_check_state()
target_compile_definitions(${target} INTERFACE
$<$<BOOL:${HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR}>:HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR=1>
)
endmacro()

function(add_libevent_if_needed)
# TODO: Not all targets, which will be added in the future,
# require libevent. Therefore, a proper check will be
# appropriate here.

set(libevent_minimum_version 2.1.8)

if(MSVC)
find_package(Libevent ${libevent_minimum_version} REQUIRED COMPONENTS extra CONFIG)
check_evhttp_connection_get_peer(libevent::extra)
add_library(libevent::libevent ALIAS libevent::extra)
return()
endif()

find_package(PkgConfig)
pkg_check_modules(libevent
REQUIRED IMPORTED_TARGET GLOBAL
libevent>=${libevent_minimum_version}
)
check_evhttp_connection_get_peer(PkgConfig::libevent)
target_link_libraries(PkgConfig::libevent INTERFACE
$<$<BOOL:${MINGW}>:iphlpapi;ssp;ws2_32>
)
add_library(libevent::libevent ALIAS PkgConfig::libevent)

if(NOT WIN32)
pkg_check_modules(libevent_pthreads
REQUIRED IMPORTED_TARGET GLOBAL
libevent_pthreads>=${libevent_minimum_version}
)
endif()
endfunction()
185 changes: 185 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,188 @@ target_link_libraries(bitcoin_consensus
core
secp256k1
)


# 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
coins.cpp
common/args.cpp
common/bloom.cpp
common/config.cpp
common/init.cpp
common/interfaces.cpp
common/run_command.cpp
common/settings.cpp
common/system.cpp
$<$<TARGET_EXISTS:libevent::libevent>: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_types.cpp
netaddress.cpp
netbase.cpp
net_permissions.cpp
outputtype.cpp
policy/feerate.cpp
policy/policy.cpp
protocol.cpp
psbt.cpp
rpc/rawtransaction_util.cpp
rpc/request.cpp
rpc/external_signer.cpp
rpc/util.cpp
scheduler.cpp
script/descriptor.cpp
script/miniscript.cpp
script/sign.cpp
script/signingprovider.cpp
script/solver.cpp
warnings.cpp
)
target_compile_definitions(bitcoin_common
PRIVATE
${THREAD_LOCAL_IF_AVAILABLE}
)
target_link_libraries(bitcoin_common
PRIVATE
core
bitcoin_consensus
bitcoin_util
univalue
secp256k1
Boost::headers
$<TARGET_NAME_IF_EXISTS:libevent::libevent>
)


# 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/mempool_persist.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_args.cpp
node/miner.cpp
node/mini_miner.cpp
node/minisketchwrapper.cpp
node/peerman_args.cpp
node/psbt.cpp
node/transaction.cpp
node/txreconciliation.cpp
node/utxo_snapshot.cpp
node/validation_cache_args.cpp
noui.cpp
policy/fees.cpp
policy/fees_args.cpp
policy/packages.cpp
policy/rbf.cpp
policy/settings.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
shutdown.cpp
signet.cpp
timedata.cpp
torcontrol.cpp
txdb.cpp
txmempool.cpp
txorphanage.cpp
txrequest.cpp
validation.cpp
validationinterface.cpp
versionbits.cpp

dummywallet.cpp
)
target_link_libraries(bitcoin_node
PRIVATE
core
bitcoin_common
bitcoin_util
leveldb
minisketch
univalue
Boost::headers
libevent::libevent
$<TARGET_NAME_IF_EXISTS:PkgConfig::libevent_pthreads>
)


# Bitcoin Core bitcoind.
if(BUILD_DAEMON)
add_executable(bitcoind
bitcoind.cpp
init/bitcoind.cpp
)
target_link_libraries(bitcoind
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is PRIVATE in the staging branch, and I don't see any explanation for the change?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Distinguishing PRIVATE vs PUBLIC vs INTERFACE scopes matters only for targets that have dependants.

That is not the case for executable targets. Therefore, target_link_libraries with a simpler signature is used.

This particular change has done for the sake of consistency with other similar cases.

core
bitcoin_node
)
endif()