diff --git a/.github/workflows/symbols-check.yml b/.github/workflows/symbols-check.yml index b0639ca33e8..aebaa7fc80b 100644 --- a/.github/workflows/symbols-check.yml +++ b/.github/workflows/symbols-check.yml @@ -13,7 +13,7 @@ concurrency: jobs: Run: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 timeout-minutes: 10 steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index cdfb9136173..4f3ab4652f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,17 @@ set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_STANDARD_REQUIRED ON) +include (cmake/CheckCXXFeature.cmake) +include (cmake/RequireCXXFeature.cmake) +# Reference: https://en.cppreference.com/w/cpp/utility/feature_test + +# Required C++ features +require_cxx_feature(__cpp_constexpr) + +# Required C++ standard library features +require_cxx_feature(__cpp_lib_format) + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -g -Wall -pedantic -Wextra -fPIC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -g -Wall -fno-strict-aliasing -pedantic -Wnon-virtual-dtor -Wextra -fPIC") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed") diff --git a/cmake/CheckCXXFeature.cmake b/cmake/CheckCXXFeature.cmake new file mode 100644 index 00000000000..27f0306ec56 --- /dev/null +++ b/cmake/CheckCXXFeature.cmake @@ -0,0 +1,24 @@ + +# https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations#table-of-feature-test-macros +# https://en.cppreference.com/w/cpp/feature_test +# https://en.cppreference.com/w/cpp/utility/feature_test + +include_guard(GLOBAL) + +#include (CheckSymbolExists) +include (CheckCXXSymbolExists) + +macro(CHECK_CXX_FEATURE SYMBOL VARIABLE) + if (NOT DEFINED "${SYMBOL}") + # Feature testing is only available since C++20 + if (NOT CMAKE_CXX_COMPILE_FEATURES MATCHES "cxx_std_20") + message(FATAL_ERROR "C++20 support is required!\n") + endif() + + # Header containing the available C++ standard library features + set(FILES "version") + + #__CHECK_SYMBOL_EXISTS_IMPL(RequireCXXFeature.cxx "${SYMBOL}" "${FILES}" "${VARIABLE}") + check_cxx_symbol_exists("${SYMBOL}" "${FILES}" "${VARIABLE}") + endif() +endmacro() diff --git a/cmake/RequireCXXFeature.cmake b/cmake/RequireCXXFeature.cmake new file mode 100644 index 00000000000..4b7cf67902d --- /dev/null +++ b/cmake/RequireCXXFeature.cmake @@ -0,0 +1,31 @@ + +# https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations#table-of-feature-test-macros +# https://en.cppreference.com/w/cpp/feature_test +# https://en.cppreference.com/w/cpp/utility/feature_test + +include_guard(GLOBAL) + +#include (CheckSymbolExists) +include (CheckCXXSymbolExists) + +macro(REQUIRE_CXX_FEATURE SYMBOL) + if (NOT DEFINED "${SYMBOL}") + # Feature testing is only available since C++20 + if (NOT CMAKE_CXX_COMPILE_FEATURES MATCHES "cxx_std_20") + message(FATAL_ERROR "C++20 support is required!\n") + endif() + + # Header containing the available C++ standard library features + set(FILES "version") + + #__CHECK_SYMBOL_EXISTS_IMPL(RequireCXXFeature.cxx "${SYMBOL}" "${FILES}" "${SYMBOL}") + check_cxx_symbol_exists("${SYMBOL}" "${FILES}" "${SYMBOL}") + + # To us, failure is a fatal error + if (NOT "${${SYMBOL}}") + # Unset the variable cached by "symbol exists" check + unset("${SYMBOL}" CACHE) + message(FATAL_ERROR "Required C++ feature ${SYMBOL} not found!\nSee the feature test documentation, or https://en.cppreference.com/w/cpp/feature_test for details.\n") + endif() + endif() +endmacro() diff --git a/doc/sphinx/.readthedocs.yaml b/doc/sphinx/.readthedocs.yaml index 19ed80c99a5..93a384c2b0f 100644 --- a/doc/sphinx/.readthedocs.yaml +++ b/doc/sphinx/.readthedocs.yaml @@ -7,7 +7,7 @@ version: 2 # Set the version of Python and other tools you might need build: - os: ubuntu-22.04 + os: ubuntu-24.04 tools: python: "3.11" # https://github.com/readthedocs/readthedocs.org/issues/9599