Merge bitcoin/bitcoin#31844: cmake: add a component for each binary

9b033bebb1 cmake: rename Kernel component to bitcoinkernel for consistency (Cory Fields)
2e0c92558e cmake: add and use install_binary_component (Cory Fields)
0264c5d86c cmake: use per-target components for bitcoin-qt and bitcoin-gui (Cory Fields)
fb0546b1c5 ci: don't try to install for a fuzz build (Cory Fields)

Pull request description:

  This makes it possible to build/install only the desired binaries regardless of the configuration.
  For consistency, the component names match the binary names. `Kernel` and `GUI` have been renamed.

  Additionally it fixes #31762 by installing only the manpages for the configured targets (and includes them in the component installs for each).

  Also fixes #31745.

  Alternative to #31765 which is (imo) more correct/thorough.

  Can be tested using (for ex):
  ```bash
  $ cmake -B build
  $ cmake --build build -t bitcoind -t bitcoin-cli
  $ cmake --install build --component bitcoind
  $ cmake --install build --component bitcoin-cli
  ```

ACKs for top commit:
  hebasto:
    ACK 9b033bebb1.
  TheCharlatan:
    Re-ACK 9b033bebb1
  stickies-v:
    re-ACK 9b033bebb1

Tree-SHA512: fd4818e76f190dbeafbf0c246b466f829771902c9d6d7111ed917093b811c8a5536a4a45e20708f73e7f581d6cb77c8e61cfa69e065788dcf0886792f553a355
This commit is contained in:
merge-script 2025-02-14 14:19:12 +01:00
commit 73e2ec1373
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1
10 changed files with 48 additions and 46 deletions

View file

@ -14,3 +14,4 @@ export OSX_SDK=""
export RUN_UNIT_TESTS=false
export RUN_FUNCTIONAL_TESTS=false
export RUN_FUZZ_TESTS=true
export GOAL="all"

View file

@ -14,7 +14,7 @@ export NO_DEPENDS=1
export RUN_UNIT_TESTS=false
export RUN_FUNCTIONAL_TESTS=false
export RUN_FUZZ_TESTS=true
export GOAL="install"
export GOAL="all"
export CI_CONTAINER_CAP="--cap-add SYS_PTRACE" # If run with (ASan + LSan), the container needs access to ptrace (https://github.com/google/sanitizers/issues/764)
export BITCOIN_CONFIG="\
-DBUILD_FOR_FUZZING=ON \

View file

@ -0,0 +1,26 @@
# Copyright (c) 2025-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
include_guard(GLOBAL)
include(GNUInstallDirs)
function(install_binary_component component)
cmake_parse_arguments(PARSE_ARGV 1
IC # prefix
"HAS_MANPAGE" # options
"" # one_value_keywords
"" # multi_value_keywords
)
set(target_name ${component})
install(TARGETS ${target_name}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT ${component}
)
if(INSTALL_MAN AND IC_HAS_MANPAGE)
install(FILES ${PROJECT_SOURCE_DIR}/doc/man/${target_name}.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
COMPONENT ${component}
)
endif()
endfunction()

View file

@ -84,7 +84,7 @@ function(add_macos_deploy_target)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/${macos_app}/Contents/MacOS/Bitcoin-Qt
COMMAND ${CMAKE_COMMAND} --install ${PROJECT_BINARY_DIR} --config $<CONFIG> --component GUI --prefix ${macos_app}/Contents/MacOS --strip
COMMAND ${CMAKE_COMMAND} --install ${PROJECT_BINARY_DIR} --config $<CONFIG> --component bitcoin-qt --prefix ${macos_app}/Contents/MacOS --strip
COMMAND ${CMAKE_COMMAND} -E rename ${macos_app}/Contents/MacOS/bin/$<TARGET_FILE_NAME:bitcoin-qt> ${macos_app}/Contents/MacOS/Bitcoin-Qt
COMMAND ${CMAKE_COMMAND} -E rm -rf ${macos_app}/Contents/MacOS/bin
VERBATIM

View file

@ -2,7 +2,6 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
include(GNUInstallDirs)
include(AddWindowsResources)
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
$<$<PLATFORM_ID:Windows>:ws2_32>
)
include(InstallBinaryComponent)
set(installable_targets)
if(ENABLE_WALLET)
add_subdirectory(wallet)
@ -189,7 +188,7 @@ if(ENABLE_WALLET)
bitcoin_util
Boost::headers
)
list(APPEND installable_targets bitcoin-wallet)
install_binary_component(bitcoin-wallet HAS_MANPAGE)
endif()
endif()
@ -318,7 +317,7 @@ if(BUILD_DAEMON)
bitcoin_node
$<TARGET_NAME_IF_EXISTS:bitcoin_wallet>
)
list(APPEND installable_targets bitcoind)
install_binary_component(bitcoind HAS_MANPAGE)
endif()
if(WITH_MULTIPROCESS AND BUILD_DAEMON)
add_executable(bitcoin-node
@ -331,7 +330,7 @@ if(WITH_MULTIPROCESS AND BUILD_DAEMON)
bitcoin_ipc
$<TARGET_NAME_IF_EXISTS:bitcoin_wallet>
)
list(APPEND installable_targets bitcoin-node)
install_binary_component(bitcoin-node)
endif()
if(WITH_MULTIPROCESS AND BUILD_TESTS)
@ -374,7 +373,7 @@ if(BUILD_CLI)
libevent::core
libevent::extra
)
list(APPEND installable_targets bitcoin-cli)
install_binary_component(bitcoin-cli HAS_MANPAGE)
endif()
@ -387,7 +386,7 @@ if(BUILD_TX)
bitcoin_util
univalue
)
list(APPEND installable_targets bitcoin-tx)
install_binary_component(bitcoin-tx HAS_MANPAGE)
endif()
@ -399,7 +398,7 @@ if(BUILD_UTIL)
bitcoin_common
bitcoin_util
)
list(APPEND installable_targets bitcoin-util)
install_binary_component(bitcoin-util HAS_MANPAGE)
endif()
@ -445,17 +444,3 @@ endif()
if(BUILD_FUZZ_BINARY)
add_subdirectory(test/fuzz)
endif()
install(TARGETS ${installable_targets}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
unset(installable_targets)
if(INSTALL_MAN)
# TODO: these stubs are no longer needed. man pages should be generated at install time.
install(DIRECTORY ../doc/man/
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
FILES_MATCHING PATTERN *.1
)
endif()

View file

@ -81,6 +81,4 @@ add_test(NAME bench_sanity_check_high_priority
COMMAND bench_bitcoin -sanity-check -priority-level=high
)
install(TARGETS bench_bitcoin
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install_binary_component(bench_bitcoin)

View file

@ -2,6 +2,8 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
include(GNUInstallDirs)
# TODO: libbitcoinkernel is a work in progress consensus engine
# library, as more and more modules are decoupled from the
# consensus engine, this list will shrink to only those
@ -121,24 +123,23 @@ if(NOT BUILD_SHARED_LIBS)
set(all_kernel_static_link_libs "")
get_target_static_link_libs(bitcoinkernel all_kernel_static_link_libs)
install(TARGETS ${all_kernel_static_link_libs} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Kernel)
install(TARGETS ${all_kernel_static_link_libs} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT bitcoinkernel)
list(TRANSFORM all_kernel_static_link_libs PREPEND "-l")
# LIBS_PRIVATE is substituted in the pkg-config file.
list(JOIN all_kernel_static_link_libs " " LIBS_PRIVATE)
endif()
configure_file(${PROJECT_SOURCE_DIR}/libbitcoinkernel.pc.in ${PROJECT_BINARY_DIR}/libbitcoinkernel.pc @ONLY)
install(FILES ${PROJECT_BINARY_DIR}/libbitcoinkernel.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" COMPONENT Kernel)
install(FILES ${PROJECT_BINARY_DIR}/libbitcoinkernel.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" COMPONENT bitcoinkernel)
include(GNUInstallDirs)
install(TARGETS bitcoinkernel
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT Kernel
COMPONENT bitcoinkernel
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Kernel
COMPONENT bitcoinkernel
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Kernel
COMPONENT bitcoinkernel
)

View file

@ -236,7 +236,7 @@ target_link_libraries(bitcoin-qt
)
import_plugins(bitcoin-qt)
set(installable_targets bitcoin-qt)
install_binary_component(bitcoin-qt HAS_MANPAGE)
if(WIN32)
set_target_properties(bitcoin-qt PROPERTIES WIN32_EXECUTABLE TRUE)
endif()
@ -253,17 +253,12 @@ if(WITH_MULTIPROCESS)
bitcoin_ipc
)
import_plugins(bitcoin-gui)
list(APPEND installable_targets bitcoin-gui)
install_binary_component(bitcoin-gui)
if(WIN32)
set_target_properties(bitcoin-gui PROPERTIES WIN32_EXECUTABLE TRUE)
endif()
endif()
install(TARGETS ${installable_targets}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT GUI
)
if(BUILD_GUI_TESTS)
add_subdirectory(test)
endif()

View file

@ -45,6 +45,4 @@ if(WIN32 AND VCPKG_TARGET_TRIPLET)
)
endif()
install(TARGETS test_bitcoin-qt
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install_binary_component(test_bitcoin-qt)

View file

@ -214,6 +214,4 @@ endfunction()
add_all_test_targets()
install(TARGETS test_bitcoin
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install_binary_component(test_bitcoin)