forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #15: build: Add CMake-based build system (6 of N)
43123cf FIXUP: Same as PR27458 (Hennadii Stepanov) 2d8930e FIXUP: Same as PR27656 (Hennadii Stepanov) a112470 cmake: Include CTest (Hennadii Stepanov) cb19814 cmake: Build `test_bitcoin` executable (Hennadii Stepanov) 751453f cmake: Build `bench_bitcoin` executable (Hennadii Stepanov) a2c3493 cmake: Add test config and runners (Hennadii Stepanov) cb7dc94 test: Explicitly specify directory where to search tests for (Hennadii Stepanov) 2fd303f test: Make `util/test_runner.py` honor `BITCOINUTIL` and `BITCOINTX` (Hennadii Stepanov) 2e3721e cmake: Add wallet functionality (Hennadii Stepanov) f944ccd cmake: Build `bitcoin-util` executable (Hennadii Stepanov) d1c319d cmake: Build `bitcoin-tx` executable (Hennadii Stepanov) 1934755 cmake: Build `bitcoin-cli` executable (Hennadii Stepanov) 5fc2cee [FIXUP] cmake: Add workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/20652 (Hennadii Stepanov) b2bea9f [FIXUP] cmake: Consider `ASM` option when checking for `HAVE_64BIT_ASM` (Hennadii Stepanov) Pull request description: The parent PR: bitcoin#25797. The previous PRs in the staging branch: #5, #6, #7, #10, #13. --- What is NEW: - `bitcoin-cli` - `bitcoin-tx` - `bitcoin-util` - wallet functionality and `bitcoin-wallet` - `bench_bitcoin` - `test_bitcoin` EXAMPLES: ``` cmake -S . -B build cd build cmake --build . -j $(nproc) ctest -j $(nproc) ./test/functional/test_runner.py -j $(nproc) ``` Using a multi-configuration generator (CMake 3.17+ is required): ``` cmake -S . -B build -G "Ninja Multi-Config" cd build cmake --build . -j $(nproc) ctest -j $(nproc) -C Debug ``` --- What to test: - old CMake versions, for example v3.13 - multi-config generators, for example `-G "Ninja Multi-Config"` --- What to consider additionally: - is it worth to pull the "[test: Make util/test_runner.py honor BITCOINUTIL and BITCOINTX](268aca3)" commit to the main repo now? FWIW, we use the same approach for functional tests providing the `BITCOIND` environment variable when needed. ACKs for top commit: TheCharlatan: ACK 43123cf Tree-SHA512: a04cfca266bcde780528c915cb01f69189f36a0e1beb521fe75e4816ca4f9ab9440646529bbf2cbdfe76275debc5107ee2433e1027405094d3e8a74ec0d1d077
- Loading branch information
Showing
19 changed files
with
780 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Copyright (c) 2023 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
if(CMAKE_HOST_APPLE) | ||
execute_process( | ||
COMMAND brew --prefix berkeley-db@4 | ||
OUTPUT_VARIABLE bdb4_brew_prefix | ||
ERROR_QUIET | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
endif() | ||
|
||
find_path(BerkeleyDB_INCLUDE_DIR | ||
NAMES db.h | ||
HINTS ${bdb4_brew_prefix}/include | ||
PATH_SUFFIXES 4.8 48 4 db4 5 5.3 db5 | ||
) | ||
|
||
if(BerkeleyDB_INCLUDE_DIR) | ||
file( | ||
STRINGS "${BerkeleyDB_INCLUDE_DIR}/db.h" version_strings | ||
REGEX ".*DB_VERSION_(MAJOR|MINOR)[ \t]+[0-9]+.*" | ||
) | ||
string(REGEX REPLACE ".*DB_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" BerkeleyDB_VERSION_MAJOR "${version_strings}") | ||
string(REGEX REPLACE ".*DB_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" BerkeleyDB_VERSION_MINOR "${version_strings}") | ||
set(BerkeleyDB_VERSION ${BerkeleyDB_VERSION_MAJOR}.${BerkeleyDB_VERSION_MINOR}) | ||
endif() | ||
|
||
if(MSVC) | ||
cmake_path(GET BerkeleyDB_INCLUDE_DIR PARENT_PATH BerkeleyDB_IMPORTED_PATH) | ||
find_library(BerkeleyDB_LIBRARY_DEBUG | ||
NAMES libdb48 PATHS ${BerkeleyDB_IMPORTED_PATH}/debug/lib | ||
NO_DEFAULT_PATH | ||
) | ||
find_library(BerkeleyDB_LIBRARY_RELEASE | ||
NAMES libdb48 PATHS ${BerkeleyDB_IMPORTED_PATH}/lib | ||
NO_DEFAULT_PATH | ||
) | ||
if(BerkeleyDB_LIBRARY_DEBUG OR BerkeleyDB_LIBRARY_RELEASE) | ||
set(BerkeleyDB_required BerkeleyDB_IMPORTED_PATH) | ||
endif() | ||
else() | ||
find_library(BerkeleyDB_LIBRARY | ||
NAMES db_cxx-4.8 libdb48 db4_cxx db_cxx db_cxx-5 | ||
HINTS ${bdb4_brew_prefix}/lib | ||
) | ||
set(BerkeleyDB_required BerkeleyDB_LIBRARY) | ||
endif() | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(BerkeleyDB | ||
REQUIRED_VARS ${BerkeleyDB_required} BerkeleyDB_INCLUDE_DIR | ||
VERSION_VAR BerkeleyDB_VERSION | ||
) | ||
|
||
if(BerkeleyDB_FOUND AND NOT TARGET BerkeleyDB::BerkeleyDB) | ||
add_library(BerkeleyDB::BerkeleyDB UNKNOWN IMPORTED) | ||
set_target_properties(BerkeleyDB::BerkeleyDB PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES "${BerkeleyDB_INCLUDE_DIR}" | ||
) | ||
if(MSVC) | ||
if(BerkeleyDB_LIBRARY_DEBUG) | ||
set_property(TARGET BerkeleyDB::BerkeleyDB APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) | ||
set_target_properties(BerkeleyDB::BerkeleyDB PROPERTIES | ||
IMPORTED_LOCATION_DEBUG "${BerkeleyDB_LIBRARY_DEBUG}" | ||
) | ||
endif() | ||
if(BerkeleyDB_LIBRARY_RELEASE) | ||
set_property(TARGET BerkeleyDB::BerkeleyDB APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) | ||
set_target_properties(BerkeleyDB::BerkeleyDB PROPERTIES | ||
IMPORTED_LOCATION_RELEASE "${BerkeleyDB_LIBRARY_RELEASE}" | ||
) | ||
endif() | ||
else() | ||
set_target_properties(BerkeleyDB::BerkeleyDB PROPERTIES | ||
IMPORTED_LOCATION "${BerkeleyDB_LIBRARY}" | ||
) | ||
endif() | ||
endif() | ||
|
||
mark_as_advanced( | ||
BerkeleyDB_INCLUDE_DIR | ||
BerkeleyDB_LIBRARY | ||
BerkeleyDB_LIBRARY_DEBUG | ||
BerkeleyDB_LIBRARY_RELEASE | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright (c) 2023 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
function(generate_header_from_json json_source_relpath) | ||
add_custom_command( | ||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${json_source_relpath}.h | ||
COMMAND ${CMAKE_COMMAND} -DJSON_SOURCE_PATH=${CMAKE_CURRENT_SOURCE_DIR}/${json_source_relpath} -DHEADER_PATH=${CMAKE_CURRENT_BINARY_DIR}/${json_source_relpath}.h -P ${CMAKE_SOURCE_DIR}/cmake/script/GenerateHeaderFromJson.cmake | ||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${json_source_relpath} | ||
VERBATIM | ||
) | ||
endfunction() | ||
|
||
function(generate_header_from_raw raw_source_relpath) | ||
add_custom_command( | ||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${raw_source_relpath}.h | ||
COMMAND ${CMAKE_COMMAND} -DRAW_SOURCE_PATH=${CMAKE_CURRENT_SOURCE_DIR}/${raw_source_relpath} -DHEADER_PATH=${CMAKE_CURRENT_BINARY_DIR}/${raw_source_relpath}.h -P ${CMAKE_SOURCE_DIR}/cmake/script/GenerateHeaderFromRaw.cmake | ||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${raw_source_relpath} | ||
VERBATIM | ||
) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) 2023 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
file(READ ${JSON_SOURCE_PATH} hex_content HEX) | ||
string(REGEX MATCHALL "([A-Za-z0-9][A-Za-z0-9])" bytes "${hex_content}") | ||
|
||
file(WRITE ${HEADER_PATH} "namespace json_tests{\n") | ||
get_filename_component(json_source_basename ${JSON_SOURCE_PATH} NAME_WE) | ||
file(APPEND ${HEADER_PATH} "static unsigned const char ${json_source_basename}[] = {\n") | ||
|
||
set(i 0) | ||
foreach(byte ${bytes}) | ||
math(EXPR i "${i} + 1") | ||
math(EXPR remainder "${i} % 8") | ||
if(remainder EQUAL 0) | ||
file(APPEND ${HEADER_PATH} "0x${byte},\n") | ||
else() | ||
file(APPEND ${HEADER_PATH} "0x${byte}, ") | ||
endif() | ||
endforeach() | ||
|
||
file(APPEND ${HEADER_PATH} "\n};};") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright (c) 2023 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
file(READ ${RAW_SOURCE_PATH} hex_content HEX) | ||
string(REGEX MATCHALL "([A-Za-z0-9][A-Za-z0-9])" bytes "${hex_content}") | ||
|
||
get_filename_component(raw_source_basename ${RAW_SOURCE_PATH} NAME_WE) | ||
file(WRITE ${HEADER_PATH} "static unsigned const char ${raw_source_basename}_raw[] = {\n") | ||
|
||
set(i 0) | ||
foreach(byte ${bytes}) | ||
math(EXPR i "${i} + 1") | ||
math(EXPR remainder "${i} % 8") | ||
if(remainder EQUAL 0) | ||
file(APPEND ${HEADER_PATH} "0x${byte},\n") | ||
else() | ||
file(APPEND ${HEADER_PATH} "0x${byte}, ") | ||
endif() | ||
endforeach() | ||
|
||
file(APPEND ${HEADER_PATH} "\n};") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.