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_deploy_qml_imports.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-deploy-qml-imports.html
6\ingroup cmake-commands-qtqml
7
8\title qt_deploy_qml_imports
9\keyword qt6_deploy_qml_imports
10
11\summary {Deploy the runtime components of QML modules needed by an executable.}
12
13\include cmake-find-package-qml.qdocinc
14
15Unlike most other CMake commands provided by Qt,
16\c{qt6_deploy_qml_imports} can only be called from a
17deployment script. It cannot be called directly by the project.
18
19\include cmake-qml-qt-finalize-target-warning.qdocinc warning
20
21\section1 Synopsis
22
23\badcode
24qt_deploy_qml_imports(
25 TARGET target
26 [QML_DIR qml_dir]
27 [PLUGINS_FOUND var_name]
28 [NO_QT_IMPORTS]
29)
30\endcode
31
32\section1 Description
33
34\note This command does not usually need to be called directly. It is used
35 internally by other higher level commands, but projects wishing to
36 implement more customized deployment logic may find it useful.
37
38When installing an application that uses QML, it may be non-trivial to work out
39which QML modules and which parts of those QML modules need to also be
40installed. Because QML plugins are not linked directly to an application's
41executable, \l{qt6_deploy_runtime_dependencies}{qt_deploy_runtime_dependencies()} won't find these QML modules.
42The \c{qt6_deploy_qml_imports} command provides the necessary logic which
43complements \l{qt6_deploy_runtime_dependencies}{qt_deploy_runtime_dependencies()} and deploys the runtime parts
44of all QML modules imported by the application.
45
46The \c{TARGET} option is mandatory and should specify a \c{target} that is an
47executable (on macOS, it should be an app bundle) and also a QML module.
48All QML sources that were added to the \c{target} via
49\l{qt6_add_qml_module}{qt_add_qml_module()} or
50\l{qt6_target_qml_sources}{qt_target_qml_sources()} will be recursively scanned
51for QML imports. The \c{NO_IMPORT_SCAN} option must not have been given to
52\l{qt6_add_qml_module}{qt_add_qml_module()}. The \c{qmldir} files and plugins
53from the imported QML modules will be deployed. The \c{NO_QT_IMPORTS} option
54can be given to skip deploying any QML modules provided by Qt.
55
56By default, the runtime parts of imported QML modules will be deployed to the
57\c{Resources/qml} directory for a macOS app bundle target, and to the \c{qml}
58directory under the base installation location for other platforms. For the
59non-macOS case, the \c{QML_DIR} option can be used to override this default
60choice.
61
62The command will store a list of all QML plugins it deploys in the variable
63named by the \c{PLUGINS_FOUND} option, if given. This is often passed as the
64\c{ADDITIONAL_MODULES} argument in a subsequent call to
65\l{qt6_deploy_runtime_dependencies}{qt_deploy_runtime_dependencies()}.
66
67\sa {qt6_generate_deploy_qml_app_script}{qt_generate_deploy_qml_app_script()},
68 {qt6_deploy_runtime_dependencies}{qt_deploy_runtime_dependencies()},
69 QT_DEPLOY_QML_DIR
70
71\section1 Example
72
73\badcode
74cmake_minimum_required(VERSION 3.16...3.22)
75project(MyThings)
76
77find_package(Qt6 6.3 REQUIRED COMPONENTS Core Qml)
78qt_standard_project_setup()
79
80qt_add_executable(MyApp main.cpp)
81qt_add_qml_module(MyApp
82 URI Application
83 VERSION 1.0
84 QML_FILES main.qml MyThing.qml
85)
86
87# The following script must only be executed at install time
88set(deploy_script "${CMAKE_CURRENT_BINARY_DIR}/deploy_MyApp.cmake")
89
90file(GENERATE OUTPUT ${deploy_script} CONTENT "
91include(\"${QT_DEPLOY_SUPPORT}\")
92qt_deploy_qml_imports(
93 # Deploy QML modules used by MyApp
94 TARGET MyApp
95
96 # The found QML plugins are stored in the plugins_found variable
97 PLUGINS_FOUND plugins_found
98
99 # The QML modules will be deployed into a custom directory
100 QML_DIR \"myqmldir\"
101
102 # Qt QML modules will be skipped, only project-created QML modules will be deployed
103 NO_QT_IMPORTS
104)
105# Deploy application runtime dependencies and runtime dependencies
106# of the found QML module plugins.
107qt_deploy_runtime_dependencies(
108 EXECUTABLE $<TARGET_FILE:MyApp>
109 ADDITIONAL_MODULES \${plugins_found}
110)
111")
112
113install(TARGETS MyApp)
114install(SCRIPT ${deploy_script})
115\endcode
116*/