Skip to content

Commit f8e38ad

Browse files
committed
cmake: Build bitcoind executable
1 parent 6f4549a commit f8e38ad

File tree

3 files changed

+258
-0
lines changed

3 files changed

+258
-0
lines changed

CMakeLists.txt

Lines changed: 40 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,50 @@ 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+
if(NOT MINGW AND NOT CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
81+
target_compile_definitions(Threads::Threads INTERFACE
82+
$<$<COMPILE_FEATURES:cxx_thread_local>:HAVE_THREAD_LOCAL>
83+
)
84+
endif()
85+
86+
if(APPLE)
87+
execute_process(
88+
COMMAND brew --prefix boost
89+
OUTPUT_VARIABLE BOOST_ROOT
90+
ERROR_QUIET
91+
OUTPUT_STRIP_TRAILING_WHITESPACE
92+
)
93+
endif()
94+
set(Boost_NO_BOOST_CMAKE ON)
95+
# Find Boost headers only.
96+
find_package(Boost 1.64.0 REQUIRED)
97+
mark_as_advanced(Boost_INCLUDE_DIR)
98+
target_compile_definitions(Boost::boost INTERFACE
99+
$<$<CONFIG:Debug>:BOOST_MULTI_INDEX_ENABLE_SAFE_MODE>
100+
)
101+
102+
pkg_check_modules(libevent REQUIRED libevent>=2.1.8 IMPORTED_TARGET)
103+
target_link_libraries(PkgConfig::libevent INTERFACE
104+
$<$<PLATFORM_ID:Windows>:iphlpapi;ws2_32>
105+
)
106+
endif()
107+
108+
if(NOT WIN32 AND BUILD_DAEMON)
109+
pkg_check_modules(libevent_pthreads REQUIRED libevent_pthreads>=2.1.8 IMPORTED_TARGET)
110+
endif()
111+
75112
add_subdirectory(src)
76113

77114
message("\n")
78115
message("Configure summary")
79116
message("=================")
117+
message("Executables:")
118+
message(" bitcoind ............................ ${BUILD_DAEMON}")
119+
message("")
80120
get_directory_property(definitions COMPILE_DEFINITIONS)
81121
string(REPLACE ";" " " definitions "${definitions}")
82122
message("Preprocessor defined macros ........... ${definitions}")

src/CMakeLists.txt

Lines changed: 164 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,166 @@ 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+
Threads::Threads
82+
$<TARGET_NAME_IF_EXISTS:PkgConfig::libevent>
83+
)
84+
85+
86+
# P2P and RPC server functionality used by `bitcoind` and `bitcoin-qt` executables.
87+
add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL
88+
addrdb.cpp
89+
addrman.cpp
90+
banman.cpp
91+
blockencodings.cpp
92+
blockfilter.cpp
93+
chain.cpp
94+
consensus/tx_verify.cpp
95+
dbwrapper.cpp
96+
deploymentstatus.cpp
97+
flatfile.cpp
98+
headerssync.cpp
99+
httprpc.cpp
100+
httpserver.cpp
101+
i2p.cpp
102+
index/base.cpp
103+
index/blockfilterindex.cpp
104+
index/coinstatsindex.cpp
105+
index/txindex.cpp
106+
init.cpp
107+
kernel/chain.cpp
108+
kernel/checks.cpp
109+
kernel/coinstats.cpp
110+
kernel/context.cpp
111+
kernel/cs_main.cpp
112+
kernel/mempool_persist.cpp
113+
mapport.cpp
114+
net.cpp
115+
netgroup.cpp
116+
net_processing.cpp
117+
node/blockstorage.cpp
118+
node/caches.cpp
119+
node/chainstate.cpp
120+
node/chainstatemanager_args.cpp
121+
node/coin.cpp
122+
node/connection_types.cpp
123+
node/context.cpp
124+
node/eviction.cpp
125+
node/interface_ui.cpp
126+
node/interfaces.cpp
127+
node/mempool_args.cpp
128+
node/mempool_persist_args.cpp
129+
node/miner.cpp
130+
node/minisketchwrapper.cpp
131+
node/psbt.cpp
132+
node/transaction.cpp
133+
node/txreconciliation.cpp
134+
node/utxo_snapshot.cpp
135+
node/validation_cache_args.cpp
136+
noui.cpp
137+
policy/fees.cpp
138+
policy/fees_args.cpp
139+
policy/packages.cpp
140+
policy/rbf.cpp
141+
policy/settings.cpp
142+
pow.cpp
143+
rest.cpp
144+
rpc/blockchain.cpp
145+
rpc/fees.cpp
146+
rpc/mempool.cpp
147+
rpc/mining.cpp
148+
rpc/net.cpp
149+
rpc/node.cpp
150+
rpc/output_script.cpp
151+
rpc/rawtransaction.cpp
152+
rpc/server.cpp
153+
rpc/server_util.cpp
154+
rpc/signmessage.cpp
155+
rpc/txoutproof.cpp
156+
script/sigcache.cpp
157+
shutdown.cpp
158+
signet.cpp
159+
timedata.cpp
160+
torcontrol.cpp
161+
txdb.cpp
162+
txmempool.cpp
163+
txorphanage.cpp
164+
txrequest.cpp
165+
validation.cpp
166+
validationinterface.cpp
167+
versionbits.cpp
168+
169+
dummywallet.cpp
170+
)
171+
target_link_libraries(bitcoin_node
172+
PRIVATE
173+
bitcoin_common
174+
bitcoin_util
175+
leveldb
176+
minisketch
177+
univalue
178+
Boost::boost
179+
$<$<NOT:$<PLATFORM_ID:Windows>>:PkgConfig::libevent_pthreads>
180+
)
181+
182+
183+
# Bitcoin Core bitcoind.
184+
if(BUILD_DAEMON)
185+
add_executable(bitcoind
186+
bitcoind.cpp
187+
init/bitcoind.cpp
188+
)
189+
target_link_libraries(bitcoind
190+
PRIVATE
191+
bitcoin_node
192+
)
193+
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)