diff options
author | Ivan Solovev <[email protected]> | 2025-04-04 16:17:44 +0200 |
---|---|---|
committer | Tor Arne Vestbø <[email protected]> | 2025-04-07 13:03:12 +0000 |
commit | f0573e93dff25c74287b3083d2c525c2daaa317c (patch) | |
tree | b1c9c0ae7dd3a5a71a1ed24ccabd6d0842a7bf02 | |
parent | d8fb42bb790f468ad1b5304b743dbff297582ddd (diff) |
Add a separate QT_FEATURE for std::format
We want tst_qfloat16 to be built in C++20 mode, even if Qt itself is
not built in C++20 mode, which means we can't use QT_FEATURE_cxx20 as
check in tst_qfloat16's CMakeLists.txt.
In addition, even if the compiler supports C++20, the standard library
may not support all features we need. Specifically, due to the
deployment target of macOS being 12 we can't rely on std::to_chars
being available, as is only available since macOS 13.4.
This patch introduces a separate QT_FEATURE_cxx20_format, and
adjusts the tst_qfloat16's CMakeLists.txt to use this feature.
Note that we intentionally do not add QT_FEATURE_cxx20 as a
hard condition to the new check, because it might be disabled
during the Qt configuration, but we still want the test to be
built in C++20 mode.
Note also, that we cannot use the QT_CONFIG(cxx20_format)
check in the qtformat_impl.h header, because the std::format
support is header-only, and user project might be compiled
for a different minimal macOS version, so we do not want to
rely on the Qt-specific config.
Pick-to: 6.9 6.8
Change-Id: Ibc43d243dbb24fcb922647fe2d90f61491144eb7
Reviewed-by: Tor Arne Vestbø <[email protected]>
-rw-r--r-- | src/corelib/configure.cmake | 27 | ||||
-rw-r--r-- | tests/auto/corelib/global/qfloat16/CMakeLists.txt | 2 |
2 files changed, 28 insertions, 1 deletions
diff --git a/src/corelib/configure.cmake b/src/corelib/configure.cmake index 0b80923cf6b..7e0c05b0148 100644 --- a/src/corelib/configure.cmake +++ b/src/corelib/configure.cmake @@ -552,6 +552,28 @@ int main(void) } ") +# std::format support +qt_config_compile_test(cxx20_format + LABEL "C++20 std::format support" + CODE +"#include <format> +#include <string> + +#if !defined(__cpp_lib_format) || (__cpp_lib_format < 202106L) +#error +#endif + +int main(void) +{ + /* BEGIN TEST: */ +const auto s = std::format(\"{}\", 1); + /* END TEST: */ + return 0; +} +" + CXX_STANDARD 20 +) + # <stacktrace> qt_config_compile_test(cxx23_stacktrace LABEL "C++23 <stacktrace> support" @@ -849,6 +871,11 @@ qt_feature("backtrace" PRIVATE LABEL "backtrace" CONDITION UNIX AND QT_FEATURE_regularexpression AND WrapBacktrace_FOUND ) +qt_feature("cxx20_format" PRIVATE + LABEL "C++20 std::format support" + CONDITION TEST_cxx20_format # intentionally not checking QT_FEATURE_cxx20! + AUTODETECT TRUE +) qt_feature("cxx23_stacktrace" PRIVATE LABEL "C++23 <stacktrace>" CONDITION TEST_cxx23_stacktrace AND QT_FEATURE_cxx2b diff --git a/tests/auto/corelib/global/qfloat16/CMakeLists.txt b/tests/auto/corelib/global/qfloat16/CMakeLists.txt index f659036073c..2d4afc6569c 100644 --- a/tests/auto/corelib/global/qfloat16/CMakeLists.txt +++ b/tests/auto/corelib/global/qfloat16/CMakeLists.txt @@ -19,7 +19,7 @@ qt_internal_add_test(tst_qfloat16 ) # To test std::format support, if possible -if(NOT VXWORKS) +if(QT_FEATURE_cxx20_format) set_target_properties(tst_qfloat16 PROPERTIES CXX_STANDARD 20 |