From 026bb226e96919603af829d0b677779a234a0f6e Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Tue, 18 Feb 2025 14:04:31 +0000 Subject: [PATCH] cmake: Set top-level target output locations This change: 1. Collects build artifacts in dedicated locations. 2. Allows running bitcoin-chainstate.exe with bitcoinkernel.dll directly from the build tree on Windows. --- .github/workflows/ci.yml | 10 +-- CMakeLists.txt | 3 - contrib/devtools/check-deps.sh | 8 +-- contrib/devtools/gen-bitcoin-conf.sh | 2 +- contrib/devtools/gen-manpages.py | 12 ++-- src/CMakeLists.txt | 64 +++++++++++++------ .../test_framework/test_framework.py | 6 +- test/fuzz/test_runner.py | 2 +- test/util/test_runner.py | 2 +- 9 files changed, 64 insertions(+), 45 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1da02a86b07..e3b55c400f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -238,10 +238,10 @@ jobs: if: matrix.job-type == 'standard' working-directory: build env: - BITCOIND: '${{ github.workspace }}\build\src\Release\bitcoind.exe' - BITCOINCLI: '${{ github.workspace }}\build\src\Release\bitcoin-cli.exe' - BITCOINUTIL: '${{ github.workspace }}\build\src\Release\bitcoin-util.exe' - BITCOINWALLET: '${{ github.workspace }}\build\src\Release\bitcoin-wallet.exe' + BITCOIND: '${{ github.workspace }}\build\bin\Release\bitcoind.exe' + BITCOINCLI: '${{ github.workspace }}\build\bin\Release\bitcoin-cli.exe' + BITCOINUTIL: '${{ github.workspace }}\build\bin\Release\bitcoin-util.exe' + BITCOINWALLET: '${{ github.workspace }}\build\bin\Release\bitcoin-wallet.exe' TEST_RUNNER_EXTRA: ${{ github.event_name != 'pull_request' && '--extended' || '' }} shell: cmd run: py -3 test\functional\test_runner.py --jobs %NUMBER_OF_PROCESSORS% --ci --quiet --tmpdirprefix=%RUNNER_TEMP% --combinedlogslen=99999999 --timeout-factor=%TEST_RUNNER_TIMEOUT_FACTOR% %TEST_RUNNER_EXTRA% @@ -258,7 +258,7 @@ jobs: if: matrix.job-type == 'fuzz' working-directory: build env: - BITCOINFUZZ: '${{ github.workspace }}\build\src\test\fuzz\Release\fuzz.exe' + BITCOINFUZZ: '${{ github.workspace }}\build\bin\Release\fuzz.exe' shell: cmd run: | py -3 test\fuzz\test_runner.py --par %NUMBER_OF_PROCESSORS% --loglevel DEBUG %RUNNER_TEMP%\qa-assets\fuzz_corpora diff --git a/CMakeLists.txt b/CMakeLists.txt index 94464907de1..88d6b950b6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -609,9 +609,6 @@ endif() add_subdirectory(test) add_subdirectory(doc) -include(cmake/crc32c.cmake) -include(cmake/leveldb.cmake) -include(cmake/minisketch.cmake) add_subdirectory(src) include(cmake/tests.cmake) diff --git a/contrib/devtools/check-deps.sh b/contrib/devtools/check-deps.sh index 54cca3846b4..25e948647c0 100755 --- a/contrib/devtools/check-deps.sh +++ b/contrib/devtools/check-deps.sh @@ -8,10 +8,10 @@ declare -A LIBS LIBS[cli]="libbitcoin_cli.a" LIBS[common]="libbitcoin_common.a" LIBS[consensus]="libbitcoin_consensus.a" -LIBS[crypto]="crypto/libbitcoin_crypto.a" +LIBS[crypto]="libbitcoin_crypto.a" LIBS[node]="libbitcoin_node.a" -LIBS[util]="util/libbitcoin_util.a" -LIBS[wallet]="wallet/libbitcoin_wallet.a" +LIBS[util]="libbitcoin_util.a" +LIBS[wallet]="libbitcoin_wallet.a" # Declare allowed dependencies "X Y" where X is allowed to depend on Y. This # list is taken from doc/design/libraries.md. @@ -187,7 +187,7 @@ fi # shellcheck disable=SC2046 cmake --build "$BUILD_DIR" -j"$(nproc)" -t $(lib_targets) TEMP_DIR="$(mktemp -d)" -cd "$BUILD_DIR/src" +cd "$BUILD_DIR/lib" extract_symbols "$TEMP_DIR" if check_libraries "$TEMP_DIR"; then echo "Success! No unexpected dependencies were detected." diff --git a/contrib/devtools/gen-bitcoin-conf.sh b/contrib/devtools/gen-bitcoin-conf.sh index 5905cc7d65a..234318e1a14 100755 --- a/contrib/devtools/gen-bitcoin-conf.sh +++ b/contrib/devtools/gen-bitcoin-conf.sh @@ -6,7 +6,7 @@ export LC_ALL=C TOPDIR=${TOPDIR:-$(git rev-parse --show-toplevel)} BUILDDIR=${BUILDDIR:-$TOPDIR/build} -BINDIR=${BINDIR:-$BUILDDIR/src} +BINDIR=${BINDIR:-$BUILDDIR/bin} BITCOIND=${BITCOIND:-$BINDIR/bitcoind} SHARE_EXAMPLES_DIR=${SHARE_EXAMPLES_DIR:-$TOPDIR/share/examples} EXAMPLE_CONF_FILE=${EXAMPLE_CONF_FILE:-$SHARE_EXAMPLES_DIR/bitcoin.conf} diff --git a/contrib/devtools/gen-manpages.py b/contrib/devtools/gen-manpages.py index cbb0abd3373..c7678817a99 100755 --- a/contrib/devtools/gen-manpages.py +++ b/contrib/devtools/gen-manpages.py @@ -9,12 +9,12 @@ import tempfile import argparse BINARIES = [ -'src/bitcoind', -'src/bitcoin-cli', -'src/bitcoin-tx', -'src/bitcoin-wallet', -'src/bitcoin-util', -'src/qt/bitcoin-qt', +'bin/bitcoind', +'bin/bitcoin-cli', +'bin/bitcoin-tx', +'bin/bitcoin-wallet', +'bin/bitcoin-util', +'bin/bitcoin-qt', ] parser = argparse.ArgumentParser( diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8862196dcf3..41577b2ad6d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,28 +7,18 @@ include(AddWindowsResources) configure_file(${PROJECT_SOURCE_DIR}/cmake/bitcoin-build-config.h.in bitcoin-build-config.h USE_SOURCE_PERMISSIONS @ONLY) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) -add_custom_target(generate_build_info - BYPRODUCTS ${PROJECT_BINARY_DIR}/src/bitcoin-build-info.h - COMMAND ${CMAKE_COMMAND} -DBUILD_INFO_HEADER_PATH=${PROJECT_BINARY_DIR}/src/bitcoin-build-info.h -DSOURCE_DIR=${PROJECT_SOURCE_DIR} -P ${PROJECT_SOURCE_DIR}/cmake/script/GenerateBuildInfo.cmake - COMMENT "Generating bitcoin-build-info.h" - VERBATIM -) -add_library(bitcoin_clientversion STATIC EXCLUDE_FROM_ALL - clientversion.cpp -) -target_link_libraries(bitcoin_clientversion - PRIVATE - core_interface -) -add_dependencies(bitcoin_clientversion generate_build_info) - -add_subdirectory(crypto) +#============================= +# Subprojects +#============================= +# Subprojects include subdirectories that do or could have tests +# and/or benchmark binaries, such as all subtrees and univalue. +# These need to be included before CMAKE_*_OUTPUT_DIRECTORY variables +# are set, so output locations of subproject tests and libraries are +# not overridden. +include(../cmake/crc32c.cmake) +include(../cmake/leveldb.cmake) +include(../cmake/minisketch.cmake) add_subdirectory(univalue) -add_subdirectory(util) -if(WITH_MULTIPROCESS) - add_subdirectory(ipc) -endif() - #============================= # secp256k1 subtree #============================= @@ -78,6 +68,38 @@ set_target_properties(secp256k1 PROPERTIES ) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +# Set top-level target output locations. +if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) +endif() +if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) +endif() +if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) +endif() + +add_custom_target(generate_build_info + BYPRODUCTS ${PROJECT_BINARY_DIR}/src/bitcoin-build-info.h + COMMAND ${CMAKE_COMMAND} -DBUILD_INFO_HEADER_PATH=${PROJECT_BINARY_DIR}/src/bitcoin-build-info.h -DSOURCE_DIR=${PROJECT_SOURCE_DIR} -P ${PROJECT_SOURCE_DIR}/cmake/script/GenerateBuildInfo.cmake + COMMENT "Generating bitcoin-build-info.h" + VERBATIM +) +add_library(bitcoin_clientversion STATIC EXCLUDE_FROM_ALL + clientversion.cpp +) +target_link_libraries(bitcoin_clientversion + PRIVATE + core_interface +) +add_dependencies(bitcoin_clientversion generate_build_info) + +add_subdirectory(crypto) +add_subdirectory(util) +if(WITH_MULTIPROCESS) + add_subdirectory(ipc) +endif() + add_library(bitcoin_consensus STATIC EXCLUDE_FROM_ALL arith_uint256.cpp consensus/merkle.cpp diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 921f12d9fb4..d5b338f2ba2 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -255,7 +255,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): for binary, [attribute_name, env_variable_name] in binaries.items(): default_filename = os.path.join( self.config["environment"]["BUILDDIR"], - "src", + "bin", binary + self.config["environment"]["EXEEXT"], ) setattr(self.options, attribute_name, os.getenv(env_variable_name, default=default_filename)) @@ -272,8 +272,8 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): self.set_binary_paths() os.environ['PATH'] = os.pathsep.join([ - os.path.join(config['environment']['BUILDDIR'], 'src'), - os.path.join(config['environment']['BUILDDIR'], 'src', 'qt'), os.environ['PATH'] + os.path.join(config['environment']['BUILDDIR'], 'bin'), + os.environ['PATH'] ]) # Set up temp directory and start logging diff --git a/test/fuzz/test_runner.py b/test/fuzz/test_runner.py index e87977edfc2..12661b4da59 100755 --- a/test/fuzz/test_runner.py +++ b/test/fuzz/test_runner.py @@ -109,7 +109,7 @@ def main(): logging.error("Must have fuzz executable built") sys.exit(1) - fuzz_bin=os.getenv("BITCOINFUZZ", default=os.path.join(config["environment"]["BUILDDIR"], 'src', 'test', 'fuzz', 'fuzz')) + fuzz_bin=os.getenv("BITCOINFUZZ", default=os.path.join(config["environment"]["BUILDDIR"], 'bin', 'fuzz')) # Build list of tests test_list_all = parse_test_list( diff --git a/test/util/test_runner.py b/test/util/test_runner.py index cac184ca302..d6faf18c5c6 100755 --- a/test/util/test_runner.py +++ b/test/util/test_runner.py @@ -73,7 +73,7 @@ def bctest(testDir, testObj, buildenv): are not as expected. Error is caught by bctester() and reported. """ # Get the exec names and arguments - execprog = os.path.join(buildenv["BUILDDIR"], "src", testObj["exec"] + buildenv["EXEEXT"]) + execprog = os.path.join(buildenv["BUILDDIR"], "bin", testObj["exec"] + buildenv["EXEEXT"]) if testObj["exec"] == "./bitcoin-util": execprog = os.getenv("BITCOINUTIL", default=execprog) elif testObj["exec"] == "./bitcoin-tx":