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_query_qml_module.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2021 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page qt-query-qml-module.html
6
\ingroup cmake-commands-qtqml
7
8
\title qt_query_qml_module
9
\keyword qt6_query_qml_module
10
11
\summary {Retrieve information about a QML module.}
12
13
\include cmake-find-package-qml.qdocinc
14
15
\cmakecommandsince 6.3
16
17
\section1 Synopsis
18
19
\badcode
20
qt_query_qml_module(
21
target
22
[URI uri_var]
23
[VERSION version_var]
24
[PLUGIN_TARGET plugin_target_var]
25
[TARGET_PATH target_path_var]
26
[MODULE_RESOURCE_PATH module_resource_path_var]
27
[QMLDIR qmldir_var]
28
[TYPEINFO typeinfo_var]
29
[QML_FILES qml_files_var]
30
[QML_FILES_DEPLOY_PATHS qml_files_deploy_paths_var]
31
[QML_FILES_PREFIX_OVERRIDES qml_files_prefix_overrides_var]
32
[RESOURCES resources_var]
33
[RESOURCES_DEPLOY_PATHS resources_deploy_paths_var]
34
[RESOURCES_PREFIX_OVERRIDES resources_prefix_overrides_var]
35
)
36
\endcode
37
38
\versionlessCMakeCommandsNote qt6_query_qml_module()
39
40
\section1 Description
41
42
This command is used to obtain information about a QML module \c target.
43
That \c target must have previously been created by or passed to an earlier
44
call to \l{qt6_add_qml_module}{qt_add_qml_module()}. The \c target cannot be an
45
imported target.
46
47
The information provided by this command enables the caller to deploy all parts
48
of a single QML module. The project should install the \c target and the
49
associated plugin target (if the module has one and it is separate from the
50
backing \c target) using the standard \l{install(TARGETS)} command.
51
Everything else can be deployed with \l{install(FILES)}.
52
53
\section1 Arguments
54
55
Each of the optional arguments specifies the name of a variable in which to
56
store the corresponding QML module property.
57
58
\c URI and \c VERSION provide the module's uri and version respectively.
59
60
\c PLUGIN_TARGET can be used to obtain the name of the plugin target for the
61
QML module. Not all QML modules have a plugin, so the value returned for this
62
option could be an empty string. If the QML module has no separate backing
63
target, then \c target will be the same as the plugin target.
64
65
\c TARGET_PATH is the \c URI with dots (.) replaced by forward slashes (/).
66
It represents the path below the base QML module installation directory where
67
this QML module's \c{qmldir} file (and possibly others) should be deployed.
68
The QML module installation directory serves as a QML import path where
69
the QML engine will look for QML modules.
70
The default base QML module installation directory used by
71
\l{qt6_generate_deploy_qml_app_script}{qt_generate_deploy_qml_app_script()}
72
is \c{qml}. A project using a deployment script can use \l{QT_DEPLOY_QML_DIR}
73
rather than hard-coding this location (also see \l{QT_DEPLOY_PREFIX}).
74
75
\c MODULE_RESOURCE_PATH provides the resource path under which the QML module's
76
compiled-in files can be found. It is formed from
77
\l{qt6_add_qml_module}{qt_add_qml_module()}'s \c{RESOURCE_PREFIX} concatenated
78
with the module's \c TARGET_PATH.
79
The queried value should not be used for deployment, but may be helpful in
80
matching up resource paths with file system locations, if needed.
81
82
\c QMLDIR provides the path to the \c{qmldir} file. When deploying the QML
83
module, this file should be copied to the target path. In a deployment script,
84
this location can be obtained using \c{${QT_DEPLOY_PREFIX}/${QT_DEPLOY_QML_DIR}}.
85
86
\c TYPEINFO provides the path to the module's typeinfo file, if it has one.
87
It will be an empty string if the module has no typeinfo file. The typeinfo
88
file should be deployed to the same path as the \c{qmldir} file.
89
90
\c QML_FILES provides a list of all files added to the QML module through one
91
of the following methods:
92
93
\list
94
\li As \c{QML_FILES} arguments in \l{qt6_add_qml_module}{qt_add_qml_module()}.
95
\li As \c{FILES} arguments in \l{qt6_target_qml_sources}{qt_target_qml_sources()}.
96
\endlist
97
98
All files will be recorded with absolute paths.
99
100
\c QML_FILES_DEPLOY_PATHS provides a list with exactly the same number of
101
elements as \c QML_FILES. Each element of the \c QML_FILES_DEPLOY_PATHS list is
102
the path below the target path where the corresponding element of \c QML_FILES
103
should be deployed. The paths in \c QML_FILES_DEPLOY_PATHS include the file
104
name, since this could be different to the file name in \c QML_FILES due to the
105
use of resource aliases (see \l{QT_RESOURCE_ALIAS}).
106
107
Entries in \c QML_FILES_DEPLOY_PATHS can also be an empty string. Any file
108
added using \l{qt6_target_qml_sources}{qt_target_qml_sources()} with a custom
109
\c PREFIX will have no deploy path, since using a custom prefix typically means
110
the file sits outside of the QML module's target path.
111
112
\c QML_FILES_PREFIX_OVERRIDES provides another list with exactly the same
113
number of elements as \c QML_FILES. Where a file has been added with a custom
114
prefix as described in the preceding paragraph, its corresponding entry in the
115
\c QML_FILES_PREFIX_OVERRIDES list will contain the custom prefix used. For all
116
other files, their list entries will be an empty string.
117
118
\note As a special case, if there is only one file in the \c QML_FILES list,
119
then \c QML_FILES_DEPLOY_PATHS or \c QML_FILES_PREFIX_OVERRIDES may be an empty
120
string depending on whether that file has a custom prefix.
121
This is because CMake's way of representing lists and strings means that
122
it is impossible to distinguish between an empty string and a list with a single
123
empty element.
124
125
The \c RESOURCES, \c RESOURCES_DEPLOY_PATHS, and \c RESOURCES_PREFIX_OVERRIDES
126
options are analogous to those for \c QML_FILES discussed above.
127
\c RESOURCES provides a list of all files added to the QML module as
128
\c RESOURCES arguments to either \l{qt6_add_qml_module}{qt_add_qml_module()} or
129
\l{qt6_target_qml_sources}{qt_target_qml_sources()}. All paths will be
130
absolute. The meaning and usage of \c RESOURCES_DEPLOY_PATHS and
131
\c RESOURCES_PREFIX_OVERRIDES follows the same patterns as
132
\c QML_FILES_DEPLOY_PATHS and \c QML_FILES_PREFIX_OVERRIDES respectively.
133
134
\section1 Example
135
136
\badcode
137
cmake_minimum_required(VERSION 3.16...3.22)
138
project(MyThings)
139
140
find_package(Qt6 6.3 REQUIRED COMPONENTS Core Qml)
141
142
set(module_name "MyThings")
143
qt_add_qml_module(${module_name}
144
URI My.Things
145
VERSION 1.3
146
RESOURCE_PREFIX org.mycompany/imports
147
QML_FILES
148
First.qml
149
Second.qml
150
RESOURCES
151
Third.txt
152
)
153
154
qt_query_qml_module(${module_name}
155
URI module_uri
156
VERSION module_version
157
PLUGIN_TARGET module_plugin_target
158
TARGET_PATH module_target_path
159
QMLDIR module_qmldir
160
TYPEINFO module_typeinfo
161
QML_FILES module_qml_files
162
QML_FILES_DEPLOY_PATHS qml_files_deploy_paths
163
RESOURCES module_resources
164
RESOURCES_DEPLOY_PATHS resources_deploy_paths
165
)
166
167
message("My QML module URI is: ${module_uri}")
168
message("My QML module version is: ${module_version}")
169
170
# Install the QML module backing library
171
set(staging_prefix "staging")
172
install(TARGETS ${module_name}
173
ARCHIVE DESTINATION "${staging_prefix}/${CMAKE_INSTALL_LIBDIR}"
174
LIBRARY DESTINATION "${staging_prefix}/${CMAKE_INSTALL_LIBDIR}"
175
RUNTIME DESTINATION "${staging_prefix}/${CMAKE_INSTALL_BINDIR}"
176
)
177
set(module_dir "${staging_prefix}/qml/${module_target_path}")
178
179
# Install the QML module runtime loadable plugin
180
install(TARGETS "${module_plugin_target}"
181
LIBRARY DESTINATION "${module_dir}"
182
RUNTIME DESTINATION "${module_dir}"
183
)
184
185
# Install the QML module meta information.
186
install(FILES "${module_qmldir}" DESTINATION "${module_dir}")
187
install(FILES "${module_typeinfo}" DESTINATION "${module_dir}")
188
189
# Install QML files, possibly renamed.
190
list(LENGTH module_qml_files num_files)
191
math(EXPR last_index "${num_files} - 1")
192
foreach(i RANGE 0 ${last_index})
193
list(GET module_qml_files ${i} src_file)
194
list(GET qml_files_deploy_paths ${i} deploy_path)
195
get_filename_component(dst_name "${deploy_path}" NAME)
196
get_filename_component(dest_dir "${deploy_path}" DIRECTORY)
197
install(FILES "${src_file}" DESTINATION "${module_dir}/${dest_dir}" RENAME "${dst_name}")
198
endforeach()
199
200
# Install resources, possibly renamed.
201
list(LENGTH module_resources num_files)
202
math(EXPR last_index "${num_files} - 1")
203
foreach(i RANGE 0 ${last_index})
204
list(GET module_resources ${i} src_file)
205
list(GET resources_deploy_paths ${i} deploy_path)
206
get_filename_component(dst_name "${deploy_path}" NAME)
207
get_filename_component(dest_dir "${deploy_path}" DIRECTORY)
208
install(FILES "${src_file}" DESTINATION "${module_dir}/${dest_dir}" RENAME "${dst_name}")
209
endforeach()
210
211
\endcode
212
213
*/
qtdeclarative
src
qml
doc
src
cmake
qt_query_qml_module.qdoc
Generated on
for Qt by
1.14.0