This commit is contained in:
Hennadii Stepanov 2025-04-29 01:14:41 +02:00 committed by GitHub
commit 5508d23002
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 56 additions and 20 deletions

View file

@ -62,20 +62,17 @@ set(COPYRIGHT_HOLDERS "The %s developers")
set(COPYRIGHT_HOLDERS_FINAL "The ${CLIENT_NAME} developers") set(COPYRIGHT_HOLDERS_FINAL "The ${CLIENT_NAME} developers")
set(CLIENT_BUGREPORT "https://github.com/bitcoin/bitcoin/issues") set(CLIENT_BUGREPORT "https://github.com/bitcoin/bitcoin/issues")
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/module)
#============================= #=============================
# Language setup # Language setup
#============================= #=============================
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_HOST_APPLE) include(EnableLanguage)
# We do not use the install_name_tool when cross-compiling for macOS. bitcoincore_enable_language(CXX)
# So disable this tool check in further enable_language() commands.
set(CMAKE_PLATFORM_HAS_INSTALLNAME FALSE)
endif()
enable_language(CXX)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/module)
include(ProcessConfigurations) include(ProcessConfigurations)
# Flatten static lib dependencies. # Flatten static lib dependencies.
@ -186,16 +183,6 @@ option(BUILD_FOR_FUZZING "Build for fuzzing. Enabling this will disable all othe
option(INSTALL_MAN "Install man pages." ON) option(INSTALL_MAN "Install man pages." ON)
set(APPEND_CPPFLAGS "" CACHE STRING "Preprocessor flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")
set(APPEND_CFLAGS "" CACHE STRING "C compiler flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")
set(APPEND_CXXFLAGS "" CACHE STRING "(Objective) C++ compiler flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")
set(APPEND_LDFLAGS "" CACHE STRING "Linker flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")
# Appending to this low-level rule variables is the only way to
# guarantee that the flags appear at the end of the command line.
string(APPEND CMAKE_CXX_COMPILE_OBJECT " ${APPEND_CPPFLAGS} ${APPEND_CXXFLAGS}")
string(APPEND CMAKE_CXX_CREATE_SHARED_LIBRARY " ${APPEND_LDFLAGS}")
string(APPEND CMAKE_CXX_LINK_EXECUTABLE " ${APPEND_LDFLAGS}")
set(configure_warnings) set(configure_warnings)
include(CheckLinkerSupportsPIE) include(CheckLinkerSupportsPIE)

View file

@ -0,0 +1,50 @@
# Copyright (c) 2025-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
# A wrapper around CMakes `enable_language()` command that
# applies Bitcoin Core-specific settings and checks.
# Implemented as a macro (not a function) because
# `enable_language()` may not be called from within a function.
macro(bitcoincore_enable_language language)
get_cmake_property(_enabled_languages ENABLED_LANGUAGES)
if(NOT "${language}" IN_LIST _enabled_languages)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_HOST_APPLE)
# We do not use the install_name_tool when cross-compiling for macOS.
# So disable this tool check in further enable_language() command.
set(CMAKE_PLATFORM_HAS_INSTALLNAME FALSE)
endif()
enable_language(${language})
set(_description "flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")
set(APPEND_CPPFLAGS "" CACHE STRING "Preprocessor ${_description}")
set(APPEND_LDFLAGS "" CACHE STRING "Linker ${_description}")
if("${language}" MATCHES "^C$")
set(APPEND_CFLAGS "" CACHE STRING "C compiler ${_description}")
endif()
if("${language}" MATCHES "^(CXX|OBJCXX)$")
set(APPEND_CXXFLAGS "" CACHE STRING "(Objective) C++ compiler ${_description}")
string(APPEND CMAKE_${language}_COMPILE_OBJECT " ${APPEND_CPPFLAGS} ${APPEND_CXXFLAGS}")
string(APPEND CMAKE_${language}_CREATE_SHARED_LIBRARY " ${APPEND_LDFLAGS}")
string(APPEND CMAKE_${language}_LINK_EXECUTABLE " ${APPEND_LDFLAGS}")
# CMake's `enable_language()` command internally checks
# whether the compiler is able to compile a simple test program.
# However, it does not take into consideration the contents
# of the user-defined `APPEND_*FLAGS` variables, because they
# modify CMake's compiler configuration variables, which in turn
# become available only after `enable_language()` is invoked.
# Therefore, we test the compiler again at this point.
include(CheckSourceCompiles)
check_source_compiles("${language}" "int main() { return 0; }" ${language}_COMPILER_WORKS)
if(NOT ${language}_COMPILER_WORKS)
unset(${language}_COMPILER_WORKS CACHE)
message(FATAL_ERROR "The ${language} compiler is not able to compile a simple test program.\n"
"Check that the \"APPEND_*FLAGS\" variables are set correctly.\n\n"
)
endif()
endif()
unset(_description)
endif()
unset(_enabled_languages)
endmacro()

View file

@ -52,7 +52,7 @@ get_target_interface(SECP256K1_APPEND_LDFLAGS "" sanitize_interface LINK_OPTIONS
string(STRIP "${SECP256K1_APPEND_LDFLAGS} ${APPEND_LDFLAGS}" SECP256K1_APPEND_LDFLAGS) string(STRIP "${SECP256K1_APPEND_LDFLAGS} ${APPEND_LDFLAGS}" SECP256K1_APPEND_LDFLAGS)
set(SECP256K1_APPEND_LDFLAGS ${SECP256K1_APPEND_LDFLAGS} CACHE STRING "" FORCE) set(SECP256K1_APPEND_LDFLAGS ${SECP256K1_APPEND_LDFLAGS} CACHE STRING "" FORCE)
# We want to build libsecp256k1 with the most tested RelWithDebInfo configuration. # We want to build libsecp256k1 with the most tested RelWithDebInfo configuration.
enable_language(C) bitcoincore_enable_language(C)
foreach(config IN LISTS CMAKE_BUILD_TYPE CMAKE_CONFIGURATION_TYPES) foreach(config IN LISTS CMAKE_BUILD_TYPE CMAKE_CONFIGURATION_TYPES)
if(config STREQUAL "") if(config STREQUAL "")
continue() continue()

View file

@ -3,12 +3,11 @@
# file COPYING or https://opensource.org/license/mit/. # file COPYING or https://opensource.org/license/mit/.
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
enable_language(OBJCXX) bitcoincore_enable_language(OBJCXX)
set(CMAKE_OBJCXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") set(CMAKE_OBJCXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
set(CMAKE_OBJCXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") set(CMAKE_OBJCXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_OBJCXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") set(CMAKE_OBJCXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_OBJCXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}") set(CMAKE_OBJCXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
string(APPEND CMAKE_OBJCXX_COMPILE_OBJECT " ${APPEND_CPPFLAGS} ${APPEND_CXXFLAGS}")
endif() endif()
get_target_property(qt_lib_type Qt6::Core TYPE) get_target_property(qt_lib_type Qt6::Core TYPE)