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
qt_add_resources.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
\page qt-add-resources.html
6
\ingroup cmake-commands-qtcore
7
8
\title qt_add_resources
9
\keyword qt6_add_resources
10
11
\summary {Compiles binary resources into source code.}
12
13
\include cmake-find-package-core.qdocinc
14
15
\section1 Synopsis
16
17
\badcode
18
qt_add_resources(<TARGET> <RESOURCE_NAME>
19
[PREFIX <PATH>]
20
[LANG <LANGUAGE>]
21
[BASE <PATH>]
22
[BIG_RESOURCES]
23
[DISCARD_FILE_CONTENTS]
24
[OUTPUT_TARGETS <VARIABLE_NAME>]
25
[FILES ...] [OPTIONS ...])
26
\endcode
27
28
Variable-based variant:
29
30
\badcode
31
qt_add_resources(<VAR> file1.qrc [file2.qrc ...]
32
[OPTIONS ...])
33
\endcode
34
35
\versionlessCMakeCommandsNote qt6_add_resources()
36
37
\section1 Description
38
39
To add resources, you can pass either a target or a variable name as the first
40
argument of the command.
41
42
When passing a target as first argument, the function creates a resource with
43
the name \c{RESOURCE_NAME}, containing the specified \c{FILES}. The resource is
44
automatically linked into \c{TARGET}.
45
46
When passing a variable name as first argument, \c qt_add_resources creates
47
source code from Qt resource files using the \l{Resource Compiler (rcc)}. Paths
48
to the generated source files are added to \c{<VAR>}.
49
50
See \l{The Qt Resource System} for a general description of Qt resources.
51
52
\section1 Arguments of the target-based variant
53
54
\c PREFIX specifies a path prefix under which all files of this resource are
55
accessible from C++ code. This corresponds to the XML attribute \c prefix of the
56
\c .qrc file format. If \c PREFIX is not given, the target property
57
\l{cmake-target-property-QT_RESOURCE_PREFIX}{QT_RESOURCE_PREFIX} is used. Since
58
Qt 6.5, \c{PREFIX} is optional. If it is omitted and not specified by
59
\c{QT_RESOURCE_PREFIX}, \c{"/"} will be used as the default path prefix.
60
61
\c LANG specifies the locale of this resource. This corresponds to the XML
62
attribute \c lang of the \c .qrc file format.
63
64
\c BASE is a path prefix that denotes the root point of the file's alias. For
65
example, if \c BASE is \c{"assets"} and \c FILES is
66
\c{"assets/images/logo.png"}, then the alias of that file is
67
\c{"images/logo.png"}.
68
69
Alias settings for files need to be set via the \c QT_RESOURCE_ALIAS source file
70
property.
71
72
\c BIG_RESOURCES can be specified to enable support for big resources. This
73
directly generates object files (\c .o, \c .obj) instead of C++ source code.
74
This allows embedding bigger resources, without having to compile generated C++
75
sources, which can be too time consuming and memory intensive.
76
77
Note that \c BIG_RESOURCES is not compatible with iOS due to restrictions of
78
CMake's Xcode project generator. See
79
\l{https://bugreports.qt.io/browse/QTBUG-103497}{QTBUG-103497} for details.
80
Also, \c BIG_RESOURCES only works reliably from CMake 3.17 onwards.
81
82
When using this command with static libraries, one or more special targets will
83
be generated. Should you wish to perform additional processing on these targets,
84
pass a variable name to the \c OUTPUT_TARGETS parameter. The \c qt_add_resources
85
function stores the names of the special targets in the specified variable.
86
87
If \c DISCARD_FILE_CONTENTS is specified, the resource files will be added to
88
the resource system without embedding their actual contents. Instead, these
89
files will be stored as empty placeholders within the generated resource.
90
91
\section1 Arguments of the variable-based variant
92
93
When using the variable-based variant, you pass one or more \c{.qrc} files as
94
arguments. The function generates source code from these Qt resource files and
95
adds the paths to the generated source files to the specified variable.
96
97
\section1 Arguments of both variants
98
99
You can set additional \c{OPTIONS} that should be added to the \c{rcc} calls.
100
You can find possible options in the \l{rcc}{rcc documentation}.
101
102
\section1 Examples
103
104
Target variant, using immediate resources:
105
\snippet cmake-macros/examples.cmake qt_add_resources_target
106
107
Variable variant, using a .qrc file:
108
\snippet cmake-macros/examples.cmake qt_add_resources
109
110
\section1 Caveats
111
112
When adding multiple resources, \c{RESOURCE_NAME} must be unique across all
113
resources linked into the final target.
114
115
This especially affects static builds. There, the same resource name in
116
different static libraries conflict in the consuming target.
117
118
In contrast to \l{qmake}'s \c{RESOURCES}, \c qt_add_resources does not
119
attempt to compile any QML or JavaScript files using \l{qmlcachegen}. Use
120
\l{qt_add_qml_module} for this.
121
122
\sa {qt6_add_big_resources}{qt_add_big_resources()}
123
*/
qtbase
src
corelib
doc
src
cmake
qt_add_resources.qdoc
Generated on
for Qt by
1.14.0