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
cmake-integration.qdoc
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page qtqml-cmake-integration.html
6\title CMake Integration for QML
7\brief CMake commands, properties, and policies for QML module development.
8
9Qt provides extensive CMake integration for building QML modules and applications.
10
11\section1 Core CMake Commands
12
13\section2 qt_add_qml_module
14
15The \l{qt_add_qml_module} command is the primary function for creating QML modules in CMake.
16It handles QML type registration, resource embedding, plugin creation, and integration with
17Qt's build system, providing a declarative way to define all aspects of a QML module.
18
19\section2 qt_target_qml_sources
20
21The \l{qt_target_qml_sources} command adds QML files and resources to an existing QML module
22target. This is useful for organizing large modules or conditionally including QML files based
23on build configuration.
24
25\section2 qt_add_qml_plugin
26
27The \l{qt_add_qml_plugin} command creates a QML plugin library that can be dynamically loaded
28by the QML engine. While \c{qt_add_qml_module} typically handles plugin creation automatically,
29this function provides lower-level control when needed.
30
31\section1 Deployment Commands
32
33\section2 qt_deploy_qml_imports
34
35The \l{qt_deploy_qml_imports} command identifies and deploys all QML imports used by your
36application, including their dependencies. This ensures that all necessary QML modules and
37plugins are packaged with your application.
38
39\section2 qt_generate_deploy_qml_app_script
40
41The \l{qt_generate_deploy_qml_app_script} command generates a platform-specific deployment
42script that handles copying QML modules, plugins, and other resources to the correct locations
43in your application bundle or installation directory.
44
45\section2 qt_import_qml_plugins
46
47The \l{qt_import_qml_plugins} command ensures that QML plugins are properly linked into
48statically-built applications, generating the necessary initialization code to register
49the plugins with the QML engine.
50
51\section1 Advanced Commands
52
53\section2 qt_generate_foreign_qml_types
54
55The \l{qt_generate_foreign_qml_types} command creates QML type registrations for C++ types
56that are defined in other libraries or modules. This enables you to expose third-party or
57Qt types to QML without modifying their source code.
58
59\section2 qt_query_qml_module
60
61The \l{qt_query_qml_module} command retrieves information about a QML module, such as its
62URI, version, plugin target, and type information file paths. This is useful for build
63system introspection and tooling integration.
64
65\section2 qt_target_compile_qml_to_cpp
66
67The \l{qt_target_compile_qml_to_cpp} command enables compilation of QML files to C++ using
68\l{qmltc}(the QML type compiler). This provides an alternative to component-based
69instantiation with improved performance for statically-known QML types.
70
71\section2 qt_add_qml_preview
72
73The \l{qt_add_qml_preview} command sets up \l{qmlpreview} live-reload support for an
74executable target that loads QML from one or more \l{qt_add_qml_module} targets, but is
75not itself a QML module. It creates an additional \c{<target>_qmlpreview} build target that
76can be used to preview the executable's QML files.
77
78\section1 CMake Variables and Properties
79
80Qt Qml provides several CMake variables and properties to configure QML module behavior:
81
82\section2 Global Variables
83
84\l{CMake Global Variables in Qt6 Qml} control default behavior across all QML modules in your
85project. These include variables for output directories, cache file generation, and tooling
86integration, allowing you to configure QML compilation settings at a project-wide level.
87
88\section2 Global Properties
89
90\l{CMake Global Properties in Qt6 Qml} affect how the build system processes QML modules and can be
91used to customize aspects like linter target organization and build-time code generation.
92
93\section2 Source File Properties
94
95\l{CMake Source File Properties in Qt6 Qml} allow fine-grained control over individual QML files
96within a module. You can use these properties to mark files as singletons, exclude them from
97compilation steps, specify custom type names, or control other per-file behaviors in the QML type
98system.
99
100\section2 Target Properties
101
102\l{CMake Target Properties in Qt6 Qml} let you fine-tune the behavior of individual targets,
103for example to opt a target out of behavior that would otherwise be enabled for it project-wide,
104such as automatic \l{qmlpreview} target creation.
105
106\section1 CMake Policies
107
108Qt Qml defines several CMake policies to control backward compatibility and behavior.
109
110\section2 CMake Policies for QML
111
112The \l{CMake Policies for QML} page provides an overview of all QML-related CMake policies
113and how they affect module behavior. Policies allow you to opt-in to new behaviors while
114maintaining compatibility with existing projects.
115
116\sa {QML Modules}, {qt_add_qml_module}, {Writing QML Modules}
117*/