Inside Bitcoin
Opening the selected file…
Inside Bitcoin
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.
251endif()253if(WITH_USDT)254find_package(USDT MODULE REQUIRED)255endif()257if(BUILD_GUI)258set(qt_components Core Gui Widgets LinguistTools)259if(ENABLE_WALLET)260list(APPEND qt_components Network)261endif()262if(WITH_DBUS)263list(APPEND qt_components DBus)264set(USE_DBUS TRUE)265endif()266if(BUILD_GUI_TESTS)267list(APPEND qt_components Test)268endif()269find_package(Qt 6.2 MODULE REQUIRED270COMPONENTS ${qt_components}271)272unset(qt_components)273if(WITH_QRENCODE)274find_package(QRencode MODULE REQUIRED)275set(USE_QRCODE TRUE)276endif()277endif()279include(TryAppendCXXFlags)280include(TryAppendLinkerFlag)282# Redefine/adjust per-configuration flags.283target_compile_definitions(core_interface_debug INTERFACE284DEBUG285DEBUG_LOCKORDER286DEBUG_LOCKCONTENTION287RPC_DOC_CHECK288ABORT_ON_FAILED_ASSUME289)291if(WIN32)292#[=[293This build system supports two ways to build binaries for Windows.2951. Building on Windows using MSVC.296Implementation notes:297- /DWIN32 and /D_WINDOWS definitions are included into the CMAKE_CXX_FLAGS_INIT298and CMAKE_CXX_FLAGS_INIT variables by default.299- A run-time library is selected using the CMAKE_MSVC_RUNTIME_LIBRARY variable.300- MSVC-specific options, for example, /Zc:__cplusplus, are additionally required.3022. Cross-compiling using MinGW.303Implementation notes:304- WIN32 and _WINDOWS definitions must be provided explicitly.305- A run-time library must be specified explicitly using _MT definition.306]=]308target_compile_definitions(core_interface INTERFACE309_WIN32_WINNT=0x0A00310_WIN32_IE=0x0A00311WIN32_LEAN_AND_MEAN312NOMINMAX313)315if(MSVC)316if(VCPKG_TARGET_TRIPLET MATCHES "-static")317set(msvc_library_linkage "")318else()319set(msvc_library_linkage "DLL")320endif()321set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>${msvc_library_linkage}")322unset(msvc_library_linkage)324target_compile_definitions(core_interface INTERFACE325_UNICODE;UNICODE326)327target_compile_options(core_interface INTERFACE328/utf-8329/Zc:preprocessor330/Zc:__cplusplus331/sdl332)333# Improve parallelism in MSBuild.334# See: https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/.335list(APPEND CMAKE_VS_GLOBALS "UseMultiToolTask=true")336endif()338if(MINGW)339target_compile_definitions(core_interface INTERFACE340WIN32341_WINDOWS342_MT343)344# Avoid the use of aligned vector instructions when building for Windows.345# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54412.346try_append_cxx_flags("-Wa,-muse-unaligned-vector-move" TARGET core_interface SKIP_LINK)347try_append_linker_flag("-static" TARGET core_interface)348# We support Windows 10+, however it's not possible to set these values accordingly,349# due to a bug in mingw-w64. See https://sourceforge.net/p/mingw-w64/bugs/968/.350# As a best effort, target Windows 8.351try_append_linker_flag("-Wl,--major-subsystem-version,6" TARGET core_interface)352try_append_linker_flag("-Wl,--minor-subsystem-version,2" TARGET core_interface)353endif()355# Workaround producing large object files, which cannot be handled by the assembler.356# More likely to happen with no, or lower levels of optimisation.357# See discussion in https://github.com/bitcoin/bitcoin/issues/28109.358if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")359try_append_cxx_flags("/bigobj" TARGET core_interface_debug SKIP_LINK)360else()361try_append_cxx_flags("-Wa,-mbig-obj" TARGET core_interface_debug SKIP_LINK)362endif()363endif()365# Use 64-bit off_t on 32-bit Linux.366if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SIZEOF_VOID_P EQUAL 4)367# Ensure 64-bit offsets are used for filesystem accesses for 32-bit compilation.368target_compile_definitions(core_interface INTERFACE369_FILE_OFFSET_BITS=64370)371endif()373if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")374target_compile_definitions(core_interface INTERFACE OBJC_OLD_DISPATCH_PROTOTYPES=0)375# These flags are specific to ld64, and may cause issues with other linkers.376# For example: GNU ld will interpret -dead_strip as -de and then try and use377# "ad_strip" as the symbol for the entry point.378try_append_linker_flag("-Wl,-dead_strip" TARGET core_interface)379try_append_linker_flag("-Wl,-dead_strip_dylibs" TARGET core_interface)380if(CMAKE_HOST_APPLE)381try_append_linker_flag("-Wl,-headerpad_max_install_names" TARGET core_interface)382endif()383endif()385# Define sanitize_interface with -fsanitize flags intended to apply to all386# libraries and executables.387add_library(sanitize_interface INTERFACE)388target_link_libraries(core_interface INTERFACE sanitize_interface)389if(SANITIZERS)390# Transform list of sanitizers into -fsanitize flags, replacing "fuzzer" with391# "fuzzer-no-link" in sanitize_interface flags, and moving "fuzzer" to392# fuzzer_interface flags. If -DSANITIZERS=fuzzer is specified, the fuzz test393# binary should be built with -fsanitize=fuzzer (so it can use libFuzzer's394# main function), but libraries should be built with -fsanitize=fuzzer-no-link395# (so they can be linked into other executables that have their own main396# functions).397string(REGEX REPLACE "(^|,)fuzzer($|,)" "\\1fuzzer-no-link\\2" sanitize_opts "${SANITIZERS}")398set(fuzz_flag "")399if(NOT sanitize_opts STREQUAL SANITIZERS)400set(fuzz_flag "-fsanitize=fuzzer")401endif()403# First check if the compiler accepts flags. If an incompatible pair like404# -fsanitize=address,thread is used here, this check will fail. This will also405# fail if a bad argument is passed, e.g. -fsanitize=undfeined406try_append_cxx_flags("-fsanitize=${sanitize_opts}" TARGET sanitize_interface407RESULT_VAR cxx_supports_sanitizers408SKIP_LINK409)410if(NOT cxx_supports_sanitizers)411message(FATAL_ERROR "Compiler did not accept requested flags.")412endif()414# Some compilers (e.g. GCC) require additional libraries like libasan,415# libtsan, libubsan, etc. Make sure linking still works with the sanitize416# flag. This is a separate check so we can give a better error message when417# the sanitize flags are supported by the compiler but the actual sanitizer418# libs are missing.419try_append_linker_flag("-fsanitize=${sanitize_opts}" VAR SANITIZER_LDFLAGS420SOURCE "421#include <cstdint>422#include <cstddef>423extern \"C\" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { return 0; }424int main() { return 0; }425"426RESULT_VAR linker_supports_sanitizers427NO_CACHE_IF_FAILED428)429if(NOT linker_supports_sanitizers)430message(FATAL_ERROR "Linker did not accept requested flags, you are missing required libraries.")431endif()432endif()433target_link_options(sanitize_interface INTERFACE ${SANITIZER_LDFLAGS})435# Define fuzzer_interface with flags intended to apply to the fuzz test binary,436# and perform a test compilation to determine correct value of437# FUZZ_BINARY_LINKS_WITHOUT_MAIN_FUNCTION.438if(BUILD_FUZZ_BINARY)439include(CheckSourceCompilesWithFlags)440check_cxx_source_compiles_with_flags("441#include <cstdint>442#include <cstddef>443extern \"C\" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { return 0; }444// No main() function.445" FUZZ_BINARY_LINKS_WITHOUT_MAIN_FUNCTION446LDFLAGS ${SANITIZER_LDFLAGS} ${fuzz_flag}447LINK_LIBRARIES ${FUZZ_LIBS}448)449add_library(fuzzer_interface INTERFACE)450target_link_options(fuzzer_interface INTERFACE ${fuzz_flag})451target_link_libraries(fuzzer_interface INTERFACE ${FUZZ_LIBS})452endif()454include(cmake/introspection.cmake)456include(cmake/ccache.cmake)458add_library(warn_interface INTERFACE)459target_link_libraries(core_interface INTERFACE warn_interface)460if(MSVC)461try_append_cxx_flags("/W3" TARGET warn_interface SKIP_LINK)462try_append_cxx_flags("/wd4018" TARGET warn_interface SKIP_LINK)463try_append_cxx_flags("/wd4146" TARGET warn_interface SKIP_LINK)464try_append_cxx_flags("/wd4244" TARGET warn_interface SKIP_LINK)465try_append_cxx_flags("/wd4267" TARGET warn_interface SKIP_LINK)466try_append_cxx_flags("/wd4715" TARGET warn_interface SKIP_LINK)467try_append_cxx_flags("/wd4805" TARGET warn_interface SKIP_LINK)468target_compile_definitions(warn_interface INTERFACE469_CRT_SECURE_NO_WARNINGS470)471else()472try_append_cxx_flags("-Wall" TARGET warn_interface SKIP_LINK)473try_append_cxx_flags("-Wextra" TARGET warn_interface SKIP_LINK)474try_append_cxx_flags("-Wgnu" TARGET warn_interface SKIP_LINK)475try_append_cxx_flags("-Wcovered-switch-default" TARGET warn_interface SKIP_LINK)476# Some compilers will ignore -Wformat-security without -Wformat, so just combine the two here.477try_append_cxx_flags("-Wformat -Wformat-security" TARGET warn_interface SKIP_LINK)478try_append_cxx_flags("-Wvla" TARGET warn_interface SKIP_LINK)479try_append_cxx_flags("-Wshadow-field" TARGET warn_interface SKIP_LINK)480try_append_cxx_flags("-Wthread-safety" TARGET warn_interface SKIP_LINK)481try_append_cxx_flags("-Wthread-safety-pointer" TARGET warn_interface SKIP_LINK)482try_append_cxx_flags("-Wloop-analysis" TARGET warn_interface SKIP_LINK)483try_append_cxx_flags("-Wredundant-decls" TARGET warn_interface SKIP_LINK)484try_append_cxx_flags("-Wunused-member-function" TARGET warn_interface SKIP_LINK)485try_append_cxx_flags("-Wdate-time" TARGET warn_interface SKIP_LINK)486try_append_cxx_flags("-Wconditional-uninitialized" TARGET warn_interface SKIP_LINK)487try_append_cxx_flags("-Wduplicated-branches" TARGET warn_interface SKIP_LINK)488try_append_cxx_flags("-Wduplicated-cond" TARGET warn_interface SKIP_LINK)489try_append_cxx_flags("-Wlogical-op" TARGET warn_interface SKIP_LINK)490try_append_cxx_flags("-Woverloaded-virtual" TARGET warn_interface SKIP_LINK)491try_append_cxx_flags("-Wsuggest-override" TARGET warn_interface SKIP_LINK)492try_append_cxx_flags("-Wimplicit-fallthrough" TARGET warn_interface SKIP_LINK)493try_append_cxx_flags("-Wunreachable-code" TARGET warn_interface SKIP_LINK)494try_append_cxx_flags("-Wdocumentation" TARGET warn_interface SKIP_LINK)495try_append_cxx_flags("-Wself-assign" TARGET warn_interface SKIP_LINK)496try_append_cxx_flags("-Wbidi-chars=any" TARGET warn_interface SKIP_LINK)497try_append_cxx_flags("-Wundef" TARGET warn_interface SKIP_LINK)498try_append_cxx_flags("-Wleading-whitespace=spaces" TARGET warn_interface SKIP_LINK)499try_append_cxx_flags("-Wtrailing-whitespace=any" TARGET warn_interface SKIP_LINK)