Skip to content

Commit

Permalink
CMake: add tests (test_bitcoin) compilation support.
Browse files Browse the repository at this point in the history
  • Loading branch information
aleflm committed Feb 16, 2025
1 parent d62a490 commit ab7d2f3
Show file tree
Hide file tree
Showing 10 changed files with 278 additions and 131 deletions.
16 changes: 5 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ set(FIRO_DAEMON_NAME firod)
set(FIRO_GUI_NAME firo-qt)
set(FIRO_CLI_NAME firo-cli)
set(FIRO_TX_NAME firo-tx)
set(FIRO_UTIL_NAME firo-util)

set(CLIENT_VERSION_STRING ${PROJECT_VERSION})
if(CLIENT_VERSION_RC GREATER 0)
Expand Down Expand Up @@ -105,14 +104,13 @@ option(BUILD_DAEMON "Build ${FIRO_DAEMON_NAME} executable." ON)
option(BUILD_GUI "Build ${FIRO_GUI_NAME} executable." OFF)
option(BUILD_CLI "Build ${FIRO_CLI_NAME} executable." ON)

option(BUILD_TESTS "Build test_firo executable." ON)
option(BUILD_TX "Build ${FIRO_TX_NAME} executable." ${BUILD_TESTS})
option(BUILD_UTIL "Build ${FIRO_UTIL_NAME} executable and library." ${BUILD_TESTS})

option(BUILD_UTIL_CHAINSTATE "Build experimental firo-chainstate executable." OFF)
option(BUILD_KERNEL_LIB "Build experimental firokernel library." ${BUILD_UTIL_CHAINSTATE})

option(ENABLE_WALLET "Enable wallet." OFF)
cmake_dependent_option(BUILD_TESTS "Build tests." OFF "ENABLE_WALLET" OFF)
option(BUILD_TX "Build ${FIRO_TX_NAME} executable." ${BUILD_TESTS})
option(WITH_BDB "Enable Berkeley DB (BDB) wallet support." OFF)
cmake_dependent_option(WARN_INCOMPATIBLE_BDB "Warn when using a Berkeley DB (BDB) version other than 4.8." ON "WITH_BDB" OFF)
if(WITH_BDB)
Expand All @@ -129,7 +127,6 @@ if(WITH_BDB)
endif()
endif()
endif()
cmake_dependent_option(BUILD_WALLET_TOOL "Build firo-wallet tool." ${BUILD_TESTS} "ENABLE_WALLET" OFF)

option(ENABLE_HARDENING "Attempt to harden the resulting executables." ON)
option(REDUCE_EXPORTS "Attempt to reduce exported symbols in the resulting executables." OFF)
Expand Down Expand Up @@ -162,7 +159,7 @@ endif()
cmake_dependent_option(WITH_DBUS "Enable DBus support." ON "CMAKE_SYSTEM_NAME STREQUAL \"Linux\" AND BUILD_GUI" OFF)


cmake_dependent_option(BUILD_GUI_TESTS "Build test_firo-qt executable." ON "BUILD_GUI;BUILD_TESTS" OFF)
cmake_dependent_option(BUILD_GUI_TESTS "Build test_bitcoin-qt executable." ON "BUILD_GUI;BUILD_TESTS" OFF)
if(BUILD_GUI)
set(qt_components Core Gui Widgets LinguistTools)
if(ENABLE_WALLET)
Expand Down Expand Up @@ -232,7 +229,6 @@ if(BUILD_FOR_FUZZING)
set(BUILD_UTIL OFF)
set(BUILD_UTIL_CHAINSTATE OFF)
set(BUILD_KERNEL_LIB OFF)
set(BUILD_WALLET_TOOL OFF)
set(BUILD_GUI OFF)
set(ENABLE_EXTERNAL_SIGNER OFF)
set(WITH_ZMQ OFF)
Expand Down Expand Up @@ -735,8 +731,6 @@ message(" firod ............................ ${BUILD_DAEMON}")
message(" firo-qt (GUI) .................... ${BUILD_GUI}")
message(" firo-cli ......................... ${BUILD_CLI}")
message(" firo-tx .......................... ${BUILD_TX}")
message(" firo-util ........................ ${BUILD_UTIL}")
message(" firo-wallet ...................... ${BUILD_WALLET_TOOL}")
message(" firo-chainstate (experimental) ... ${BUILD_UTIL_CHAINSTATE}")
message(" libfirokernel (experimental) ..... ${BUILD_KERNEL_LIB}")
message("Optional features:")
Expand All @@ -750,8 +744,8 @@ message(" USDT tracing ........................ ${WITH_USDT}")
message(" QR code (GUI) ....................... ${WITH_QRENCODE}")
message(" DBus (GUI, Linux only) .............. ${WITH_DBUS}")
message("Tests:")
message(" test_firo ........................ ${BUILD_TESTS}")
message(" test_firo-qt ..................... ${BUILD_GUI_TESTS}")
message(" test_bitcoin ........................ ${BUILD_TESTS}")
message(" test_bitcoin-qt ..................... ${BUILD_GUI_TESTS}")
message(" bench_firo ....................... ${BUILD_BENCH}")
message(" fuzz binary ......................... ${BUILD_FUZZ_BINARY}")
message("")
Expand Down
40 changes: 26 additions & 14 deletions cmake/script/GenerateHeaderFromJson.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,33 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

cmake_path(GET JSON_SOURCE_PATH STEM json_source_basename)
message(STATUS "Generating header ${HEADER_PATH} from ${JSON_SOURCE_PATH}")

file(READ ${JSON_SOURCE_PATH} hex_content HEX)
string(REGEX REPLACE "................" "\\0\n" formatted_bytes "${hex_content}")
string(REGEX REPLACE "[^\n][^\n]" "0x\\0, " formatted_bytes "${formatted_bytes}")
# Generate a header file from a JSON file containing a hex dump
function(generate_json_header JSON_SOURCE_PATH HEADER_PATH)
# Use get_filename_component instead of cmake_path
get_filename_component(json_source_basename "${JSON_SOURCE_PATH}" NAME_WE)

set(header_content
"#include <string_view>
# Create directory
get_filename_component(header_dir "${HEADER_PATH}" DIRECTORY)
file(MAKE_DIRECTORY "${header_dir}")

# Read and convert to hex
file(READ ${JSON_SOURCE_PATH} hex_content HEX)
string(REGEX REPLACE ".." "0x\\0, " formatted_bytes "${hex_content}")

namespace json_tests {
inline constexpr char detail_${json_source_basename}_bytes[] {
${formatted_bytes}
};
# Generate content
set(header_content
"namespace json_tests{
static unsigned const char ${json_source_basename}[] = {
${formatted_bytes}
};
};"
)

# Atomic write using temporary file
file(WRITE "${HEADER_PATH}.new" "${header_content}")
file(RENAME "${HEADER_PATH}.new" "${HEADER_PATH}")
endfunction()

inline constexpr std::string_view ${json_source_basename}{std::begin(detail_${json_source_basename}_bytes), std::end(detail_${json_source_basename}_bytes)};
}
")
file(WRITE ${HEADER_PATH} "${header_content}")
generate_json_header(${JSON_SOURCE_PATH} ${HEADER_PATH})
74 changes: 0 additions & 74 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,70 +249,9 @@ target_link_libraries(bitcoin_common
$<$<PLATFORM_ID:Windows>:ws2_32>
)

add_library(bitcoin_wallet STATIC EXCLUDE_FROM_ALL
activemasternode.cpp
hdmint/hdmint.cpp
masternode-sync.cpp
hdmint/mintpool.cpp
hdmint/wallet.cpp
sigma.cpp
lelantus.cpp
spark/state.cpp
wallet/crypter.cpp
wallet/bip39.cpp
wallet/mnemoniccontainer.cpp
wallet/db.cpp
wallet/rpcdump.cpp
wallet/rpcwallet.cpp
wallet/sigmaspendbuilder.cpp
wallet/txbuilder.cpp
wallet/lelantusjoinsplitbuilder.cpp
wallet/walletexcept.cpp
wallet/wallet.cpp
spark/sparkwallet.cpp
spark/primitives.cpp
wallet/walletdb.cpp
wallet/authhelper.cpp
hdmint/tracker.cpp
policy/rbf.cpp
bip47/account.cpp
bip47/paymentchannel.cpp
bip47/bip47utils.cpp
bip47/paymentcode.cpp
bip47/secretpoint.cpp
primitives/mint_spend.cpp
)
target_link_libraries(bitcoin_wallet
PUBLIC
core_interface
bitcoin_util
univalue
secp256k1
Boost::headers
leveldb
)

set(installable_targets)
if(ENABLE_WALLET)
add_subdirectory(wallet)

if(BUILD_WALLET_TOOL)
add_executable(firo-wallet
bitcoin-wallet.cpp
init/bitcoin-wallet.cpp
wallet/wallettool.cpp
)
add_windows_resources(firo-wallet bitcoin-wallet-res.rc)
target_link_libraries(firo-wallet
core_interface
firo_wallet
bitcoin_common
bitcoin_util
bitcoin_wallet
Boost::headers
)
list(APPEND installable_targets firo-wallet)
endif()
endif()


Expand All @@ -322,7 +261,6 @@ add_library(firo_node STATIC EXCLUDE_FROM_ALL
addrman.cpp
blockencodings.cpp
chain.cpp
consensus/tx_verify.cpp
dbwrapper.cpp
httprpc.cpp
httpserver.cpp
Expand Down Expand Up @@ -502,7 +440,6 @@ if(BUILD_DAEMON)
firo_cli
secp256k1
secp256k1pp
bitcoin_wallet
$<TARGET_NAME_IF_EXISTS:firo_wallet>
)
list(APPEND installable_targets firod)
Expand Down Expand Up @@ -592,17 +529,6 @@ if(BUILD_TX)
endif()


if(BUILD_UTIL)
add_executable(bitcoin-util bitcoin-util.cpp)
add_windows_resources(bitcoin-util bitcoin-util-res.rc)
target_link_libraries(bitcoin-util
core_interface
bitcoin_common
bitcoin_util
)
list(APPEND installable_targets bitcoin-util)
endif()


if(BUILD_GUI)
add_subdirectory(qt)
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ BITCOIN_TESTS += \
wallet/test/wallet_tests.cpp \
wallet/test/crypto_tests.cpp \
wallet/test/lelantus_tests.cpp \
wallet/test/spark_tests.cpp \
wallet/test/spark_wallet_tests.cpp \
wallet/test/sigma_tests.cpp \
wallet/test/mnemonic_tests.cpp \
wallet/test/txbuilder_tests.cpp
Expand Down
Loading

0 comments on commit ab7d2f3

Please sign in to comment.