mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-28 14:55:22 +02:00
build: Add CTAD feature check
This commit is contained in:
@@ -189,6 +189,14 @@ 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}")
|
||||
|
||||
#=============================
|
||||
# C++ Feature Detection
|
||||
#=============================
|
||||
# In case the compiler is not GCC, Clang or MSVC this provides extra checks
|
||||
# which verify that some features are available in the standard library.
|
||||
include(CheckCXXFeatures)
|
||||
check_cxx_features()
|
||||
|
||||
set(configure_warnings)
|
||||
|
||||
include(CheckLinkerSupportsPIE)
|
||||
|
||||
45
cmake/module/CheckCXXFeatures.cmake
Normal file
45
cmake/module/CheckCXXFeatures.cmake
Normal file
@@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2026-present The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or https://opensource.org/license/mit/.
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
#Checks for C++ features required to compile Bitcoin Core.
|
||||
|
||||
include(CheckCXXSourceCompiles)
|
||||
|
||||
function(check_cxx_features)
|
||||
set(CMAKE_REQUIRED_QUIET TRUE)
|
||||
|
||||
message(STATUS "Checking for required C++ features")
|
||||
|
||||
# Checks for Class Template Argument Deduction for aggregate types - used in src/util/overloaded.h
|
||||
check_cxx_source_compiles("
|
||||
#include <variant>
|
||||
|
||||
template<class... Ts> struct Overloaded : Ts... { using Ts::operator()...; };
|
||||
|
||||
int main() {
|
||||
std::variant<int, double> v = 42;
|
||||
return std::visit(Overloaded{
|
||||
[](int) { return 0; },
|
||||
[](double) { return 1; }
|
||||
}, v);
|
||||
}
|
||||
" HAVE_CTAD_FOR_AGGREGATES)
|
||||
|
||||
if(NOT HAVE_CTAD_FOR_AGGREGATES)
|
||||
message(FATAL_ERROR
|
||||
"Compiler lacks Class Template Argument Deduction (CTAD) for aggregates.\n"
|
||||
"This C++ feature is required for src/util/overloaded.h.\n"
|
||||
"You are probably using an old compiler version\n"
|
||||
"The recommended compiler versions can be checked in:\n"
|
||||
" - GCC -> ${MIN_GCC_DOCS}\n"
|
||||
" - Clang -> ${MIN_CLANG_DOCS}\n"
|
||||
" - MSVC -> ${MIN_MSVC_DOCS}\n"
|
||||
)
|
||||
endif()
|
||||
|
||||
message(STATUS "Checking for required C++ features - done")
|
||||
|
||||
endfunction()
|
||||
Reference in New Issue
Block a user