From 862019e6de9c896e6e876c272db3e5c95393ac3c Mon Sep 17 00:00:00 2001 From: Alexey Rochev Date: Thu, 23 Aug 2018 20:25:29 +0300 Subject: [PATCH] Qt: Allow passing dependency objects to preprocess method (#3470, #3875) --- mesonbuild/modules/qt.py | 25 ++++++++++++++++------ test cases/frameworks/4 qt/meson.build | 10 +++++++++ test cases/frameworks/4 qt/qtinterface.cpp | 8 +++++++ 3 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 test cases/frameworks/4 qt/qtinterface.cpp diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index ccf0930cf..a8e916ab1 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -16,7 +16,7 @@ import os from .. import mlog from .. import build from ..mesonlib import MesonException, Popen_safe, extract_as_list, File -from ..dependencies import Qt4Dependency, Qt5Dependency +from ..dependencies import Dependency, Qt4Dependency, Qt5Dependency import xml.etree.ElementTree as ET from . import ModuleReturnValue, get_include_args from ..interpreterbase import permittedKwargs, FeatureNewKwargs @@ -117,10 +117,10 @@ class QtBaseModule: return [] @FeatureNewKwargs('qt.preprocess', '0.44.0', ['moc_extra_arguments']) - @permittedKwargs({'moc_headers', 'moc_sources', 'moc_extra_arguments', 'include_directories', 'ui_files', 'qresources', 'method'}) + @permittedKwargs({'moc_headers', 'moc_sources', 'moc_extra_arguments', 'include_directories', 'dependencies', 'ui_files', 'qresources', 'method'}) def preprocess(self, state, args, kwargs): - rcc_files, ui_files, moc_headers, moc_sources, moc_extra_arguments, sources, include_directories \ - = extract_as_list(kwargs, 'qresources', 'ui_files', 'moc_headers', 'moc_sources', 'moc_extra_arguments', 'sources', 'include_directories', pop = True) + rcc_files, ui_files, moc_headers, moc_sources, moc_extra_arguments, sources, include_directories, dependencies \ + = extract_as_list(kwargs, 'qresources', 'ui_files', 'moc_headers', 'moc_sources', 'moc_extra_arguments', 'sources', 'include_directories', 'dependencies', pop = True) sources += args[1:] method = kwargs.get('method', 'auto') self._detect_tools(state.environment, method) @@ -166,15 +166,28 @@ class QtBaseModule: ui_output = ui_gen.process_files('Qt{} ui'.format(self.qt_version), ui_files, state) sources.append(ui_output) inc = get_include_args(include_dirs=include_directories) + compile_args = [] + for dep in dependencies: + if hasattr(dep, 'held_object'): + dep = dep.held_object + if isinstance(dep, Dependency): + for arg in dep.get_compile_args(): + if arg.startswith('-I') or arg.startswith('-D'): + compile_args.append(arg) + else: + raise MesonException('Argument is of an unacceptable type {!r}.\nMust be ' + 'either an external dependency (returned by find_library() or ' + 'dependency()) or an internal dependency (returned by ' + 'declare_dependency()).'.format(type(dep).__name__)) if len(moc_headers) > 0: - arguments = moc_extra_arguments + inc + ['@INPUT@', '-o', '@OUTPUT@'] + arguments = moc_extra_arguments + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT@'] moc_kwargs = {'output': 'moc_@BASENAME@.cpp', 'arguments': arguments} moc_gen = build.Generator([self.moc], moc_kwargs) moc_output = moc_gen.process_files('Qt{} moc header'.format(self.qt_version), moc_headers, state) sources.append(moc_output) if len(moc_sources) > 0: - arguments = moc_extra_arguments + inc + ['@INPUT@', '-o', '@OUTPUT@'] + arguments = moc_extra_arguments + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT@'] moc_kwargs = {'output': '@BASENAME@.moc', 'arguments': arguments} moc_gen = build.Generator([self.moc], moc_kwargs) diff --git a/test cases/frameworks/4 qt/meson.build b/test cases/frameworks/4 qt/meson.build index 1d7ff4e57..ae80287b1 100644 --- a/test cases/frameworks/4 qt/meson.build +++ b/test cases/frameworks/4 qt/meson.build @@ -100,6 +100,16 @@ foreach qt : ['qt4', 'qt5'] plugin = library(qt + 'plugin', 'plugin/plugin.cpp', pluginpreprocess, include_directories : plugin_includes, dependencies : qtcore) + + # implementing Qt interfaces requires passing Qt include paths to moc + qtinterfacepreprocess = qtmodule.preprocess( + moc_sources : 'qtinterface.cpp', + dependencies : qtdep + ) + qtinterface = library(qt + 'qtinterface', + sources : ['qtinterface.cpp', qtinterfacepreprocess], + dependencies : qtdep) + if qt == 'qt5' subdir('subfolder') endif diff --git a/test cases/frameworks/4 qt/qtinterface.cpp b/test cases/frameworks/4 qt/qtinterface.cpp new file mode 100644 index 000000000..b2da99f55 --- /dev/null +++ b/test cases/frameworks/4 qt/qtinterface.cpp @@ -0,0 +1,8 @@ +#include + +class Foo : public QGraphicsLayout +{ + Q_INTERFACES(QGraphicsLayout) +}; + +#include "qtinterface.moc"