| 1 |
## compile_resources |
| 2 |
|
| 3 |
*New in 0.59.0* |
| 4 |
|
| 5 |
Compiles Qt's resources collection files (.qrc) into c++ files for compilation. |
| 6 |
|
| 7 |
It takes no positional arguments, and the following keyword arguments: |
| 8 |
- `name` (string | empty): if provided a single .cpp file will be generated, |
| 9 |
and the output of all qrc files will be combined in this file, otherwise |
| 10 |
each qrc file be written to its own cpp file. |
| 11 |
- `sources` (File | string | custom_target | custom_target index | generator_output)[]: |
| 12 |
A list of sources to be transpiled. Required, must have at least one source |
| 13 |
*New in 0.60.0*: support for custom_target, custom_target_index, and generator_output. |
| 14 |
- `extra_args` string[]: Extra arguments to pass directly to `qt-rcc` |
| 15 |
- `method` string: The method to use to detect Qt, see `dependency()` for more |
| 16 |
information. |
| 17 |
|
| 18 |
## compile_ui |
| 19 |
|
| 20 |
*New in 0.59.0* |
| 21 |
|
| 22 |
Compiles Qt's ui files (.ui) into header files. |
| 23 |
|
| 24 |
It takes no positional arguments, and the following keyword arguments: |
| 25 |
- `sources` (File | string | custom_target | custom_target index | generator_output)[]: |
| 26 |
A list of sources to be transpiled. Required, must have at least one source |
| 27 |
*New in 0.60.0*: support for custom_target, custom_target_index, and generator_output. |
| 28 |
- `extra_args` string[]: Extra arguments to pass directly to `qt-uic` |
| 29 |
- `method` string: The method to use to detect Qt, see `dependency()` for more |
| 30 |
information. |
| 31 |
- `preserve_paths` bool: *Since 1.4.0*. If `true`, specifies that the output |
| 32 |
files need to maintain their directory structure inside the target temporary |
| 33 |
directory. For instance, when a file called `subdir/one.input` is processed |
| 34 |
it generates a file `{target private directory}/subdir/one.out` when `true`, |
| 35 |
and `{target private directory}/one.out` when `false` (default). |
| 36 |
|
| 37 |
## compile_moc |
| 38 |
|
| 39 |
*New in 0.59.0* |
| 40 |
|
| 41 |
Compiles Qt's moc files (.moc) into header and/or source files. At least one of |
| 42 |
the keyword arguments `headers` and `sources` must be provided. |
| 43 |
|
| 44 |
It takes no positional arguments, and the following keyword arguments: |
| 45 |
- `sources` (File | string | custom_target | custom_target index | generator_output)[]: |
| 46 |
A list of sources to be transpiled into .moc files for manual inclusion. |
| 47 |
*New in 0.60.0*: support for custom_target, custom_target_index, and generator_output. |
| 48 |
- `headers` (File | string | custom_target | custom_target index | generator_output)[]: |
| 49 |
A list of headers to be transpiled into .cpp files |
| 50 |
*New in 0.60.0*: support for custom_target, custom_target_index, and generator_output. |
| 51 |
- `extra_args` string[]: Extra arguments to pass directly to `qt-moc` |
| 52 |
- `method` string: The method to use to detect Qt, see `dependency()` for more |
| 53 |
information. |
| 54 |
- `dependencies`: dependency objects whose include directories are used by moc. |
| 55 |
- `include_directories` (string | IncludeDirectory)[]: A list of `include_directory()` |
| 56 |
objects used when transpiling the .moc files |
| 57 |
- `preserve_paths` bool: *New in 1.4.0*. If `true`, specifies that the output |
| 58 |
files need to maintain their directory structure inside the target temporary |
| 59 |
directory. For instance, when a file called `subdir/one.input` is processed |
| 60 |
it generates a file `{target private directory}/subdir/one.out` when `true`, |
| 61 |
and `{target private directory}/one.out` when `false` (default). |
| 62 |
|
| 63 |
## preprocess |
| 64 |
|
| 65 |
Consider using `compile_resources`, `compile_ui`, and `compile_moc` instead. |
| 66 |
|
| 67 |
Takes sources for moc, uic, and rcc, and converts them into c++ files for |
| 68 |
compilation. |
| 69 |
|
| 70 |
Has the following signature: `qt.preprocess(name: str | None, *sources: str)` |
| 71 |
|
| 72 |
If the `name` parameter is passed then all of the rcc files will be written to a single output file |
| 73 |
|
| 74 |
The variadic `sources` arguments have been deprecated since Meson 0.59.0, as has the `sources` keyword argument. These passed files unmodified through the preprocessor, don't do this, just add the output of the generator to another sources list: |
| 75 |
```meson |
| 76 |
sources = files('a.cpp', 'main.cpp', 'bar.c') |
| 77 |
sources += qt.preprocess(qresources : ['resources']) |
| 78 |
``` |
| 79 |
|
| 80 |
This method takes the following keyword arguments: |
| 81 |
- `qresources` (string | File)[]: Passed to the RCC compiler |
| 82 |
- `ui_files`: (string | File | CustomTarget)[]: Passed the `uic` compiler |
| 83 |
- `moc_sources`: (string | File | CustomTarget)[]: Passed the `moc` compiler. These are converted into .moc files meant to be `#include`ed |
| 84 |
- `moc_headers`: (string | File | CustomTarget)[]: Passed the `moc` compiler. These will be converted into .cpp files |
| 85 |
- `include_directories` (IncludeDirectories | string)[], the directories to add to header search path for `moc` |
| 86 |
- `moc_extra_arguments` string[]: any additional arguments to `moc`. Since v0.44.0. |
| 87 |
- `uic_extra_arguments` string[]: any additional arguments to `uic`. Since v0.49.0. |
| 88 |
- `rcc_extra_arguments` string[]: any additional arguments to `rcc`. Since v0.49.0. |
| 89 |
- `dependencies` Dependency[]: dependency objects needed by moc. Available since v0.48.0. |
| 90 |
- `sources`: a list of extra sources, which are added to the output unchanged. Deprecated in 0.59.0. |
| 91 |
- `preserve_paths` bool: *New in 1.4.0*. If `true`, specifies that the output |
| 92 |
files need to maintain their directory structure inside the target temporary |
| 93 |
directory. For instance, when a file called `subdir/one.input` is processed |
| 94 |
it generates a file `{target private directory}/subdir/one.out` when `true`, |
| 95 |
and `{target private directory}/one.out` when `false` (default). |
| 96 |
|
| 97 |
It returns an array of targets and sources to pass to a compilation target. |
| 98 |
|
| 99 |
## compile_translations |
| 100 |
|
| 101 |
*since 0.44.0* |
| 102 |
|
| 103 |
This method generates the necessary targets to build translation files with |
| 104 |
lrelease, it takes no positional arguments, and the following keyword arguments: |
| 105 |
|
| 106 |
- `ts_files` (File | string | custom_target | custom_target index | generator_output)[]: |
| 107 |
the list of input translation files produced by Qt's lupdate tool. |
| 108 |
*New in 0.60.0*: support for custom_target, custom_target_index, and generator_output. |
| 109 |
- `install` bool: when true, this target is installed during the install step (optional). |
| 110 |
- `install_dir` string: directory to install to (optional). |
| 111 |
- `build_by_default` bool: when set to true, to have this target be built by |
| 112 |
default, that is, when invoking `meson compile`; the default value is false |
| 113 |
(optional). |
| 114 |
- `qresource` string: rcc source file to extract ts_files from; cannot be used |
| 115 |
with ts_files kwarg. Available since v0.56.0. |
| 116 |
- `rcc_extra_arguments` string[]: any additional arguments to `rcc` (optional), |
| 117 |
when used with `qresource. Available since v0.56.0. |
| 118 |
|
| 119 |
Returns either: a list of custom targets for the compiled |
| 120 |
translations, or, if using a `qresource` file, a single custom target |
| 121 |
containing the processed source file, which should be passed to a main |
| 122 |
build target. |
| 123 |
|
| 124 |
## has_tools |
| 125 |
|
| 126 |
*since 0.54.0* |
| 127 |
|
| 128 |
This method returns `true` if all tools used by this module are found, |
| 129 |
`false` otherwise. |
| 130 |
|
| 131 |
It should be used to compile optional Qt code: |
| 132 |
```meson |
| 133 |
qt5 = import('qt5') |
| 134 |
if qt5.has_tools(required: get_option('qt_feature')) |
| 135 |
moc_files = qt5.preprocess(...) |
| 136 |
... |
| 137 |
endif |
| 138 |
``` |
| 139 |
|
| 140 |
This method takes the following keyword arguments: |
| 141 |
- `required` bool | FeatureOption: by default, `required` is set to `false`. If `required` is set to |
| 142 |
`true` or an enabled [`feature`](Build-options.md#features) and some tools are |
| 143 |
missing Meson will abort. |
| 144 |
- `method` string: method used to find the Qt dependency (`auto` by default). |
| 145 |
|
| 146 |
## Dependencies |
| 147 |
|
| 148 |
See [Qt dependencies](Dependencies.md#qt) |
| 149 |
|
| 150 |
The 'modules' argument is used to include Qt modules in the project. |
| 151 |
See the Qt documentation for the [list of |
| 152 |
modules](http://doc.qt.io/qt-5/qtmodules.html). |
| 153 |
|
| 154 |
The 'private_headers' argument allows usage of Qt's modules private |
| 155 |
headers. (since v0.47.0) |
| 156 |
|
| 157 |
## Example |
| 158 |
A simple example would look like this: |
| 159 |
|
| 160 |
```meson |
| 161 |
qt5 = import('qt5') |
| 162 |
qt5_dep = dependency('qt5', modules: ['Core', 'Gui']) |
| 163 |
inc = include_directories('includes') |
| 164 |
moc_files = qt5.compile_moc(headers : 'myclass.h', |
| 165 |
extra_args: ['-DMAKES_MY_MOC_HEADER_COMPILE'], |
| 166 |
include_directories: inc, |
| 167 |
dependencies: qt5_dep) |
| 168 |
translations = qt5.compile_translations(ts_files : 'myTranslation_fr.ts', build_by_default : true) |
| 169 |
executable('myprog', 'main.cpp', 'myclass.cpp', moc_files, |
| 170 |
include_directories: inc, |
| 171 |
dependencies : qt5_dep) |
| 172 |
``` |
| 173 |
|
| 174 |
Sometimes, translations are embedded inside the binary using qresource |
| 175 |
files. In this case the ts files do not need to be explicitly listed, |
| 176 |
but will be inferred from the built qm files listed in the qresource |
| 177 |
file. For example: |
| 178 |
|
| 179 |
```meson |
| 180 |
qt5 = import('qt5') |
| 181 |
qt5_dep = dependency('qt5', modules: ['Core', 'Gui']) |
| 182 |
lang_cpp = qt5.compile_translations(qresource: 'lang.qrc') |
| 183 |
executable('myprog', 'main.cpp', lang_cpp, |
| 184 |
dependencies: qt5_dep) |
| 185 |
``` |