aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/src/cmake/qt_deploy_qml_imports.qdoc
blob: 87125cd0bf849c8d55ec4e76a6c0f7f3da96a63e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
\page qt-deploy-qml-imports.html
\ingroup cmake-commands-qtqml

\title qt_deploy_qml_imports
\keyword qt6_deploy_qml_imports

\summary {Deploy the runtime components of QML modules needed by an executable.}

\include cmake-find-package-qml.qdocinc

Unlike most other CMake commands provided by Qt,
\c{qt6_deploy_qml_imports} can only be called from a
deployment script. It cannot be called directly by the project.

\include cmake-qml-qt-finalize-target-warning.qdocinc warning

\section1 Synopsis

\badcode
qt_deploy_qml_imports(
    TARGET target
    [QML_DIR qml_dir]
    [PLUGINS_FOUND var_name]
    [NO_QT_IMPORTS]
)
\endcode

\section1 Description

\note This command does not usually need to be called directly. It is used
      internally by other higher level commands, but projects wishing to
      implement more customized deployment logic may find it useful.

When installing an application that uses QML, it may be non-trivial to work out
which QML modules and which parts of those QML modules need to also be
installed. Because QML plugins are not linked directly to an application's
executable, \l{qt6_deploy_runtime_dependencies}{qt_deploy_runtime_dependencies()} won't find these QML modules.
The \c{qt6_deploy_qml_imports} command provides the necessary logic which
complements \l{qt6_deploy_runtime_dependencies}{qt_deploy_runtime_dependencies()} and deploys the runtime parts
of all QML modules imported by the application.

The \c{TARGET} option is mandatory and should specify a \c{target} that is an
executable (on macOS, it should be an app bundle) and also a QML module.
All QML sources that were added to the \c{target} via
\l{qt6_add_qml_module}{qt_add_qml_module()} or
\l{qt6_target_qml_sources}{qt_target_qml_sources()} will be recursively scanned
for QML imports. The \c{NO_IMPORT_SCAN} option must not have been given to
\l{qt6_add_qml_module}{qt_add_qml_module()}. The \c{qmldir} files and plugins
from the imported QML modules will be deployed. The \c{NO_QT_IMPORTS} option
can be given to skip deploying any QML modules provided by Qt.

By default, the runtime parts of imported QML modules will be deployed to the
\c{Resources/qml} directory for a macOS app bundle target, and to the \c{qml}
directory under the base installation location for other platforms. For the
non-macOS case, the \c{QML_DIR} option can be used to override this default
choice.

The command will store a list of all QML plugins it deploys in the variable
named by the \c{PLUGINS_FOUND} option, if given. This is often passed as the
\c{ADDITIONAL_MODULES} argument in a subsequent call to
\l{qt6_deploy_runtime_dependencies}{qt_deploy_runtime_dependencies()}.

\sa {qt6_generate_deploy_qml_app_script}{qt_generate_deploy_qml_app_script()},
    {qt6_deploy_runtime_dependencies}{qt_deploy_runtime_dependencies()},
    QT_DEPLOY_QML_DIR

\section1 Example

\badcode
cmake_minimum_required(VERSION 3.16...3.22)
project(MyThings)

find_package(Qt6 6.3 REQUIRED COMPONENTS Core Qml)
qt_standard_project_setup()

qt_add_executable(MyApp main.cpp)
qt_add_qml_module(MyApp
    URI Application
    VERSION 1.0
    QML_FILES main.qml MyThing.qml
)

# The following script must only be executed at install time
set(deploy_script "${CMAKE_CURRENT_BINARY_DIR}/deploy_MyApp.cmake")

file(GENERATE OUTPUT ${deploy_script} CONTENT "
include(\"${QT_DEPLOY_SUPPORT}\")
qt_deploy_qml_imports(
    # Deploy QML modules used by MyApp
    TARGET MyApp

    # The found QML plugins are stored in the plugins_found variable
    PLUGINS_FOUND plugins_found

    # The QML modules will be deployed into a custom directory
    QML_DIR \"myqmldir\"

    # Qt QML modules will be skipped, only project-created QML modules will be deployed
    NO_QT_IMPORTS
)
# Deploy application runtime dependencies and runtime dependencies
# of the found QML module plugins.
qt_deploy_runtime_dependencies(
    EXECUTABLE $<TARGET_FILE:MyApp>
    ADDITIONAL_MODULES \${plugins_found}
)
")

install(TARGETS MyApp)
install(SCRIPT ${deploy_script})
\endcode
*/