Skip to content

Commit 5931a38

Browse files
committed
cmake: Build bitcoind executable
1 parent b9d3217 commit 5931a38

File tree

3 files changed

+209
-2
lines changed

3 files changed

+209
-2
lines changed

CMakeLists.txt

Lines changed: 42 additions & 2 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

@@ -87,14 +88,53 @@ include(cmake/secp256k1.cmake)
8788
include(CheckStdFilesystem)
8889
check_std_filesystem()
8990

90-
set(THREADS_PREFER_PTHREAD_FLAG ON)
91-
find_package(Threads REQUIRED)
91+
find_package(PkgConfig)
92+
if(BUILD_DAEMON)
93+
set(THREADS_PREFER_PTHREAD_FLAG ON)
94+
find_package(Threads REQUIRED)
95+
if(NOT MINGW AND NOT CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
96+
target_compile_definitions(Threads::Threads INTERFACE
97+
$<$<COMPILE_FEATURES:cxx_thread_local>:HAVE_THREAD_LOCAL>
98+
)
99+
endif()
100+
101+
if(APPLE AND BREW_COMMAND)
102+
execute_process(
103+
COMMAND ${BREW_COMMAND} --prefix boost
104+
OUTPUT_VARIABLE BOOST_ROOT
105+
ERROR_QUIET
106+
OUTPUT_STRIP_TRAILING_WHITESPACE
107+
)
108+
endif()
109+
set(Boost_NO_BOOST_CMAKE ON)
110+
# Find Boost headers only.
111+
find_package(Boost 1.64.0 REQUIRED)
112+
mark_as_advanced(Boost_INCLUDE_DIR)
113+
target_compile_definitions(Boost::boost INTERFACE
114+
$<$<CONFIG:Debug>:BOOST_MULTI_INDEX_ENABLE_SAFE_MODE>
115+
)
116+
if(CMAKE_VERSION VERSION_LESS 3.15)
117+
add_library(Boost::headers ALIAS Boost::boost)
118+
endif()
119+
120+
pkg_check_modules(libevent REQUIRED libevent>=2.1.8 IMPORTED_TARGET)
121+
target_link_libraries(PkgConfig::libevent INTERFACE
122+
$<$<PLATFORM_ID:Windows>:iphlpapi;ws2_32>
123+
)
124+
endif()
125+
126+
if(NOT WIN32 AND BUILD_DAEMON)
127+
pkg_check_modules(libevent_pthreads REQUIRED libevent_pthreads>=2.1.8 IMPORTED_TARGET)
128+
endif()
92129

93130
add_subdirectory(src)
94131

95132
message("\n")
96133
message("Configure summary")
97134
message("=================")
135+
message("Executables:")
136+
message(" bitcoind ............................ ${BUILD_DAEMON}")
137+
message("")
98138
get_directory_property(definitions COMPILE_DEFINITIONS)
99139
string(REPLACE ";" " " definitions "${definitions}")
100140
message("Preprocessor defined macros ........... ${definitions}")

cmake/introspection.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,7 @@ check_cxx_source_compiles("
195195
int main(){}
196196
" HAVE_DLLEXPORT_ATTRIBUTE
197197
)
198+
199+
if(APPLE)
200+
find_program(BREW_COMMAND brew)
201+
endif()

src/CMakeLists.txt

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,166 @@ add_library(bitcoin_consensus OBJECT EXCLUDE_FROM_ALL
2828
util/strencodings.cpp
2929
)
3030
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::headers
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::headers
179+
$<TARGET_NAME_IF_EXISTS: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()

0 commit comments

Comments
 (0)