Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtp0005.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2023 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page qt-cmake-policy-qtp0005.html
6
\ingroup qt-cmake-policies
7
8
\title QTP0005
9
\keyword qt_cmake_policy_qtp0005
10
11
\summary {qt_add_qml_module dependency keywords accept CMake targets}
12
13
This policy was introduced in Qt 6.8. It allows passing CMake targets to
14
\l{qt_add_qml_module}{qt_add_qml_module()} via the \c DEPENDENCIES, \c IMPORTS,
15
\c OPTIONAL_IMPORTS, and \c DEFAULT_IMPORTS keywords.
16
17
Enabling this policy means that arguments passed to those keywords can be prefixed
18
with \c TARGET, and are then treated as a CMake target name. The QML module URI
19
and import path are derived automatically from the target.
20
21
The \c OLD behavior of this policy is that the token sequence \c{TARGET name} is
22
treated as two separate URIs, \c{TARGET} and \c{name}.
23
24
The \c NEW behavior of this policy is that \c TARGET is a keyword. The URI is
25
extracted from the QML module target that follows. It is a hard error if the name
26
following \c TARGET does not refer to an existing target, or if that target does
27
not correspond to a QML module.
28
29
In both the \c NEW and the \c OLD behavior it is possible to specify a module
30
version by appending a slash and the version. See
31
\l{Declaring module dependencies} for more details.
32
33
\section1 Background
34
35
Before this policy, QML module dependencies had to be declared by their string
36
URI, for example \c{QtQuick} or \c{com.example.mymodule}. This meant that the
37
URI and, when needed, the import path of the dependency had to be kept consistent
38
with the CMake target that provides the module.
39
40
With the \c NEW behavior, you can refer to a dependency by its CMake target
41
name instead. The build system then determines the correct URI and import path
42
from the target automatically. This removes the need to manually specify
43
\l{qt_add_qml_module}{IMPORT_PATH} entries for dependencies outside the default
44
QML import path, reduces redundancy, and eliminates a class of copy-paste
45
mistakes.
46
47
\section1 Example
48
49
Consider a module that depends on another module defined in the same project.
50
With the \c OLD behavior (or before Qt 6.8), the URI must be spelled out
51
explicitly:
52
53
\badcode
54
qt_add_qml_module(my_module
55
URI MyModule
56
VERSION 1.0
57
DEPENDENCIES
58
OtherModule
59
)
60
\endcode
61
62
With the \c NEW behavior (policy QTP0005 set to \c NEW), you can refer to the
63
dependency by its CMake target name:
64
65
\badcode
66
qt_policy(SET QTP0005 NEW)
67
68
qt_add_qml_module(other_module
69
URI OtherModule
70
VERSION 1.0
71
)
72
73
qt_add_qml_module(my_module
74
URI MyModule
75
VERSION 1.0
76
DEPENDENCIES
77
TARGET other_module
78
)
79
\endcode
80
81
The same \c TARGET syntax is available for \c IMPORTS, \c OPTIONAL_IMPORTS,
82
and \c DEFAULT_IMPORTS.
83
84
As shown above, you can set the policy explicitly with
85
\c{qt_policy(SET QTP0005 NEW)} before calling \c{qt_add_qml_module()}.
86
Alternatively, call
87
\l{qt6_standard_project_setup}{qt_standard_project_setup()} with a
88
\c REQUIRES version of 6.8 or later to enable all policies up to that version.
89
90
Qt 6.8 issues a deprecation warning if you use \c TARGET as a token in
91
\c DEPENDENCIES, \c IMPORTS, \c OPTIONAL_IMPORTS, or \c DEFAULT_IMPORTS while
92
the policy is set to \c OLD.
93
Use the \l qt_policy command to suppress the warning by explicitly setting
94
the policy to \c OLD or \c NEW.
95
96
\qtpolicydeprecatedbehavior
97
98
\sa qt_policy, {qt6_standard_project_setup}{qt_standard_project_setup()},
99
qt_cmake_policies, qt_add_qml_module
100
101
*/
qtdeclarative
src
qml
doc
src
cmake
policy
qtp0005.qdoc
Generated on
for Qt by
1.16.1