diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake index 50cebbf342a..c53df7e6bfe 100644 --- a/cmake/QtInternalTargets.cmake +++ b/cmake/QtInternalTargets.cmake @@ -156,6 +156,7 @@ qt_internal_add_global_definition(QT_NO_NARROWING_CONVERSIONS_IN_CONNECT) qt_internal_add_global_definition(QT_EXPLICIT_QFILE_CONSTRUCTION_FROM_PATH) qt_internal_add_global_definition(QT_USE_QSTRINGBUILDER SCOPE PLUGIN TOOL MODULE) qt_internal_add_global_definition(QT_NO_FOREACH) +qt_internal_add_global_definition(QT_NO_STD_FORMAT_SUPPORT SCOPE PLUGIN TOOL MODULE) if(WARNINGS_ARE_ERRORS) qt_internal_set_warnings_are_errors_flags(PlatformModuleInternal INTERFACE) diff --git a/src/corelib/io/qtformat_impl.h b/src/corelib/io/qtformat_impl.h index 31031324ae6..648d0a9afe2 100644 --- a/src/corelib/io/qtformat_impl.h +++ b/src/corelib/io/qtformat_impl.h @@ -12,11 +12,22 @@ #include #include +// Users can disable std::format support in their +// projects by using this definition. +#ifndef QT_NO_STD_FORMAT_SUPPORT + #if (defined(__cpp_lib_format) && (__cpp_lib_format >= 202106L)) #include +// If this macro is defined, std::format support is actually available. +// Use it to provide the implementation! +// Note that any out-of-line helper function should not depend on this +// definition, as it should be unconditionally available even in C++17 builds +// to keep BC. #define QT_SUPPORTS_STD_FORMAT 1 #endif // __cpp_lib_format +#endif // QT_NO_STD_FORMAT_SUPPORT + #endif // QTFORMAT_IMPL_H