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(CheckCXXSourceCompiles)6include(CheckCXXSymbolExists)8check_cxx_symbol_exists(O_CLOEXEC "fcntl.h" HAVE_O_CLOEXEC)9check_cxx_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC)10check_cxx_symbol_exists(fork "unistd.h" HAVE_DECL_FORK)11if (NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")12check_cxx_symbol_exists(pipe2 "unistd.h" HAVE_DECL_PIPE2)13endif()14check_cxx_symbol_exists(setsid "unistd.h" HAVE_DECL_SETSID)16if(NOT WIN32)17include(TestAppendRequiredLibraries)18test_append_socket_library(core_interface)19endif()21include(TestAppendRequiredLibraries)22if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")23test_append_atomic_library(core_interface)24endif()26# Even though ::system is part of the standard library, we still check27# for it, to support building targets that don't have it, such as iOS.28check_cxx_symbol_exists(std::system "cstdlib" HAVE_STD_SYSTEM)29if(HAVE_STD_SYSTEM)30set(HAVE_SYSTEM 1)31endif()33check_cxx_source_compiles("34#include <string.h>36int main()37{38char buf[100];39char* p{strerror_r(0, buf, sizeof buf)};40(void)p;41}42" STRERROR_R_CHAR_P43)45# Check for malloc_info (for memory statistics information in getmemoryinfo).46check_cxx_symbol_exists(malloc_info "malloc.h" HAVE_MALLOC_INFO)48# Check for mallopt(M_ARENA_MAX) (to set glibc arenas).49check_cxx_source_compiles("50#include <malloc.h>52int main()53{54mallopt(M_ARENA_MAX, 1);55}56" HAVE_MALLOPT_ARENA_MAX57)59# Check for posix_fallocate().60check_cxx_source_compiles("61#include <fcntl.h>63int main()64{65return posix_fallocate(0, 0, 0);66}67" HAVE_POSIX_FALLOCATE68)70# Check for strong getauxval() support in the system headers.71check_cxx_source_compiles("72#include <sys/auxv.h>74int main()75{76getauxval(AT_HWCAP);77}78" HAVE_STRONG_GETAUXVAL79)81# Check for SetThreadDescription(), which is missing from mingw-w64 headers82# before 12.0.0.83check_cxx_symbol_exists(SetThreadDescription "windows.h" HAVE_SETTHREADDESCRIPTION)85# Check for UNIX sockets.86check_cxx_source_compiles("87#include <sys/socket.h>88#include <sys/un.h>90int main()91{92struct sockaddr_un addr;93addr.sun_family = AF_UNIX;94}95" HAVE_SOCKADDR_UN96)98# Check for different ways of gathering OS randomness:99# - Linux getrandom()100check_cxx_source_compiles("101#include <sys/random.h>103int main()104{105getrandom(nullptr, 32, 0);106}107" HAVE_GETRANDOM108)110# - BSD getentropy()111check_cxx_source_compiles("112#include <sys/random.h>114int main()115{116getentropy(nullptr, 32);117}118" HAVE_GETENTROPY_RAND119)122# - BSD sysctl()123check_cxx_source_compiles("124#include <sys/types.h>125#include <sys/sysctl.h>127#ifdef __linux__128#error Don't use sysctl on Linux, it's deprecated even when it works129#endif131int main()132{133sysctl(nullptr, 2, nullptr, nullptr, nullptr, 0);134}135" HAVE_SYSCTL136)138# - BSD sysctl(KERN_ARND)139check_cxx_source_compiles("140#include <sys/types.h>141#include <sys/sysctl.h>143#ifdef __linux__144#error Don't use sysctl on Linux, it's deprecated even when it works145#endif147int main()148{149static int name[2] = {CTL_KERN, KERN_ARND};150sysctl(name, 2, nullptr, nullptr, nullptr, 0);151}152" HAVE_SYSCTL_ARND153)155if(NOT MSVC)156include(CheckSourceCompilesWithFlags)158# Check for SSE4.1 intrinsics.159set(SSE41_CXXFLAGS -msse4.1)160check_cxx_source_compiles_with_flags("161#include <immintrin.h>163int main()164{165__m128i a = _mm_set1_epi32(0);166__m128i b = _mm_set1_epi32(1);167__m128i r = _mm_blend_epi16(a, b, 0xFF);168return _mm_extract_epi32(r, 3);169}170" HAVE_SSE41171CXXFLAGS ${SSE41_CXXFLAGS}172)174# Check for AVX2 intrinsics.175set(AVX2_CXXFLAGS -mavx -mavx2)176check_cxx_source_compiles_with_flags("177#include <immintrin.h>179int main()180{181__m256i l = _mm256_set1_epi32(0);182return _mm256_extract_epi32(l, 7);183}184" HAVE_AVX2185CXXFLAGS ${AVX2_CXXFLAGS}186)188# Check for x86 SHA-NI intrinsics.189set(X86_SHANI_CXXFLAGS -msse4 -msha)190check_cxx_source_compiles_with_flags("191#include <immintrin.h>193int main()194{195__m128i i = _mm_set1_epi32(0);196__m128i j = _mm_set1_epi32(1);197__m128i k = _mm_set1_epi32(2);198return _mm_extract_epi32(_mm_sha256rnds2_epu32(i, j, k), 0);199}200" HAVE_X86_SHANI201CXXFLAGS ${X86_SHANI_CXXFLAGS}202)204# Check for ARMv8 SHA-NI intrinsics.205set(ARM_SHANI_CXXFLAGS -march=armv8-a+crypto)206check_cxx_source_compiles_with_flags("207#include <arm_neon.h>209int main()210{211uint32x4_t a, b, c;212vsha256h2q_u32(a, b, c);213vsha256hq_u32(a, b, c);214vsha256su0q_u32(a, b);215vsha256su1q_u32(a, b, c);216}217" HAVE_ARM_SHANI218CXXFLAGS ${ARM_SHANI_CXXFLAGS}219)220endif()
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.