Skip to content

Commit

Permalink
cmake: Build libbitcoinconsensus library
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Nov 3, 2023
1 parent 1e8eee9 commit 6ce3e63
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ option(BUILD_DAEMON "Build bitcoind executable." ON)
option(BUILD_CLI "Build bitcoin-cli executable." ON)
option(BUILD_TX "Build bitcoin-tx executable." ON)
option(BUILD_UTIL "Build bitcoin-util executable." ON)
option(BUILD_BITCOINCONSENSUS_LIB "Build bitcoinconsensus library." ON)
option(ASM "Use assembly routines." ON)

option(ENABLE_WALLET "Enable wallet." ON)
Expand Down Expand Up @@ -306,6 +307,10 @@ if(WERROR)
unset(werror_flag)
endif()

if(BUILD_BITCOINCONSENSUS_LIB)
set(HAVE_CONSENSUS_LIB TRUE)
endif()

find_package(Python3 3.9 COMPONENTS Interpreter)
set(PYTHON_COMMAND ${Python3_EXECUTABLE})

Expand All @@ -326,6 +331,13 @@ message(" bitcoin-cli ......................... ${BUILD_CLI}")
message(" bitcoin-tx .......................... ${BUILD_TX}")
message(" bitcoin-util ........................ ${BUILD_UTIL}")
message(" bitcoin-wallet ...................... ${BUILD_WALLET_TOOL}")
message("Libraries:")
if(BUILD_SHARED_LIBS)
message(" library type ........................ Shared")
else()
message(" library type ........................ Static")
endif()
message(" libbitcoinconsensus ................. ${BUILD_BITCOINCONSENSUS_LIB}")
message("Wallet support:")
message(" SQLite, descriptor wallets .......... ${WITH_SQLITE}")
message(" Berkeley DB, legacy wallets ......... ${WITH_BDB}")
Expand Down
3 changes: 3 additions & 0 deletions cmake/bitcoin-config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
/* Define to 1 if you have the <byteswap.h> header file. */
#cmakedefine HAVE_BYTESWAP_H 1

/* Define this symbol if the consensus lib has been built */
#cmakedefine HAVE_CONSENSUS_LIB 1

/* Define to 1 if you have the declaration of `be16toh', and to 0 if you
don't. */
#cmakedefine01 HAVE_DECL_BE16TOH
Expand Down
13 changes: 13 additions & 0 deletions cmake/module/GeneratePkgConfigFile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

function(generate_pkg_config_file in_file out_file)
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "\${prefix}")
set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
set(PACKAGE_NAME ${PROJECT_NAME})
set(PACKAGE_VERSION ${PROJECT_VERSION})
configure_file(${in_file} ${out_file} @ONLY)
endfunction()
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ if(BUILD_UTIL)
endif()


if(BUILD_BITCOINCONSENSUS_LIB)
add_subdirectory(script)
endif()


add_subdirectory(test/util)
if(BUILD_BENCH)
add_subdirectory(bench)
Expand Down
3 changes: 3 additions & 0 deletions src/bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ target_link_libraries(bench_bitcoin
test_util
leveldb
univalue
$<TARGET_NAME_IF_EXISTS:bitcoinconsensus>
Boost::headers
)

Expand All @@ -68,6 +69,8 @@ if(ENABLE_WALLET)
target_link_libraries(bench_bitcoin bitcoin_wallet)
endif()

make_bitcoinconsensus_dll_available(bench_bitcoin)

install(TARGETS bench_bitcoin
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
58 changes: 58 additions & 0 deletions src/script/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

# Must be included before CMAKE_INSTALL_INCLUDEDIR is used.
include(GNUInstallDirs)

add_library(bitcoinconsensus
../support/cleanse.cpp
bitcoinconsensus.cpp
${bitcoin_crypto_base_sources}
${bitcoin_consensus_sources}
)
target_compile_definitions(bitcoinconsensus
PRIVATE
BUILD_BITCOIN_INTERNAL
)
target_include_directories(bitcoinconsensus
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(bitcoinconsensus
PRIVATE
core
secp256k1
)
set_target_properties(bitcoinconsensus PROPERTIES
SOVERSION 0
VERSION 0.0.0
)

install(TARGETS bitcoinconsensus
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(FILES bitcoinconsensus.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

include(GeneratePkgConfigFile)
generate_pkg_config_file(${PROJECT_SOURCE_DIR}/libbitcoinconsensus.pc.in libbitcoinconsensus.pc)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libbitcoinconsensus.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)

function(make_bitcoinconsensus_dll_available target)
if(WIN32 AND BUILD_SHARED_LIBS)
# The DLL must reside either in the same folder where the executable is
# or somewhere in PATH. Using the former option.
add_custom_command(
TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink $<TARGET_FILE:bitcoinconsensus> $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_NAME:bitcoinconsensus>
VERBATIM
)
endif()
endfunction()
3 changes: 3 additions & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ target_link_libraries(test_bitcoin
minisketch
leveldb
univalue
$<TARGET_NAME_IF_EXISTS:bitcoinconsensus>
Boost::headers
libevent::libevent
)
Expand Down Expand Up @@ -175,6 +176,8 @@ if(ENABLE_WALLET)
endif()
endif()

make_bitcoinconsensus_dll_available(test_bitcoin)

install(TARGETS test_bitcoin
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

0 comments on commit 6ce3e63

Please sign in to comment.