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-generate-deploy-qml-app-script.html
6\ingroup cmake-commands-qtqml
8\title qt_generate_deploy_qml_app_script
9\target qt6_generate_deploy_qml_app_script
11\summary {Generate a deployment script for a QML application.}
13\include cmake-find-package-qml.qdocinc
17\include cmake-qml-qt-finalize-target-warning.qdocinc warning
22qt_generate_deploy_qml_app_script(
25 [NO_UNSUPPORTED_PLATFORM_ERROR]
28 [DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM]
29 [MACOS_BUNDLE_POST_BUILD]
30 [PRE_INCLUDE_REGEXES regexes...]
31 [PRE_EXCLUDE_REGEXES regexes...]
32 [POST_INCLUDE_REGEXES regexes...]
33 [POST_EXCLUDE_REGEXES regexes...]
34 [POST_INCLUDE_FILES files...]
35 [POST_EXCLUDE_FILES files...]
39\versionlessCMakeCommandsNote qt6_generate_deploy_qml_app_script()
43Installing an executable target that is also a QML module requires deploying
44a number of things in addition to the target itself. Qt libraries and other
45libraries from the project, Qt plugins, and the runtime parts of all QML modules
46the application uses may all need to be installed too. The installed layout
47is also going to be different for macOS app bundles compared to other platforms.
48The \c{qt_generate_deploy_qml_app_script()} is a convenience command intended
49to simplify that process, similar to what
50\l{qt6_generate_deploy_app_script}{qt_generate_deploy_app_script()} does for
53The command expects the application to follow Qt's recommended install
54directory structure fairly closely. That structure is based on CMake's default
55install layout, as determined by \l{GNUInstallDirs} (except for macOS app
56bundles, which follow Apple's requirements instead). QML modules are installed
57to the appropriate location for the platform. For macOS bundles, each QML
58module's \c{qmldir} file is installed under the appropriate subdirectory below
59\c{Resources/qml} and the module's plugin (if present) is installed under
60\c{PlugIns}. The app bundle is assumed to be installed directly to the base
61installation location (see the \l{Example} further below). For all other platforms,
62both the \c{qmldir} and the module's plugin are installed under the appropriate
63subdirectory below \c{qml}, which itself is relative to the base installation
66\c{qt_generate_deploy_qml_app_script()} generates a script whose name will be
67stored in the variable named by the \c{OUTPUT_SCRIPT} option. That script
68is only written at CMake generate-time. It is intended to be used with the
69\l{install(SCRIPT)} command, which should come after the application's target
70has been installed using \l{install(TARGETS)}.
72The deployment script will call
73\l{qt6_deploy_qml_imports}{qt_deploy_qml_imports()} with a suitable set of
74options for the standard install layout. For macOS app bundles and Windows
75targets, it will then also call
76\l{qt6_deploy_runtime_dependencies}{qt_deploy_runtime_dependencies()}, again
77with suitable options for the standard install layout.
79Calling \c{qt_generate_deploy_qml_app_script()} for a platform that is not
80supported by \c{qt_deploy_runtime_dependencies} will result in a fatal error,
81unless the \c{NO_UNSUPPORTED_PLATFORM_ERROR} option is given. When the option
82is given and the project is built for an unsupported platform, neither QML modules
83nor regular runtime dependencies will be installed.
84To ensure that the QML modules are still installed, specify both the
85\c{NO_UNSUPPORTED_PLATFORM_ERROR} and
86\c{DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM} options.
87The latter option will ensure that QML modules built as part of the project
90The \c{MACOS_BUNDLE_POST_BUILD} option enables an extra step when \c{target}
91is a macOS app bundle. A post-build rule will be created which uses the
92deployment script to deploy enough of the imported QML modules to allow the
93application to run directly from the build directory (essentially just the
94\c{qmldir} files and symlinks to plugins). This is usually desirable to support
95development of the application. \c{MACOS_BUNDLE_POST_BUILD} is ignored for all
98On platforms other than macOS, Qt translations are automatically deployed. To
99inhibit this behavior, specify \c{NO_TRANSLATIONS}. Use
100\l{qt_deploy_translations}{qt_deploy_translations()} to deploy translations in a
103For Windows desktop applications, the required runtime files for the compiler
104are also installed by default. To prevent this, specify \c{NO_COMPILER_RUNTIME}.
106The options \c{PRE_INCLUDE_REGEXES}, \c{PRE_EXCLUDE_REGEXES},
107\c{POST_INCLUDE_REGEXES}, \c{POST_EXCLUDE_REGEXES}, \c{POST_INCLUDE_FILES}, and
108\c{POST_EXCLUDE_FILES} can be specified to control the deployment of runtime
109dependencies. These options do not apply to all platforms and are forwarded
111\l{qt6_deploy_runtime_dependencies}{qt_deploy_runtime_dependencies()}.
113For deploying a non-QML application, use
114\l{qt6_generate_deploy_app_script}{qt_generate_deploy_app_script()}
115instead. It is an error to call both \c{qt_generate_deploy_qml_app_script()}
116and \l{qt6_generate_deploy_app_script}{qt_generate_deploy_app_script()} for the
119\sa {qt6_standard_project_setup}{qt_standard_project_setup()},
120 {qt6_generate_deploy_app_script}{qt_generate_deploy_app_script()}
125cmake_minimum_required(VERSION 3.16...3.22)
128find_package(Qt6 6.3 REQUIRED COMPONENTS Core Qml)
129qt_standard_project_setup()
131qt_add_executable(MyApp main.cpp)
132qt_add_qml_module(MyApp
135 QML_FILES main.qml MyThing.qml
140 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
143qt_generate_deploy_qml_app_script(
145 OUTPUT_SCRIPT deploy_script
146 MACOS_BUNDLE_POST_BUILD
147 NO_UNSUPPORTED_PLATFORM_ERROR
148 DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
150install(SCRIPT ${deploy_script})