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