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/.5function(add_boost_if_needed)6#[=[7TODO: Not all targets, which will be added in the future, require8Boost. Therefore, a proper check will be appropriate here.10Implementation notes:11Although only Boost headers are used to build Bitcoin Core,12we still leverage a standard CMake's approach to handle13dependencies, i.e., the Boost::headers "library".14A command target_link_libraries(target PRIVATE Boost::headers)15will propagate Boost::headers usage requirements to the target.16For Boost::headers such usage requirements is an include17directory and other added INTERFACE properties.18]=]20if(CMAKE_HOST_APPLE)21find_program(HOMEBREW_EXECUTABLE brew)22if(HOMEBREW_EXECUTABLE)23execute_process(24COMMAND ${HOMEBREW_EXECUTABLE} --prefix boost25OUTPUT_VARIABLE Boost_ROOT26ERROR_QUIET27OUTPUT_STRIP_TRAILING_WHITESPACE28)29endif()30endif()32find_package(Boost 1.74.0 REQUIRED CONFIG)33mark_as_advanced(Boost_INCLUDE_DIR boost_headers_DIR)34set_target_properties(Boost::headers PROPERTIES IMPORTED_GLOBAL TRUE)35target_compile_definitions(Boost::headers INTERFACE36# We don't use multi_index serialization.37BOOST_MULTI_INDEX_DISABLE_SERIALIZATION38)39if(DEFINED VCPKG_TARGET_TRIPLET)40# Workaround for https://github.com/microsoft/vcpkg/issues/36955.41target_compile_definitions(Boost::headers INTERFACE42BOOST_NO_USER_CONFIG43)44endif()46# Prevent use of std::unary_function, which was removed in C++17,47# and will generate warnings with newer compilers for Boost48# older than 1.80.49# See: https://github.com/boostorg/config/pull/430.50set(CMAKE_REQUIRED_DEFINITIONS -DBOOST_NO_CXX98_FUNCTION_BASE)51get_target_property(CMAKE_REQUIRED_INCLUDES Boost::headers INTERFACE_INCLUDE_DIRECTORIES)52set(CMAKE_REQUIRED_FLAGS ${working_compiler_werror_flag})53set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)54include(CheckCXXSourceCompiles)55check_cxx_source_compiles("56#include <boost/config.hpp>57" NO_DIAGNOSTICS_BOOST_NO_CXX98_FUNCTION_BASE58)59if(NO_DIAGNOSTICS_BOOST_NO_CXX98_FUNCTION_BASE)60target_compile_definitions(Boost::headers INTERFACE61BOOST_NO_CXX98_FUNCTION_BASE62)63endif()65# Some package managers, such as vcpkg, vendor Boost.Test separately66# from the rest of the headers, so we have to check for it individually.67if(BUILD_TESTS AND DEFINED VCPKG_TARGET_TRIPLET)68find_package(boost_included_unit_test_framework ${Boost_VERSION} EXACT REQUIRED CONFIG)69endif()71endfunction()
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.