Skip to content

Commit

Permalink
bitcoin-cli: add CMake compilation.
Browse files Browse the repository at this point in the history
  • Loading branch information
aleflm committed Jan 16, 2025
1 parent 38159c9 commit 2621168
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 66 deletions.
60 changes: 54 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -65,24 +71,29 @@ 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)

#=============================
# Configurable options
#=============================
include(CMakeDependentOption)
# When adding a new option, end the <help_text> 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})
Expand Down Expand Up @@ -190,6 +201,9 @@ target_link_libraries(core_interface INTERFACE
$<$<CONFIG:RelWithDebInfo>:core_interface_relwithdebinfo>
$<$<CONFIG:Debug>: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.")
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions cmake/module/AddBoostIfNeeded.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions cmake/module/TestAppendRequiredLibraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion depends/packages/boost.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 21 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ target_link_libraries(bitcoin_util
core_interface
bitcoin_clientversion
bitcoin_crypto
secp256k1
leveldb
$<$<PLATFORM_ID:Windows>:ws2_32>
$<$<PLATFORM_ID:Windows>:iphlpapi>
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
$<TARGET_NAME_IF_EXISTS:USDT::headers>
$<$<PLATFORM_ID:Windows>:ws2_32>
)


set(installable_targets)
if(ENABLE_WALLET)
add_subdirectory(wallet)
Expand Down Expand Up @@ -226,17 +230,18 @@ target_link_libraries(bitcoin_node
core_interface
bitcoin_common
bitcoin_util
secp256k1
$<TARGET_NAME_IF_EXISTS:bitcoin_zmq>
leveldb
univalue
Boost::headers
Boost::thread
$<TARGET_NAME_IF_EXISTS:libevent::core>
$<TARGET_NAME_IF_EXISTS:libevent::extra>
$<TARGET_NAME_IF_EXISTS:libevent::pthreads>
$<TARGET_NAME_IF_EXISTS:USDT::headers>
)


# Bitcoin Core bitcoind.
if(BUILD_DAEMON)
add_executable(bitcoind
Expand All @@ -246,6 +251,8 @@ if(BUILD_DAEMON)
target_link_libraries(bitcoind
core_interface
bitcoin_node
univalue
Boost::thread
$<TARGET_NAME_IF_EXISTS:bitcoin_wallet>
)
list(APPEND installable_targets bitcoind)
Expand Down Expand Up @@ -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)
Expand All @@ -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()


Expand Down
8 changes: 4 additions & 4 deletions src/bitcoin_bignum/bignum.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include <vector>
#include <openssl/bn.h>

#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
{
Expand Down
6 changes: 3 additions & 3 deletions src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
24 changes: 6 additions & 18 deletions src/crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
2 changes: 1 addition & 1 deletion src/crypto/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdint.h>
Expand Down
2 changes: 1 addition & 1 deletion src/dbwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <leveldb/cache.h>
#include <leveldb/env.h>
#include <leveldb/filter_policy.h>
#include <memenv.h>
#include <leveldb/helpers/memenv/memenv.h>
#include <stdint.h>

static leveldb::Options GetOptions(size_t nCacheSize)
Expand Down
2 changes: 1 addition & 1 deletion src/sigma/sigma_primitives.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../../crypto/sha256.h"
#include "../crypto/sha256.h"

namespace sigma {

Expand Down
17 changes: 9 additions & 8 deletions src/support/allocators/secure.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
template <typename T>
struct secure_allocator : public std::allocator<T> {
// MSVC8 default copy constructor is broken
typedef std::allocator<T> 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<T>;
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 <typename U>
Expand Down
17 changes: 9 additions & 8 deletions src/support/allocators/zeroafterfree.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
template <typename T>
struct zero_after_free_allocator : public std::allocator<T> {
// MSVC8 default copy constructor is broken
typedef std::allocator<T> 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<T>;
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 <typename U>
Expand Down
Loading

0 comments on commit 2621168

Please sign in to comment.