From 973a3b0c5dcbf6b3fd155b2dda4c2e94a0b0ee5f Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 24 Jul 2024 12:29:12 +0100 Subject: [PATCH] cmake: Implement `install` build target --- CMakeLists.txt | 2 ++ src/CMakeLists.txt | 23 +++++++++++++++++++++++ src/bench/CMakeLists.txt | 4 ++++ src/kernel/CMakeLists.txt | 7 +++++++ src/qt/CMakeLists.txt | 6 ++++++ src/test/CMakeLists.txt | 4 ++++ 6 files changed, 46 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f62c75794cf..3b033383d81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -187,6 +187,8 @@ option(BUILD_BENCH "Build bench_bitcoin executable." OFF) option(BUILD_FUZZ_BINARY "Build fuzz binary." OFF) cmake_dependent_option(BUILD_FOR_FUZZING "Build for fuzzing. Enabling this will disable all other targets and override BUILD_FUZZ_BINARY." OFF "NOT MSVC" OFF) +option(INSTALL_MAN "Install man pages." ON) + set(configure_warnings) include(CheckPIESupported) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ba2beba4723..4f6c0250862 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,8 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or https://opensource.org/license/mit/. +include(GNUInstallDirs) + configure_file(${PROJECT_SOURCE_DIR}/cmake/bitcoin-config.h.in config/bitcoin-config.h @ONLY) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) @@ -160,6 +162,7 @@ target_link_libraries(bitcoin_common ) +set(installable_targets) if(ENABLE_WALLET) add_subdirectory(wallet) @@ -176,6 +179,7 @@ if(ENABLE_WALLET) bitcoin_util Boost::headers ) + list(APPEND installable_targets bitcoin-wallet) endif() endif() @@ -304,6 +308,7 @@ if(BUILD_DAEMON) bitcoin_node $ ) + list(APPEND installable_targets bitcoind) endif() if(WITH_MULTIPROCESS) add_executable(bitcoin-node @@ -316,6 +321,7 @@ if(WITH_MULTIPROCESS) bitcoin_ipc $ ) + list(APPEND installable_targets bitcoin-node) endif() @@ -340,6 +346,7 @@ if(BUILD_CLI) bitcoin_util $ ) + list(APPEND installable_targets bitcoin-cli) endif() @@ -351,6 +358,7 @@ if(BUILD_TX) bitcoin_util univalue ) + list(APPEND installable_targets bitcoin-tx) endif() @@ -361,6 +369,7 @@ if(BUILD_UTIL) bitcoin_common bitcoin_util ) + list(APPEND installable_targets bitcoin-util) endif() @@ -406,3 +415,17 @@ 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() diff --git a/src/bench/CMakeLists.txt b/src/bench/CMakeLists.txt index 777bf2bbbd3..61a1126904e 100644 --- a/src/bench/CMakeLists.txt +++ b/src/bench/CMakeLists.txt @@ -79,3 +79,7 @@ endif() 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} +) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 722fd31aebf..ffb1a857ac1 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -97,3 +97,10 @@ target_link_libraries(bitcoinkernel set_target_properties(bitcoinkernel PROPERTIES CXX_VISIBILITY_PRESET default ) + +include(GNUInstallDirs) +install(TARGETS bitcoinkernel + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} +) diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index 71f769b651e..df51782488a 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -255,11 +255,17 @@ if(WITH_MULTIPROCESS) bitcoin_ipc ) import_plugins(bitcoin-gui) + list(APPEND installable_targets 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() diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index a3624065b2f..a666a76f8f3 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -217,3 +217,7 @@ function(add_all_test_targets) endfunction() add_all_test_targets() + +install(TARGETS test_bitcoin + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +)