From 5dc14c88f9510795835fb4f0a0d46d67c40f7020 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 2 Jun 2020 16:50:20 +0200 Subject: Allow QML plugins to be optional If a plugin does nothing but load the library that provides the types, we can skip the plugin loading by linking the library directly. State that in the qmldir file, and evaluate it when loading the module. Task-number: QTBUG-84639 Change-Id: I2097237866a50f66c55e4653ad119fe10e18a893 Reviewed-by: Paul Wicking Reviewed-by: Fabian Kosmale --- src/qml/Qt6QmlMacros.cmake | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/qml/Qt6QmlMacros.cmake') diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake index 9671712bd3..43a590d310 100644 --- a/src/qml/Qt6QmlMacros.cmake +++ b/src/qml/Qt6QmlMacros.cmake @@ -68,6 +68,10 @@ # to not list any qml types. These are expected to be registered by the # c++ plugin code instead. # +# PLUGIN_OPTIONAL: The plugin is marked as optional in the qmldir file. If the +# type registration functions are already available by other means, typically +# by linking a library proxied by the plugin, it won't be loaded. +# function(qt6_add_qml_module target) @@ -76,6 +80,7 @@ function(qt6_add_qml_module target) DESIGNER_SUPPORTED DO_NOT_INSTALL_METADATA SKIP_TYPE_REGISTRATION + PLUGIN_OPTIONAL INSTALL_QML_FILES ) @@ -224,7 +229,13 @@ function(qt6_add_qml_module target) set(qmldir_file "${CMAKE_CURRENT_BINARY_DIR}/qmldir") set_target_properties(${target} PROPERTIES QT_QML_MODULE_QMLDIR_FILE ${qmldir_file}) set(qmldir_file_contents "module ${arg_URI}\n") - string(APPEND qmldir_file_contents "plugin ${target}\n") + + if (arg_PLUGIN_OPTIONAL) + string(APPEND qmldir_file_contents "optional plugin ${target}\n") + else() + string(APPEND qmldir_file_contents "plugin ${target}\n") + endif() + if (arg_CLASSNAME) string(APPEND qmldir_file_contents "classname ${arg_CLASSNAME}\n") endif() -- cgit v1.2.3