Skip to content

Commit e52f40b

Browse files
committed
cmake: add and use install_binary_component
Add a separate component for each binary for fine-grained installation options. Also install the man pages for only for the targets enabled.
1 parent 00c670f commit e52f40b

File tree

7 files changed

+40
-40
lines changed

7 files changed

+40
-40
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (c) 2025-present The Bitcoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or https://opensource.org/license/mit/.
4+
5+
include_guard(GLOBAL)
6+
include(GNUInstallDirs)
7+
8+
function(install_binary_component component)
9+
cmake_parse_arguments(PARSE_ARGV 1
10+
IC # prefix
11+
"HAS_MANPAGE" # options
12+
"" # one_value_keywords
13+
"" # multi_value_keywords
14+
)
15+
set(target_name ${component})
16+
install(TARGETS ${target_name}
17+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
18+
COMPONENT ${component}
19+
)
20+
if(INSTALL_MAN AND IC_HAS_MANPAGE)
21+
install(FILES ${PROJECT_SOURCE_DIR}/doc/man/${target_name}.1
22+
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
23+
COMPONENT ${component}
24+
)
25+
endif()
26+
endfunction()

src/CMakeLists.txt

+7-23
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Distributed under the MIT software license, see the accompanying
33
# file COPYING or https://opensource.org/license/mit/.
44

5-
include(GNUInstallDirs)
65
include(AddWindowsResources)
76

87
configure_file(${PROJECT_SOURCE_DIR}/cmake/bitcoin-build-config.h.in bitcoin-build-config.h USE_SOURCE_PERMISSIONS @ONLY)
@@ -170,8 +169,8 @@ target_link_libraries(bitcoin_common
170169
$<$<PLATFORM_ID:Windows>:ws2_32>
171170
)
172171

172+
include(InstallBinaryComponent)
173173

174-
set(installable_targets)
175174
if(ENABLE_WALLET)
176175
add_subdirectory(wallet)
177176

@@ -189,7 +188,7 @@ if(ENABLE_WALLET)
189188
bitcoin_util
190189
Boost::headers
191190
)
192-
list(APPEND installable_targets bitcoin-wallet)
191+
install_binary_component(bitcoin-wallet HAS_MANPAGE)
193192
endif()
194193
endif()
195194

@@ -318,7 +317,7 @@ if(BUILD_DAEMON)
318317
bitcoin_node
319318
$<TARGET_NAME_IF_EXISTS:bitcoin_wallet>
320319
)
321-
list(APPEND installable_targets bitcoind)
320+
install_binary_component(bitcoind HAS_MANPAGE)
322321
endif()
323322
if(WITH_MULTIPROCESS AND BUILD_DAEMON)
324323
add_executable(bitcoin-node
@@ -331,8 +330,7 @@ if(WITH_MULTIPROCESS AND BUILD_DAEMON)
331330
bitcoin_ipc
332331
$<TARGET_NAME_IF_EXISTS:bitcoin_wallet>
333332
)
334-
list(APPEND installable_targets bitcoin-node)
335-
endif()
333+
install_binary_component(bitcoin-node HAS_MANPAGE)
336334

337335
if(WITH_MULTIPROCESS AND BUILD_TESTS)
338336
# bitcoin_ipc_test library target is defined here in src/CMakeLists.txt
@@ -374,7 +372,7 @@ if(BUILD_CLI)
374372
libevent::core
375373
libevent::extra
376374
)
377-
list(APPEND installable_targets bitcoin-cli)
375+
install_binary_component(bitcoin-cli HAS_MANPAGE)
378376
endif()
379377

380378

@@ -387,7 +385,7 @@ if(BUILD_TX)
387385
bitcoin_util
388386
univalue
389387
)
390-
list(APPEND installable_targets bitcoin-tx)
388+
install_binary_component(bitcoin-tx HAS_MANPAGE)
391389
endif()
392390

393391

@@ -399,7 +397,7 @@ if(BUILD_UTIL)
399397
bitcoin_common
400398
bitcoin_util
401399
)
402-
list(APPEND installable_targets bitcoin-util)
400+
install_binary_component(bitcoin-util HAS_MANPAGE)
403401
endif()
404402

405403

@@ -445,17 +443,3 @@ endif()
445443
if(BUILD_FUZZ_BINARY)
446444
add_subdirectory(test/fuzz)
447445
endif()
448-
449-
450-
install(TARGETS ${installable_targets}
451-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
452-
)
453-
unset(installable_targets)
454-
455-
if(INSTALL_MAN)
456-
# TODO: these stubs are no longer needed. man pages should be generated at install time.
457-
install(DIRECTORY ../doc/man/
458-
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
459-
FILES_MATCHING PATTERN *.1
460-
)
461-
endif()

src/bench/CMakeLists.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,4 @@ add_test(NAME bench_sanity_check_high_priority
8181
COMMAND bench_bitcoin -sanity-check -priority-level=high
8282
)
8383

84-
install(TARGETS bench_bitcoin
85-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
86-
)
84+
install_binary_component(bench_bitcoin)

src/kernel/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Distributed under the MIT software license, see the accompanying
33
# file COPYING or https://opensource.org/license/mit/.
44

5+
include(GNUInstallDirs)
6+
57
# TODO: libbitcoinkernel is a work in progress consensus engine
68
# library, as more and more modules are decoupled from the
79
# consensus engine, this list will shrink to only those

src/qt/CMakeLists.txt

+2-8
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,7 @@ target_link_libraries(bitcoin-qt
236236
)
237237

238238
import_plugins(bitcoin-qt)
239-
install(TARGETS bitcoin-qt
240-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
241-
COMPONENT bitcoin-qt
242-
)
239+
install_binary_component(bitcoin-qt HAS_MANPAGE)
243240
if(WIN32)
244241
set_target_properties(bitcoin-qt PROPERTIES WIN32_EXECUTABLE TRUE)
245242
endif()
@@ -256,10 +253,7 @@ if(WITH_MULTIPROCESS)
256253
bitcoin_ipc
257254
)
258255
import_plugins(bitcoin-gui)
259-
install(TARGETS bitcoin-gui
260-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
261-
COMPONENT bitcoin-gui
262-
)
256+
install_binary_component(bitcoin-gui)
263257
if(WIN32)
264258
set_target_properties(bitcoin-gui PROPERTIES WIN32_EXECUTABLE TRUE)
265259
endif()

src/qt/test/CMakeLists.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,4 @@ if(WIN32 AND VCPKG_TARGET_TRIPLET)
4545
)
4646
endif()
4747

48-
install(TARGETS test_bitcoin-qt
49-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
50-
)
48+
install_binary_component(test_bitcoin-qt)

src/test/CMakeLists.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,4 @@ endfunction()
213213

214214
add_all_test_targets()
215215

216-
install(TARGETS test_bitcoin
217-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
218-
)
216+
install_binary_component(test_bitcoin)

0 commit comments

Comments
 (0)