summaryrefslogtreecommitdiffstats
path: root/mkspecs/features
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 /mkspecs/features
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 'mkspecs/features')
-rw-r--r--mkspecs/features/qt_configure.prf15
-rw-r--r--mkspecs/features/qt_functions.prf9
2 files changed, 24 insertions, 0 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}.")
+}