Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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(<VAR> file1.qrc [file2.qrc ...]
19 [OPTIONS ...])
20\endcode
21
22\versionlessCMakeCommandsNote qt6_add_resources()
23
24Since 6.0:
25
26\badcode
27qt_add_resources(<TARGET> <RESOURCE_NAME>
28 [PREFIX <PATH>]
29 [LANG <LANGUAGE>]
30 [BASE <PATH>]
31 [BIG_RESOURCES]
32 [OUTPUT_TARGETS <VARIABLE_NAME>]
33 [FILES ...] [OPTIONS ...])
34\endcode
35
36\versionlessCMakeCommandsNote qt6_add_resources()
37
38\section1 Description
39
40To add resources, you can pass either a variable name or a target as the first
41argument of the command.
42
43When passing a variable name as first argument, \c qt_add_resources creates
44source code from Qt resource files using the \l{Resource Compiler (rcc)}. Paths
45to the generated source files are added to \c{<VAR>}.
46
47When passing a target as first argument, the function creates a resource with
48the name \c{RESOURCE_NAME}, containing the specified \c{FILES}. The resource is
49automatically linked into \c{TARGET}.
50
51See \l{The Qt Resource System} for a general description of Qt resources.
52
53\section1 Arguments of the target-based variant
54
55\c PREFIX specifies a path prefix under which all files of this resource are
56accessible from C++ code. This corresponds to the XML attribute \c prefix of the
57\c .qrc file format. If \c PREFIX is not given, the target property
58\l{cmake-target-property-QT_RESOURCE_PREFIX}{QT_RESOURCE_PREFIX} is used. Since
596.5, \c{PREFIX} is optional. If it is omitted and not specified by
60\c{QT_RESOURCE_PREFIX}, \c{"/"} will be used as the default path prefix.
61
62\c LANG specifies the locale of this resource. This corresponds to the XML
63attribute \c lang of the \c .qrc file format.
64
65\c BASE is a path prefix that denotes the root point of the file's alias. For
66example, if \c BASE is \c{"assets"} and \c FILES is
67\c{"assets/images/logo.png"}, then the alias of that file is
68\c{"images/logo.png"}.
69
70Alias settings for files need to be set via the \c QT_RESOURCE_ALIAS source file
71property.
72
73\c BIG_RESOURCES can be specified to enable support for big resources. This
74directly generates object files (\c .o, \c .obj) instead of C++ source code.
75This allows embedding bigger resources, without having to compile generated C++
76sources, which can be too time consuming and memory intensive.
77
78Note that \c BIG_RESOURCES is not compatible with iOS due to restrictions of
79CMake's Xcode project generator. See
80\l{https://bugreports.qt.io/browse/QTBUG-103497}{QTBUG-103497} for details.
81Also, \c BIG_RESOURCES only works reliably from CMake 3.17 onwards.
82
83When using this command with static libraries, one or more special targets will
84be generated. Should you wish to perform additional processing on these targets,
85pass a variable name to the \c OUTPUT_TARGETS parameter. The \c qt_add_resources
86function stores the names of the special targets in the specified variable.
87
88\section1 Arguments of both variants
89
90You can set additional \c{OPTIONS} that should be added to the \c{rcc} calls.
91You can find possible options in the \l{rcc}{rcc documentation}.
92
93\section1 Examples
94
95Variable variant, using a .qrc file:
96\snippet cmake-macros/examples.cmake qt_add_resources
97
98Target variant, using immediate resources:
99\snippet cmake-macros/examples.cmake qt_add_resources_target
100
101\section1 Caveats
102
103When adding multiple resources, \c{RESOURCE_NAME} must be unique across all
104resources linked into the final target.
105
106This especially affects static builds. There, the same resource name in
107different static libraries conflict in the consuming target.
108
109\sa {qt6_add_big_resources}{qt_add_big_resources()}
110*/