Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qt_generate_deploy_qml_app_script.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-generate-deploy-qml-app-script.html
6\ingroup cmake-commands-qtqml
7
8\title qt_generate_deploy_qml_app_script
9\target qt6_generate_deploy_qml_app_script
10
11\summary {Generate a deployment script for a QML application.}
12
13\include cmake-find-package-qml.qdocinc
14
15\cmakecommandsince 6.3
16
17\include cmake-qml-qt-finalize-target-warning.qdocinc warning
18
19\section1 Synopsis
20
21\badcode
22qt_generate_deploy_qml_app_script(
23 TARGET <target>
24 OUTPUT_SCRIPT <var>
25 [NO_UNSUPPORTED_PLATFORM_ERROR]
26 [NO_TRANSLATIONS]
27 [NO_COMPILER_RUNTIME]
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...]
36)
37\endcode
38
39\versionlessCMakeCommandsNote qt6_generate_deploy_qml_app_script()
40
41\section1 Description
42
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
51non-QML applications.
52
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
64location.
65
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)}.
71
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.
78
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
88are still installed.
89
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
96other platforms.
97
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
101customized way.
102
103For Windows desktop applications, the required runtime files for the compiler
104are also installed by default. To prevent this, specify \c{NO_COMPILER_RUNTIME}.
105
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
110unmodified to
111\l{qt6_deploy_runtime_dependencies}{qt_deploy_runtime_dependencies()}.
112
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
117same target.
118
119\sa {qt6_standard_project_setup}{qt_standard_project_setup()},
120 {qt6_generate_deploy_app_script}{qt_generate_deploy_app_script()}
121
122\section1 Example
123
124\badcode
125cmake_minimum_required(VERSION 3.16...3.22)
126project(MyThings)
127
128find_package(Qt6 6.3 REQUIRED COMPONENTS Core Qml)
129qt_standard_project_setup()
130
131qt_add_executable(MyApp main.cpp)
132qt_add_qml_module(MyApp
133 URI Application
134 VERSION 1.0
135 QML_FILES main.qml MyThing.qml
136)
137
138install(TARGETS MyApp
139 BUNDLE DESTINATION .
140 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
141)
142
143qt_generate_deploy_qml_app_script(
144 TARGET MyApp
145 OUTPUT_SCRIPT deploy_script
146 MACOS_BUNDLE_POST_BUILD
147 NO_UNSUPPORTED_PLATFORM_ERROR
148 DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
149)
150install(SCRIPT ${deploy_script})
151\endcode
152*/