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
18qt_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
28Variable-based variant:
29
30\badcode
31qt_add_resources(<VAR> file1.qrc [file2.qrc ...]
32 [OPTIONS ...])
33\endcode
34
35\versionlessCMakeCommandsNote qt6_add_resources()
36
37\section1 Description
38
39To add resources, you can pass either a target or a variable name as the first
40argument of the command.
41
42When passing a target as first argument, the function creates a resource with
43the name \c{RESOURCE_NAME}, containing the specified \c{FILES}. The resource is
44automatically linked into \c{TARGET}.
45
46When passing a variable name as first argument, \c qt_add_resources creates
47source code from Qt resource files using the \l{Resource Compiler (rcc)}. Paths
48to the generated source files are added to \c{<VAR>}.
49
50See \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
55accessible 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
58Qt 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
62attribute \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
65example, 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
69Alias settings for files need to be set via the \c QT_RESOURCE_ALIAS source file
70property.
71
72\c BIG_RESOURCES can be specified to enable support for big resources. This
73directly generates object files (\c .o, \c .obj) instead of C++ source code.
74This allows embedding bigger resources, without having to compile generated C++
75sources, which can be too time consuming and memory intensive.
76
77Note that \c BIG_RESOURCES is not compatible with iOS due to restrictions of
78CMake's Xcode project generator. See
79\l{https://bugreports.qt.io/browse/QTBUG-103497}{QTBUG-103497} for details.
80Also, \c BIG_RESOURCES only works reliably from CMake 3.17 onwards.
81
82When using this command with static libraries, one or more special targets will
83be generated. Should you wish to perform additional processing on these targets,
84pass a variable name to the \c OUTPUT_TARGETS parameter. The \c qt_add_resources
85function stores the names of the special targets in the specified variable.
86
87If \c DISCARD_FILE_CONTENTS is specified, the resource files will be added to
88the resource system without embedding their actual contents. Instead, these
89files will be stored as empty placeholders within the generated resource.
90
91\section1 Arguments of the variable-based variant
92
93When using the variable-based variant, you pass one or more \c{.qrc} files as
94arguments. The function generates source code from these Qt resource files and
95adds the paths to the generated source files to the specified variable.
96
97\section1 Arguments of both variants
98
99You can set additional \c{OPTIONS} that should be added to the \c{rcc} calls.
100You can find possible options in the \l{rcc}{rcc documentation}.
101
102\section1 Examples
103
104Target variant, using immediate resources:
105\snippet cmake-macros/examples.cmake qt_add_resources_target
106
107Variable variant, using a .qrc file:
108\snippet cmake-macros/examples.cmake qt_add_resources
109
110\section1 Caveats
111
112When adding multiple resources, \c{RESOURCE_NAME} must be unique across all
113resources linked into the final target.
114
115This especially affects static builds. There, the same resource name in
116different static libraries conflict in the consuming target.
117
118In contrast to \l{qmake}'s \c{RESOURCES}, \c qt_add_resources does not
119attempt 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*/