From 7400ca57874919e30cc19ac9db63e0fdccfbb8ff Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sun, 2 Apr 2023 20:36:56 +0100 Subject: [PATCH] cmake: Implement `make install` --- CMakeLists.txt | 1 + src/CMakeLists.txt | 22 ++++++++++++++++++++++ src/bench/CMakeLists.txt | 4 ++++ src/test/CMakeLists.txt | 4 ++++ 4 files changed, 31 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f2bf38b910341..d30cfae98fb77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,7 @@ tristate_option(WITH_USDT option(BUILD_TESTS "Build test_bitcoin executable." ON) option(BUILD_BENCH "Build bench_bitcoin executable." ON) +option(INSTALL_MAN "Install man pages." ON) if(CXX20) set(CMAKE_CXX_STANDARD 20) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aa49eb77c60d8..3caa2c2d25e1a 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 http://www.opensource.org/licenses/mit-license.php. +include(GNUInstallDirs) + configure_file(${CMAKE_SOURCE_DIR}/cmake/bitcoin-config.h.in config/bitcoin-config.h @ONLY) add_compile_definitions(HAVE_CONFIG_H) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) @@ -101,6 +103,7 @@ target_link_libraries(bitcoin_common ) +set(installable_targets) if(ENABLE_WALLET) add_subdirectory(wallet) @@ -117,6 +120,7 @@ if(ENABLE_WALLET) bitcoin_util Boost::headers ) + list(APPEND installable_targets bitcoin-wallet) endif() endif() @@ -244,6 +248,7 @@ if(BUILD_DAEMON) bitcoin_node $ ) + list(APPEND installable_targets bitcoind) endif() @@ -268,6 +273,7 @@ if(BUILD_CLI) bitcoin_util libevent::libevent ) + list(APPEND installable_targets bitcoin-cli) endif() @@ -279,6 +285,7 @@ if(BUILD_TX) bitcoin_util univalue ) + list(APPEND installable_targets bitcoin-tx) endif() @@ -289,6 +296,7 @@ if(BUILD_UTIL) bitcoin_common bitcoin_util ) + list(APPEND installable_targets bitcoin-util) endif() @@ -300,3 +308,17 @@ endif() if(BUILD_TESTS) add_subdirectory(test) 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 355e4c7909a5d..58d3d1016b456 100644 --- a/src/bench/CMakeLists.txt +++ b/src/bench/CMakeLists.txt @@ -66,3 +66,7 @@ if(ENABLE_WALLET) ) target_link_libraries(bench_bitcoin bitcoin_wallet) endif() + +install(TARGETS bench_bitcoin + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 3a5a9ae00082a..99ca6aeb10d88 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -171,3 +171,7 @@ if(ENABLE_WALLET) target_sources(test_bitcoin PRIVATE ../wallet/test/db_tests.cpp) endif() endif() + +install(TARGETS test_bitcoin + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +)