diff options
| author | Pierre Lamot <pierre@videolabs.io> | 2024-06-05 10:11:59 +0200 |
|---|---|---|
| committer | Pierre Lamot <pierre@videolabs.io> | 2025-01-08 09:50:51 +0100 |
| commit | 7c68090a33cdf3e8cc96ee98529da89756c014e4 (patch) | |
| tree | c858070c4a2f21a2943be16dda4e552e4cd0bd5f | |
| parent | 223388a91e62b9a916900ebf15a96cecfb7e2eb0 (diff) | |
| download | meson-7c68090a33cdf3e8cc96ee98529da89756c014e4.tar.gz | |
qt module: allow moc to generate json introspection file
| -rw-r--r-- | docs/markdown/Qt6-module.md | 4 | ||||
| -rw-r--r-- | mesonbuild/modules/_qt.py | 24 |
2 files changed, 25 insertions, 3 deletions
diff --git a/docs/markdown/Qt6-module.md b/docs/markdown/Qt6-module.md index 7b6f94715..9e4e01637 100644 --- a/docs/markdown/Qt6-module.md +++ b/docs/markdown/Qt6-module.md @@ -69,6 +69,8 @@ It takes no positional arguments, and the following keyword arguments: directory. For instance, when a file called `subdir/one.input` is processed it generates a file `{target private directory}/subdir/one.out` when `true`, and `{target private directory}/one.out` when `false` (default). + - `output_json` bool: *New in 1.7.0*. If `true`, generates additionnaly a + JSON representation which may be used by external tools such as qmltyperegistrar ## preprocess @@ -111,6 +113,8 @@ This method takes the following keyword arguments: directory. For instance, when a file called `subdir/one.input` is processed it generates a file `{target private directory}/subdir/one.out` when `true`, and `{target private directory}/one.out` when `false` (default). + - `moc_output_json` bool: *New in 1.7.0*. If `true`, generates additionnaly a + JSON representation which may be used by external tools such as qmltyperegistrar It returns an array of targets and sources to pass to a compilation target. diff --git a/mesonbuild/modules/_qt.py b/mesonbuild/modules/_qt.py index 04929a1b0..c37b1034d 100644 --- a/mesonbuild/modules/_qt.py +++ b/mesonbuild/modules/_qt.py @@ -62,6 +62,7 @@ if T.TYPE_CHECKING: include_directories: T.List[T.Union[str, build.IncludeDirs]] dependencies: T.List[T.Union[Dependency, ExternalLibrary]] preserve_paths: bool + output_json: bool class PreprocessKwArgs(TypedDict): @@ -73,6 +74,7 @@ if T.TYPE_CHECKING: moc_extra_arguments: T.List[str] rcc_extra_arguments: T.List[str] uic_extra_arguments: T.List[str] + moc_output_json: bool include_directories: T.List[T.Union[str, build.IncludeDirs]] dependencies: T.List[T.Union[Dependency, ExternalLibrary]] method: str @@ -108,6 +110,7 @@ class QtBaseModule(ExtensionModule): _rcc_supports_depfiles = False _moc_supports_depfiles = False _set_of_qt_tools = {'moc', 'uic', 'rcc', 'lrelease'} + _moc_supports_json = False def __init__(self, interpreter: Interpreter, qt_version: int = 5): ExtensionModule.__init__(self, interpreter) @@ -182,6 +185,7 @@ class QtBaseModule(ExtensionModule): self.compilers_detect(state, qt) if version_compare(qt.version, '>=5.15.0'): self._moc_supports_depfiles = True + self._moc_supports_json = True else: mlog.warning('moc dependencies will not work properly until you move to Qt >= 5.15', fatal=False) if version_compare(qt.version, '>=5.14.0'): @@ -443,6 +447,7 @@ class QtBaseModule(ExtensionModule): KwargInfo('include_directories', ContainerTypeInfo(list, (build.IncludeDirs, str)), listify=True, default=[]), KwargInfo('dependencies', ContainerTypeInfo(list, (Dependency, ExternalLibrary)), listify=True, default=[]), KwargInfo('preserve_paths', bool, default=False, since='1.4.0'), + KwargInfo('output_json', bool, default=False, since='1.7.0'), ) def compile_moc(self, state: ModuleState, args: T.Tuple, kwargs: MocCompilerKwArgs) -> ModuleReturnValue: if any(isinstance(s, (build.CustomTarget, build.CustomTargetIndex, build.GeneratedList)) for s in kwargs['headers']): @@ -475,20 +480,31 @@ class QtBaseModule(ExtensionModule): output: T.List[build.GeneratedList] = [] + do_output_json: bool = kwargs['output_json'] + if do_output_json and not self._moc_supports_json: + raise MesonException(f'moc-qt{self.qt_version} doesn\'t support "output_json" option') + # depfile arguments (defaults to <output-name>.d) DEPFILE_ARGS: T.List[str] = ['--output-dep-file'] if self._moc_supports_depfiles else [] + JSON_ARGS: T.List[str] = ['--output-json'] if do_output_json else [] - arguments = kwargs['extra_args'] + DEPFILE_ARGS + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT@'] + arguments = kwargs['extra_args'] + DEPFILE_ARGS + JSON_ARGS + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT0@'] preserve_path_from = os.path.join(state.source_root, state.subdir) if kwargs['preserve_paths'] else None if kwargs['headers']: + header_gen_output: T.List[str] = ['moc_@BASENAME@.cpp'] + if do_output_json: + header_gen_output.append('moc_@BASENAME@.cpp.json') moc_gen = build.Generator( - self.tools['moc'], arguments, ['moc_@BASENAME@.cpp'], + self.tools['moc'], arguments, header_gen_output, depfile='moc_@BASENAME@.cpp.d', name=f'Qt{self.qt_version} moc header') output.append(moc_gen.process_files(kwargs['headers'], state, preserve_path_from)) if kwargs['sources']: + source_gen_output: T.List[str] = ['@BASENAME@.moc'] + if do_output_json: + source_gen_output.append('@BASENAME@.moc.json') moc_gen = build.Generator( - self.tools['moc'], arguments, ['@BASENAME@.moc'], + self.tools['moc'], arguments, source_gen_output, depfile='@BASENAME@.moc.d', name=f'Qt{self.qt_version} moc source') output.append(moc_gen.process_files(kwargs['sources'], state, preserve_path_from)) @@ -510,6 +526,7 @@ class QtBaseModule(ExtensionModule): KwargInfo('include_directories', ContainerTypeInfo(list, (build.IncludeDirs, str)), listify=True, default=[]), KwargInfo('dependencies', ContainerTypeInfo(list, (Dependency, ExternalLibrary)), listify=True, default=[]), KwargInfo('preserve_paths', bool, default=False, since='1.4.0'), + KwargInfo('moc_output_json', bool, default=False, since='1.7.0'), ) def preprocess(self, state: ModuleState, args: T.List[T.Union[str, File]], kwargs: PreprocessKwArgs) -> ModuleReturnValue: _sources = args[1:] @@ -551,6 +568,7 @@ class QtBaseModule(ExtensionModule): 'dependencies': kwargs['dependencies'], 'method': method, 'preserve_paths': kwargs['preserve_paths'], + 'output_json': kwargs['moc_output_json'] } sources.extend(self._compile_moc_impl(state, moc_kwargs)) |
