aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2020-03-03 10:50:15 -0500
committerJussi Pakkanen <jpakkane@gmail.com>2020-03-08 13:48:27 +0200
commitecb076ba002afb6a6678983dd02ac53d9b751f12 (patch)
tree3a56cfbd3c949efc4cc9434a708772099c19bf7b
parent18f5a197da982ec48473903c0e2defd2d7797eb2 (diff)
downloadmeson-ecb076ba002afb6a6678983dd02ac53d9b751f12.zip
meson-ecb076ba002afb6a6678983dd02ac53d9b751f12.tar.gz
meson-ecb076ba002afb6a6678983dd02ac53d9b751f12.tar.bz2
qt5: Add has_tools() method
-rw-r--r--docs/markdown/Qt5-module.md22
-rw-r--r--docs/markdown/snippets/qt_has_tools.md10
-rw-r--r--mesonbuild/modules/qt.py21
-rw-r--r--test cases/frameworks/4 qt/meson.build1
4 files changed, 53 insertions, 1 deletions
diff --git a/docs/markdown/Qt5-module.md b/docs/markdown/Qt5-module.md
index 3a51954..f1c2f6c 100644
--- a/docs/markdown/Qt5-module.md
+++ b/docs/markdown/Qt5-module.md
@@ -23,6 +23,28 @@ This method generates the necessary targets to build translation files with lrel
- `install_dir` directory to install to (optional).
- `build_by_default` when set to true, to have this target be built by default, that is, when invoking plain ninja; the default value is false (optional).
+## has_tools
+
+This method returns `true` if all tools used by this module are found, `false`
+otherwise.
+
+It should be used to compile optional Qt code:
+```meson
+qt5 = import('qt5')
+if qt5.has_tools(required: get_option('qt_feature'))
+ moc_files = qt5.preprocess(...)
+ ...
+endif
+```
+
+This method takes the following keyword arguments:
+- `required`: by default, `required` is set to `false`. If `required` is set to
+ `true` or an enabled [`feature`](Build-options.md#features) and some tools are
+ missing Meson will abort.
+- `method`: method used to find the Qt dependency (`auto` by default).
+
+*Since: 0.54.0*
+
## Dependencies
See [Qt dependencies](Dependencies.md#qt4-qt5)
diff --git a/docs/markdown/snippets/qt_has_tools.md b/docs/markdown/snippets/qt_has_tools.md
new file mode 100644
index 0000000..3569ecb
--- /dev/null
+++ b/docs/markdown/snippets/qt_has_tools.md
@@ -0,0 +1,10 @@
+## Added `has_tools` method to qt module
+
+It should be used to compile optional Qt code:
+```meson
+qt5 = import('qt5')
+if qt5.has_tools(required: get_option('qt_feature'))
+ moc_files = qt5.preprocess(...)
+ ...
+endif
+```
diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py
index 6887bc7..76edb7e 100644
--- a/mesonbuild/modules/qt.py
+++ b/mesonbuild/modules/qt.py
@@ -19,7 +19,8 @@ from ..mesonlib import MesonException, Popen_safe, extract_as_list, File
from ..dependencies import Dependency, Qt4Dependency, Qt5Dependency
import xml.etree.ElementTree as ET
from . import ModuleReturnValue, get_include_args, ExtensionModule
-from ..interpreterbase import permittedKwargs, FeatureNew, FeatureNewKwargs
+from ..interpreterbase import noPosargs, permittedKwargs, FeatureNew, FeatureNewKwargs
+from ..interpreter import extract_required_kwarg
_QT_DEPS_LUT = {
4: Qt4Dependency,
@@ -32,6 +33,7 @@ class QtBaseModule(ExtensionModule):
def __init__(self, interpreter, qt_version=5):
ExtensionModule.__init__(self, interpreter)
+ self.snippets.add('has_tools')
self.qt_version = qt_version
def _detect_tools(self, env, method):
@@ -117,6 +119,23 @@ class QtBaseModule(ExtensionModule):
except Exception:
return []
+ @noPosargs
+ @permittedKwargs({'method', 'required'})
+ @FeatureNew('qt.has_tools', '0.54.0')
+ def has_tools(self, interpreter, state, args, kwargs):
+ method = kwargs.get('method', 'auto')
+ disabled, required, feature = extract_required_kwarg(kwargs, state.subproject, default=False)
+ if disabled:
+ mlog.log('qt.has_tools skipped: feature', mlog.bold(feature), 'disabled')
+ return False
+ self._detect_tools(state.environment, method)
+ for tool in (self.moc, self.uic, self.rcc, self.lrelease):
+ if not tool.found():
+ if required:
+ raise MesonException('Qt tools not found')
+ return False
+ return True
+
@FeatureNewKwargs('qt.preprocess', '0.49.0', ['uic_extra_arguments'])
@FeatureNewKwargs('qt.preprocess', '0.44.0', ['moc_extra_arguments'])
@FeatureNewKwargs('qt.preprocess', '0.49.0', ['rcc_extra_arguments'])
diff --git a/test cases/frameworks/4 qt/meson.build b/test cases/frameworks/4 qt/meson.build
index 7934572..8f18809 100644
--- a/test cases/frameworks/4 qt/meson.build
+++ b/test cases/frameworks/4 qt/meson.build
@@ -42,6 +42,7 @@ foreach qt : ['qt4', 'qt5']
qtdep = dependency(qt, modules : qt_modules, main : true, private_headers: true, required : required, method : get_option('method'))
if qtdep.found()
qtmodule = import(qt)
+ assert(qtmodule.has_tools())
# The following has two resource files because having two in one target
# requires you to do it properly or you get linker symbol clashes.