summaryrefslogtreecommitdiffstats
path: root/src/linguist/linguist/doc/cmake-macros.qdoc
blob: c069a542667d9cdfa46b2dc95258420ebeefeb19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
\page qtlinguist-cmake-qt-add-translation.html
\ingroup cmake-macros-qtlinguisttools

\title qt_add_translation
\target qt6_add_translation

\brief Compiles Qt Linguist .ts files into .qm files.

\warning This function is deprecated. Consider using the target-based
functions \l{qt6_add_lrelease} or \l{qt6_add_translations} instead.

\section1 Synopsis

\badcode
qt_add_translation(<VAR> file1.ts [file2.ts ...]
                    [OPTIONS ...])

qt6_add_translation(<VAR> file1.ts [file2.ts ...]
                    [OPTIONS ...])
\endcode

\section1 Description

Calls \c{lrelease} on each \c{.ts} file passed as an argument, generating
\c{.qm} files. The paths of the generated files are added to \c{<VAR>}.

\section1 Options

You can set additional \c{OPTIONS} that should be passed when \c{lrelease} is
invoked. You can find possible options in the \l{lrelease}{lrelease documentation}.

By default, the \c{qm} files will be placed in the root level of the build
directory. To change this, you can set \c{OUTPUT_LOCATION} as a property
of the source \c{.ts} file.

For example, with the following code, the \c{.qm} files are generated
in a \c{translations} directory below the build directory.

\snippet cmake-macros/examples.cmake set_output_location_on_ts_file

\section1 Examples

Generating \c{helloworld_en.qm}, \c{helloworld_de.qm} in the build
directory:

\snippet cmake-macros/examples.cmake qt_add_translation

Generating \c{helloworld_en.qm}, \c{helloworld_de.qm} in a \c{l10n}
sub-directory:

\snippet cmake-macros/examples.cmake qt_add_translation_output_location
*/

/*!
\page qtlinguist-cmake-qt-create-translation.html
\ingroup cmake-macros-qtlinguisttools

\title qt_create_translation
\target qt6_create_translation

\warning This function is deprecated. Consider using the target-based
functions \l{qt6_add_lupdate} or \l{qt6_add_translations} instead.

\brief Sets up the Qt Linguist translation toolchain.

\section1 Synopsis

\badcode
qt6_create_translation(<VAR> ts-file-or-sources [ts-file-or-sources2 ...]
                       [OPTIONS ...])
\endcode

\section1 Description

Processes given sources (directories or individual files) to generate
Qt Linguist \c{.ts} files. The \c{.ts} files are in turn compiled into \c{.qm}
files of the same base name that are stored in the build
directory. Paths to the generated \c{.qm} files are added to \c{<VAR>}.

The translation files to create or update need to have a \c{.ts} suffix. If
the given file path is not absolute it is resolved relative to the current
source directory. If no \c{.ts} file is passed as an argument, the macro
does nothing.

Any arguments that do not have a \c{.ts} suffix are passed as input to the
\c{lupdate}. \c{lupdate} accepts directories and source files as input.
See also the \l{lupdate}{lupdate documentation} on further details.

\section1 Options

You can set additional \c{OPTIONS} that should be passed when \c{lupdate} is
invoked. You can find possible options in the \l{lupdate}{lupdate documentation}.

\section1 Examples

Recursively look up Qt translations from source files in current directory and
generate or update \c{helloworld_en.ts} and \c{helloworld_de.ts} file using
\c{lupdate}. Compile said files into \c{helloworld_en.qm} and \c{helloworld.de.qm}
files in the build directory:

\snippet cmake-macros/examples.cmake qt_create_translation
*/

/*!
\page qtlinguist-cmake-qt-add-lupdate.html
\ingroup cmake-macros-qtlinguisttools

\title qt_add_lupdate
\target qt6_add_lupdate

\brief Add targets to generate or update Qt Linguist .ts files.

\section1 Synopsis

\badcode
qt_add_lupdate(target TS_FILES file1.ts [file2.ts ...]
               [SOURCES source1.cpp [sources2.cpp ...]]
               [INCLUDE_DIRECTORIES directory1 [directory2 ...]]
               [NO_GLOBAL_TARGET]
               [OPTIONS ...])
\endcode

\versionlessCMakeCommandsNote qt6_add_lupdate()

\section1 Description

Creates a target \c{${target}_lupdate} to generate or update Qt Linguist \c{.ts}
files with \l{lupdate}.

The parameter \c{target} is an existing executable or library target that
contains sources with translatable strings.

The \c{.ts} files must be specified with the argument \c{TS_FILES}.

This function is designed to be used in conjunction with
\l{qt6_add_lrelease}{qt_add_lrelease}.  See also the convenience wrapper
\l{qt6_add_translations}{qt_add_translations}.

\section1 Sources and Include Directories

By default, \c{qt_add_lupdate} extracts the source files and include directories
from the given target and passes them to \c{lupdate}.

With \c{SOURCES} one may explicitly specify source files that contain
translatable strings. This turns off the automatic extraction of source files
from the target.

\c{INCLUDE_DIRECTORIES} can be used to explicitly specify include directories.
This turns off the automatic extraction of include directories from the target.

\section1 Options

You can set additional \c{OPTIONS} that should be passed when \c{lupdate} is
invoked. You can find possible options in the \l{lupdate}{lupdate
documentation}.

\section1 Umbrella Target

In addition to the target \c{${target}_lupdate}, an umbrella target
\c{update_translations} is created. This target will build all
\c{${target}_lupdate} targets that were created with \c{qt_add_lupdate}.

Pass \c{NO_GLOBAL_TARGET} to \c{qt_add_lupdate} to prevent this behavior.

The name of this target can be overridden by setting the variable
\c{QT_GLOBAL_LUPDATE_TARGET} before calling \c{qt_add_lupdate}.

\section1 Examples

Add the targets \c{myapp_lupdate} and \c{update_translations} for updating the
\c{.ts} file of an application \c{myapp}.

\snippet cmake-macros/examples.cmake qt_add_lupdate
*/

/*!
\page qtlinguist-cmake-qt-add-lrelease.html
\ingroup cmake-macros-qtlinguisttools

\title qt_add_lrelease
\target qt6_add_lrelease

\brief Add targets to transform Qt Linguist .ts files into .qm files.

\section1 Synopsis

\badcode
qt_add_lrelease(target TS_FILES file1.ts [file2.ts ...]
                [NO_TARGET_DEPENDENCY]
                [NO_GLOBAL_TARGET]
                [QM_FILES_OUTPUT_VARIABLE variable-name]
                [OPTIONS ...])
\endcode

\versionlessCMakeCommandsNote qt6_add_lrelease()

\section1 Description

Creates a target \c{${target}_lrelease} to transform \c{.ts} files into \c{.qm}
files with \l{lrelease}.

The parameter \c{target} is an existing executable or library target that
contains sources with translatable strings.

The \c{.ts} files must be specified with the argument \c{TS_FILES}.

This function is designed to be used in conjunction with
\l{qt6_add_lupdate}{qt_add_lupdate}.  See also the convenience wrapper
\l{qt6_add_translations}{qt_add_translations}.

\section1 Options

You can set additional \c{OPTIONS} that should be passed when \c{lrelease} is
invoked. You can find possible options in the \l{lrelease}{lrelease
documentation}.

By default, the \c{.qm} files will be placed in the root level of the build
directory. To change this, you can set \c{OUTPUT_LOCATION} as a property
of the source \c{.ts} file.

For example, with the following code, the \c{.qm} files are generated
in a \c{translations} directory below the build directory.

\snippet cmake-macros/examples.cmake set_output_location_on_ts_file

\section1 Processing Generated .qm Files

To further process the generated \c{.qm} files, for example to create install
rules, \c{qt_add_lrelease} can store the paths of the \c{.qm} files in a
variable. Pass \c{QM_FILES_OUTPUT_VARIABLE <variable-name>} to the function for
that.

\section1 Build by Default

By default, the command makes \c{${target}} depend on \c{${target}_lrelease}.
This ensures that the \c{.qm} files are always up-to-date when \c{${target}} is
built. This behavior can be turned off with \c{NO_TARGET_DEPENDENCY}. In this
case, the user must build the \c{${target}_lrelease} target manually.

\section1 Umbrella Target

In addition to the target \c{${target}_lrelease}, an umbrella target
\c{release_translations} is created. This target will build all
\c{${target}_lrelease} targets that were created with \c{qt_add_lrelease}.

Pass \c{NO_GLOBAL_TARGET} to \c{qt_add_lrelease} to prevent this behavior.

The name of this target can be overridden by setting the variable
\c{QT_GLOBAL_LRELEASE_TARGET} before calling \c{qt_add_lrelease}.

\section1 Examples

Add the targets \c{myapp_lrelease} and \c{update_translations} for updating the
\c{.ts} file of an application \c{myapp}. Also, install the generated \c{.qm}
files.

\snippet cmake-macros/examples.cmake qt_add_lrelease_install
*/

/*!
\page qtlinguist-cmake-qt-add-translations.html
\ingroup cmake-macros-qtlinguisttools

\title qt_add_translations
\target qt6_add_translations

\brief Add targets to update and transform Qt Linguist .ts files into .qm files.

\section1 Synopsis

\badcode
qt_add_translations(target TS_FILES file1.ts [file2.ts ...]
                    [RESOURCE_PREFIX [OUTPUT_TARGETS variable-name]]
                    [QM_FILES_OUTPUT_VARIABLE variable-name]
                    [SOURCES]
                    [INCLUDE_DIRECTORIES]
                    [LUPDATE_OPTIONS]
                    [LRELEASE_OPTIONS])
\endcode

\versionlessCMakeCommandsNote qt6_add_translations()

\preliminarycmakecommand

\section1 Description

Creates targets for updating Qt Linguist \c{.ts} files and for transforming them
into \c{.qm} files. This function is a convenience wrapper around
\l{qt6_add_lupdate}{qt_add_lupdate} and \l{qt6_add_lrelease}{qt_add_lrelease}
and aims to offer the most common usage of both functions with one call.

The parameter \c{target} is an existing executable or library target that
contains sources with translatable strings. This function will create the
targets \c{${target}_lupdate}, \c{${target}_lrelease}, \c{update_translations}
and \c{release_translations}. The latter targets are umbrella targets that build
all \c{${target}_lupdate} and \c{${target}}_lrelease targets.

\c{${target}_lrelease} is built automatically whenever \c{${target}} needs to be
built.

The \c{.ts} files must be specified with the argument \c{TS_FILES}.

\section1 Options

You can set additional options for \l{lupdate} and \l{lrelease} with
\c{LUPDATE_OPTIONS} and \c{LRELEASE_OPTIONS}. You can find possible options in
the \l{translations}{translations documentation}.

By default, the \c{.qm} files will be placed in the root level of the build
directory. To change this, you can set \c{OUTPUT_LOCATION} as a property
of the source \c{.ts} file.

For example, with the following code, the \c{.qm} files are generated
in a \c{translations} directory below the build directory.

\snippet cmake-macros/examples.cmake set_output_location_on_ts_file

\section1 Embedding Generated .qm Files in Resources

By default, the generated \c{.qm} files are embedded in a Qt resource that will
be linked into \c{${target}}. The files in the resource are accessible under the
resource prefix \c{"/i18n"}.

You can set the resource prefix with \c{RESOURCE_PREFIX}.

In a static Qt build, when a resource target is created, additional targets can
be created. You can instruct \c{qt_add_translations} to store these targets in a
variable, by passing \c{OUTPUT_TARGETS <variable-name>}.

The automatic resource embedding can be turned off by giving the
\c{QM_FILES_OUTPUT_VARIABLE} option, followed by the name of a variable in which
the command should store the list of generated \c{.qm} files.

\section1 Examples

Add a German translation to a target \c{super_calc} using
\c{qt_add_translations}.

\snippet cmake-macros/examples.cmake qt_add_translations_default

This is roughly equivalent to the following.

\snippet cmake-macros/examples.cmake qt_lupdate_lrelease

Add a Norwegian translation to \c{frogger_game} with a custom resource prefix.

\snippet cmake-macros/examples.cmake qt_add_translations_resource_prefix

Add a Finnish translation to \c{business_logic}, and install the generated
\c{.qm} files.

\snippet cmake-macros/examples.cmake qt_add_translations_install
*/