bitcoin/src/kernel/CMakeLists.txt
TheCharlatan 2cf136dec4
kernel: Introduce initial kernel C header API
As a first step, implement the equivalent of what was implemented in the
now deprecated libbitcoinconsensus header. Also add a test binary to
exercise the header and library.

Unlike the deprecated libbitcoinconsensus the kernel library can now use
the hardware-accelerated sha256 implementations thanks for its
statically-initialzed context. The functions kept around for
backwards-compatibility in the libbitcoinconsensus header are not ported
over. As a new header, it should not be burdened by previous
implementations. Also add a new error code for handling invalid flag
combinations, which would otherwise cause a crash.

The macros used in the new C header were adapted from the libsecp256k1
header.

To make use of the C header from C++ code, a C++ header is also
introduced for wrapping the C header. This makes it safer and easier to
use from C++ code.

Co-authored-by: stickies-v <stickies-v@protonmail.com>
2025-11-04 08:31:51 +01:00

134 lines
3.7 KiB
CMake

# Copyright (c) 2024-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
include(GNUInstallDirs)
# TODO: libbitcoinkernel is a work in progress consensus engine
# library, as more and more modules are decoupled from the
# consensus engine, this list will shrink to only those
# which are absolutely necessary.
add_library(bitcoinkernel
bitcoinkernel.cpp
chain.cpp
checks.cpp
chainparams.cpp
coinstats.cpp
context.cpp
cs_main.cpp
disconnected_transactions.cpp
mempool_removal_reason.cpp
../arith_uint256.cpp
../chain.cpp
../coins.cpp
../compressor.cpp
../consensus/merkle.cpp
../consensus/tx_check.cpp
../consensus/tx_verify.cpp
../core_read.cpp
../dbwrapper.cpp
../deploymentinfo.cpp
../deploymentstatus.cpp
../flatfile.cpp
../hash.cpp
../logging.cpp
../node/blockstorage.cpp
../node/chainstate.cpp
../node/utxo_snapshot.cpp
../policy/ephemeral_policy.cpp
../policy/feerate.cpp
../policy/packages.cpp
../policy/policy.cpp
../policy/rbf.cpp
../policy/settings.cpp
../policy/truc_policy.cpp
../pow.cpp
../primitives/block.cpp
../primitives/transaction.cpp
../pubkey.cpp
../random.cpp
../randomenv.cpp
../script/interpreter.cpp
../script/script.cpp
../script/script_error.cpp
../script/sigcache.cpp
../script/solver.cpp
../signet.cpp
../streams.cpp
../support/lockedpool.cpp
../sync.cpp
../txdb.cpp
../txmempool.cpp
../uint256.cpp
../util/chaintype.cpp
../util/check.cpp
../util/feefrac.cpp
../util/fs.cpp
../util/fs_helpers.cpp
../util/hasher.cpp
../util/moneystr.cpp
../util/rbf.cpp
../util/serfloat.cpp
../util/signalinterrupt.cpp
../util/strencodings.cpp
../util/string.cpp
../util/syserror.cpp
../util/threadnames.cpp
../util/time.cpp
../util/tokenpipe.cpp
../validation.cpp
../validationinterface.cpp
../versionbits.cpp
$<TARGET_OBJECTS:bitcoin_clientversion>
$<TARGET_OBJECTS:bitcoin_crypto>
$<TARGET_OBJECTS:leveldb>
$<TARGET_OBJECTS:crc32c>
)
target_link_libraries(bitcoinkernel
PRIVATE
core_interface
secp256k1_objs
$<$<PLATFORM_ID:Windows>:bcrypt>
$<TARGET_NAME_IF_EXISTS:USDT::headers>
PUBLIC
Boost::headers
)
target_include_directories(bitcoinkernel PRIVATE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/leveldb/include>)
# libbitcoinkernel requires default symbol visibility, explicitly
# specify that here so that things still work even when user
# configures with -DREDUCE_EXPORTS=ON
#
# Note this is a quick hack that will be removed as we
# incrementally define what to export from the library.
set_target_properties(bitcoinkernel PROPERTIES
CXX_VISIBILITY_PRESET default
)
# Add a convenience libbitcoinkernel target as a synonym for bitcoinkernel.
add_custom_target(libbitcoinkernel)
add_dependencies(libbitcoinkernel bitcoinkernel)
get_target_property(bitcoinkernel_type bitcoinkernel TYPE)
if(bitcoinkernel_type STREQUAL "STATIC_LIBRARY")
target_compile_definitions(bitcoinkernel PUBLIC BITCOINKERNEL_STATIC)
endif()
configure_file(${PROJECT_SOURCE_DIR}/libbitcoinkernel.pc.in ${PROJECT_BINARY_DIR}/libbitcoinkernel.pc @ONLY)
install(FILES ${PROJECT_BINARY_DIR}/libbitcoinkernel.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" COMPONENT libbitcoinkernel)
install(TARGETS bitcoinkernel
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT libbitcoinkernel
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT libbitcoinkernel
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT libbitcoinkernel
)
install(FILES bitcoinkernel.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT libbitcoinkernel)