summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mkspecs/features/qt_configure.prf15
-rw-r--r--mkspecs/features/qt_functions.prf9
-rw-r--r--src/corelib/global/qglobal.h12
3 files changed, 35 insertions, 1 deletions
diff --git a/mkspecs/features/qt_configure.prf b/mkspecs/features/qt_configure.prf
index 7d5814e4b1..72dd1c4c8d 100644
--- a/mkspecs/features/qt_configure.prf
+++ b/mkspecs/features/qt_configure.prf
@@ -1397,6 +1397,21 @@ defineTest(qtConfOutput_feature) {
}
}
+defineTest(qtConfOutput_publicFeature) {
+ name = "$$eval($${1}.name)"
+ isEmpty(name): \
+ name = $$eval($${1}.feature)
+ feature = $$replace(name, [-+.], _)
+
+ $${2} {
+ qtConfOutputVar(append, "publicPro", "QT.global.enabled_features", $$name)
+ qtConfOutputSetDefine("publicHeader", "QT_FEATURE_$$feature", 1)
+ } else {
+ qtConfOutputVar(append, "publicPro", "QT.global.disabled_features", $$name)
+ qtConfOutputSetDefine("publicHeader", "QT_FEATURE_$$feature", -1)
+ }
+}
+
# currently this is somewhat inconsistent, as the feature is output to the public pro file,
# whereas the define is being added to the private pro file.
# This should get cleaned up to add to the private pro and header instead.
diff --git a/mkspecs/features/qt_functions.prf b/mkspecs/features/qt_functions.prf
index f03472d940..7e6433814b 100644
--- a/mkspecs/features/qt_functions.prf
+++ b/mkspecs/features/qt_functions.prf
@@ -302,3 +302,12 @@ defineTest(prepareRecursiveTarget) {
export($${target}.CONFIG)
export($${target}.recurse_target)
}
+
+defineTest(qtConfig) {
+ contains(QT.global.enabled_features, $$1): \
+ return(true)
+ contains(QT.global.disabled_features, $$1): \
+ return(false)
+
+ error("Could not find feature $${1}.")
+}
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index d9ffca3810..e6d65b0f99 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -62,13 +62,23 @@
#endif
// The QT_SUPPORTS macro is deprecated. Don't use it in new code.
-// Instead, use #ifdef/ndef QT_NO_feature.
+// Instead, use QT_CONFIG(feature)
// ### Qt6: remove macro
#ifdef _MSC_VER
# define QT_SUPPORTS(FEATURE) (!defined QT_NO_##FEATURE)
#else
# define QT_SUPPORTS(FEATURE) (!defined(QT_NO_##FEATURE))
#endif
+
+/*
+ The QT_CONFIG macro implements a safe compile time check for features of Qt.
+ Features can be in three states:
+ 0 or undefined: This will lead to a compile error when testing for it
+ -1: The feature is not available
+ 1: The feature is available
+*/
+#define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1)
+
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
# define QT_NO_UNSHARABLE_CONTAINERS
#endif