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 6b8636a
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 67 deletions.
118 changes: 112 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,98 @@ 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
include(CheckIncludeFile)
include(CheckSymbolExists)

# Check for headers
CHECK_INCLUDE_FILE(endian.h HAVE_ENDIAN_H)
CHECK_INCLUDE_FILE(sys/endian.h HAVE_SYS_ENDIAN_H)

# Setup test code header section
if(HAVE_ENDIAN_H)
set(ENDIAN_HEADER "endian.h")
add_compile_definitions(HAVE_ENDIAN_H=1)
elseif(HAVE_SYS_ENDIAN_H)
set(ENDIAN_HEADER "sys/endian.h")
add_compile_definitions(HAVE_SYS_ENDIAN_H=1)
endif(HAVE_ENDIAN_H)

# Functions to check
set(ENDIAN_FUNCTIONS
le16toh le32toh le64toh
htole16 htole32 htole64
be16toh be32toh be64toh
htobe16 htobe32 htobe64
)

# Check each function
foreach(func ${ENDIAN_FUNCTIONS})
string(TOUPPER "HAVE_DECL_${func}" var_name)
check_symbol_exists(${func} "${ENDIAN_HEADER}" ${var_name})
if(${var_name})
add_compile_definitions(${var_name}=1)
else()
add_compile_definitions(${var_name}=0)
endif()
endforeach()

# Check for byteswap.h header
CHECK_INCLUDE_FILE(byteswap.h HAVE_BYTESWAP_H)

# Setup test code header section
if(HAVE_BYTESWAP_H)
set(BYTESWAP_HEADER "byteswap.h")
add_compile_definitions(HAVE_BYTESWAP_H=1)
endif(HAVE_BYTESWAP_H)

# Functions to check
set(BSWAP_FUNCTIONS
bswap_16 bswap_32 bswap_64
)

# Check each function
foreach(func ${BSWAP_FUNCTIONS})
string(TOUPPER "HAVE_DECL_${func}" var_name)
check_symbol_exists(${func} "${BYTESWAP_HEADER}" ${var_name})
if(${var_name})
add_compile_definitions(${var_name}=1)
else()
add_compile_definitions(${var_name}=0)
endif()
endforeach()

# 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)

# Functions to check
set(BUILTIN_FUNCTIONS
__builtin_clz
__builtin_clzl
__builtin_clzll
)

# Check each function
foreach(func ${BUILTIN_FUNCTIONS})
string(TOUPPER "HAVE_DECL_${func}" var_name)
set(TEST_SOURCE_CODE "
int main() {
int x = 0;
(void)${func}(x);
return 0;
}
")
check_cxx_source_compiles("${TEST_SOURCE_CODE}" ${var_name})
if(${var_name})
add_compile_definitions(${var_name}=1)
else()
add_compile_definitions(${var_name}=0)
endif()
endforeach()

include(cmake/ccache.cmake)

Expand Down
31 changes: 29 additions & 2 deletions cmake/module/AddBoostIfNeeded.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,35 @@ 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)

include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${Boost_LIBRARIES})
# Test source code
set(SLEEPTEST_SOURCE_CODE "
#include <boost/thread/thread.hpp>
#include <boost/version.hpp>
int main() {
#if BOOST_VERSION >= 105000 && (!defined(BOOST_HAS_NANOSLEEP) || BOOST_VERSION >= 105200)
boost::this_thread::sleep_for(boost::chrono::milliseconds(0));
return 0;
#else
choke me
#endif
}
")

# Check if the test source code compiles
check_cxx_source_compiles("${SLEEPTEST_SOURCE_CODE}" HAVE_WORKING_BOOST_SLEEP_FOR)

# Define the macro if the test passed
if(HAVE_WORKING_BOOST_SLEEP_FOR)
add_compile_definitions(HAVE_WORKING_BOOST_SLEEP_FOR=1)
endif()

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
Loading

0 comments on commit 6b8636a

Please sign in to comment.