2024-04-16 11:33:14 +02:00
# 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/.
# Ubuntu 22.04 LTS Jammy Jellyfish, https://wiki.ubuntu.com/Releases, EOSS in June 2027:
# - CMake 3.22.1, https://packages.ubuntu.com/jammy/cmake
#
# Centos Stream 9, EOL in May 2027:
# - CMake 3.26.5, https://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/Packages/
cmake_minimum_required ( VERSION 3.22 )
if ( POLICY CMP0141 )
# MSVC debug information format flags are selected by an abstraction.
# We want to use the CMAKE_MSVC_DEBUG_INFORMATION_FORMAT variable
# to select the MSVC debug information format.
cmake_policy ( SET CMP0141 NEW )
endif ( )
if ( ${ CMAKE_SOURCE_DIR } STREQUAL ${ CMAKE_BINARY_DIR } )
message ( FATAL_ERROR "In-source builds are not allowed." )
endif ( )
#=============================
# Project / Package metadata
#=============================
set ( PACKAGE_NAME "Bitcoin Core" )
set ( CLIENT_VERSION_MAJOR 27 )
set ( CLIENT_VERSION_MINOR 99 )
set ( CLIENT_VERSION_BUILD 0 )
set ( CLIENT_VERSION_RC 0 )
set ( CLIENT_VERSION_IS_RELEASE "false" )
set ( COPYRIGHT_YEAR "2024" )
project ( BitcoinCore
V E R S I O N $ { C L I E N T _ V E R S I O N _ M A J O R } . $ { C L I E N T _ V E R S I O N _ M I N O R } . $ { C L I E N T _ V E R S I O N _ B U I L D }
D E S C R I P T I O N " B i t c o i n c l i e n t s o f t w a r e "
H O M E P A G E _ U R L " h t t p s : / / b i t c o i n c o r e . o r g / "
L A N G U A G E S N O N E
)
set ( PACKAGE_VERSION ${ PROJECT_VERSION } )
if ( CLIENT_VERSION_RC GREATER 0 )
string ( APPEND PACKAGE_VERSION "rc${CLIENT_VERSION_RC}" )
endif ( )
set ( COPYRIGHT_HOLDERS "The %s developers" )
set ( COPYRIGHT_HOLDERS_FINAL "The ${PACKAGE_NAME} developers" )
set ( PACKAGE_BUGREPORT "https://github.com/bitcoin/bitcoin/issues" )
#=============================
# Language setup
#=============================
if ( CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_HOST_APPLE )
# We do not use the install_name_tool when cross-compiling for macOS.
# So disable this tool check in further enable_language() commands.
set ( CMAKE_PLATFORM_HAS_INSTALLNAME FALSE )
endif ( )
enable_language ( CXX )
set ( CMAKE_CXX_STANDARD 20 )
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
set ( CMAKE_CXX_EXTENSIONS OFF )
2024-08-16 20:27:34 +02:00
list ( APPEND CMAKE_MODULE_PATH ${ PROJECT_SOURCE_DIR } /cmake/module )
2024-06-30 12:02:05 +02:00
#=============================
# Configurable options
#=============================
2024-07-24 13:53:35 +02:00
include ( CMakeDependentOption )
2024-06-30 12:02:05 +02:00
# When adding a new option, end the <help_text> with a full stop for consistency.
2024-07-13 13:39:32 +02:00
option ( BUILD_DAEMON "Build bitcoind executable." ON )
2024-05-20 22:10:46 +02:00
option ( BUILD_CLI "Build bitcoin-cli executable." ON )
2024-07-13 13:39:32 +02:00
2024-08-10 12:06:36 +02:00
option ( BUILD_TESTS "Build test_bitcoin executable." ON )
2024-06-30 13:40:17 +02:00
option ( BUILD_TX "Build bitcoin-tx executable." ${ BUILD_TESTS } )
2024-01-09 21:34:51 +01:00
option ( BUILD_UTIL "Build bitcoin-util executable." ${ BUILD_TESTS } )
2024-08-10 12:06:36 +02:00
2024-07-24 13:53:35 +02:00
option ( ENABLE_WALLET "Enable wallet." ON )
option ( WITH_SQLITE "Enable SQLite wallet support." ${ ENABLE_WALLET } )
if ( WITH_SQLITE )
if ( VCPKG_TARGET_TRIPLET )
# Use of the `unofficial::` namespace is a vcpkg package manager convention.
find_package ( unofficial-sqlite3 CONFIG REQUIRED )
else ( )
find_package ( SQLite3 3.7.17 REQUIRED )
endif ( )
set ( USE_SQLITE ON )
set ( ENABLE_WALLET ON )
endif ( )
option ( WITH_BDB "Enable Berkeley DB (BDB) wallet support." OFF )
cmake_dependent_option ( WARN_INCOMPATIBLE_BDB "Warn when using a Berkeley DB (BDB) version other than 4.8." ON "WITH_BDB" OFF )
if ( WITH_BDB )
find_package ( BerkeleyDB 4.8 MODULE REQUIRED )
set ( USE_BDB ON )
set ( ENABLE_WALLET ON )
if ( NOT BerkeleyDB_VERSION VERSION_EQUAL 4.8 )
message ( WARNING "Found Berkeley DB (BDB) other than 4.8.\n"
" BDB ( legacy ) w a l l e t s o p e n e d b y t h i s b u i l d w i l l n o t b e p o r t a b l e ! "
)
if ( WARN_INCOMPATIBLE_BDB )
message ( WARNING "If this is intended, pass \" -DWARN_INCOMPATIBLE_BDB=OFF\ ".\n"
" P a s s i n g \ " - D W I T H _ B D B = O F F \ " w i l l s u p p r e s s t h i s w a r n i n g . "
)
endif ( )
endif ( )
endif ( )
cmake_dependent_option ( BUILD_WALLET_TOOL "Build bitcoin-wallet tool." ${ BUILD_TESTS } "ENABLE_WALLET" OFF )
2024-06-30 12:02:05 +02:00
option ( WITH_CCACHE "Attempt to use ccache for compiling." ON )
2024-06-04 14:44:32 +02:00
option ( WITH_NATPMP "Enable NAT-PMP." OFF )
if ( WITH_NATPMP )
find_package ( NATPMP MODULE REQUIRED )
endif ( )
2024-04-29 22:10:22 +02:00
option ( WITH_MINIUPNPC "Enable UPnP." OFF )
if ( WITH_MINIUPNPC )
find_package ( MiniUPnPc MODULE REQUIRED )
endif ( )
2024-04-29 22:23:42 +02:00
option ( WITH_ZMQ "Enable ZMQ notifications." OFF )
if ( WITH_ZMQ )
if ( VCPKG_TARGET_TRIPLET )
find_package ( ZeroMQ CONFIG REQUIRED )
else ( )
# The ZeroMQ project has provided config files since v4.2.2.
# TODO: Switch to find_package(ZeroMQ) at some point in the future.
find_package ( PkgConfig REQUIRED )
pkg_check_modules ( libzmq REQUIRED IMPORTED_TARGET libzmq>=4 )
# TODO: This command will be redundant once
# https://github.com/bitcoin/bitcoin/pull/30508 is merged.
target_link_libraries ( PkgConfig::libzmq INTERFACE
$ < $ < P L A T F O R M _ I D : W i n d o w s > : i p h l p a p i ; w s 2 _ 3 2 >
)
endif ( )
endif ( )
2024-07-24 14:11:05 +02:00
option ( WITH_USDT "Enable tracepoints for Userspace, Statically Defined Tracing." OFF )
if ( WITH_USDT )
find_package ( USDT MODULE REQUIRED )
endif ( )
2024-07-24 14:08:55 +02:00
cmake_dependent_option ( ENABLE_EXTERNAL_SIGNER "Enable external signer support." ON "NOT WIN32" OFF )
2024-07-31 11:42:19 +02:00
option ( BUILD_BENCH "Build bench_bitcoin executable." OFF )
2024-08-16 20:26:17 +02:00
option ( BUILD_FUZZ_BINARY "Build fuzz binary." OFF )
cmake_dependent_option ( BUILD_FOR_FUZZING "Build for fuzzing. Enabling this will disable all other targets and override BUILD_FUZZ_BINARY." OFF "NOT MSVC" OFF )
2024-07-31 11:42:19 +02:00
2024-04-16 11:33:14 +02:00
set ( configure_warnings )
2024-01-09 18:25:47 +01:00
include ( CheckPIESupported )
check_pie_supported ( OUTPUT_VARIABLE check_pie_output LANGUAGES CXX )
if ( CMAKE_CXX_LINK_PIE_SUPPORTED )
set ( CMAKE_POSITION_INDEPENDENT_CODE ON )
elseif ( NOT WIN32 )
# The warning is superfluous for Windows.
message ( WARNING "PIE is not supported at link time: ${check_pie_output}" )
list ( APPEND configure_warnings "Position independent code disabled." )
endif ( )
unset ( check_pie_output )
2024-08-16 20:27:34 +02:00
# The core_interface library aims to encapsulate common build flags.
# It is a usage requirement for all targets except for secp256k1, which
# gets its flags by other means.
add_library ( core_interface INTERFACE )
add_library ( core_interface_relwithdebinfo INTERFACE )
add_library ( core_interface_debug INTERFACE )
target_link_libraries ( core_interface INTERFACE
$ < $ < C O N F I G : R e l W i t h D e b I n f o > : c o r e _ i n t e r f a c e _ r e l w i t h d e b i n f o >
$ < $ < C O N F I G : D e b u g > : c o r e _ i n t e r f a c e _ d e b u g >
)
2024-06-30 11:13:51 +02:00
2024-08-16 20:26:17 +02:00
if ( BUILD_FOR_FUZZING )
message ( WARNING "BUILD_FOR_FUZZING=ON will disable all other targets and force BUILD_FUZZ_BINARY=ON." )
set ( BUILD_DAEMON OFF )
set ( BUILD_CLI OFF )
set ( BUILD_TX OFF )
set ( BUILD_UTIL OFF )
set ( BUILD_WALLET_TOOL OFF )
set ( ENABLE_EXTERNAL_SIGNER OFF )
set ( WITH_NATPMP OFF )
set ( WITH_MINIUPNPC OFF )
set ( WITH_ZMQ OFF )
set ( BUILD_TESTS OFF )
set ( BUILD_BENCH OFF )
set ( BUILD_FUZZ_BINARY ON )
target_compile_definitions ( core_interface INTERFACE
A B O R T _ O N _ F A I L E D _ A S S U M E
)
endif ( )
2024-08-05 14:18:57 +02:00
include ( ProcessConfigurations )
2024-07-24 12:58:27 +02:00
include ( TryAppendCXXFlags )
include ( TryAppendLinkerFlag )
if ( WIN32 )
#[=[
T h i s b u i l d s y s t e m s u p p o r t s t w o w a y s t o b u i l d b i n a r i e s f o r W i n d o w s .
1 . B u i l d i n g o n W i n d o w s u s i n g MSVC .
I m p l e m e n t a t i o n n o t e s :
- / D W I N 3 2 a n d / D _ W I N D O W S d e f i n i t i o n s a r e i n c l u d e d i n t o t h e C M A K E _ C X X _ F L A G S _ I N I T
a n d C M A K E _ C X X _ F L A G S _ I N I T v a r i a b l e s b y d e f a u l t .
- A r u n - t i m e l i b r a r y i s s e l e c t e d u s i n g t h e C M A K E _ M S V C _ R U N T I M E _ L I B R A R Y v a r i a b l e .
- MSVC - s p e c i f i c o p t i o n s , f o r e x a m p l e , / Z c : _ _ c p l u s p l u s , a r e a d d i t i o n a l l y r e q u i r e d .
2 . C r o s s - c o m p i l i n g u s i n g M i n G W .
I m p l e m e n t a t i o n n o t e s :
- WIN32 a n d _ W I N D O W S d e f i n i t i o n s m u s t b e p r o v i d e d e x p l i c i t l y .
- A r u n - t i m e l i b r a r y m u s t b e s p e c i f i e d e x p l i c i t l y u s i n g _ M T d e f i n i t i o n .
] = ]
target_compile_definitions ( core_interface INTERFACE
_ W I N 3 2 _ W I N N T = 0 x 0 6 0 1
_ W I N 3 2 _ I E = 0 x 0 5 0 1
W I N 3 2 _ L E A N _ A N D _ M E A N
N O M I N M A X
)
if ( MSVC )
if ( VCPKG_TARGET_TRIPLET MATCHES "-static" )
set ( msvc_library_linkage "" )
else ( )
set ( msvc_library_linkage "DLL" )
endif ( )
set ( CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>${msvc_library_linkage}" )
unset ( msvc_library_linkage )
target_compile_definitions ( core_interface INTERFACE
_ U N I C O D E ; U N I C O D E
)
target_compile_options ( core_interface INTERFACE
/ u t f - 8
/ Z c : p r e p r o c e s s o r
/ Z c : _ _ c p l u s p l u s
/ s d l
)
# Improve parallelism in MSBuild.
# See: https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/.
list ( APPEND CMAKE_VS_GLOBALS "UseMultiToolTask=true" )
endif ( )
if ( MINGW )
target_compile_definitions ( core_interface INTERFACE
WIN32
_ W I N D O W S
_ M T
)
# Avoid the use of aligned vector instructions when building for Windows.
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54412.
try_append_cxx_flags ( "-Wa,-muse-unaligned-vector-move" TARGET core_interface SKIP_LINK )
try_append_linker_flag ( "-static" TARGET core_interface )
# We require Windows 7 (NT 6.1) or later.
try_append_linker_flag ( "-Wl,--major-subsystem-version,6" TARGET core_interface )
try_append_linker_flag ( "-Wl,--minor-subsystem-version,1" TARGET core_interface )
endif ( )
endif ( )
# Use 64-bit off_t on 32-bit Linux.
if ( CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SIZEOF_VOID_P EQUAL 4 )
# Ensure 64-bit offsets are used for filesystem accesses for 32-bit compilation.
target_compile_definitions ( core_interface INTERFACE
_ F I L E _ O F F S E T _ B I T S = 6 4
)
endif ( )
if ( CMAKE_SYSTEM_NAME STREQUAL "Darwin" )
target_compile_definitions ( core_interface INTERFACE
M A C _ O S X
O B J C _ O L D _ D I S P A T C H _ P R O T O T Y P E S = 0
)
# These flags are specific to ld64, and may cause issues with other linkers.
# For example: GNU ld will interpret -dead_strip as -de and then try and use
# "ad_strip" as the symbol for the entry point.
try_append_linker_flag ( "-Wl,-dead_strip" TARGET core_interface )
try_append_linker_flag ( "-Wl,-dead_strip_dylibs" TARGET core_interface )
if ( CMAKE_HOST_APPLE )
try_append_linker_flag ( "-Wl,-headerpad_max_install_names" TARGET core_interface )
endif ( )
endif ( )
2024-06-30 11:13:51 +02:00
set ( THREADS_PREFER_PTHREAD_FLAG ON )
find_package ( Threads REQUIRED )
2024-07-24 12:58:27 +02:00
target_link_libraries ( core_interface INTERFACE
2024-06-30 11:13:51 +02:00
T h r e a d s : : T h r e a d s
)
2024-08-16 20:27:34 +02:00
2024-07-04 01:35:27 +02:00
add_library ( sanitize_interface INTERFACE )
target_link_libraries ( core_interface INTERFACE sanitize_interface )
if ( SANITIZERS )
# First check if the compiler accepts flags. If an incompatible pair like
# -fsanitize=address,thread is used here, this check will fail. This will also
# fail if a bad argument is passed, e.g. -fsanitize=undfeined
try_append_cxx_flags ( "-fsanitize=${SANITIZERS}" TARGET sanitize_interface
R E S U L T _ V A R c x x _ s u p p o r t s _ s a n i t i z e r s
S K I P _ L I N K
)
if ( NOT cxx_supports_sanitizers )
message ( FATAL_ERROR "Compiler did not accept requested flags." )
endif ( )
# Some compilers (e.g. GCC) require additional libraries like libasan,
# libtsan, libubsan, etc. Make sure linking still works with the sanitize
# flag. This is a separate check so we can give a better error message when
# the sanitize flags are supported by the compiler but the actual sanitizer
# libs are missing.
try_append_linker_flag ( "-fsanitize=${SANITIZERS}" VAR SANITIZER_LDFLAGS
S O U R C E "
#include <cstdint>
#include <cstddef>
e x t e r n \ " C \ " i n t LLVMFuzzerTestOneInput ( const uint8_t* data, size_t size ) { r e t u r n 0 ; }
__attribute__ ( ( weak ) ) / / a l l o w f o r l i b F u z z e r l i n k i n g
i n t main ( ) { r e t u r n 0 ; }
"
R E S U L T _ V A R l i n k e r _ s u p p o r t s _ s a n i t i z e r s
)
if ( NOT linker_supports_sanitizers )
message ( FATAL_ERROR "Linker did not accept requested flags, you are missing required libraries." )
endif ( )
endif ( )
target_link_options ( sanitize_interface INTERFACE ${ SANITIZER_LDFLAGS } )
2024-08-16 20:26:17 +02:00
if ( BUILD_FUZZ_BINARY )
include ( CheckSourceCompilesAndLinks )
check_cxx_source_links_with_flags ( "${SANITIZER_LDFLAGS}" "
#include <cstdint>
#include <cstddef>
e x t e r n \ " C \ " i n t LLVMFuzzerTestOneInput ( const uint8_t* data, size_t size ) { r e t u r n 0 ; }
/ / N o main ( ) f u n c t i o n .
" F U Z Z _ B I N A R Y _ L I N K S _ W I T H O U T _ M A I N _ F U N C T I O N
)
endif ( )
2024-07-13 13:39:32 +02:00
include ( AddBoostIfNeeded )
add_boost_if_needed ( )
2024-08-16 20:26:17 +02:00
if ( BUILD_DAEMON OR BUILD_CLI OR BUILD_TESTS OR BUILD_BENCH OR BUILD_FUZZ_BINARY )
2024-07-13 13:39:32 +02:00
find_package ( Libevent 2.1.8 MODULE REQUIRED )
endif ( )
2024-03-23 17:50:57 +01:00
include ( cmake/introspection.cmake )
2024-06-30 12:02:05 +02:00
include ( cmake/ccache.cmake )
2024-07-24 12:58:27 +02:00
# Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review.
try_append_cxx_flags ( "-fno-extended-identifiers" TARGET core_interface SKIP_LINK )
# Currently all versions of gcc are subject to a class of bugs, see the
# gccbug_90348 test case (only reproduces on GCC 11 and earlier) and
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111843. To work around that, set
# -fstack-reuse=none for all gcc builds. (Only gcc understands this flag).
try_append_cxx_flags ( "-fstack-reuse=none" TARGET core_interface )
2024-08-06 19:14:37 +02:00
find_package ( Python3 3.9 COMPONENTS Interpreter )
if ( Python3_EXECUTABLE )
set ( PYTHON_COMMAND ${ Python3_EXECUTABLE } )
else ( )
list ( APPEND configure_warnings
" M i n i m u m r e q u i r e d P y t h o n n o t f o u n d . U t i l s a n d r p c a u t h t e s t s a r e d i s a b l e d . "
)
endif ( )
2024-07-24 13:28:10 +02:00
if ( BUILD_TESTS )
enable_testing ( )
endif ( )
2024-08-06 19:16:47 +02:00
# TODO: The `CMAKE_SKIP_BUILD_RPATH` variable setting can be deleted
# in the future after reordering Guix script commands to
# perform binary checks after the installation step.
# Relevant discussions:
# - https://github.com/hebasto/bitcoin/pull/236#issuecomment-2183120953
# - https://github.com/bitcoin/bitcoin/pull/30312#issuecomment-2191235833
set ( CMAKE_SKIP_BUILD_RPATH TRUE )
set ( CMAKE_SKIP_INSTALL_RPATH TRUE )
2024-08-06 19:14:37 +02:00
add_subdirectory ( test )
2024-07-13 15:26:37 +02:00
include ( cmake/crc32c.cmake )
2024-07-04 01:27:40 +02:00
include ( cmake/leveldb.cmake )
2024-07-04 01:29:33 +02:00
include ( cmake/minisketch.cmake )
2024-08-06 19:16:47 +02:00
add_subdirectory ( src )
2024-08-06 19:14:37 +02:00
include ( cmake/tests.cmake )
2024-04-16 11:33:14 +02:00
message ( "\n" )
message ( "Configure summary" )
message ( "=================" )
2024-07-13 13:39:32 +02:00
message ( "Executables:" )
message ( " bitcoind ............................ ${BUILD_DAEMON}" )
2024-05-20 22:10:46 +02:00
message ( " bitcoin-cli ......................... ${BUILD_CLI}" )
2024-06-30 13:40:17 +02:00
message ( " bitcoin-tx .......................... ${BUILD_TX}" )
2024-01-09 21:34:51 +01:00
message ( " bitcoin-util ........................ ${BUILD_UTIL}" )
2024-07-24 13:53:35 +02:00
message ( " bitcoin-wallet ...................... ${BUILD_WALLET_TOOL}" )
message ( "Optional features:" )
message ( " wallet support ...................... ${ENABLE_WALLET}" )
if ( ENABLE_WALLET )
message ( " - descriptor wallets (SQLite) ...... ${WITH_SQLITE}" )
message ( " - legacy wallets (Berkeley DB) ..... ${WITH_BDB}" )
endif ( )
2024-07-24 14:08:55 +02:00
message ( " external signer ..................... ${ENABLE_EXTERNAL_SIGNER}" )
2024-06-04 14:44:32 +02:00
message ( " port mapping:" )
message ( " - using NAT-PMP .................... ${WITH_NATPMP}" )
2024-04-29 22:10:22 +02:00
message ( " - using UPnP ....................... ${WITH_MINIUPNPC}" )
2024-04-29 22:23:42 +02:00
message ( " ZeroMQ .............................. ${WITH_ZMQ}" )
2024-07-24 14:11:05 +02:00
message ( " USDT tracing ........................ ${WITH_USDT}" )
2024-08-10 12:06:36 +02:00
message ( "Tests:" )
message ( " test_bitcoin ........................ ${BUILD_TESTS}" )
2024-07-31 11:42:19 +02:00
message ( " bench_bitcoin ....................... ${BUILD_BENCH}" )
2024-08-16 20:26:17 +02:00
message ( " fuzz binary ......................... ${BUILD_FUZZ_BINARY}" )
2024-07-13 13:39:32 +02:00
message ( "" )
2024-04-16 11:33:14 +02:00
message ( "C++ compiler .......................... ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}, ${CMAKE_CXX_COMPILER}" )
2024-07-04 01:00:07 +02:00
include ( FlagsSummary )
flags_summary ( )
2024-06-30 12:02:05 +02:00
message ( "Use ccache for compiling .............. ${WITH_CCACHE}" )
2024-04-16 11:33:14 +02:00
message ( "\n" )
if ( configure_warnings )
message ( " ******\n" )
foreach ( warning IN LISTS configure_warnings )
message ( WARNING "${warning}" )
endforeach ( )
message ( " ******\n" )
endif ( )
2024-08-16 20:27:34 +02:00
# We want all build properties to be encapsulated properly.
include ( WarnAboutGlobalProperties )