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) 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)6include(CheckCXXSourceCompiles)8#[=[9Usage example:11try_append_linker_flag("-Wl,--major-subsystem-version,6" TARGET core_interface)14In configuration output, this function prints a string by the following pattern:16-- Performing Test LINKER_SUPPORTS_[flag]17-- Performing Test LINKER_SUPPORTS_[flag] - Success19]=]20function(try_append_linker_flag flag)21cmake_parse_arguments(PARSE_ARGV 122TALF # prefix23"NO_CACHE_IF_FAILED" # options24"TARGET;VAR;SOURCE;RESULT_VAR" # one_value_keywords25"IF_CHECK_PASSED" # multi_value_keywords26)28string(MAKE_C_IDENTIFIER "${flag}" result)29string(TOUPPER "${result}" result)30string(PREPEND result LINKER_SUPPORTS_)32set(source "int main() { return 0; }")33if(DEFINED TALF_SOURCE AND NOT TALF_SOURCE STREQUAL source)34set(source "${TALF_SOURCE}")35string(SHA256 source_hash "${source}")36string(SUBSTRING ${source_hash} 0 4 source_hash_head)37string(APPEND result _${source_hash_head})38endif()40# This forces running a linker.41set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE)42set(CMAKE_REQUIRED_LINK_OPTIONS ${flag} ${working_linker_werror_flag})43check_cxx_source_compiles("${source}" ${result})45if(${result})46if(DEFINED TALF_IF_CHECK_PASSED)47if(DEFINED TALF_TARGET)48target_link_options(${TALF_TARGET} INTERFACE ${TALF_IF_CHECK_PASSED})49endif()50if(DEFINED TALF_VAR)51list(JOIN TALF_IF_CHECK_PASSED " " flags_if_check_passed_as_string)52string(STRIP "${${TALF_VAR}} ${flags_if_check_passed_as_string}" ${TALF_VAR})53endif()54else()55if(DEFINED TALF_TARGET)56target_link_options(${TALF_TARGET} INTERFACE ${flag})57endif()58if(DEFINED TALF_VAR)59string(STRIP "${${TALF_VAR}} ${flag}" ${TALF_VAR})60endif()61endif()62endif()64if(DEFINED TALF_VAR)65set(${TALF_VAR} "${${TALF_VAR}}" PARENT_SCOPE)66endif()68if(DEFINED TALF_RESULT_VAR)69set(${TALF_RESULT_VAR} "${${result}}" PARENT_SCOPE)70endif()72if(NOT ${result} AND TALF_NO_CACHE_IF_FAILED)73unset(${result} CACHE)74endif()75endfunction()77if(MSVC)78try_append_linker_flag("/WX" VAR working_linker_werror_flag)79elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")80try_append_linker_flag("-Wl,-fatal_warnings" VAR working_linker_werror_flag)81else()82try_append_linker_flag("-Wl,--fatal-warnings" VAR working_linker_werror_flag)83endif()
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.