diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake index b9af6395036..cb4718845d0 100644 --- a/cmake/QtFeature.cmake +++ b/cmake/QtFeature.cmake @@ -938,7 +938,9 @@ function(qt_config_compile_test name) endif() if(arg_CXX_STANDARD) - set(CMAKE_CXX_STANDARD "${arg_CXX_STANDARD}") + if(${arg_CXX_STANDARD} LESS 23 OR ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.20") + set(CMAKE_CXX_STANDARD "${arg_CXX_STANDARD}") + endif() endif() set(CMAKE_REQUIRED_FLAGS ${arg_COMPILE_OPTIONS}) diff --git a/cmake/QtFlagHandlingHelpers.cmake b/cmake/QtFlagHandlingHelpers.cmake index c01b596b802..e678e66bebb 100644 --- a/cmake/QtFlagHandlingHelpers.cmake +++ b/cmake/QtFlagHandlingHelpers.cmake @@ -230,7 +230,9 @@ endfunction() function(qt_set_language_standards) ## Use the latest standard the compiler supports (same as qt_common.prf) - if (QT_FEATURE_cxx20) + if (QT_FEATURE_cxx2b) + set(CMAKE_CXX_STANDARD 23 PARENT_SCOPE) + elseif (QT_FEATURE_cxx20) set(CMAKE_CXX_STANDARD 20 PARENT_SCOPE) else() set(CMAKE_CXX_STANDARD 17 PARENT_SCOPE) diff --git a/config_help.txt b/config_help.txt index 2a97f525ea0..aabf2aab4ad 100644 --- a/config_help.txt +++ b/config_help.txt @@ -110,7 +110,7 @@ Build options: for example, -sanitize address cannot be combined with -sanitize thread. - -c++std .... Select C++ standard [c++20/c++17/c++14/c++11] + -c++std .... Select C++ standard [c++2b/c++20/c++17/c++14/c++11] -sse2 ................ Use SSE2 instructions [auto] -sse3/-ssse3/-sse4.1/-sse4.2/-avx/-avx2/-avx512 diff --git a/configure.cmake b/configure.cmake index 381bcf7bd1f..d8d5f99a1da 100644 --- a/configure.cmake +++ b/configure.cmake @@ -177,6 +177,25 @@ int main(void) CXX_STANDARD 20 ) +qt_config_compile_test(cxx2b + LABEL "C++2b support" + CODE +"#if __cplusplus > 202002L +// Compiler claims to support C++2B, trust it +#else +# error __cplusplus must be > 202002L (the value for C++20) +#endif + +int main(void) +{ + /* BEGIN TEST: */ + /* END TEST: */ + return 0; +} +" + CXX_STANDARD 23 +) + # precompile_header qt_config_compile_test(precompile_header LABEL "precompiled header support" @@ -642,6 +661,11 @@ qt_feature("c++2b" PUBLIC AUTODETECT OFF ) qt_feature_config("c++2b" QMAKE_PUBLIC_QT_CONFIG) +qt_feature("c++2b" PUBLIC + LABEL "C++2b" + AUTODETECT FALSE + CONDITION QT_FEATURE_cxx20 AND (CMAKE_VERSION VERSION_GREATER_EQUAL "3.20") AND TEST_cxx2b +) qt_feature("c89" LABEL "C89" ) @@ -1061,7 +1085,7 @@ qt_configure_add_summary_entry( ) qt_configure_add_summary_entry( TYPE "firstAvailableFeature" - ARGS "c++20 c++17 c++14 c++11" + ARGS "c++2b c++20 c++17 c++14 c++11" MESSAGE "Using C++ standard" ) qt_configure_add_summary_entry( diff --git a/qt_cmdline.cmake b/qt_cmdline.cmake index a6dd809bf64..c0c875fa783 100644 --- a/qt_cmdline.cmake +++ b/qt_cmdline.cmake @@ -138,18 +138,27 @@ function(qt_commandline_cxxstd arg val nextok) qtConfCommandlineSetInput(c++14 no) qtConfCommandlineSetInput(c++17 no) qtConfCommandlineSetInput(c++20 no) + qtConfCommandlineSetInput(c++2b no) elseif(val MATCHES "(c\\+\\+)?(14|1y)") qtConfCommandlineSetInput(c++14 yes) qtConfCommandlineSetInput(c++17 no) qtConfCommandlineSetInput(c++20 no) + qtConfCommandlineSetInput(c++2b no) elseif(val MATCHES "(c\\+\\+)?(17|1z)") qtConfCommandlineSetInput(c++14 yes) qtConfCommandlineSetInput(c++17 yes) qtConfCommandlineSetInput(c++20 no) + qtConfCommandlineSetInput(c++2b no) elseif(val MATCHES "(c\\+\\+)?(20|2a)") qtConfCommandlineSetInput(c++14 yes) qtConfCommandlineSetInput(c++17 yes) qtConfCommandlineSetInput(c++20 yes) + qtConfCommandlineSetInput(c++2b no) + elseif(val MATCHES "(c\\+\\+)?(2b)") + qtConfCommandlineSetInput(c++14 yes) + qtConfCommandlineSetInput(c++17 yes) + qtConfCommandlineSetInput(c++20 yes) + qtConfCommandlineSetInput(c++2b yes) else() qtConfAddError("Invalid argument '${val}' to command line parameter '${arg}'") endif()