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.
1# Copyright (c) The Bitcoin Core developers2# Distributed under the MIT software license, see the accompanying3# file COPYING or http://www.opensource.org/licenses/mit-license.php.5cmake_minimum_required(VERSION 3.12)7project("Libmultiprocess" CXX)8if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)9set(CMAKE_CXX_STANDARD 20)10set(CMAKE_CXX_STANDARD_REQUIRED YES)11endif()13include("cmake/compat_find.cmake")15find_package(Threads REQUIRED)16find_package(CapnProto 0.7 QUIET NO_MODULE)17if(NOT CapnProto_FOUND)18message(FATAL_ERROR19"Cap'n Proto is required but was not found.\n"20"To resolve, choose one of the following:\n"21" - Install Cap'n Proto (version 1.0+ recommended)\n"22" - For Bitcoin Core compilation build with -DENABLE_IPC=OFF to disable multiprocess support\n"23)24endif()26# Cap'n Proto compatibility checks27set(CAPNPROTO_ISSUES "")28set(CAPNPROTO_CVE_AFFECTED FALSE)29set(CAPNPROTO_CLANG_INCOMPATIBLE FALSE)31# Check for list-of-pointers memory access bug from Nov 202232# https://nvd.nist.gov/vuln/detail/CVE-2022-4614933# https://github.com/advisories/GHSA-qqff-4vw4-f6hx34# https://github.com/capnproto/capnproto/security/advisories/GHSA-qqff-4vw4-f6hx35# https://github.com/capnproto/capnproto/blob/master/security-advisories/2022-11-30-0-pointer-list-bounds.md36# https://capnproto.org/news/2022-11-30-CVE-2022-46149-security-advisory.html37# https://dwrensha.github.io/capnproto-rust/2022/11/30/out_of_bounds_memory_access_bug.html38if(CapnProto_VERSION STREQUAL "0.7.0"39OR CapnProto_VERSION STREQUAL "0.8.0"40OR CapnProto_VERSION STREQUAL "0.9.0"41OR CapnProto_VERSION STREQUAL "0.9.1"42OR CapnProto_VERSION STREQUAL "0.10.0"43OR CapnProto_VERSION STREQUAL "0.10.1"44OR CapnProto_VERSION STREQUAL "0.10.2")45set(CAPNPROTO_CVE_AFFECTED TRUE)46string(APPEND CAPNPROTO_ISSUES "- CVE-2022-46149 security vulnerability (details: https://github.com/advisories/GHSA-qqff-4vw4-f6hx)\n")47endif()49# Check for Cap'n Proto / Clang / C++20 incompatibility50# Cap'n Proto 0.9.x and 0.10.x are incompatible with Clang 16+ when using C++2051# due to P2468R2 implementation. This was fixed in Cap'n Proto 1.0+.52# See: https://github.com/bitcoin-core/libmultiprocess/issues/19953if((CapnProto_VERSION VERSION_GREATER_EQUAL "0.9.0") AND54(CapnProto_VERSION VERSION_LESS "1.0.0") AND55(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND56(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "16") AND57(CMAKE_CXX_STANDARD EQUAL 20))58set(CAPNPROTO_CLANG_INCOMPATIBLE TRUE)59string(APPEND CAPNPROTO_ISSUES "- Incompatible with Clang ${CMAKE_CXX_COMPILER_VERSION} when using C++20\n")60endif()62if(CAPNPROTO_CVE_AFFECTED OR CAPNPROTO_CLANG_INCOMPATIBLE)63set(RESOLUTION_OPTIONS "")65# Fixes both issues66string(APPEND RESOLUTION_OPTIONS " - Upgrade to Cap'n Proto version 1.0 or newer (recommended)\n")68if(CAPNPROTO_CVE_AFFECTED AND NOT CAPNPROTO_CLANG_INCOMPATIBLE)69string(APPEND RESOLUTION_OPTIONS " - Upgrade to a patched minor version (0.7.1, 0.8.1, 0.9.2, 0.10.3, or later)\n")70elseif(CAPNPROTO_CLANG_INCOMPATIBLE AND NOT CAPNPROTO_CVE_AFFECTED)71string(APPEND RESOLUTION_OPTIONS " - Use GCC instead of Clang\n")72endif()74string(APPEND RESOLUTION_OPTIONS " - For Bitcoin Core compilation build with -DENABLE_IPC=OFF to disable multiprocess support\n")76message(FATAL_ERROR77"The version of Cap'n Proto detected: ${CapnProto_VERSION} has known compatibility issues:\n"78"${CAPNPROTO_ISSUES}"79"To resolve, choose one of the following:\n"80"${RESOLUTION_OPTIONS}"81)82endif()84set(MPGEN_EXECUTABLE "" CACHE FILEPATH "If specified, should be full path to an external mpgen binary to use rather than the one built internally.")86option(MP_ENABLE_CLANG_TIDY "Run clang-tidy with the compiler." OFF)87if(MP_ENABLE_CLANG_TIDY)88find_program(CLANG_TIDY_EXECUTABLE NAMES clang-tidy)89if(NOT CLANG_TIDY_EXECUTABLE)90message(FATAL_ERROR "MP_ENABLE_CLANG_TIDY is ON but clang-tidy is not found.")91endif()92set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE}")93endif()95option(MP_ENABLE_IWYU "Run include-what-you-use with the compiler." OFF)96if(MP_ENABLE_IWYU)97find_program(IWYU_EXECUTABLE NAMES include-what-you-use iwyu)98if(NOT IWYU_EXECUTABLE)99message(FATAL_ERROR "MP_ENABLE_IWYU is ON but include-what-you-use was not found.")100endif()101set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${IWYU_EXECUTABLE};-Xiwyu;--error")102if(DEFINED ENV{IWYU_MAPPING_FILE})103list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE "-Xiwyu" "--mapping_file=$ENV{IWYU_MAPPING_FILE}")104endif()105endif()107if(MP_ENABLE_CLANG_TIDY OR MP_ENABLE_IWYU)108# Workaround for nix from https://gitlab.kitware.com/cmake/cmake/-/issues/20912#note_793338109# Nix injects header paths via $NIX_CFLAGS_COMPILE; CMake tags these as110# CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES and omits them from the compile111# database, so clang-tidy, which ignores $NIX_CFLAGS_COMPILE, can't find capnp112# headers. Setting them as standard passes them to clang-tidy.113set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})114endif()116include("cmake/compat_config.cmake")117include("cmake/pthread_checks.cmake")118include(GNUInstallDirs)120# Set MP_INCLUDE_DIR as a global property so target_capnp_sources function can121# use it, and its callers don't need to specify the include directory manually122# to avoid "error: Import failed: /mp/proxy.capnp" failures from capnproto.123set_property(GLOBAL PROPERTY MP_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")125# Set a convenience variable for subdirectories.126if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)127set(MP_STANDALONE TRUE)128include(CTest)129else()130set(MP_STANDALONE FALSE)131endif()133# Prevent include directories from parent project from leaking into this one.134set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES "")136# Generated C++ preprocessor defines137configure_file(include/mp/config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/mp/config.h")139# Generated C++ Capn'Proto schema files140capnp_generate_cpp(MP_PROXY_SRCS MP_PROXY_HDRS include/mp/proxy.capnp)141set_source_files_properties("${MP_PROXY_SRCS}" PROPERTIES SKIP_LINTING TRUE) # Ignored before cmake 3.27142# Build-graph node for generated headers. This lets targets that include143# the headers order themselves after generation without depending on the144# library target that also uses them.145add_custom_target(mp_headers DEPENDS ${MP_PROXY_HDRS})147# util library148add_library(mputil OBJECT src/mp/util.cpp)149target_include_directories(mputil PRIVATE150$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>151$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)152target_link_libraries(mputil PUBLIC CapnProto::kj)154# libmultiprocess.a runtime library155set(MP_PUBLIC_HEADERS156${MP_PROXY_HDRS}157include/mp/proxy-io.h158include/mp/proxy-types.h159include/mp/proxy.h160include/mp/type-char.h161include/mp/type-chrono.h162include/mp/type-context.h163include/mp/type-data.h164include/mp/type-decay.h165include/mp/type-exception.h166include/mp/type-function.h167include/mp/type-interface.h168include/mp/type-map.h169include/mp/type-message.h170include/mp/type-number.h171include/mp/type-optional.h172include/mp/type-pair.h173include/mp/type-pointer.h174include/mp/type-set.h175include/mp/type-string.h176include/mp/type-struct.h177include/mp/type-threadmap.h178include/mp/type-tuple.h179include/mp/type-vector.h180include/mp/type-void.h181include/mp/util.h)182add_library(multiprocess STATIC183${MP_PROXY_SRCS}184${MP_PUBLIC_HEADERS}185src/mp/proxy.cpp186$<TARGET_OBJECTS:mputil>)187add_library(Libmultiprocess::multiprocess ALIAS multiprocess)188target_include_directories(multiprocess PUBLIC189$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>190$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>191$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)192target_link_libraries(multiprocess PUBLIC CapnProto::capnp)193target_link_libraries(multiprocess PUBLIC CapnProto::capnp-rpc)194target_link_libraries(multiprocess PUBLIC CapnProto::kj)195target_link_libraries(multiprocess PUBLIC CapnProto::kj-async)196set_target_properties(multiprocess PROPERTIES197PUBLIC_HEADER "${MP_PUBLIC_HEADERS}")198install(TARGETS multiprocess EXPORT LibTargets199ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib200PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mp COMPONENT lib)202# mpgen code generator203add_executable(mpgen src/mp/gen.cpp $<TARGET_OBJECTS:mputil>)204add_executable(Libmultiprocess::mpgen ALIAS mpgen)205target_include_directories(mpgen PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)206target_include_directories(mpgen PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)207target_link_libraries(mpgen PRIVATE CapnProto::capnp)208target_link_libraries(mpgen PRIVATE CapnProto::capnp-rpc)209target_link_libraries(mpgen PRIVATE CapnProto::capnpc)210target_link_libraries(mpgen PRIVATE CapnProto::kj)211target_link_libraries(mpgen PRIVATE Threads::Threads)212set_target_properties(mpgen PROPERTIES213INSTALL_RPATH_USE_LINK_PATH TRUE)214set_target_properties(mpgen PROPERTIES215PUBLIC_HEADER include/mp/proxy.capnp)216install(TARGETS mpgen EXPORT BinTargets217RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bin218PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mp COMPONENT bin)220# makefile include to invoke mpgen code generator, for downstream Make projects221install(FILES "include/mpgen.mk"222DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT bin)224# pkg-config module to build against libmultiprocess library, for downstream autoconf projects225configure_file(pkgconfig/libmultiprocess.pc.in "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/libmultiprocess.pc" @ONLY)226install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/libmultiprocess.pc"227DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT lib)229# cmake include to invoke mpgen code generator, for downstream CMake projects230install(231FILES232${CMAKE_CURRENT_SOURCE_DIR}/cmake/TargetCapnpSources.cmake233DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess COMPONENT bin)235# CMake target import files, for downstream CMake projects236install(EXPORT BinTargets237NAMESPACE Libmultiprocess::238DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess COMPONENT bin)239install(EXPORT LibTargets240NAMESPACE Libmultiprocess::241DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess COMPONENT lib)243# CMake find_package config file, for downstream CMake projects244include(CMakePackageConfigHelpers)245configure_package_config_file(246${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in247LibmultiprocessConfig.cmake248INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess249NO_SET_AND_CHECK_MACRO)250install(
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.