Skip to content

Commit 4f66c81

Browse files
committed
cmake: Build bitcoind executable
1 parent faecb1a commit 4f66c81

File tree

3 files changed

+252
-0
lines changed

3 files changed

+252
-0
lines changed

CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/module)
3838
# Configurable options.
3939
# When adding a new option, end the <help_text> with a full stop for consistency.
4040
include(CMakeDependentOption)
41+
option(BUILD_DAEMON "Build bitcoind executable." ON)
4142
option(ASM "Use assembly routines." ON)
4243
cmake_dependent_option(CXX20 "Enable compilation in C++20 mode." OFF "NOT MSVC" ON)
4344

@@ -72,11 +73,45 @@ include(cmake/secp256k1.cmake)
7273
include(CheckStdFilesystem)
7374
check_std_filesystem()
7475

76+
find_package(PkgConfig)
77+
if(BUILD_DAEMON)
78+
set(THREADS_PREFER_PTHREAD_FLAG ON)
79+
find_package(Threads REQUIRED)
80+
81+
if(APPLE)
82+
execute_process(
83+
COMMAND brew --prefix boost
84+
OUTPUT_VARIABLE BOOST_ROOT
85+
ERROR_QUIET
86+
OUTPUT_STRIP_TRAILING_WHITESPACE
87+
)
88+
endif()
89+
set(Boost_NO_BOOST_CMAKE ON)
90+
# Find Boost headers only.
91+
find_package(Boost 1.64.0 REQUIRED)
92+
mark_as_advanced(Boost_INCLUDE_DIR)
93+
target_compile_definitions(Boost::boost INTERFACE
94+
$<$<CONFIG:Debug>:BOOST_MULTI_INDEX_ENABLE_SAFE_MODE>
95+
)
96+
97+
pkg_check_modules(libevent REQUIRED libevent>=2.1.8 IMPORTED_TARGET)
98+
target_link_libraries(PkgConfig::libevent INTERFACE
99+
$<$<PLATFORM_ID:Windows>:iphlpapi;ws2_32>
100+
)
101+
endif()
102+
103+
if(NOT WIN32 AND BUILD_DAEMON)
104+
pkg_check_modules(libevent_pthreads REQUIRED libevent_pthreads>=2.1.8 IMPORTED_TARGET)
105+
endif()
106+
75107
add_subdirectory(src)
76108

77109
message("\n")
78110
message("Configure summary")
79111
message("=================")
112+
message("Executables:")
113+
message(" bitcoind ............................ ${BUILD_DAEMON}")
114+
message("")
80115
get_directory_property(definitions COMPILE_DEFINITIONS)
81116
string(REPLACE ";" " " definitions "${definitions}")
82117
message("Preprocessor defined macros ........... ${definitions}")

src/CMakeLists.txt

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
88

99
add_subdirectory(crypto)
1010
add_subdirectory(univalue)
11+
add_subdirectory(util)
1112

1213

1314
# Stable, backwards-compatible consensus functionality
@@ -27,3 +28,165 @@ add_library(bitcoin_consensus OBJECT EXCLUDE_FROM_ALL
2728
util/strencodings.cpp
2829
)
2930
target_link_libraries(bitcoin_consensus PRIVATE secp256k1)
31+
32+
33+
# Home for common functionality shared by different executables and libraries.
34+
# Similar to `bitcoin_util` library, but higher-level.
35+
add_library(bitcoin_common STATIC EXCLUDE_FROM_ALL
36+
base58.cpp
37+
bech32.cpp
38+
chainparams.cpp
39+
coins.cpp
40+
common/bloom.cpp
41+
common/interfaces.cpp
42+
common/run_command.cpp
43+
$<$<TARGET_EXISTS:PkgConfig::libevent>:common/url.cpp>
44+
compressor.cpp
45+
core_read.cpp
46+
core_write.cpp
47+
deploymentinfo.cpp
48+
external_signer.cpp
49+
init/common.cpp
50+
key.cpp
51+
key_io.cpp
52+
merkleblock.cpp
53+
net_types.cpp
54+
netaddress.cpp
55+
netbase.cpp
56+
net_permissions.cpp
57+
outputtype.cpp
58+
policy/feerate.cpp
59+
policy/policy.cpp
60+
protocol.cpp
61+
psbt.cpp
62+
rpc/rawtransaction_util.cpp
63+
rpc/request.cpp
64+
rpc/external_signer.cpp
65+
rpc/util.cpp
66+
scheduler.cpp
67+
script/descriptor.cpp
68+
script/miniscript.cpp
69+
script/sign.cpp
70+
script/signingprovider.cpp
71+
script/standard.cpp
72+
warnings.cpp
73+
)
74+
target_link_libraries(bitcoin_common
75+
PRIVATE
76+
bitcoin_consensus
77+
bitcoin_util
78+
univalue
79+
secp256k1
80+
Boost::boost
81+
$<TARGET_NAME_IF_EXISTS:PkgConfig::libevent>
82+
)
83+
84+
85+
# P2P and RPC server functionality used by `bitcoind` and `bitcoin-qt` executables.
86+
add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL
87+
addrdb.cpp
88+
addrman.cpp
89+
banman.cpp
90+
blockencodings.cpp
91+
blockfilter.cpp
92+
chain.cpp
93+
consensus/tx_verify.cpp
94+
dbwrapper.cpp
95+
deploymentstatus.cpp
96+
flatfile.cpp
97+
headerssync.cpp
98+
httprpc.cpp
99+
httpserver.cpp
100+
i2p.cpp
101+
index/base.cpp
102+
index/blockfilterindex.cpp
103+
index/coinstatsindex.cpp
104+
index/txindex.cpp
105+
init.cpp
106+
kernel/chain.cpp
107+
kernel/checks.cpp
108+
kernel/coinstats.cpp
109+
kernel/context.cpp
110+
kernel/cs_main.cpp
111+
kernel/mempool_persist.cpp
112+
mapport.cpp
113+
net.cpp
114+
netgroup.cpp
115+
net_processing.cpp
116+
node/blockstorage.cpp
117+
node/caches.cpp
118+
node/chainstate.cpp
119+
node/chainstatemanager_args.cpp
120+
node/coin.cpp
121+
node/connection_types.cpp
122+
node/context.cpp
123+
node/eviction.cpp
124+
node/interface_ui.cpp
125+
node/interfaces.cpp
126+
node/mempool_args.cpp
127+
node/mempool_persist_args.cpp
128+
node/miner.cpp
129+
node/minisketchwrapper.cpp
130+
node/psbt.cpp
131+
node/transaction.cpp
132+
node/txreconciliation.cpp
133+
node/utxo_snapshot.cpp
134+
node/validation_cache_args.cpp
135+
noui.cpp
136+
policy/fees.cpp
137+
policy/fees_args.cpp
138+
policy/packages.cpp
139+
policy/rbf.cpp
140+
policy/settings.cpp
141+
pow.cpp
142+
rest.cpp
143+
rpc/blockchain.cpp
144+
rpc/fees.cpp
145+
rpc/mempool.cpp
146+
rpc/mining.cpp
147+
rpc/net.cpp
148+
rpc/node.cpp
149+
rpc/output_script.cpp
150+
rpc/rawtransaction.cpp
151+
rpc/server.cpp
152+
rpc/server_util.cpp
153+
rpc/signmessage.cpp
154+
rpc/txoutproof.cpp
155+
script/sigcache.cpp
156+
shutdown.cpp
157+
signet.cpp
158+
timedata.cpp
159+
torcontrol.cpp
160+
txdb.cpp
161+
txmempool.cpp
162+
txorphanage.cpp
163+
txrequest.cpp
164+
validation.cpp
165+
validationinterface.cpp
166+
versionbits.cpp
167+
168+
dummywallet.cpp
169+
)
170+
target_link_libraries(bitcoin_node
171+
PRIVATE
172+
bitcoin_common
173+
bitcoin_util
174+
leveldb
175+
minisketch
176+
univalue
177+
Boost::boost
178+
$<$<NOT:$<PLATFORM_ID:Windows>>:PkgConfig::libevent_pthreads>
179+
)
180+
181+
182+
# Bitcoin Core bitcoind.
183+
if(BUILD_DAEMON)
184+
add_executable(bitcoind
185+
bitcoind.cpp
186+
init/bitcoind.cpp
187+
)
188+
target_link_libraries(bitcoind
189+
PRIVATE
190+
bitcoin_node
191+
)
192+
endif()

src/util/CMakeLists.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
add_library(bitcoin_util STATIC EXCLUDE_FROM_ALL
6+
asmap.cpp
7+
bip32.cpp
8+
bytevectorhash.cpp
9+
check.cpp
10+
error.cpp
11+
fees.cpp
12+
getuniquepath.cpp
13+
hasher.cpp
14+
message.cpp
15+
moneystr.cpp
16+
rbf.cpp
17+
readwritefile.cpp
18+
settings.cpp
19+
serfloat.cpp
20+
sock.cpp
21+
spanparsing.cpp
22+
strencodings.cpp
23+
string.cpp
24+
syscall_sandbox.cpp
25+
syserror.cpp
26+
system.cpp
27+
thread.cpp
28+
threadinterrupt.cpp
29+
threadnames.cpp
30+
time.cpp
31+
tokenpipe.cpp
32+
../chainparamsbase.cpp
33+
../clientversion.cpp
34+
../fs.cpp
35+
../logging.cpp
36+
../random.cpp
37+
../randomenv.cpp
38+
../support/cleanse.cpp
39+
../support/lockedpool.cpp
40+
../sync.cpp
41+
)
42+
43+
target_compile_definitions(bitcoin_util
44+
PRIVATE
45+
$<$<CXX_COMPILER_ID:MSVC>:_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING>
46+
)
47+
48+
target_link_libraries(bitcoin_util
49+
PRIVATE
50+
bitcoin_crypto
51+
univalue
52+
Threads::Threads
53+
$<TARGET_NAME_IF_EXISTS:std_filesystem>
54+
)

0 commit comments

Comments
 (0)