Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1# Copyright (c) 2023-present The Bitcoin Core developers2# Distributed under the MIT software license, see the accompanying3# file COPYING or https://opensource.org/license/mit/.5# Ubuntu 22.04 LTS Jammy Jellyfish, https://wiki.ubuntu.com/Releases, EOSS in June 2027:6# - CMake 3.22.1, https://packages.ubuntu.com/jammy/cmake7#8# Centos Stream 9, https://www.centos.org/cl-vs-cs/#end-of-life, EOL in May 2027:9# - CMake 3.26.5, https://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/Packages/10cmake_minimum_required(VERSION 3.22)12if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)13message(FATAL_ERROR "In-source builds are not allowed.")14endif()16if(POLICY CMP0171)17# `codegen` is a reserved target name.18# See: https://cmake.org/cmake/help/latest/policy/CMP0171.html19cmake_policy(SET CMP0171 NEW)20endif()22# When adjusting CMake flag variables, we must not override those explicitly23# set by the user. These are a subset of the CACHE_VARIABLES property.24get_directory_property(precious_variables CACHE_VARIABLES)26#=============================27# Project / Package metadata28#=============================29set(CLIENT_NAME "Bitcoin Core")30set(CLIENT_VERSION_MAJOR 32)31set(CLIENT_VERSION_MINOR 1)32set(CLIENT_VERSION_BUILD 0)33set(CLIENT_VERSION_RC 0)34set(CLIENT_VERSION_IS_RELEASE "true")35set(COPYRIGHT_YEAR "2026")37# During the enabling of the CXX and CXXOBJ languages, we modify38# CMake's compiler/linker invocation strings by appending the content39# of the user-defined `APPEND_*` variables, which allows overriding40# any flag. We also ensure that the APPEND_* flags are considered41# during CMake's tests, which use the `try_compile()` command.42#43# CMake's docs state that the `CMAKE_TRY_COMPILE_PLATFORM_VARIABLES`44# variable "is meant to be set by CMake's platform information modules45# for the current toolchain, or by a toolchain file." We do our best46# to set it before the `project()` command.47set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES48CMAKE_CXX_COMPILE_OBJECT49CMAKE_OBJCXX_COMPILE_OBJECT50CMAKE_CXX_LINK_EXECUTABLE51)53project(BitcoinCore54VERSION ${CLIENT_VERSION_MAJOR}.${CLIENT_VERSION_MINOR}.${CLIENT_VERSION_BUILD}55DESCRIPTION "Bitcoin client software"56HOMEPAGE_URL "https://bitcoincore.org/"57LANGUAGES NONE58)60set(CLIENT_VERSION_STRING ${PROJECT_VERSION})61if(CLIENT_VERSION_RC GREATER 0)62string(APPEND CLIENT_VERSION_STRING "rc${CLIENT_VERSION_RC}")63endif()65set(COPYRIGHT_HOLDERS "The %s developers")66set(COPYRIGHT_HOLDERS_FINAL "The ${CLIENT_NAME} developers")67set(CLIENT_BUGREPORT "https://github.com/bitcoin/bitcoin/issues")69#=============================70# Language setup71#=============================72if(CMAKE_VERSION VERSION_LESS 4.2 AND CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_HOST_APPLE)73# We do not use the install_name_tool when cross-compiling for macOS.74# However, CMake < 4.2 still searches for Apple's version of the tool,75# which causes an error during configuration.76# See:77# - https://gitlab.kitware.com/cmake/cmake/-/issues/2706978# - https://gitlab.kitware.com/cmake/cmake/-/merge_requests/1095579# So disable this tool check in further enable_language() commands.80set(CMAKE_INSTALL_NAME_TOOL "${CMAKE_COMMAND} -E true")81endif()82enable_language(CXX)84set(CMAKE_CXX_STANDARD 20)85set(CMAKE_CXX_STANDARD_REQUIRED ON)86set(CMAKE_CXX_EXTENSIONS OFF)88list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/module)89include(ProcessConfigurations)91# Flatten static lib dependencies.92# Without this, if libfoo.a depends on libbar.a, libfoo's objects can't begin93# to be compiled until libbar.a has been created.94if (NOT DEFINED CMAKE_OPTIMIZE_DEPENDENCIES)95set(CMAKE_OPTIMIZE_DEPENDENCIES TRUE)96endif()98#=============================99# Configurable options100#=============================101include(CMakeDependentOption)102# When adding a new option, end the <help_text> with a full stop for consistency.103option(BUILD_BITCOIN_BIN "Build bitcoin executable." ON)104option(BUILD_DAEMON "Build bitcoind executable." ON)105option(BUILD_GUI "Build bitcoin-qt executable." OFF)106option(BUILD_CLI "Build bitcoin-cli executable." ON)108option(BUILD_TESTS "Build test_bitcoin and other unit test executables." ON)109option(BUILD_TX "Build bitcoin-tx executable." ${BUILD_TESTS})110option(BUILD_UTIL "Build bitcoin-util executable." ${BUILD_TESTS})111cmake_dependent_option(BUILD_GUI_TESTS "Build test_bitcoin-qt executable." ON "BUILD_GUI;BUILD_TESTS" OFF)113option(BUILD_UTIL_CHAINSTATE "Build experimental bitcoin-chainstate executable." OFF)114option(BUILD_KERNEL_LIB "Build experimental bitcoinkernel library." ${BUILD_UTIL_CHAINSTATE})115cmake_dependent_option(BUILD_KERNEL_TEST "Build tests for the experimental bitcoinkernel library." ON "BUILD_KERNEL_LIB" OFF)117option(ENABLE_WALLET "Enable wallet." ON)118cmake_dependent_option(BUILD_WALLET_TOOL "Build bitcoin-wallet tool." ${BUILD_TESTS} "ENABLE_WALLET" OFF)120option(ENABLE_EXTERNAL_SIGNER "Enable external signer support." ON)121option(WITH_ZMQ "Enable ZMQ notifications." OFF)122cmake_dependent_option(ENABLE_IPC "Build multiprocess bitcoin-node and bitcoin-gui executables in addition to monolithic bitcoind and bitcoin-qt executables." ON "NOT WIN32" OFF)123cmake_dependent_option(WITH_EXTERNAL_LIBMULTIPROCESS "Build with external libmultiprocess library instead of with local git subtree when ENABLE_IPC is enabled. This is not normally recommended, but can be useful for developing libmultiprocess itself." OFF "ENABLE_IPC" OFF)124option(WITH_EMBEDDED_ASMAP "Embed default ASMap data." ON)125option(WITH_USDT "Enable tracepoints for Userspace, Statically Defined Tracing." OFF)127cmake_dependent_option(WITH_QRENCODE "Enable QR code support." ON "BUILD_GUI" OFF)128cmake_dependent_option(WITH_DBUS "Enable DBus support." ON "NOT CMAKE_SYSTEM_NAME MATCHES \"(Windows|Darwin)\" AND BUILD_GUI" OFF)130option(BUILD_BENCH "Build bench_bitcoin executable." OFF)131option(BUILD_FUZZ_BINARY "Build fuzz binary." OFF)132option(BUILD_FOR_FUZZING "Build for fuzzing. Enabling this will disable all other targets and override BUILD_FUZZ_BINARY." OFF)134option(REDUCE_EXPORTS "Attempt to reduce exported symbols in the resulting executables." OFF)135option(CMAKE_COMPILE_WARNING_AS_ERROR "Treat compiler warnings as errors." OFF)136option(WITH_CCACHE "Attempt to use ccache for compiling." ON)138option(INSTALL_MAN "Install man pages." ON)140set(APPEND_CPPFLAGS "" CACHE STRING "Preprocessor flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")141set(APPEND_CFLAGS "" CACHE STRING "C compiler flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")142set(APPEND_CXXFLAGS "" CACHE STRING "(Objective) C++ compiler flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")143set(APPEND_LDFLAGS "" CACHE STRING "Linker flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")144# Appending to this low-level rule variables is the only way to145# guarantee that the flags appear at the end of the command line.146string(APPEND CMAKE_CXX_COMPILE_OBJECT " ${APPEND_CPPFLAGS} ${APPEND_CXXFLAGS}")147string(APPEND CMAKE_CXX_CREATE_SHARED_LIBRARY " ${APPEND_LDFLAGS}")148string(APPEND CMAKE_CXX_LINK_EXECUTABLE " ${APPEND_LDFLAGS}")150# Check required C++ toolchain features early.151include(CheckCXXFeatures)152check_cxx_features()154#=============================155# Core interface library156#=============================157# The core_interface library aims to encapsulate common build flags.158# It is a usage requirement for all targets except for secp256k1, which159# gets its flags by other means.160add_library(core_interface INTERFACE)161add_library(core_interface_relwithdebinfo INTERFACE)162add_library(core_interface_debug INTERFACE)163target_link_libraries(core_interface INTERFACE164$<$<CONFIG:RelWithDebInfo>:core_interface_relwithdebinfo>165$<$<CONFIG:Debug>:core_interface_debug>166)168#=============================169# Option interaction170#=============================171# Compute the final state of build options.172# This must be done after all options have been initially set,173# as some options (e.g., BUILD_FOR_FUZZING) may override or adjust others.174# It must also come before any dependency checks to ensure that the set175# of dependencies checked is consistent with the final option values,176# that is, that all required, and only the required, dependencies are tested.177if(BUILD_FOR_FUZZING)178message(WARNING "BUILD_FOR_FUZZING=ON will disable all other targets and force BUILD_FUZZ_BINARY=ON.")179set(BUILD_BITCOIN_BIN OFF)180set(BUILD_DAEMON OFF)181set(BUILD_CLI OFF)182set(BUILD_TX OFF)183set(BUILD_UTIL OFF)184set(BUILD_UTIL_CHAINSTATE OFF)185set(BUILD_KERNEL_LIB OFF)186set(BUILD_KERNEL_TEST OFF)187set(BUILD_WALLET_TOOL OFF)188set(BUILD_GUI OFF)189set(ENABLE_EXTERNAL_SIGNER OFF)190set(WITH_ZMQ OFF)191set(WITH_EMBEDDED_ASMAP OFF)192set(BUILD_TESTS OFF)193set(BUILD_GUI_TESTS OFF)194set(BUILD_BENCH OFF)195set(BUILD_FUZZ_BINARY ON)197target_compile_definitions(core_interface INTERFACE198FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION199)200endif()202#=============================203# Check and set PIC/PIE204#=============================205set(configure_warnings)206if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")207include(CheckLinkerSupportsPIE)208# Set CMAKE_POSITION_INDEPENDENT_CODE early so it applies to all209# subsequent checks, including dependency packages and tool flags.210check_linker_supports_pie(configure_warnings)211endif()213#=============================214# Find dependencies215#=============================216if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")217set(THREADS_PREFER_PTHREAD_FLAG ON)218find_package(Threads REQUIRED)219target_link_libraries(core_interface INTERFACE220Threads::Threads221)222endif()224if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")225include(AddBoostIfNeeded)226add_boost_if_needed()227endif()229if(ENABLE_WALLET)230if(VCPKG_TARGET_TRIPLET)231# Use of the `unofficial::` namespace is a vcpkg package manager convention.232find_package(unofficial-sqlite3 CONFIG REQUIRED)233add_library(SQLite3::SQLite3 ALIAS unofficial::sqlite3::sqlite3)234else()235find_package(SQLite3 3.7.17 REQUIRED)236if(NOT TARGET SQLite3::SQLite3) # CMake < 4.3237add_library(SQLite3::SQLite3 ALIAS SQLite::SQLite3)238endif()239endif()240endif()242if(WITH_ZMQ)243find_package(ZeroMQ 4.0.0 MODULE REQUIRED)244endif()246if(ENABLE_IPC AND WITH_EXTERNAL_LIBMULTIPROCESS)247find_package(Libmultiprocess REQUIRED COMPONENTS Lib)248find_package(LibmultiprocessNative REQUIRED COMPONENTS Bin249NAMES Libmultiprocess250)