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/.5include_guard(GLOBAL)7# Illumos/SmartOS requires linking with -lsocket if8# using getifaddrs & freeifaddrs.9# See:10# - https://github.com/bitcoin/bitcoin/pull/2148611# - https://smartos.org/man/3socket/getifaddrs12function(test_append_socket_library target)13if (NOT TARGET ${target})14message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}() called with non-existent target \"${target}\".")15endif()17set(check_socket_source "18#include <ifaddrs.h>20int main() {21struct ifaddrs* ifaddr;22getifaddrs(&ifaddr);23freeifaddrs(ifaddr);24}25")27include(CheckCXXSourceCompiles)28check_cxx_source_compiles("${check_socket_source}" IFADDR_LINKS_WITHOUT_LIBSOCKET)29if(NOT IFADDR_LINKS_WITHOUT_LIBSOCKET)30include(CheckSourceCompilesWithFlags)31check_cxx_source_compiles_with_flags("${check_socket_source}" IFADDR_NEEDS_LINK_TO_LIBSOCKET32LINK_LIBRARIES socket33)34if(IFADDR_NEEDS_LINK_TO_LIBSOCKET)35target_link_libraries(${target} INTERFACE socket)36else()37message(FATAL_ERROR "Cannot figure out how to use getifaddrs/freeifaddrs.")38endif()39endif()40set(HAVE_IFADDRS TRUE PARENT_SCOPE)41endfunction()43# Clang, when building for 32-bit,44# and linking against libstdc++, requires linking with45# -latomic if using the C++ atomic library.46# Can be tested with: clang++ -std=c++20 test.cpp -m3247#48# Sourced from http://bugs.debian.org/79722849function(test_append_atomic_library target)50if (NOT TARGET ${target})51message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}() called with non-existent target \"${target}\".")52endif()54set(check_atomic_source "55#include <atomic>56#include <cstdint>57#include <chrono>59using namespace std::chrono_literals;61int main() {62std::atomic<bool> lock{true};63lock.exchange(false);65std::atomic<std::chrono::seconds> t{0s};66t.store(2s);67auto t1 = t.load();68t.compare_exchange_strong(t1, 3s);70std::atomic<double> d{};71d.store(3.14);72auto d1 = d.load();74std::atomic<int64_t> a{};75int64_t v = 5;76int64_t r = a.fetch_add(v);77return static_cast<int>(r);78}79")81include(CheckCXXSourceCompiles)82check_cxx_source_compiles("${check_atomic_source}" STD_ATOMIC_LINKS_WITHOUT_LIBATOMIC)83if(NOT STD_ATOMIC_LINKS_WITHOUT_LIBATOMIC)84include(CheckSourceCompilesWithFlags)85check_cxx_source_compiles_with_flags("${check_atomic_source}" STD_ATOMIC_NEEDS_LINK_TO_LIBATOMIC86LINK_LIBRARIES atomic87)88if(STD_ATOMIC_NEEDS_LINK_TO_LIBATOMIC)89target_link_libraries(${target} INTERFACE atomic)90else()91message(FATAL_ERROR "Cannot figure out how to use std::atomic.")92endif()93endif()94endfunction()
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.