CheckCXXFeatures.cmake raw
1 # Copyright (c) 2026-present The Bitcoin Core developers
2 # Distributed under the MIT software license, see the accompanying
3 # file COPYING or https://opensource.org/license/mit/.
4
5 include_guard(GLOBAL)
6
7 # Checks for C++ features required to compile Bitcoin Core.
8
9 include(CheckCXXSourceCompiles)
10
11 function(check_cxx_features)
12 set(CMAKE_REQUIRED_QUIET TRUE)
13
14 message(STATUS "Checking for required C++ features")
15
16 # Checks for Class Template Argument Deduction for aggregate types - used in src/util/overloaded.h
17 check_cxx_source_compiles("
18 #include <variant>
19
20 template<class... Ts> struct Overloaded : Ts... { using Ts::operator()...; };
21
22 int main() {
23 std::variant<int, double> v = 42;
24 return std::visit(Overloaded{
25 [](int) { return 0; },
26 [](double) { return 1; }
27 }, v);
28 }
29 " HAVE_CTAD_FOR_AGGREGATES)
30
31 if(NOT HAVE_CTAD_FOR_AGGREGATES)
32 message(FATAL_ERROR
33 "Compiler lacks Class Template Argument Deduction (CTAD) for aggregates.\n"
34 "This C++ feature is required for src/util/overloaded.h.\n"
35 "You are probably using an old compiler version\n"
36 "The recommended compiler versions can be checked in\n"
37 "doc/dependencies.md#compiler.\n"
38 )
39 endif()
40
41 message(STATUS "Checking for required C++ features - done")
42
43 endfunction()
44