Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for required C++ features during initial build (std::format, etc) #3479

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/symbols-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ concurrency:

jobs:
Run:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems incidental. Is this a required part of the PR, or a remnant of a previous test?


timeout-minutes: 10
steps:
Expand Down
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
24 changes: 24 additions & 0 deletions cmake/CheckCXXFeature.cmake
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here!

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}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also commented out remnant of testing?

check_cxx_symbol_exists("${SYMBOL}" "${FILES}" "${VARIABLE}")
endif()
endmacro()
31 changes: 31 additions & 0 deletions cmake/RequireCXXFeature.cmake
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably don't need to leave commented-out remnants of testing 😉

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()
2 changes: 1 addition & 1 deletion doc/sphinx/.readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, is this required?

tools:
python: "3.11"
# https://github.com/readthedocs/readthedocs.org/issues/9599
Expand Down
Loading