1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5\page qt-deploy-qml-imports.html
6\ingroup cmake-commands-qtqml
8\title qt_deploy_qml_imports
9\keyword qt6_deploy_qml_imports
11\summary {Deploy the runtime components of QML modules needed by an executable.}
13\include cmake-find-package-qml.qdocinc
15Unlike most other CMake commands provided by Qt,
16\c{qt6_deploy_qml_imports}{qt_deploy_qml_imports()} can only be called from a
17deployment script. It cannot be called directly by the project.
19\include cmake-qml-qt-finalize-target-warning.qdocinc warning
27 [PLUGINS_FOUND var_name]
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.
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}{qt_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.
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.
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
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()}.
67\sa {qt6_generate_deploy_qml_app_script}{qt_generate_deploy_qml_app_script()},
68 {qt6_deploy_runtime_dependencies}{qt_deploy_runtime_dependencies()},
74cmake_minimum_required(VERSION 3.16...3.22)
77find_package(Qt6 6.3 REQUIRED COMPONENTS Core Qml)
78qt_standard_project_setup()
80qt_add_executable(MyApp main.cpp)
81qt_add_qml_module(MyApp
84 QML_FILES main.qml MyThing.qml
87# The following script must only be executed at install time
88set(deploy_script "${CMAKE_CURRENT_BINARY_DIR}/deploy_MyApp.cmake")
90file(GENERATE OUTPUT ${deploy_script} CONTENTS "
91include(\"${QT_DEPLOY_SUPPORT}\")
93 # Deploy QML modules used by MyApp
96 # The found QML plugins are stored in the plugins_found variable
97 PLUGINS_FOUND plugins_found
99 # The QML modules will be deployed into a custom directory
102 # Qt QML modules will be skipped, only project-created QML modules will be deployed
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}
113install(TARGETS MyApp)
114install(SCRIPT ${deploy_script})