summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2016-08-18 22:24:26 +0200
committerLars Knoll <lars.knoll@qt.io>2016-08-19 04:27:17 +0000
commit606924132ff1f11b9d7b4357251f07ccabb8bdb6 (patch)
tree0888b5429afa9194725cf492d17f7bbfb1af01c6 /src
parent48b4e0bf6f1cc4ce4831c2212d57f00fe792468f (diff)
Add support for safe feature checking at compile time
Added a qtConfig(feature) function to qmake, and a QT_CONFIG(feature) macro. These can safely check whether a certain compile time feature of Qt is enabled or not. For this to work the feature has to have a publicFeature or privateFeature output in the configure.json file. In pro files, please use the qtConfig(feature) test function instead of checking contains(QT_CONFIG, feature), as the latter will be unreliable with the upcoming modularization (it requires a load(qt_module_config) before doing any such checks). Note that feature names are now lowercase, and identical (except for hyphens versus underscores currently) in the pro and c++ files. This makes the logic easier to follow, as we avoid all double negations, and most importantly, QT_CONFIG and qtConfig are implemented in a way that you'll get a build error for a mistyped or non-existent feature. This will also prevent accidental use of a widget feature in gui in the future. This gives us complete symmetry between the handling in pro and c++ files. Change-Id: I60404f97953724e639ffb6386cce2e8b1e4b735a Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/qglobal.h12
1 files changed, 11 insertions, 1 deletions
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