Skip to content

Commit

Permalink
cmake: Build bitcoind executable
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Feb 24, 2023
1 parent b9d3217 commit 5931a38
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 2 deletions.
44 changes: 42 additions & 2 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)

Expand Down Expand Up @@ -87,14 +88,53 @@ include(cmake/secp256k1.cmake)
include(CheckStdFilesystem)
check_std_filesystem()

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(PkgConfig)
if(BUILD_DAEMON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(NOT MINGW AND NOT CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
target_compile_definitions(Threads::Threads INTERFACE
$<$<COMPILE_FEATURES:cxx_thread_local>:HAVE_THREAD_LOCAL>
)
endif()

if(APPLE AND BREW_COMMAND)
execute_process(
COMMAND ${BREW_COMMAND} --prefix boost
OUTPUT_VARIABLE BOOST_ROOT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
set(Boost_NO_BOOST_CMAKE ON)
# Find Boost headers only.
find_package(Boost 1.64.0 REQUIRED)
mark_as_advanced(Boost_INCLUDE_DIR)
target_compile_definitions(Boost::boost INTERFACE
$<$<CONFIG:Debug>:BOOST_MULTI_INDEX_ENABLE_SAFE_MODE>
)
if(CMAKE_VERSION VERSION_LESS 3.15)
add_library(Boost::headers ALIAS Boost::boost)
endif()

pkg_check_modules(libevent REQUIRED libevent>=2.1.8 IMPORTED_TARGET)
target_link_libraries(PkgConfig::libevent INTERFACE
$<$<PLATFORM_ID:Windows>:iphlpapi;ws2_32>
)
endif()

if(NOT WIN32 AND BUILD_DAEMON)
pkg_check_modules(libevent_pthreads REQUIRED libevent_pthreads>=2.1.8 IMPORTED_TARGET)
endif()

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 @@ -195,3 +195,7 @@ check_cxx_source_compiles("
int main(){}
" HAVE_DLLEXPORT_ATTRIBUTE
)

if(APPLE)
find_program(BREW_COMMAND brew)
endif()
163 changes: 163 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,166 @@ add_library(bitcoin_consensus OBJECT EXCLUDE_FROM_ALL
util/strencodings.cpp
)
target_link_libraries(bitcoin_consensus PRIVATE 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
base58.cpp
bech32.cpp
chainparams.cpp
coins.cpp
common/bloom.cpp
common/interfaces.cpp
common/run_command.cpp
$<$<TARGET_EXISTS:PkgConfig::libevent>:common/url.cpp>
compressor.cpp
core_read.cpp
core_write.cpp
deploymentinfo.cpp
external_signer.cpp
init/common.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/standard.cpp
warnings.cpp
)
target_link_libraries(bitcoin_common
PRIVATE
bitcoin_consensus
bitcoin_util
univalue
secp256k1
Boost::headers
Threads::Threads
$<TARGET_NAME_IF_EXISTS:PkgConfig::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
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
mapport.cpp
net.cpp
netgroup.cpp
net_processing.cpp
node/blockstorage.cpp
node/caches.cpp
node/chainstate.cpp
node/chainstatemanager_args.cpp
node/coin.cpp
node/connection_types.cpp
node/context.cpp
node/eviction.cpp
node/interface_ui.cpp
node/interfaces.cpp
node/mempool_args.cpp
node/mempool_persist_args.cpp
node/miner.cpp
node/minisketchwrapper.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
bitcoin_common
bitcoin_util
leveldb
minisketch
univalue
Boost::headers
$<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
PRIVATE
bitcoin_node
)
endif()

0 comments on commit 5931a38

Please sign in to comment.