Qt5-Module: Add `moc_extra_arguments` keyword support.
This commit adds support for an additional `moc_extra_arguments` keyword. It becomes especially handy, when `moc`-ed sources conditionally provide `slots`, depending on compile time macros (i.e. defines).
This commit is contained in:
parent
14e7b0af25
commit
050a56ad47
|
@ -5,11 +5,11 @@ tools and steps required for Qt. The module has one method.
|
|||
|
||||
## preprocess
|
||||
|
||||
This method takes five keyword arguments, `moc_headers`,
|
||||
`moc_sources`, `ui_files` and `qresources` which define the files that
|
||||
require preprocessing with `moc`, `uic` and `rcc` and 'include_directories' which might be needed by moc. It returns an
|
||||
opaque object that should be passed to a main build target. A simple
|
||||
example would look like this:
|
||||
This method takes six keyword arguments, `moc_headers`, `moc_sources`, `ui_files`, `qresources`
|
||||
and `moc_extra_arguments` which define the files that require preprocessing with `moc`, `uic`
|
||||
and `rcc` and 'include_directories' which might be needed by moc as well as (optional)
|
||||
additional arguments. It returns an opaque object that should be passed to a main build target.
|
||||
A simple example would look like this:
|
||||
|
||||
```meson
|
||||
qt5 = import('qt5')
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
# Adds support for additional Qt5-Module keyword `moc_extra_arguments`
|
||||
|
||||
When `moc`-ing sources, the `moc` tool does not know about any
|
||||
preprocessor macros. The generated code might not match the input
|
||||
files when the linking with the moc input sources happens.
|
||||
|
||||
This amendment allows to specify a a list of additional arguments
|
||||
passed to the `moc` tool. They are called `moc_extra_arguments`.
|
|
@ -84,10 +84,10 @@ class QtBaseModule:
|
|||
except Exception:
|
||||
return []
|
||||
|
||||
@permittedKwargs({'moc_headers', 'moc_sources', 'include_directories', 'ui_files', 'qresources', 'method'})
|
||||
@permittedKwargs({'moc_headers', 'moc_sources', 'moc_extra_arguments', 'include_directories', 'ui_files', 'qresources', 'method'})
|
||||
def preprocess(self, state, args, kwargs):
|
||||
rcc_files, ui_files, moc_headers, moc_sources, sources, include_directories \
|
||||
= extract_as_list(kwargs, 'qresources', 'ui_files', 'moc_headers', 'moc_sources', 'sources', 'include_directories', pop = True)
|
||||
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)
|
||||
sources += args[1:]
|
||||
method = kwargs.get('method', 'auto')
|
||||
self._detect_tools(state.environment, method)
|
||||
|
@ -122,14 +122,23 @@ class QtBaseModule:
|
|||
sources.append(ui_output)
|
||||
inc = get_include_args(include_dirs=include_directories)
|
||||
if len(moc_headers) > 0:
|
||||
if len(moc_extra_arguments) > 0:
|
||||
arguments = moc_extra_arguments + inc + ['@INPUT@', '-o', '@OUTPUT@']
|
||||
else:
|
||||
arguments = inc + ['@INPUT@', '-o', '@OUTPUT@']
|
||||
moc_kwargs = {'output': 'moc_@BASENAME@.cpp',
|
||||
'arguments': inc + ['@INPUT@', '-o', '@OUTPUT@']}
|
||||
'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:
|
||||
if len(moc_extra_arguments) > 0:
|
||||
concatinated_moc_extra_arguments = ' '.join(moc_extra_arguments)
|
||||
arguments = [concatinated_moc_extra_arguments, '@INPUT@', '-o', '@OUTPUT@']
|
||||
else:
|
||||
arguments = ['@INPUT@', '-o', '@OUTPUT@']
|
||||
moc_kwargs = {'output': '@BASENAME@.moc',
|
||||
'arguments': ['@INPUT@', '-o', '@OUTPUT@']}
|
||||
'arguments': arguments}
|
||||
moc_gen = build.Generator([self.moc], moc_kwargs)
|
||||
moc_output = moc_gen.process_files('Qt{} moc source'.format(self.qt_version), moc_sources, state)
|
||||
sources.append(moc_output)
|
||||
|
|
Loading…
Reference in New Issue