From 26211680981452666eaa0768f56d98b67d360a8d Mon Sep 17 00:00:00 2001 From: AlefLm Date: Thu, 16 Jan 2025 15:54:53 +0000 Subject: [PATCH] bitcoin-cli: add CMake compilation. --- CMakeLists.txt | 60 +++++++++++++++++-- cmake/module/AddBoostIfNeeded.cmake | 5 +- .../module/TestAppendRequiredLibraries.cmake | 19 +++--- depends/packages/boost.mk | 2 +- src/CMakeLists.txt | 27 +++++++-- src/bitcoin_bignum/bignum.h | 8 +-- src/consensus/tx_verify.cpp | 6 +- src/crypto/CMakeLists.txt | 24 ++------ src/crypto/common.h | 2 +- src/dbwrapper.cpp | 2 +- src/sigma/sigma_primitives.hpp | 2 +- src/support/allocators/secure.h | 17 +++--- src/support/allocators/zeroafterfree.h | 17 +++--- src/wallet/CMakeLists.txt | 2 + 14 files changed, 127 insertions(+), 66 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eaa97e6045..779e1b73bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,12 @@ project(FiroCore LANGUAGES NONE ) +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) string(APPEND CLIENT_VERSION_STRING "rc${CLIENT_VERSION_RC}") @@ -65,10 +71,15 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_HOST_APPLE) set(CMAKE_PLATFORM_HAS_INSTALLNAME FALSE) endif() enable_language(CXX) -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +enable_language(C) +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS ON) + list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/module) #============================= @@ -76,13 +87,13 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/module) #============================= include(CMakeDependentOption) # When adding a new option, end the with a full stop for consistency. -option(BUILD_DAEMON "Build firod executable." ON) -option(BUILD_GUI "Build firo-qt executable." OFF) -option(BUILD_CLI "Build firo-cli executable." ON) +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 executable." ${BUILD_TESTS}) -option(BUILD_UTIL "Build firo-util executable." ${BUILD_TESTS}) +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}) @@ -190,6 +201,9 @@ target_link_libraries(core_interface INTERFACE $<$:core_interface_relwithdebinfo> $<$:core_interface_debug> ) +target_compile_definitions(core_interface + INTERFACE + HAVE_CONFIG_H=1) if(BUILD_FOR_FUZZING) message(WARNING "BUILD_FOR_FUZZING=ON will disable all other targets and force BUILD_FUZZ_BINARY=ON.") @@ -362,6 +376,40 @@ if(BUILD_DAEMON OR BUILD_GUI OR BUILD_CLI OR BUILD_TESTS OR BUILD_BENCH OR BUILD endif() include(cmake/introspection.cmake) +#################### +# Check functions and define +CHECK_INCLUDE_FILE(endian.h HAVE_ENDIAN_H) + +if(HAVE_ENDIAN_H) + # Check all endian conversion functions for 16-bit + check_function_exists_and_define(htole16 "endian.h" HAVE_DECL_HTOLE16) + check_function_exists_and_define(be16toh "endian.h" HAVE_DECL_BE16TOH) + check_function_exists_and_define(le16toh "endian.h" HAVE_DECL_LE16TOH) + check_function_exists_and_define(htobe16 "endian.h" HAVE_DECL_HTOBE16) + + # Check all endian conversion functions for 32-bit + check_function_exists_and_define(htobe32 "endian.h" HAVE_DECL_HTOBE32) + check_function_exists_and_define(htole32 "endian.h" HAVE_DECL_HTOLE32) + check_function_exists_and_define(be32toh "endian.h" HAVE_DECL_BE32TOH) + check_function_exists_and_define(le32toh "endian.h" HAVE_DECL_LE32TOH) + + # Check all endian conversion functions for 64-bit + check_function_exists_and_define(htobe64 "endian.h" HAVE_DECL_HTOBE64) + check_function_exists_and_define(htole64 "endian.h" HAVE_DECL_HTOLE64) + check_function_exists_and_define(be64toh "endian.h" HAVE_DECL_BE64TOH) + check_function_exists_and_define(le64toh "endian.h" HAVE_DECL_LE64TOH) +endif(HAVE_ENDIAN_H) + +CHECK_INCLUDE_FILE(byteswap.h HAVE_BYTESWAP_H) +if(HAVE_BYTESWAP_H) + check_function_exists_and_define(bswap_16 "byteswap.h" HAVE_DECL_HTOBE16) +endif(HAVE_BYTESWAP_H) + +# strnlen +CHECK_INCLUDE_FILE(string.h HAVE_STRING_H) +if(HAVE_STRING_H) + check_function_exists_and_define(strnlen "string.h" HAVE_DECL_STRNLEN) +endif(HAVE_STRING_H) include(cmake/ccache.cmake) diff --git a/cmake/module/AddBoostIfNeeded.cmake b/cmake/module/AddBoostIfNeeded.cmake index ecd0d6f2ab..19e0918515 100644 --- a/cmake/module/AddBoostIfNeeded.cmake +++ b/cmake/module/AddBoostIfNeeded.cmake @@ -25,8 +25,9 @@ function(add_boost_if_needed) if(POLICY CMP0167) cmake_policy(SET CMP0167 OLD) endif() - set(Boost_NO_BOOST_CMAKE ON) - find_package(Boost 1.73.0 REQUIRED) + set(Boost_NO_BOOST_CMAKE OFF) + find_package(Boost 1.81.0 REQUIRED COMPONENTS atomic chrono filesystem program_options system thread) + add_compile_definitions(HAVE_WORKING_BOOST_SLEEP_FOR=1) mark_as_advanced(Boost_INCLUDE_DIR) set_target_properties(Boost::headers PROPERTIES IMPORTED_GLOBAL TRUE) target_compile_definitions(Boost::headers INTERFACE diff --git a/cmake/module/TestAppendRequiredLibraries.cmake b/cmake/module/TestAppendRequiredLibraries.cmake index d3e4662d2e..26981aeeea 100644 --- a/cmake/module/TestAppendRequiredLibraries.cmake +++ b/cmake/module/TestAppendRequiredLibraries.cmake @@ -91,11 +91,16 @@ function(test_append_atomic_library target) endif() endfunction() -macro(check_function_exists_and_define FUNC_NAME TARGET_NAME SCOPE MACRO_NAME) - check_function_exists(${FUNC_NAME} ${MACRO_NAME}) - if(${MACRO_NAME}) - target_compile_definitions(${TARGET_NAME} ${SCOPE} ${MACRO_NAME}=0) - else() - target_compile_definitions(${TARGET_NAME} ${SCOPE} ${MACRO_NAME}=1) - endif() +include(CheckSymbolExists) +include(CheckFunctionExists) +include(CheckIncludeFile) +macro(check_function_exists_and_define FUNC_NAME HEADER_NAME MACRO_NAME) + check_cxx_symbol_exists(${FUNC_NAME} ${HEADER_NAME} ${MACRO_NAME}) + if(${MACRO_NAME}) + message(STATUS "Defined ${MACRO_NAME} = 1") + add_compile_definitions(${MACRO_NAME}=1) + else() + message(STATUS "Defined ${MACRO_NAME} = 0") + add_compile_definitions(${MACRO_NAME}=0) + endif() endmacro() \ No newline at end of file diff --git a/depends/packages/boost.mk b/depends/packages/boost.mk index 859ac1af28..92c05d4334 100644 --- a/depends/packages/boost.mk +++ b/depends/packages/boost.mk @@ -8,7 +8,7 @@ $(package)_dependencies=native_b2 define $(package)_set_vars $(package)_config_opts_release=variant=release $(package)_config_opts_debug=variant=debug -$(package)_config_opts=--layout=tagged --build-type=complete --user-config=user-config.jam +$(package)_config_opts=--layout=system --user-config=user-config.jam $(package)_config_opts+=threading=multi link=static -sNO_COMPRESSION=1 $(package)_config_opts_linux=target-os=linux threadapi=pthread runtime-link=shared $(package)_config_opts_darwin=target-os=darwin runtime-link=shared diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0afb88110d..5c89fa793c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -46,6 +46,8 @@ target_link_libraries(bitcoin_util core_interface bitcoin_clientversion bitcoin_crypto + secp256k1 + leveldb $<$:ws2_32> $<$:iphlpapi> ) @@ -120,8 +122,10 @@ add_library(bitcoin_consensus STATIC EXCLUDE_FROM_ALL target_link_libraries(bitcoin_consensus PRIVATE core_interface - bitcoin_crypto secp256k1 + leveldb + PUBLIC + bitcoin_crypto ) if(WITH_ZMQ) @@ -153,18 +157,18 @@ add_library(bitcoin_common STATIC EXCLUDE_FROM_ALL script/sign.cpp ) target_link_libraries(bitcoin_common - PRIVATE + PUBLIC core_interface bitcoin_consensus bitcoin_util univalue secp256k1 Boost::headers + leveldb $ $<$:ws2_32> ) - set(installable_targets) if(ENABLE_WALLET) add_subdirectory(wallet) @@ -226,17 +230,18 @@ target_link_libraries(bitcoin_node core_interface bitcoin_common bitcoin_util + secp256k1 $ leveldb univalue Boost::headers + Boost::thread $ $ $ $ ) - # Bitcoin Core bitcoind. if(BUILD_DAEMON) add_executable(bitcoind @@ -246,6 +251,8 @@ if(BUILD_DAEMON) target_link_libraries(bitcoind core_interface bitcoin_node + univalue + Boost::thread $ ) list(APPEND installable_targets bitcoind) @@ -283,13 +290,20 @@ endif() add_library(bitcoin_cli STATIC EXCLUDE_FROM_ALL rpc/client.cpp + rpc/protocol.cpp + util.cpp ) target_link_libraries(bitcoin_cli PUBLIC core_interface univalue + Boost::filesystem + Boost::thread + Boost::program_options +) +target_include_directories(bitcoin_cli + PUBLIC ) - # Bitcoin Core RPC client if(BUILD_CLI) @@ -300,10 +314,11 @@ if(BUILD_CLI) bitcoin_cli bitcoin_common bitcoin_util - libevent::core libevent::extra + libevent::core ) list(APPEND installable_targets bitcoin-cli) + set_target_properties(bitcoin-cli PROPERTIES OUTPUT_NAME ${FIRO_CLI_NAME}) endif() diff --git a/src/bitcoin_bignum/bignum.h b/src/bitcoin_bignum/bignum.h index b1df2a67fc..19b155e42f 100644 --- a/src/bitcoin_bignum/bignum.h +++ b/src/bitcoin_bignum/bignum.h @@ -9,10 +9,10 @@ #include #include -#include "../../uint256.h" // for uint64 -#include "../../arith_uint256.h" -#include "../../version.h" -#include "../../clientversion.h" +#include "../uint256.h" // for uint64 +#include "../arith_uint256.h" +#include "../version.h" +#include "../clientversion.h" /** Errors thrown by the bignum class */ class bignum_error : public std::runtime_error { diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp index bf68f8754b..cf81d2779f 100644 --- a/src/consensus/tx_verify.cpp +++ b/src/consensus/tx_verify.cpp @@ -2,8 +2,6 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "tx_verify.h" - #include "consensus.h" #include "primitives/transaction.h" #include "script/interpreter.h" @@ -201,7 +199,8 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe return true; } -bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight) +namespace Consensus { +bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight) { // This doesn't trigger the DoS code on purpose; if it did, it would make it easier // for an attacker to attempt to split the network. @@ -244,3 +243,4 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, c return state.DoS(100, false, REJECT_INVALID, "bad-txns-fee-outofrange"); return true; } +} // namespace Consensus \ No newline at end of file diff --git a/src/crypto/CMakeLists.txt b/src/crypto/CMakeLists.txt index 07f3c5dd54..0b461e522a 100644 --- a/src/crypto/CMakeLists.txt +++ b/src/crypto/CMakeLists.txt @@ -15,25 +15,13 @@ add_library(bitcoin_crypto STATIC EXCLUDE_FROM_ALL ../support/cleanse.cpp ) -# Check all endian conversion functions for 16-bit -check_function_exists_and_define(htobe16 bitcoin_crypto PRIVATE HAVE_DECL_HTOBE16) -check_function_exists_and_define(htole16 bitcoin_crypto PRIVATE HAVE_DECL_HTOLE16) -check_function_exists_and_define(be16toh bitcoin_crypto PRIVATE HAVE_DECL_BE16TOH) -check_function_exists_and_define(le16toh bitcoin_crypto PRIVATE HAVE_DECL_LE16TOH) - -# Check all endian conversion functions for 32-bit -check_function_exists_and_define(htobe32 bitcoin_crypto PRIVATE HAVE_DECL_HTOBE32) -check_function_exists_and_define(htole32 bitcoin_crypto PRIVATE HAVE_DECL_HTOLE32) -check_function_exists_and_define(be32toh bitcoin_crypto PRIVATE HAVE_DECL_BE32TOH) -check_function_exists_and_define(le32toh bitcoin_crypto PRIVATE HAVE_DECL_LE32TOH) - -# Check all endian conversion functions for 64-bit -check_function_exists_and_define(htobe64 bitcoin_crypto PRIVATE HAVE_DECL_HTOBE64) -check_function_exists_and_define(htole64 bitcoin_crypto PRIVATE HAVE_DECL_HTOLE64) -check_function_exists_and_define(be64toh bitcoin_crypto PRIVATE HAVE_DECL_BE64TOH) -check_function_exists_and_define(le64toh bitcoin_crypto PRIVATE HAVE_DECL_LE64TOH) - target_link_libraries(bitcoin_crypto PRIVATE core_interface + ${Boost_LIBRARIES} ) + +target_include_directories(bitcoin_crypto + PUBLIC + ${Boost_INCLUDE_DIR} +) \ No newline at end of file diff --git a/src/crypto/common.h b/src/crypto/common.h index 45b23960ea..db19283881 100644 --- a/src/crypto/common.h +++ b/src/crypto/common.h @@ -6,7 +6,7 @@ #define BITCOIN_CRYPTO_COMMON_H #if defined(HAVE_CONFIG_H) -#include "bitcoin-config.h" +#include "../config/bitcoin-config.h" #endif #include diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index 94ebedeb72..88aa72ef52 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include static leveldb::Options GetOptions(size_t nCacheSize) diff --git a/src/sigma/sigma_primitives.hpp b/src/sigma/sigma_primitives.hpp index ce3c8ee93a..2db8639ca3 100644 --- a/src/sigma/sigma_primitives.hpp +++ b/src/sigma/sigma_primitives.hpp @@ -1,4 +1,4 @@ -#include "../../crypto/sha256.h" +#include "../crypto/sha256.h" namespace sigma { diff --git a/src/support/allocators/secure.h b/src/support/allocators/secure.h index 7fc0e269f4..3477c2933d 100644 --- a/src/support/allocators/secure.h +++ b/src/support/allocators/secure.h @@ -19,14 +19,15 @@ template struct secure_allocator : public std::allocator { // MSVC8 default copy constructor is broken - typedef std::allocator base; - typedef typename base::size_type size_type; - typedef typename base::difference_type difference_type; - typedef typename base::pointer pointer; - typedef typename base::const_pointer const_pointer; - typedef typename base::reference reference; - typedef typename base::const_reference const_reference; - typedef typename base::value_type value_type; + using base = std::allocator; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + using value_type = T; + using pointer = T*; + using const_pointer = const T*; + using reference = T&; + using const_reference = const T&; + secure_allocator() throw() {} secure_allocator(const secure_allocator& a) throw() : base(a) {} template diff --git a/src/support/allocators/zeroafterfree.h b/src/support/allocators/zeroafterfree.h index 8ac7f890ed..5da7ebfd45 100644 --- a/src/support/allocators/zeroafterfree.h +++ b/src/support/allocators/zeroafterfree.h @@ -14,14 +14,15 @@ template struct zero_after_free_allocator : public std::allocator { // MSVC8 default copy constructor is broken - typedef std::allocator base; - typedef typename base::size_type size_type; - typedef typename base::difference_type difference_type; - typedef typename base::pointer pointer; - typedef typename base::const_pointer const_pointer; - typedef typename base::reference reference; - typedef typename base::const_reference const_reference; - typedef typename base::value_type value_type; + using base = std::allocator; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + using value_type = T; + using pointer = T*; + using const_pointer = const T*; + using reference = T&; + using const_reference = const T&; + zero_after_free_allocator() throw() {} zero_after_free_allocator(const zero_after_free_allocator& a) throw() : base(a) {} template diff --git a/src/wallet/CMakeLists.txt b/src/wallet/CMakeLists.txt index 6895ace860..7ceb9899bb 100644 --- a/src/wallet/CMakeLists.txt +++ b/src/wallet/CMakeLists.txt @@ -25,6 +25,8 @@ target_link_libraries(bitcoin_wallet bitcoin_common univalue Boost::headers + secp256k1 + leveldb $ )