- Qt 6.12
- Qt Qml
- CMake Integration for QML
- Qt 6.12.0 Reference Documentation

qmlcontextpropertydump ◦ qt_add_qml_module

# CMake Integration for QML

Qt provides extensive CMake integration for building QML modules and applications.

## Core CMake Commands

### qt_add_qml_module

The qt_add_qml_module command is the primary function for creating QML modules in CMake. It handles QML type registration, resource embedding, plugin creation, and integration with Qt's build system, providing a declarative way to define all aspects of a QML module.

### qt_target_qml_sources

The qt_target_qml_sources command adds QML files and resources to an existing QML module target. This is useful for organizing large modules or conditionally including QML files based on build configuration.

### qt_add_qml_plugin

The qt_add_qml_plugin command creates a QML plugin library that can be dynamically loaded by the QML engine. While `qt_add_qml_module` typically handles plugin creation automatically, this function provides lower-level control when needed.

## Deployment Commands

### qt_deploy_qml_imports

The qt_deploy_qml_imports command identifies and deploys all QML imports used by your application, including their dependencies. This ensures that all necessary QML modules and plugins are packaged with your application.

### qt_generate_deploy_qml_app_script

The qt_generate_deploy_qml_app_script command generates a platform-specific deployment script that handles copying QML modules, plugins, and other resources to the correct locations in your application bundle or installation directory.

### qt_import_qml_plugins

The qt_import_qml_plugins command ensures that QML plugins are properly linked into statically-built applications, generating the necessary initialization code to register the plugins with the QML engine.

## Advanced Commands

### qt_generate_foreign_qml_types

The qt_generate_foreign_qml_types command creates QML type registrations for C++ types that are defined in other libraries or modules. This enables you to expose third-party or Qt types to QML without modifying their source code.

### qt_query_qml_module

The qt_query_qml_module command retrieves information about a QML module, such as its URI, version, plugin target, and type information file paths. This is useful for build system introspection and tooling integration.

### qt_target_compile_qml_to_cpp

The qt_target_compile_qml_to_cpp command enables compilation of QML files to C++ using qmltc(the QML type compiler). This provides an alternative to component-based instantiation with improved performance for statically-known QML types.

## CMake Variables and Properties

Qt Qml provides several CMake variables and properties to configure QML module behavior:

### Global Variables

CMake Global Variables in Qt6 Qml control default behavior across all QML modules in your project. These include variables for output directories, cache file generation, and tooling integration, allowing you to configure QML compilation settings at a project-wide level.

### Global Properties

CMake Global Properties in Qt6 Qml affect how the build system processes QML modules and can be used to customize aspects like linter target organization and build-time code generation.

### Source File Properties

CMake Source File Properties in Qt6 Qml allow fine-grained control over individual QML files within a module. You can use these properties to mark files as singletons, exclude them from compilation steps, specify custom type names, or control other per-file behaviors in the QML type system.

## CMake Policies

Qt Qml defines several CMake policies to control backward compatibility and behavior.

### CMake Policies for QML

The CMake Policies for QML page provides an overview of all QML-related CMake policies and how they affect module behavior. Policies allow you to opt-in to new behaviors while maintaining compatibility with existing projects.

See also QML Modules, qt_add_qml_module, and Writing QML Modules.

qmlcontextpropertydump ◦ qt_add_qml_module