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_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\target 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
20qt_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
42This command is used to obtain information about a QML module \c target.
43That \c target must have previously been created by or passed to an earlier
44call to \l{qt6_add_qml_module}{qt_add_qml_module()}. The \c target cannot be an
45imported target.
46
47The information provided by this command enables the caller to deploy all parts
48of a single QML module. The project should install the \c target and the
49associated plugin target (if the module has one and it is separate from the
50backing \c target) using the standard \l{install(TARGETS)} command.
51Everything else can be deployed with \l{install(FILES)}.
52
53\section1 Arguments
54
55Each of the optional arguments specifies the name of a variable in which to
56store 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
61QML module. Not all QML modules have a plugin, so the value returned for this
62option could be an empty string. If the QML module has no separate backing
63target, 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 (/).
66It represents the path below the base QML module installation directory where
67this QML module's \c{qmldir} file (and possibly others) should be deployed.
68The QML module installation directory serves as a QML import path where
69the QML engine will look for QML modules.
70The default base QML module installation directory used by
71\l{qt6_generate_deploy_qml_app_script}{qt_generate_deploy_qml_app_script()}
72is \c{qml}. A project using a deployment script can use \l{QT_DEPLOY_QML_DIR}
73rather 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
76compiled-in files can be found. It is formed from
77\l{qt6_add_qml_module}{qt_add_qml_module()}'s \c{RESOURCE_PREFIX} concatenated
78with the module's \c TARGET_PATH.
79The queried value should not be used for deployment, but may be helpful in
80matching 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
83module, this file should be copied to the target path. In a deployment script,
84this 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.
87It will be an empty string if the module has no typeinfo file. The typeinfo
88file 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
91of 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
98All files will be recorded with absolute paths.
99
100\c QML_FILES_DEPLOY_PATHS provides a list with exactly the same number of
101elements as \c QML_FILES. Each element of the \c QML_FILES_DEPLOY_PATHS list is
102the path below the target path where the corresponding element of \c QML_FILES
103should be deployed. The paths in \c QML_FILES_DEPLOY_PATHS include the file
104name, since this could be different to the file name in \c QML_FILES due to the
105use of resource aliases (see \l{QT_RESOURCE_ALIAS}).
106
107Entries in \c QML_FILES_DEPLOY_PATHS can also be an empty string. Any file
108added 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
110the file sits outside of the QML module's target path.
111
112\c QML_FILES_PREFIX_OVERRIDES provides another list with exactly the same
113number of elements as \c QML_FILES. Where a file has been added with a custom
114prefix 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
116other 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,
119then \c QML_FILES_DEPLOY_PATHS or \c QML_FILES_PREFIX_OVERRIDES may be an empty
120string depending on whether that file has a custom prefix.
121This is because CMake's way of representing lists and strings means that
122it is impossible to distinguish between an empty string and a list with a single
123empty element.
124
125The \c RESOURCES, \c RESOURCES_DEPLOY_PATHS, and \c RESOURCES_PREFIX_OVERRIDES
126options 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
130absolute. 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
137cmake_minimum_required(VERSION 3.16...3.22)
138project(MyThings)
139
140find_package(Qt6 6.3 REQUIRED COMPONENTS Core Qml)
141
142set(module_name "MyThings")
143qt_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
154qt_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
167message("My QML module URI is: ${module_uri}")
168message("My QML module version is: ${module_version}")
169
170# Install the QML module backing library
171set(staging_prefix "staging")
172install(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)
177set(module_dir "${staging_prefix}/qml/${module_target_path}")
178
179# Install the QML module runtime loadable plugin
180install(TARGETS "${module_plugin_target}"
181 LIBRARY DESTINATION "${module_dir}"
182 RUNTIME DESTINATION "${module_dir}"
183)
184
185# Install the QML module meta information.
186install(FILES "${module_qmldir}" DESTINATION "${module_dir}")
187install(FILES "${module_typeinfo}" DESTINATION "${module_dir}")
188
189# Install QML files, possibly renamed.
190list(LENGTH module_qml_files num_files)
191math(EXPR last_index "${num_files} - 1")
192foreach(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}")
198endforeach()
199
200# Install resources, possibly renamed.
201list(LENGTH module_resources num_files)
202math(EXPR last_index "${num_files} - 1")
203foreach(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}")
209endforeach()
210
211\endcode
212
213*/