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
8The following CMake commands are defined when Qt6::LinguistTools is loaded, for instance
9with
10
11\code
12find_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
30functions \l{qt6_add_lrelease} or \l{qt6_add_translations} instead.
31
32\section1 Synopsis
33
34\badcode
35qt_add_translation(<VAR> file1.ts [file2.ts ...]
36 [OPTIONS ...])
37\endcode
38
39\versionlessCMakeCommandsNote qt6_add_translation
40
41\section1 Description
42
43Calls \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
48You can set additional \c{OPTIONS} that should be passed when \c{lrelease} is
49invoked. You can find possible options in the \l{lrelease}{lrelease documentation}.
50
51By 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}
53as a property of the source \c{.ts} file.
54
55For example, with the following code, the \c{.qm} files are generated
56in 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
62Generating \c{helloworld_en.qm}, \c{helloworld_de.qm} in the build
63directory:
64
65\snippet cmake-macros/examples.cmake qt_add_translation
66
67Generating \c{helloworld_en.qm}, \c{helloworld_de.qm} in a \c{l10n}
68sub-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
85functions \l{qt6_add_lupdate} or \l{qt6_add_translations} instead.
86
87\section1 Synopsis
88
89\badcode
90qt_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
98Processes given sources (directories or individual files) to generate
99Qt Linguist \c{.ts} files. The \c{.ts} files are in turn compiled into \c{.qm}
100files of the same base name that are stored in the build
101directory. Paths to the generated \c{.qm} files are added to \c{<VAR>}.
102
103The translation files to create or update need to have a \c{.ts} suffix. If
104the given file path is not absolute it is resolved relative to the current
105source directory. If no \c{.ts} file is passed as an argument, the macro
106does nothing.
107
108Any 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.
110See also the \l{lupdate}{lupdate documentation} on further details.
111
112\section1 Options
113
114You can set additional \c{OPTIONS} that should be passed when \c{lupdate} is
115invoked. You can find possible options in the \l{lupdate}{lupdate documentation}.
116
117\section1 Examples
118
119Recursively look up Qt translations from source files in current directory and
120generate 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}
122files 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
142Since 6.7:
143\badcode
144qt_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
154Since 6.2 (deprecated):
155\badcode
156qt_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
167Creates a custom target to generate or update Qt Linguist \c{.ts}
168files with \l{lupdate}.
169
170The name of that custom target defaults to \c{${PROJECT_NAME}_lupdate}. Further
171calls of \c qt_add_lupdate will create target names with an increasing number
172appended. The custom target name can be specified with the \c LUPDATE_TARGET
173option.
174
175With the \c{SOURCE_TARGETS} argument you can specify a list of targets that
176contain sources with translatable strings. If \c{SOURCE_TARGETS} is not
177specified, 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}
180is called to retrieve the list of targets.
181
182The \c{.ts} files must be specified with the argument \c{TS_FILES}.
183
184This 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
191With \c{SOURCES} you can explicitly specify additional source files that contain
192translatable strings.
193
194You can use \c{INCLUDE_DIRECTORIES} to explicitly specify include directories
195for those source files.
196//! [sources-and-include-dirs]
197
198\section1 Options
199
200You can set additional \c{OPTIONS} that should be passed when \c{lupdate} is
201invoked. You can find possible options in the \l{lupdate}{lupdate
202documentation}.
203
204\section1 Umbrella Target
205
206In 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
210Pass \c{NO_GLOBAL_TARGET} to \c{qt_add_lupdate} to prevent this behavior.
211
212The 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
219strings are written. For handling plural forms correctly, create an additional
220\c{.ts} file for that language that only contains translatable strings for
221plural forms. See \l{Handle Plural Forms} for details.
222
223With \c PLURALS_TS_FILE you can specify the \c{.ts} file for the source
224language. This file will only contain plural forms.
225//! [plurals-ts-file]
226
227\section1 Deprecated Command Signature
228
229Older versions of \c qt_add_lupdate took a target as the first argument. This is
230deprecated. Use the \c SOURCE_TARGETS argument instead.
231
232\section1 Examples
233
234Add 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
239You can specify the name of the created target by passing the \c LUPDATE_TARGET
240argument:
241
242\badcode
243qt_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
266Since 6.7:
267\badcode
268qt_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
276Since 6.2 (deprecated):
277\badcode
278qt_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
288target directory scope requires at least CMake version 3.18.
289
290\section1 Description
291
292Creates a custom command to transform \c{.ts} files into \c{.qm} files with
293\l{lrelease}.
294
295The execution of the custom command is driven by a custom target that is built
296by default. The name of that custom target defaults to
297\c{${PROJECT_NAME}_lrelease}. Further calls of \c qt_add_lrelease will create
298target names with an increasing number appended. The custom target name can be
299specified with the \c LRELEASE_TARGET option.
300
301The \c{.ts} files must be specified with the argument \c{TS_FILES}.
302
303This 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
309You can set additional \c{OPTIONS} that should be passed when \c{lrelease} is
310invoked. You can find possible options in the \l{lrelease}{lrelease
311documentation}.
312
313By 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}
315as a property of the source \c{.ts} file.
316
317For example, with the following code, the \c{.qm} files are generated
318in 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
324To further process the generated \c{.qm} files, for example to create install
325rules, \c{qt_add_lrelease} can store the paths of the \c{.qm} files in a
326variable. Pass \c{QM_FILES_OUTPUT_VARIABLE <variable-name>} to the function for
327that.
328
329\section1 Build by Default
330
331By default, the command creates a custom target that is added to the default
332build target. This ensures that the \c{.qm} files are always up-to-date when the
333project is built. This behavior can be turned off with the \c{EXCLUDE_FROM_ALL}
334argument. In this case, the user must build the \c{${PROJECT_NAME}_lrelease}
335target manually.
336
337\section1 Umbrella Target
338
339In 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
343Pass \c{NO_GLOBAL_TARGET} to \c{qt_add_lrelease} to prevent this behavior.
344
345The 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
350Older versions of \c qt_add_lrelease took a target as the first argument. This
351is still possible but deprecated.
352
353\section1 Examples
354
355Add the targets \c{myapp_lrelease} and \c{release_translations} for transforming
356the given \c{.ts} files into \c{.qm} files. Also, install the generated \c{.qm}
357files. The target \c{myapp_lrelease} is built by default.
358
359\badcode
360project(myapp)
361...
362qt_add_lrelease(
363 TS_FILES myapp_de.ts myapp_fr.ts
364 QM_FILES_OUTPUT_VARIABLE qm_files
365)
366install(FILES ${qm_files} DESTINATION "translations")
367\endcode
368
369You can specify the name of the created target by passing the \c LRELEASE_TARGET
370argument:
371
372\badcode
373qt_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
396Since Qt 6.7:
397\badcode
398qt_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
419Since Qt 6.2 (deprecated):
420\badcode
421qt_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
434target directory scope requires at least CMake version 3.18.
435
436\section1 Description
437
438Creates targets for updating Qt Linguist \c{.ts} files and for transforming them
439into \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}
441and aims to offer the most common usage of both functions with one call.
442
443The parameter \c TARGETS specifies a list of targets that intend to load the
444generated \c{.qm} files at run time. If there's only one such target, you may
445directly pass the target's name as the first argument.
446
447The parameter \c SOURCE_TARGETS specifies a list of executable or library
448targets that contain sources with translatable strings. From the sources of
449these targets, \c{.ts} files will be created.
450
451If \c SOURCE_TARGETS is not given, targets are automatically gathered by calling
452\l{qt6_collect_translation_source_targets}{qt_collect_translation_source_targets}
453at the end of the directory scope of \c{PROJECT_SOURCE_DIR}. This functionality
454requires CMake 3.19 or newer. This functionality can be turned off with the
455argument \c{IMMEDIATE_CALL}.
456
457This function will create the target \c{update_translations} that scans all
458source files with \c lupdate and creates and updates the \c{.ts} files.
459
460This 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
463The \c{.ts} files may be specified with the argument \c{TS_FILES}, but it's more
464convenient to let \c qt_add_translations figure out the file paths
465automatically. See \l{Automatic Determination of .ts File Paths} for
466details.
467
468\include cmake-macros.qdoc sources-and-include-dirs
469
470\section1 Automatic Determination of .ts File Paths
471
472The paths of the \c{.ts} files that are used as input for \c qt_add_translations
473can be automatically determined if \l{QT_I18N_TRANSLATED_LANGUAGES} has been
474set. This variable can be conveniently set with \l qt_standard_project_setup.
475
476The following project setup is usually enough:
477
478\snippet cmake-macros/examples.cmake auto_determine_ts_file_paths
479
480This will create the files \c{myproject_de.ts} and \c{myproject_fr.ts} in the
481project's source directory.
482
483By default, the \c{.ts} files are created in \c{CMAKE_CURRENT_SOURCE_DIR}. You
484can change the location by passing a different directory with the \c TS_FILE_DIR
485argument.
486
487By default, the \c{.ts} file names are constructed from \c{PROJECT_NAME}. You
488can 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
493Since Qt 6.8, you can specify the \c TS_FILES_OUTPUT_VARIABLE argument to store
494the automatically determined \c{.ts} file paths in a variable.
495
496\include cmake-macros.qdoc plurals-ts-file
497
498A plurals-only \c{.ts} is automatically generated unless the option \c
499NO_GENERATE_PLURALS_TS_FILE is specified.
500
501For example,
502\badcode
503project(myapp)
504qt_standard_project_setup(
505 I18N_SOURCE_LANGUAGE en # optional - this is the default
506 I18N_TRANSLATED_LANGUAGES de
507)
508qt_add_executable(myapp ...)
509...
510qt_add_translations(myapp)
511\endcode
512creates the full translation file \c{myapp_de.ts} and the plurals-only file
513\c{myapp_en.ts}.
514
515If you need a full translation of the source language, add it to
516\l{QT_I18N_TRANSLATED_LANGUAGES}
517
518For example,
519\badcode
520project(myapp)
521qt_standard_project_setup(I18N_TRANSLATED_LANGUAGES en de)
522qt_add_executable(myapp ...)
523...
524qt_add_translations(myapp)
525\endcode
526creates 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
534You can specify the name of the custom target that calls lupdate with the \c
535LUPDATE_TARGET option. Likewise, \c LRELEASE_TARGET controls the name of the
536custom target that drives the call to \c lrelease.
537
538You 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
540the \l{lupdate options} and \l{lrelease options}.
541
542For example, to use \l{Text ID based translations}{ID based translations}, you
543need to pass \c{LRELEASE_OPTIONS -idbased} to \c qt_add_translations.
544
545By 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}
547as a property of the source \c{.ts} file.
548
549For example, with the following code, the \c{.qm} files are generated
550in 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
556By default, the generated \c{.qm} files are embedded in a Qt resource that will
557be linked into the targets passed with \c{TARGETS}. The files in the resource
558are accessible under the resource prefix \c{"/i18n"}.
559
560You can set the resource prefix with \c{RESOURCE_PREFIX}.
561
562In a static Qt build, when a resource target is created, additional targets can
563be created. You can instruct \c{qt_add_translations} to store these targets in a
564variable, by passing \c{OUTPUT_TARGETS <variable-name>}.
565
566If \c OUTPUT_TARGETS is used, either \c IMMEDIATE_CALL or \c SOURCE_TARGETS must
567be specified.
568
569The 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
571the command should store the list of generated \c{.qm} files.
572
573\section1 \c{qt_add_translations} before Qt 6.7
574
575Before Qt 6.7, this command accepted only one target as the first argument. This
576target was used for both, extracting translatable sources and embedding \c{.qm}
577files.
578
579Since Qt 6.7, the target in the first argument is not used for source extraction
580anymore.
581
582\section1 Examples
583
584Add 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
589This will create the \c{.ts} files \c{frogger_de.ts} and \c{frogger_fr.ts} in
590the source directory. \l lupdate sees the source files of all targets that are
591eligible for translation, according to the rules of \l
592qt_collect_translation_source_targets.
593
594The \c{.qm} files that are created from the \c{.ts} files
595are embedded in the \c frogger_game target under the resource prefix \c{"i18n"}.
596
597The \c qt_add_translations call in the above example is roughly equivalent to
598the following:
599
600\snippet cmake-macros/examples.cmake qt_lupdate_lrelease
601
602\section2 Excluding directories, targets, and sources
603
604You can exclude targets and directories from the automatic collection of source
605targets. The following excludes the target \c helper_lib and everything under
606the \c tests directory. See the \l{directory property
607QT_EXCLUDE_FROM_TRANSLATION} and the \l{target property
608QT_EXCLUDE_FROM_TRANSLATION}.
609
610\badcode
611# <project_root>/CMakeLists.txt
612qt_add_translations(frogger_game)
613\endcode
614
615\badcode
616# <project_root>/src/helper_lib/CMakeLists.txt
617qt_add_library(helper_lib STATIC helpers.cpp)
618set_property(TARGET helper_lib PROPERTY QT_EXCLUDE_FROM_TRANSLATION ON)
619\endcode
620
621\badcode
622# <project_root>/tests/CMakeLists.txt
623add_subdirectory(behavior_tests)
624add_subdirectory(physics_tests)
625set_directory_properties(PROPERTIES QT_EXCLUDE_FROM_TRANSLATION ON)
626\endcode
627
628In the following example, we exclude source files that are part of the \c
629frogger_game target using the \l QT_EXCLUDE_SOURCES_FROM_TRANSLATION target
630property:
631
632\badcode
633qt_add_executable(frogger_game
634 main.cpp
635 3rdparty/jumpsim.cpp
636 3rdparty/frogmath.cpp
637)
638set_property(TARGET frogger_game
639 PROPERTY QT_EXCLUDE_SOURCES_FROM_TRANSLATION "3rdparty/*"
640)
641\endcode
642
643\section2 Explicit specification of source targets
644
645If you don't want to use the automatic collection of source targets you can
646specify the source targets explicitly:
647
648\snippet cmake-macros/examples.cmake qt_add_translations_explicit_source_targets
649
650\section2 Custom resource prefix
651
652Now, let's embed the \c{.qm} files in \c frogger_game and \c
653frogger_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
659Instead 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
665Place the \c{.ts} files in a \c translations directory and change the base name
666to \c frogger_i18n:
667
668\badcode
669qt_standard_project_setup(I18N_TRANSLATED_LANGUAGES de fr)
670...
671qt_add_translations(frogger
672 TS_FILE_BASE froggo
673 TS_FILE_DIR translations
674)
675\endcode
676
677This creates the following files
678\list
679\li \c translations/froggo_de.ts
680\li \c translations/froggo_fr.ts
681\endlist
682
683You can also specify the paths explicitly:
684\badcode
685qt_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
708qt_collect_translation_source_targets(out_var [DIRECTORY path])
709\endcode
710
711\versionlessCMakeCommandsNote qt6_collect_translation_source_targets()
712
713\section1 Description
714
715Collect targets that are eligible for translation in the given \c DIRECTORY and
716all subdirectories. If \c DIRECTORY is not specified, start the target
717collection at \c{CMAKE_CURRENT_SOURCE_DIR}.
718
719The command stores the list of targets in the variable that is specified as
720first argument.
721
722\section1 Excluding targets from translation
723
724By default, all non-imported executable and library targets are eligible for
725translation.
726
727Single targets can be excluded by setting the \l{target property
728QT_EXCLUDE_FROM_TRANSLATION}.
729
730Targets below a certain directory can be excluded by setting the \l{directory
731property QT_EXCLUDE_FROM_TRANSLATION}.
732
733\section1 When to call this command
734
735The \c qt_collect_translation_source_targets command reads the
736\l{https://cmake.org/cmake/help/latest/prop_dir/BUILDSYSTEM_TARGETS.html}{BUILDSYSTEM_TARGETS}
737directory properties. As a consequence, it only collects targets that already
738have been created. Targets that are created after \c
739qt_collect_translation_source_targets has been called are not collected.
740
741To collect all targets of the build system, call \c
742qt_collect_translation_source_targets at the end of the top-level \c
743CMakeLists.txt or use \c{cmake_language(DEFER CALL)} to set up i18n at the end
744of the top-level directory scope.
745
746\section1 Examples
747
748Use the result of \c qt_collect_translation_source_targets as input for \c
749qt_add_lupdate.
750
751\snippet cmake-macros/examples.cmake qt_collect_translation_source_targets
752
753With CMake 3.19 and above, you can collect the source targets at the end of the
754directory scope. This way, \c qt_collect_translation_source_targets can be
755called before all targets have been defined. However, you need to exclude the
756tests by setting the directory property \l{directory property
757QT_EXCLUDE_FROM_TRANSLATION}{QT_EXCLUDE_FROM_TRANSLATION} to \c{ON}.
758
759\snippet cmake-macros/examples.cmake qt_collect_translation_source_targets_deferred
760*/