Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cmake-macros.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2020 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\group cmake-commands-qtlinguisttools
6
\title CMake Commands in Qt6 LinguistTools
7
8
The following CMake commands are defined when Qt6::LinguistTools is loaded, for instance
9
with
10
11
\code
12
find_package(Qt6 REQUIRED COMPONENTS LinguistTools)
13
\endcode
14
15
\sa{CMake Command Reference}
16
*/
17
18
/*!
19
\page qtlinguist-cmake-qt-add-translation.html
20
\ingroup cmake-commands-qtlinguisttools
21
22
\title qt_add_translation
23
\keyword qt6_add_translation
24
25
\summary {Compiles Qt Linguist .ts files into .qm files.}
26
27
\include cmake-find-package-linguisttools.qdocinc
28
29
\warning This function is deprecated. Consider using the target-based
30
functions \l{qt6_add_lrelease} or \l{qt6_add_translations} instead.
31
32
\section1 Synopsis
33
34
\badcode
35
qt_add_translation(<VAR> file1.ts [file2.ts ...]
36
[OPTIONS ...])
37
\endcode
38
39
\versionlessCMakeCommandsNote qt6_add_translation
40
41
\section1 Description
42
43
Calls \c{lrelease} on each \c{.ts} file passed as an argument, generating
44
\c{.qm} files. The paths of the generated files are added to \c{<VAR>}.
45
46
\section1 Options
47
48
You can set additional \c{OPTIONS} that should be passed when \c{lrelease} is
49
invoked. You can find possible options in the \l{lrelease}{lrelease documentation}.
50
51
By default, the \c{qm} files will be placed in the current build directory
52
(\c{CMAKE_CURRENT_BINARY_DIR}). To change this, you can set \c{OUTPUT_LOCATION}
53
as a property of the source \c{.ts} file.
54
55
For example, with the following code, the \c{.qm} files are generated
56
in a \c{translations} directory below the current build directory.
57
58
\snippet cmake-macros/examples.cmake set_output_location_on_ts_file
59
60
\section1 Examples
61
62
Generating \c{helloworld_en.qm}, \c{helloworld_de.qm} in the build
63
directory:
64
65
\snippet cmake-macros/examples.cmake qt_add_translation
66
67
Generating \c{helloworld_en.qm}, \c{helloworld_de.qm} in a \c{l10n}
68
sub-directory:
69
70
\snippet cmake-macros/examples.cmake qt_add_translation_output_location
71
*/
72
73
/*!
74
\page qtlinguist-cmake-qt-create-translation.html
75
\ingroup cmake-commands-qtlinguisttools
76
77
\title qt_create_translation
78
\keyword qt6_create_translation
79
80
\summary {Sets up the Qt Linguist translation toolchain.}
81
82
\include cmake-find-package-linguisttools.qdocinc
83
84
\warning This function is deprecated. Consider using the target-based
85
functions \l{qt6_add_lupdate} or \l{qt6_add_translations} instead.
86
87
\section1 Synopsis
88
89
\badcode
90
qt_create_translation(<VAR> ts-file-or-sources [ts-file-or-sources2 ...]
91
[OPTIONS ...])
92
\endcode
93
94
\versionlessCMakeCommandsNote qt6_create_translation
95
96
\section1 Description
97
98
Processes given sources (directories or individual files) to generate
99
Qt Linguist \c{.ts} files. The \c{.ts} files are in turn compiled into \c{.qm}
100
files of the same base name that are stored in the build
101
directory. Paths to the generated \c{.qm} files are added to \c{<VAR>}.
102
103
The translation files to create or update need to have a \c{.ts} suffix. If
104
the given file path is not absolute it is resolved relative to the current
105
source directory. If no \c{.ts} file is passed as an argument, the macro
106
does nothing.
107
108
Any arguments that do not have a \c{.ts} suffix are passed as input to the
109
\c{lupdate}. \c{lupdate} accepts directories and source files as input.
110
See also the \l{lupdate}{lupdate documentation} on further details.
111
112
\section1 Options
113
114
You can set additional \c{OPTIONS} that should be passed when \c{lupdate} is
115
invoked. You can find possible options in the \l{lupdate}{lupdate documentation}.
116
117
\section1 Examples
118
119
Recursively look up Qt translations from source files in current directory and
120
generate or update \c{helloworld_en.ts} and \c{helloworld_de.ts} file using
121
\c{lupdate}. Compile said files into \c{helloworld_en.qm} and \c{helloworld.de.qm}
122
files in the build directory:
123
124
\snippet cmake-macros/examples.cmake qt_create_translation
125
*/
126
127
/*!
128
\page qtlinguist-cmake-qt-add-lupdate.html
129
\ingroup cmake-commands-qtlinguisttools
130
131
\title qt_add_lupdate
132
\keyword qt6_add_lupdate
133
134
\summary {Add targets to generate or update Qt Linguist .ts files.}
135
136
\include cmake-find-package-linguisttools.qdocinc
137
138
\cmakecommandsince 6.2
139
140
\section1 Synopsis
141
142
Since 6.7:
143
\badcode
144
qt_add_lupdate(TS_FILES file1.ts [file2.ts ...]
145
[PLURALS_TS_FILE file.ts]
146
[SOURCE_TARGETS target1 [target2 ...]]
147
[SOURCES source1.cpp [sources2.cpp ...]]
148
[INCLUDE_DIRECTORIES directory1 [directory2 ...]]
149
[LUPDATE_TARGET target-name]
150
[NO_GLOBAL_TARGET]
151
[OPTIONS ...])
152
\endcode
153
154
Since 6.2 (deprecated):
155
\badcode
156
qt_add_lupdate(target TS_FILES file1.ts [file2.ts ...]
157
[SOURCES source1.cpp [sources2.cpp ...]]
158
[INCLUDE_DIRECTORIES directory1 [directory2 ...]]
159
[NO_GLOBAL_TARGET]
160
[OPTIONS ...])
161
\endcode
162
163
\versionlessCMakeCommandsNote qt6_add_lupdate()
164
165
\section1 Description
166
167
Creates a custom target to generate or update Qt Linguist \c{.ts}
168
files with \l{lupdate}.
169
170
The name of that custom target defaults to \c{${PROJECT_NAME}_lupdate}. Further
171
calls of \c qt_add_lupdate will create target names with an increasing number
172
appended. The custom target name can be specified with the \c LUPDATE_TARGET
173
option.
174
175
With the \c{SOURCE_TARGETS} argument you can specify a list of targets that
176
contain sources with translatable strings. If \c{SOURCE_TARGETS} is not
177
specified, you can specify \c{SOURCES}, which is described below. If neither
178
\c{SOURCE_TARGETS} nor \c{SOURCES} is given, the command
179
\l{qt6_collect_translation_source_targets}{qt_collect_translation_source_targets}
180
is called to retrieve the list of targets.
181
182
The \c{.ts} files must be specified with the argument \c{TS_FILES}.
183
184
This function is designed to be used in conjunction with
185
\l{qt6_add_lrelease}{qt_add_lrelease}. See also the convenience wrapper
186
\l{qt6_add_translations}{qt_add_translations}.
187
188
//! [sources-and-include-dirs]
189
\section1 Sources and Include Directories
190
191
With \c{SOURCES} you can explicitly specify additional source files that contain
192
translatable strings.
193
194
You can use \c{INCLUDE_DIRECTORIES} to explicitly specify include directories
195
for those source files.
196
//! [sources-and-include-dirs]
197
198
\section1 Options
199
200
You can set additional \c{OPTIONS} that should be passed when \c{lupdate} is
201
invoked. You can find possible options in the \l{lupdate}{lupdate
202
documentation}.
203
204
\section1 Umbrella Target
205
206
In addition to the target \c{${target}_lupdate}, an umbrella target
207
\c{update_translations} is created. This target will build all
208
\c{${target}_lupdate} targets that were created with \c{qt_add_lupdate}.
209
210
Pass \c{NO_GLOBAL_TARGET} to \c{qt_add_lupdate} to prevent this behavior.
211
212
The name of this target can be overridden by setting the variable
213
\c{QT_GLOBAL_LUPDATE_TARGET} before calling \c{qt_add_lupdate}.
214
215
//! [plurals-ts-file]
216
\section1 Plural Forms
217
218
\l QT_I18N_SOURCE_LANGUAGE specifies the language in which the source code
219
strings are written. For handling plural forms correctly, create an additional
220
\c{.ts} file for that language that only contains translatable strings for
221
plural forms. See \l{Handle Plural Forms} for details.
222
223
With \c PLURALS_TS_FILE you can specify the \c{.ts} file for the source
224
language. This file will only contain plural forms.
225
//! [plurals-ts-file]
226
227
\section1 Deprecated Command Signature
228
229
Older versions of \c qt_add_lupdate took a target as the first argument. This is
230
deprecated. Use the \c SOURCE_TARGETS argument instead.
231
232
\section1 Examples
233
234
Add the targets \c{myapp_lupdate} and \c{update_translations} for updating the
235
\c{.ts} file of an application \c{myapp}.
236
237
\snippet cmake-macros/examples.cmake qt_add_lupdate
238
239
You can specify the name of the created target by passing the \c LUPDATE_TARGET
240
argument:
241
242
\badcode
243
qt_add_lupdate(
244
LUPDATE_TARGET update_application_translations
245
TS_FILES myapp_de.ts
246
PLURALS_TS_FILE myapp_en.ts
247
)
248
\endcode
249
*/
250
251
/*!
252
\page qtlinguist-cmake-qt-add-lrelease.html
253
\ingroup cmake-commands-qtlinguisttools
254
255
\title qt_add_lrelease
256
\keyword qt6_add_lrelease
257
258
\summary {Add targets to transform Qt Linguist .ts files into .qm files.}
259
260
\include cmake-find-package-linguisttools.qdocinc
261
262
\cmakecommandsince 6.2
263
264
\section1 Synopsis
265
266
Since 6.7:
267
\badcode
268
qt_add_lrelease(TS_FILES file1.ts [file2.ts ...]
269
[LRELEASE_TARGET target-name]
270
[EXCLUDE_FROM_ALL]
271
[NO_GLOBAL_TARGET]
272
[QM_FILES_OUTPUT_VARIABLE variable-name]
273
[OPTIONS ...])
274
\endcode
275
276
Since 6.2 (deprecated):
277
\badcode
278
qt_add_lrelease(target TS_FILES file1.ts [file2.ts ...]
279
[NO_TARGET_DEPENDENCY]
280
[NO_GLOBAL_TARGET]
281
[QM_FILES_OUTPUT_VARIABLE variable-name]
282
[OPTIONS ...])
283
\endcode
284
285
\versionlessCMakeCommandsNote qt6_add_lrelease()
286
287
\warning Calling \c qt_add_lrelease in a directory scope different than the
288
target directory scope requires at least CMake version 3.18.
289
290
\section1 Description
291
292
Creates a custom command to transform \c{.ts} files into \c{.qm} files with
293
\l{lrelease}.
294
295
The execution of the custom command is driven by a custom target that is built
296
by default. The name of that custom target defaults to
297
\c{${PROJECT_NAME}_lrelease}. Further calls of \c qt_add_lrelease will create
298
target names with an increasing number appended. The custom target name can be
299
specified with the \c LRELEASE_TARGET option.
300
301
The \c{.ts} files must be specified with the argument \c{TS_FILES}.
302
303
This function is designed to be used in conjunction with
304
\l{qt6_add_lupdate}{qt_add_lupdate}. See also the convenience wrapper
305
\l{qt6_add_translations}{qt_add_translations}.
306
307
\section1 Options
308
309
You can set additional \c{OPTIONS} that should be passed when \c{lrelease} is
310
invoked. You can find possible options in the \l{lrelease}{lrelease
311
documentation}.
312
313
By default, the \c{.qm} files will be placed in the current build directory
314
(\c{CMAKE_CURRENT_BINARY_DIR}). To change this, you can set \c{OUTPUT_LOCATION}
315
as a property of the source \c{.ts} file.
316
317
For example, with the following code, the \c{.qm} files are generated
318
in a \c{translations} directory below the current build directory.
319
320
\snippet cmake-macros/examples.cmake set_output_location_on_ts_file
321
322
\section1 Processing Generated .qm Files
323
324
To further process the generated \c{.qm} files, for example to create install
325
rules, \c{qt_add_lrelease} can store the paths of the \c{.qm} files in a
326
variable. Pass \c{QM_FILES_OUTPUT_VARIABLE <variable-name>} to the function for
327
that.
328
329
\section1 Build by Default
330
331
By default, the command creates a custom target that is added to the default
332
build target. This ensures that the \c{.qm} files are always up-to-date when the
333
project is built. This behavior can be turned off with the \c{EXCLUDE_FROM_ALL}
334
argument. In this case, the user must build the \c{${PROJECT_NAME}_lrelease}
335
target manually.
336
337
\section1 Umbrella Target
338
339
In addition to the target \c{${target}_lrelease}, an umbrella target
340
\c{release_translations} is created. This target will build all
341
\c{${target}_lrelease} targets that were created with \c{qt_add_lrelease}.
342
343
Pass \c{NO_GLOBAL_TARGET} to \c{qt_add_lrelease} to prevent this behavior.
344
345
The name of this target can be overridden by setting the variable
346
\c{QT_GLOBAL_LRELEASE_TARGET} before calling \c{qt_add_lrelease}.
347
348
\section1 Deprecated Command Signature
349
350
Older versions of \c qt_add_lrelease took a target as the first argument. This
351
is still possible but deprecated.
352
353
\section1 Examples
354
355
Add the targets \c{myapp_lrelease} and \c{release_translations} for transforming
356
the given \c{.ts} files into \c{.qm} files. Also, install the generated \c{.qm}
357
files. The target \c{myapp_lrelease} is built by default.
358
359
\badcode
360
project(myapp)
361
...
362
qt_add_lrelease(
363
TS_FILES myapp_de.ts myapp_fr.ts
364
QM_FILES_OUTPUT_VARIABLE qm_files
365
)
366
install(FILES ${qm_files} DESTINATION "translations")
367
\endcode
368
369
You can specify the name of the created target by passing the \c LRELEASE_TARGET
370
argument:
371
372
\badcode
373
qt_add_lrelease(
374
LRELEASE_TARGET create_myapp_qm_files
375
TS_FILES myapp_de.ts myapp_fr.ts
376
QM_FILES_OUTPUT_VARIABLE qm_files
377
)
378
\endcode
379
*/
380
381
/*!
382
\page qtlinguist-cmake-qt-add-translations.html
383
\ingroup cmake-commands-qtlinguisttools
384
385
\title qt_add_translations
386
\keyword qt6_add_translations
387
388
\summary {Add targets to update and transform Qt Linguist .ts files into .qm files.}
389
390
\include cmake-find-package-linguisttools.qdocinc
391
392
\cmakecommandsince 6.2
393
394
\section1 Synopsis
395
396
Since Qt 6.7:
397
\badcode
398
qt_add_translations([target]
399
[TARGETS target1 [target2...]]
400
[SOURCE_TARGETS target1 [target2...]]
401
[TS_FILE_BASE name]
402
[TS_FILE_DIR directory]
403
[TS_FILES file1.ts [file2.ts ...]]
404
[PLURALS_TS_FILE file.ts]
405
[NO_GENERATE_PLURALS_TS_FILE]
406
[RESOURCE_PREFIX prefix]
407
[OUTPUT_TARGETS variable-name]
408
[TS_FILES_OUTPUT_VARIABLE variable-name] # since 6.8
409
[QM_FILES_OUTPUT_VARIABLE variable-name]
410
[SOURCES source1.cpp [sources2.cpp ...]]
411
[INCLUDE_DIRECTORIES directory1 [directory2 ...]]
412
[LUPDATE_TARGET target-name]
413
[LUPDATE_OPTIONS ...]
414
[LRELEASE_TARGET target-name]
415
[LRELEASE_OPTIONS ...]
416
[IMMEDIATE_CALL])
417
\endcode
418
419
Since Qt 6.2 (deprecated):
420
\badcode
421
qt_add_translations(target TS_FILES file1.ts [file2.ts ...]
422
[RESOURCE_PREFIX prefix]
423
[OUTPUT_TARGETS variable-name]
424
[QM_FILES_OUTPUT_VARIABLE variable-name]
425
[SOURCES source1.cpp [sources2.cpp ...]]
426
[INCLUDE_DIRECTORIES directory1 [directory2 ...]]
427
[LUPDATE_OPTIONS ...]
428
[LRELEASE_OPTIONS ...])
429
\endcode
430
431
\versionlessCMakeCommandsNote qt6_add_translations()
432
433
\warning Calling \c qt_add_translations in a directory scope different than the
434
target directory scope requires at least CMake version 3.18.
435
436
\section1 Description
437
438
Creates targets for updating Qt Linguist \c{.ts} files and for transforming them
439
into \c{.qm} files. This function is a convenience wrapper around
440
\l{qt6_add_lupdate}{qt_add_lupdate} and \l{qt6_add_lrelease}{qt_add_lrelease}
441
and aims to offer the most common usage of both functions with one call.
442
443
The parameter \c TARGETS specifies a list of targets that intend to load the
444
generated \c{.qm} files at run time. If there's only one such target, you may
445
directly pass the target's name as the first argument.
446
447
The parameter \c SOURCE_TARGETS specifies a list of executable or library
448
targets that contain sources with translatable strings. From the sources of
449
these targets, \c{.ts} files will be created.
450
451
If \c SOURCE_TARGETS is not given, targets are automatically gathered by calling
452
\l{qt6_collect_translation_source_targets}{qt_collect_translation_source_targets}
453
at the end of the directory scope of \c{PROJECT_SOURCE_DIR}. This functionality
454
requires CMake 3.19 or newer. This functionality can be turned off with the
455
argument \c{IMMEDIATE_CALL}.
456
457
This function will create the target \c{update_translations} that scans all
458
source files with \c lupdate and creates and updates the \c{.ts} files.
459
460
This function will create the target \c{release_translations} that generates the
461
\c{.qm} files from the \c{.ts} files. This target is built by default.
462
463
The \c{.ts} files may be specified with the argument \c{TS_FILES}, but it's more
464
convenient to let \c qt_add_translations figure out the file paths
465
automatically. See \l{Automatic Determination of .ts File Paths} for
466
details.
467
468
\include cmake-macros.qdoc sources-and-include-dirs
469
470
\section1 Automatic Determination of .ts File Paths
471
472
The paths of the \c{.ts} files that are used as input for \c qt_add_translations
473
can be automatically determined if \l{QT_I18N_TRANSLATED_LANGUAGES} has been
474
set. This variable can be conveniently set with \l qt_standard_project_setup.
475
476
The following project setup is usually enough:
477
478
\snippet cmake-macros/examples.cmake auto_determine_ts_file_paths
479
480
This will create the files \c{myproject_de.ts} and \c{myproject_fr.ts} in the
481
project's source directory.
482
483
By default, the \c{.ts} files are created in \c{CMAKE_CURRENT_SOURCE_DIR}. You
484
can change the location by passing a different directory with the \c TS_FILE_DIR
485
argument.
486
487
By default, the \c{.ts} file names are constructed from \c{PROJECT_NAME}. You
488
can specify a different base name with the \c{TS_FILE_BASE} argument.
489
490
\note \c TS_FILE_DIR and \c TS_FILE_BASE have no effect for explicitly specified
491
\c{.ts} files.
492
493
Since Qt 6.8, you can specify the \c TS_FILES_OUTPUT_VARIABLE argument to store
494
the automatically determined \c{.ts} file paths in a variable.
495
496
\include cmake-macros.qdoc plurals-ts-file
497
498
A plurals-only \c{.ts} is automatically generated unless the option \c
499
NO_GENERATE_PLURALS_TS_FILE is specified.
500
501
For example,
502
\badcode
503
project(myapp)
504
qt_standard_project_setup(
505
I18N_SOURCE_LANGUAGE en # optional - this is the default
506
I18N_TRANSLATED_LANGUAGES de
507
)
508
qt_add_executable(myapp ...)
509
...
510
qt_add_translations(myapp)
511
\endcode
512
creates the full translation file \c{myapp_de.ts} and the plurals-only file
513
\c{myapp_en.ts}.
514
515
If you need a full translation of the source language, add it to
516
\l{QT_I18N_TRANSLATED_LANGUAGES}
517
518
For example,
519
\badcode
520
project(myapp)
521
qt_standard_project_setup(I18N_TRANSLATED_LANGUAGES en de)
522
qt_add_executable(myapp ...)
523
...
524
qt_add_translations(myapp)
525
\endcode
526
creates the full translation files
527
\list
528
\li \c{myapp_en.ts}
529
\li \c{myapp_de.ts}
530
\endlist
531
532
\section1 Options
533
534
You can specify the name of the custom target that calls lupdate with the \c
535
LUPDATE_TARGET option. Likewise, \c LRELEASE_TARGET controls the name of the
536
custom target that drives the call to \c lrelease.
537
538
You can set additional options for \l{lupdate} and \l{lrelease} with
539
\c{LUPDATE_OPTIONS} and \c{LRELEASE_OPTIONS}. You can find possible options in
540
the \l{lupdate options} and \l{lrelease options}.
541
542
For example, to use \l{Text ID based translations}{ID based translations}, you
543
need to pass \c{LRELEASE_OPTIONS -idbased} to \c qt_add_translations.
544
545
By default, the \c{.qm} files will be placed in the current build directory
546
(\c{CMAKE_CURRENT_BINARY_DIR}). To change this, you can set \c{OUTPUT_LOCATION}
547
as a property of the source \c{.ts} file.
548
549
For example, with the following code, the \c{.qm} files are generated
550
in a \c{translations} directory below the current build directory.
551
552
\snippet cmake-macros/examples.cmake set_output_location_on_ts_file
553
554
\section1 Embedding Generated .qm Files in Resources
555
556
By default, the generated \c{.qm} files are embedded in a Qt resource that will
557
be linked into the targets passed with \c{TARGETS}. The files in the resource
558
are accessible under the resource prefix \c{"/i18n"}.
559
560
You can set the resource prefix with \c{RESOURCE_PREFIX}.
561
562
In a static Qt build, when a resource target is created, additional targets can
563
be created. You can instruct \c{qt_add_translations} to store these targets in a
564
variable, by passing \c{OUTPUT_TARGETS <variable-name>}.
565
566
If \c OUTPUT_TARGETS is used, either \c IMMEDIATE_CALL or \c SOURCE_TARGETS must
567
be specified.
568
569
The automatic resource embedding can be turned off by giving the
570
\c{QM_FILES_OUTPUT_VARIABLE} option, followed by the name of a variable in which
571
the command should store the list of generated \c{.qm} files.
572
573
\section1 \c{qt_add_translations} before Qt 6.7
574
575
Before Qt 6.7, this command accepted only one target as the first argument. This
576
target was used for both, extracting translatable sources and embedding \c{.qm}
577
files.
578
579
Since Qt 6.7, the target in the first argument is not used for source extraction
580
anymore.
581
582
\section1 Examples
583
584
Add a German and a French translation to the target \c{frogger} using
585
\c{qt_add_translations}:
586
587
\snippet cmake-macros/examples.cmake qt_add_translations_default
588
589
This will create the \c{.ts} files \c{frogger_de.ts} and \c{frogger_fr.ts} in
590
the source directory. \l lupdate sees the source files of all targets that are
591
eligible for translation, according to the rules of \l
592
qt_collect_translation_source_targets.
593
594
The \c{.qm} files that are created from the \c{.ts} files
595
are embedded in the \c frogger_game target under the resource prefix \c{"i18n"}.
596
597
The \c qt_add_translations call in the above example is roughly equivalent to
598
the following:
599
600
\snippet cmake-macros/examples.cmake qt_lupdate_lrelease
601
602
\section2 Excluding directories, targets, and sources
603
604
You can exclude targets and directories from the automatic collection of source
605
targets. The following excludes the target \c helper_lib and everything under
606
the \c tests directory. See the \l{directory property
607
QT_EXCLUDE_FROM_TRANSLATION} and the \l{target property
608
QT_EXCLUDE_FROM_TRANSLATION}.
609
610
\badcode
611
# <project_root>/CMakeLists.txt
612
qt_add_translations(frogger_game)
613
\endcode
614
615
\badcode
616
# <project_root>/src/helper_lib/CMakeLists.txt
617
qt_add_library(helper_lib STATIC helpers.cpp)
618
set_property(TARGET helper_lib PROPERTY QT_EXCLUDE_FROM_TRANSLATION ON)
619
\endcode
620
621
\badcode
622
# <project_root>/tests/CMakeLists.txt
623
add_subdirectory(behavior_tests)
624
add_subdirectory(physics_tests)
625
set_directory_properties(PROPERTIES QT_EXCLUDE_FROM_TRANSLATION ON)
626
\endcode
627
628
In the following example, we exclude source files that are part of the \c
629
frogger_game target using the \l QT_EXCLUDE_SOURCES_FROM_TRANSLATION target
630
property:
631
632
\badcode
633
qt_add_executable(frogger_game
634
main.cpp
635
3rdparty/jumpsim.cpp
636
3rdparty/frogmath.cpp
637
)
638
set_property(TARGET frogger_game
639
PROPERTY QT_EXCLUDE_SOURCES_FROM_TRANSLATION "3rdparty/*"
640
)
641
\endcode
642
643
\section2 Explicit specification of source targets
644
645
If you don't want to use the automatic collection of source targets you can
646
specify the source targets explicitly:
647
648
\snippet cmake-macros/examples.cmake qt_add_translations_explicit_source_targets
649
650
\section2 Custom resource prefix
651
652
Now, let's embed the \c{.qm} files in \c frogger_game and \c
653
frogger_level_editor and set a custom resource prefix.
654
655
\snippet cmake-macros/examples.cmake qt_add_translations_resource_prefix
656
657
\section2 Installing .qm files
658
659
Instead of embedding the \c{.qm} files we can install them as regular files:
660
661
\snippet cmake-macros/examples.cmake qt_add_translations_install
662
663
\section2 Influencing the names of the .ts files
664
665
Place the \c{.ts} files in a \c translations directory and change the base name
666
to \c frogger_i18n:
667
668
\badcode
669
qt_standard_project_setup(I18N_TRANSLATED_LANGUAGES de fr)
670
...
671
qt_add_translations(frogger
672
TS_FILE_BASE froggo
673
TS_FILE_DIR translations
674
)
675
\endcode
676
677
This creates the following files
678
\list
679
\li \c translations/froggo_de.ts
680
\li \c translations/froggo_fr.ts
681
\endlist
682
683
You can also specify the paths explicitly:
684
\badcode
685
qt_add_translations(frogger
686
TS_FILES translations/froggo_de.ts translations/froggo_fr.ts
687
)
688
\endcode
689
690
*/
691
692
/*!
693
\page qtlinguist-cmake-qt-collect-targets-for-translation.html
694
\ingroup cmake-commands-qtlinguisttools
695
696
\title qt_collect_translation_source_targets
697
\keyword qt6_collect_translation_source_targets
698
699
\summary {Collects targets that are eligible for translation.}
700
701
\include cmake-find-package-linguisttools.qdocinc
702
703
\cmakecommandsince 6.7
704
705
\section1 Synopsis
706
707
\badcode
708
qt_collect_translation_source_targets(out_var [DIRECTORY path])
709
\endcode
710
711
\versionlessCMakeCommandsNote qt6_collect_translation_source_targets()
712
713
\section1 Description
714
715
Collect targets that are eligible for translation in the given \c DIRECTORY and
716
all subdirectories. If \c DIRECTORY is not specified, start the target
717
collection at \c{CMAKE_CURRENT_SOURCE_DIR}.
718
719
The command stores the list of targets in the variable that is specified as
720
first argument.
721
722
\section1 Excluding targets from translation
723
724
By default, all non-imported executable and library targets are eligible for
725
translation.
726
727
Single targets can be excluded by setting the \l{target property
728
QT_EXCLUDE_FROM_TRANSLATION}.
729
730
Targets below a certain directory can be excluded by setting the \l{directory
731
property QT_EXCLUDE_FROM_TRANSLATION}.
732
733
\section1 When to call this command
734
735
The \c qt_collect_translation_source_targets command reads the
736
\l{https://cmake.org/cmake/help/latest/prop_dir/BUILDSYSTEM_TARGETS.html}{BUILDSYSTEM_TARGETS}
737
directory properties. As a consequence, it only collects targets that already
738
have been created. Targets that are created after \c
739
qt_collect_translation_source_targets has been called are not collected.
740
741
To collect all targets of the build system, call \c
742
qt_collect_translation_source_targets at the end of the top-level \c
743
CMakeLists.txt or use \c{cmake_language(DEFER CALL)} to set up i18n at the end
744
of the top-level directory scope.
745
746
\section1 Examples
747
748
Use the result of \c qt_collect_translation_source_targets as input for \c
749
qt_add_lupdate.
750
751
\snippet cmake-macros/examples.cmake qt_collect_translation_source_targets
752
753
With CMake 3.19 and above, you can collect the source targets at the end of the
754
directory scope. This way, \c qt_collect_translation_source_targets can be
755
called before all targets have been defined. However, you need to exclude the
756
tests by setting the directory property \l{directory property
757
QT_EXCLUDE_FROM_TRANSLATION}{QT_EXCLUDE_FROM_TRANSLATION} to \c{ON}.
758
759
\snippet cmake-macros/examples.cmake qt_collect_translation_source_targets_deferred
760
*/
qttools
src
linguist
linguist
doc
cmake-macros.qdoc
Generated on Sat Sep 21 2024 01:05:51 for Qt by
1.12.0