summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/src/cmake-macros.qdoc
blob: d14fc5badbd25777159ed17e37e7308c44a2f583 (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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
/****************************************************************************
**
** 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 qt_wrap_cpp.html
\ingroup cmake-macros-qtcore

\title qt_wrap_cpp
\target qt6_wrap_cpp

\brief Creates \c{.moc} files from sources.

\section1 Synopsis

\badcode
qt_wrap_cpp(<VAR> src_file1 [src_file2 ...]
            [TARGET target]
            [OPTIONS ...]
            [DEPENDS ...])

qt6_wrap_cpp(<VAR> src_file1 [src_file2 ...]
             [TARGET target]
             [OPTIONS ...]
             [DEPENDS ...])
\endcode

\section1 Description

Creates rules for calling the \l{moc}{Meta-Object Compiler (moc)} on the given
source files. For each input file, an output file is generated in the build
directory. The paths of the generated files are added to \c{<VAR>}.

\note This is a low-level macro. See the \l{CMake AUTOMOC Documentation} for a
more convenient way to let source files be processed with \c{moc}.

\section1 Arguments

You can set an explicit \c{TARGET}. This will make sure that the target
properties \c{INCLUDE_DIRECTORIES} and \c{COMPILE_DEFINITIONS} are also used
when scanning the source files with \c{moc}.

You can set additional \c{OPTIONS} that should be added to the \c{moc} calls.
You can find possible options in the \l{moc}{moc documentation}.

\c{DEPENDS} allows you to add additional dependencies for recreation of the
generated files. This is useful when the sources have implicit dependencies,
like code for a Qt plugin that includes a \c{.json} file using the
Q_PLUGIN_METADATA() macro.

\section1 Examples

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

/*!
\page qt_add_resources.html
\ingroup cmake-macros-qtcore

\title qt_add_resources
\target qt6_add_resources

\brief Compiles binary resources into source code.

\section1 Synopsis

\badcode
qt_add_resources(<VAR> file1.qrc [file2.qrc ...]
                  [OPTIONS ...])

qt6_add_resources(<VAR> file1.qrc [file2.qrc ...]
                  [OPTIONS ...])
\endcode

\section1 Description

Creates source code from Qt resource files using the
\l{Resource Compiler (rcc)}. Paths to the generated source files are added to
\c{<VAR>}.

For embedding bigger resources, see \l qt_add_big_resources.

\section1 Arguments

You can set additional \c{OPTIONS} that should be added to the \c{rcc} calls.
You can find possible options in the \l{rcc}{rcc documentation}.

\section1 Examples

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

/*!
\page qt_add_bigresources.html
\ingroup cmake-macros-qtcore

\title qt_add_big_resources
\target qt6_add_big_resources

\brief Compiles big binary resources into object code.

\section1 Synopsis

\badcode
qt_add_big_resources(<VAR> file1.qrc [file2.qrc ...]
                     [OPTIONS ...])

qt6_add_big_resources(<VAR> file1.qrc [file2.qrc ...]
                     [OPTIONS ...])
\endcode

\section1 Description

Creates compiled object files from Qt resource files using the
\l{Resource Compiler (rcc)}. Paths to the generated files are added to
\c{<VAR>}.

This is similar to \l qt_add_resources, but directly
generates object files (\c .o, \c .obj) files instead of C++ source code.
This allows to embed bigger resources, where compiling to C++ sources and then
to binaries would be too time consuming or memory intensive.

\note This macro is only available if using \c{CMake} 3.9 or later.

\section1 Arguments

You can set additional \c{OPTIONS} that should be added to the \c{rcc} calls.
You can find possible options in the \l{rcc}{rcc documentation}.

\section1 Examples

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

/*!
\page qt_add_binary_resources.html
\ingroup cmake-macros-qtcore

\title qt_add_binary_resources
\target qt6_add_binary_resources

\brief Creates an \c{RCC} file from a list of Qt resource files.

\section1 Synopsis

\badcode
qt_add_binary_resources(target file1.qrc [file2.qrc ...]
                        [DESTINATION ...]
                        [OPTIONS ...])

qt6_add_binary_resources(target file1.qrc [file2.qrc ...]
                        [DESTINATION ...]
                        [OPTIONS ...])
\endcode

\section1 Description

Adds a custom \c target that compiles Qt resource files into a binary \c{.rcc}
file.

\section1 Arguments

\c{DESTINATION} sets the path of the generated \c{.rcc} file. The default is
\c{${CMAKE_CURRENT_BINARY_DIR}/${target}.rcc}.

You can set additional \c{OPTIONS} that should be added to the \c{rcc} calls.
You can find possible options in the \l{rcc}{rcc documentation}.

\section1 Examples

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

/*!
\page qt_generate_moc.html
\ingroup cmake-macros-qtcore

\title qt_generate_moc
\target qt6_generate_moc

\brief Calls moc on an input file.

\section1 Synopsis

\badcode
qt_generate_moc(src_file dest_file
                [TARGET target])

qt6_generate_moc(src_file dest_file
                [TARGET target])
\endcode

\section1 Description

Creates a rule to call the \l{moc}{Meta-Object Compiler (moc)} on \c src_file
and store the output in \c dest_file.

\note This is a low-level macro. See the \l{CMake AUTOMOC Documentation} for a
more convenient way to let source files be processed with \c{moc}.
\l qt_wrap_cpp is also similar, but automatically generates a temporary file
path for you.

\section1 Arguments

You can set an explicit \c{TARGET}. This will make sure that the target
properties \c{INCLUDE_DIRECTORIES} and \c{COMPILE_DEFINITIONS} are also used
when scanning the source files with \c{moc}.

\section1 Examples

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

/*!
\page qt_import_plugins.html
\ingroup cmake-macros-qtcore

\title qt_import_plugins
\target qt6_import_plugins

\brief Specifies a custom set of plugins to import for a static Qt build.

\section1 Synopsis

\badcode
qt_import_plugins(target
                  [INCLUDE plugin ...]
                  [EXCLUDE plugin ...]
                  [INCLUDE_BY_TYPE plugin_type plugin ...]
                  [EXCLUDE_BY_TYPE plugin_type])

qt6_import_plugins(target
                  [INCLUDE plugin ...]
                  [EXCLUDE plugin ...]
                  [INCLUDE_BY_TYPE plugin_type plugin ...]
                  [EXCLUDE_BY_TYPE plugin_type])
\endcode

\section1 Description

Specifies a custom set of plugins to import. The optional arguments:
\c INCLUDE, \c EXCLUDE, \c INCLUDE_BY_TYPE, and \c EXCLUDE_BY_TYPE,
can be used more than once.

\list
\li \c INCLUDE -- can be used to specify a list of plugins to import.
\li \c EXCLUDE -- can be used to specify a list of plugins to exclude.
\li \c INCLUDE_BY_TYPE -- can be used to override the list of plugins to
       import for a certain plugin type.
\li \c EXCLUDE_BY_TYPE -- can be used to specify a plugin type to exclude;
       then no plugins of that type are imported.
\endlist

Qt provides plugin types such as \c imageformats, \c platforms,
and \c sqldrivers.

If the command isn't used the target automatically links against
a sane set of default plugins, for each Qt module that the target is linked
against. For more information, see
\l{CMake target_link_libraries Documentation}{target_link_libraries}.

Each plugin comes with a C++ stub file that automatically
initializes the plugin. Consequently, any target that links against a plugin
has this C++ file added to its \c SOURCES.

\note This command imports plugins from static Qt builds only.
On shared builds, it does nothing.

\section1 Examples

\snippet cmake-macros/examples.cmake qt_import_plugins

In the snippet above, the following occurs with the executable \c myapp:

\list
\li The \c Qt6::QCocoaIntegrationPlugin is imported into myapp.
\li The \c Qt6::QMinimalIntegrationPlugin plugin is
    excluded from being automatically imported into myapp.
\li The default list of plugins for \c imageformats is
    overridden to only include Qt6::QGifPlugin and Qt6::QJpegPlugin.
\li All \c sqldrivers plugins are excluded from automatic importing.
\endlist
*/

/*!
\page qt_add_executable.html
\ingroup cmake-macros-qtcore

\title qt_add_executable
\target qt6_add_executable

\brief Creates and finalizes an application target of a platform-specific type.

\preliminarycmakecommand

\section1 Synopsis

\badcode
qt_add_executable(target
                  [WIN32] [MACOSX_BUNDLE]
                  [MANUAL_FINALIZATION]
                  sources...)

qt6_add_executable(target
                   [WIN32] [MACOSX_BUNDLE]
                   [MANUAL_FINALIZATION]
                   sources...)
\endcode

\section1 Description

This command performs the following tasks:

\list
\li Create a CMake target of the appropriate type for the target platform.
\li Link the target to the \c{Qt::Core} library.
\li Handle finalization of the CMake target.
\endlist

\section2 Target Creation

On all platforms except Android, an executable target will be created.
All arguments will be passed through to the standard CMake \c{add_executable()}
command, except \c{MANUAL_FINALIZATION} (if present). On Android, a \c{MODULE}
library will be created and any \c{WIN32} or \c{MACOSX_BUNDLE} options will be
ignored. Some target properties will also be set for Android:

\list
\li The \c{SUFFIX} target property will be set to give the library file name an
    architecture-specific suffix.
\li Various \c{<lang>_VISIBILITY_PRESET} target properties will be set to
    \c{default} to ensure that the \c{main()} function is visible in the
    resultant binary.
\endlist

\section2 Linking Qt::Core

Since all Qt applications need to link to the \c{Qt::Core} library, this is done
for you as a convenience.

\section2 Finalization

After a target is created, further processing or \e{finalization} steps are
commonly needed. The steps to perform depend on the platform and on various
properties of the target. The finalization processing is implemented by the
\l{qt6_finalize_executable}{qt_finalize_executable()} command.

Finalization can occur either as part of this call or be deferred to sometime
after this command returns (but it should still be in the same directory scope).
When using CMake 3.19 or later, finalization is automatically deferred to the
end of the current directory scope. This gives the caller an opportunity to
modify properties of the created target before it is finalized. When using
CMake versions earlier than 3.19, automatic deferral isn't supported. In that
case, finalization is performed immediately before this command returns.

Regardless of the CMake version, the \c{MANUAL_FINALIZATION} keyword can be given to
indicate that you will explicitly call \l{qt6_finalize_executable}{qt_finalize_executable()}
yourself instead at some later time. In general, \c MANUAL_FINALIZATION should
not be needed unless the project has to support CMake 3.18 or earlier.

\sa {qt6_finalize_executable}{qt_finalize_executable()}

\section1 Examples

In the following simple case, finalization is handled automatically. If using a
CMake version earlier than 3.19, finalization will be performed immediately as
part of the call. When using CMake 3.19 or later, finalization will occur at the
end of the current directory scope.

\snippet cmake-macros/examples.cmake qt_add_executable_simple

The following example shows a scenario where finalization must be deferred.
The \c OUTPUT_NAME target property affects deployment settings on Android, but
those settings are written out as part of finalizing the target. In order to
support using CMake versions earlier than 3.19, we take over responsibility
for finalizing the target by adding the \c{MANUAL_FINALIZATION} keyword.

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

/*!
\page qt_finalize_executable.html
\ingroup cmake-macros-qtcore

\title qt_finalize_executable
\target qt6_finalize_executable

\brief Handles various common platform-specific tasks associated with Qt targets.

\preliminarycmakecommand

\section1 Synopsis

\badcode
qt_finalize_executable(target)

qt6_finalize_executable(target)
\endcode

\section1 Description

After a target is created, further processing or \e{finalization} steps are
commonly needed. The steps to perform depend on the platform and on various
properties of the target. These steps are expected to be performed within the
same directory scope as the one in which the \c{target} was created, so this
command should also be called from that same directory scope.

This command implements the following, as appropriate for the platform and
target provided:

\list
\li When targeting Android, generate a deployment settings file for the target.
\li Create a build target for generating an APK if building for Android.
\endlist

This command is ordinarily invoked as part of a call to
\l{qt6_add_executable}{qt_add_executable()}. The timing of when that call takes
place and when it might need to be called explicitly by a project is discussed
in the documentation of that command.
*/

/*!
\page qt_android_apply_arch_suffix.html
\ingroup cmake-macros-qtcore

\title qt_android_apply_arch_suffix
\target qt6_android_apply_arch_suffix

\brief Configures the target binary's name to include an architecture-specific suffix.

\preliminarycmakecommand
\cmakecommandandroidonly

\section1 Synopsis

\badcode
qt_android_apply_arch_suffix(target)

qt6_android_apply_arch_suffix(target)
\endcode

\section1 Description

The CMake \c{SUFFIX} target property controls the suffix used on the file name
of the target's built binary. This command is a convenience for setting that
property to an architecture-specific value. This is useful when installing
multiple builds for different Android architectures into the same install
location, as it prevents the libraries for different architectures from
overwriting each other.
*/

/*!
\page qt_android_generate_deployment_settings.html
\ingroup cmake-macros-qtcore

\title qt_android_generate_deployment_settings
\target qt6_android_generate_deployment_settings

\brief Generates the deployment settings file needed by androiddeployqt.

\preliminarycmakecommand
\cmakecommandandroidonly

\section1 Synopsis

\badcode
qt_android_generate_deployment_settings(target)

qt6_android_generate_deployment_settings(target)
\endcode

\section1 Description

The \c{androiddeployqt} tool expects a deployment settings file as input. This
command reads CMake variables and properties of the \c{target} to generate such
a file in the target's binary directory. Upon return, the full path to this file
is available in the target's \c{QT_ANDROID_DEPLOYMENT_SETTINGS_FILE} property.

\section2 CMake Variables

A number of variables are used while generating the deployment settings file.
Some are provided by Qt, others by CMake or the Android NDK.

\list
\li \l{cmake-variable-ANDROID_NDK_HOST_SYSTEM_NAME}{ANDROID_NDK_HOST_SYSTEM_NAME}
\li \l{cmake-variable-ANDROID_SDK_ROOT}{ANDROID_SDK_ROOT}
\li \c{CMAKE_ANDROID_ARCH_ABI}
\li \c{CMAKE_ANDROID_NDK}
\li \c{CMAKE_SYSROOT}
\li \l{cmake-variable-QT_ANDROID_APPLICATION_ARGUMENTS}{QT_ANDROID_APPLICATION_ARGUMENTS}
\li \l{cmake-variable-QT_HOST_PATH}{QT_HOST_PATH}
\endlist

\section2 Target Properties

The properties below will be read from the specified \c{target}. Note that this
command is called as part of target finalization (see
\l{qt6_finalize_executable}{qt_finalize_executable()}). If you are using
\l{qt6_add_executable}{qt_add_executable()} to create the target and you need to
modify some of these target properties, you need to ensure that target
finalization is deferred. See \l{qt6_add_executable}{qt_add_executable()} for
how to accomplish this.

\list
\li \l{cmake-target-property-QT_ANDROID_DEPLOYMENT_DEPENDENCIES}{QT_ANDROID_DEPLOYMENT_DEPENDENCIES}
\li \l{cmake-target-property-QT_ANDROID_EXTRA_LIBS}{QT_ANDROID_EXTRA_LIBS}
\li \l{cmake-target-property-QT_ANDROID_EXTRA_PLUGINS}{QT_ANDROID_EXTRA_PLUGINS}
\li \l{cmake-target-property-QT_ANDROID_PACKAGE_SOURCE_DIR}{QT_ANDROID_PACKAGE_SOURCE_DIR}
\li \l{cmake-target-property-QT_QML_IMPORT_PATH}{QT_QML_IMPORT_PATH}
\li \l{cmake-target-property-QT_QML_ROOT_PATH}{QT_QML_ROOT_PATH}
\li \l{cmake-target-property-qt_no_entrypoint}{qt_no_entrypoint}
\endlist

Upon return, the \c{QT_ANDROID_DEPLOYMENT_SETTINGS_FILE} target property will
contain the location of the generated deployment settings file.

\sa {qt6_android_add_apk_target}{qt_android_add_apk_target()},
    {qt6_finalize_executable}{qt_finalize_executable()}

\section1 Example

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

/*!
\page qt_android_add_apk_target.html
\ingroup cmake-macros-qtcore

\title qt_android_add_apk_target
\target qt6_android_add_apk_target

\brief Defines a build target that runs androiddeployqt to produce an APK.

\preliminarycmakecommand
\cmakecommandandroidonly

\section1 Synopsis

\badcode
qt_android_add_apk_target(target)

qt6_android_add_apk_target(target)
\endcode

\section1 Description

The \c{<target>_make_apk} custom target created by this command takes an Android
deployment settings file and generates an APK by running \c{androiddeployqt}.
The location of the settings file is taken from the \c{target}'s
\c{QT_ANDROID_DEPLOYMENT_SETTINGS_FILE} property. This file is typically created by
\l{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()}.
The \c{.apk} file will be generated in an \c{android-build} subdirectory below
the CMake build directory of the \c{target}.

The \c{<target>_make_apk} target will be automatically added as a dependency of
the \c{apk} build target, which will be created if it doesn't already exist.
This can be disabled by setting the \c{QT_NO_GLOBAL_APK_TARGET} variable to true.

\sa {qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()},
    {qt6_finalize_executable}{qt_finalize_executable()}

\section1 Example

\snippet cmake-macros/examples.cmake qt_android_deploy_basic

The above commands define the build targets \c{myapp_make_apk} and \c{apk},
which can be used to generate just the \c{myapp} APK or all APKs in the project
respectively.
*/