diff options
-rw-r--r-- | src/qml/Qt6QmlBuildInternals.cmake | 19 | ||||
-rw-r--r-- | src/qml/Qt6QmlMacros.cmake | 33 |
2 files changed, 52 insertions, 0 deletions
diff --git a/src/qml/Qt6QmlBuildInternals.cmake b/src/qml/Qt6QmlBuildInternals.cmake index 915c71de6c..03db29b8db 100644 --- a/src/qml/Qt6QmlBuildInternals.cmake +++ b/src/qml/Qt6QmlBuildInternals.cmake @@ -391,6 +391,25 @@ function(qt_internal_add_qml_module target) FILES ${arg_OUTPUT_DIRECTORY}/$<TARGET_PROPERTY:${target},QT_QML_MODULE_TYPEINFO> DESTINATION "${arg_INSTALL_DIRECTORY}" ) + + # Assign the install time metatypes file of the backing library to the plugin. + # Only do it if the backing library is different from the plugin and we do generate + # qml types. + # The install time metatypes only apply to Qt's own qml plugins, not to user project + # qml plugins. + if(arg_PLUGIN_TARGET AND + TARGET "${arg_PLUGIN_TARGET}" AND NOT target STREQUAL arg_PLUGIN_TARGET) + _qt_internal_get_metatypes_install_dir( + "" + "${INSTALL_ARCHDATADIR}" + install_dir + ) + + _qt_internal_assign_install_metatypes_files_and_properties( + "${arg_PLUGIN_TARGET}" + INSTALL_DIR "${install_dir}" + ) + endif() endif() if(NOT arg_NO_GENERATE_QMLDIR) diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake index 76db0301bc..8aea3a759d 100644 --- a/src/qml/Qt6QmlMacros.cmake +++ b/src/qml/Qt6QmlMacros.cmake @@ -537,7 +537,10 @@ Check https://doc.qt.io/qt-6/qt-cmake-policy-qtp0001.html for policy details." if(arg_NAMESPACE) list(APPEND type_registration_extra_args NAMESPACE ${arg_NAMESPACE}) endif() + set_target_properties(${target} PROPERTIES _qt_internal_has_qmltypes TRUE) _qt_internal_qml_type_registration(${target} ${type_registration_extra_args}) + else() + set_target_properties(${target} PROPERTIES _qt_internal_has_qmltypes FALSE) endif() set(output_targets) @@ -1747,6 +1750,36 @@ function(qt6_add_qml_plugin target) ) endif() + # Work around QTBUG-115152. + # Assign / duplicate the backing library's metatypes file to the qml plugin. + # This ensures that the metatypes are passed as foreign types to qmltyperegistrar when + # a consumer links against the plugin, but not the backing library. + # This is needed because the plugin links PRIVATEly to the backing library and thus the + # backing library's INTERFACE_SOURCES don't end up in the final consumer's SOURCES. + # Arguably doing this is cleaner than changing the linkage to PUBLIC, because that will + # propagate not only the INTERFACE_SOURCES, but also other link dependencies, which might + # be unwanted. + # In general this is a workaround due to CMake's limitations around support for propagating + # custom properties across targets to a final consumer target. + # https://gitlab.kitware.com/cmake/cmake/-/issues/20416 + if(arg_BACKING_TARGET + AND TARGET "${arg_BACKING_TARGET}" AND NOT arg_BACKING_TARGET STREQUAL target) + get_target_property(plugin_meta_types_file "${target}" INTERFACE_QT_META_TYPES_BUILD_FILE) + get_target_property( + backing_meta_types_file "${arg_BACKING_TARGET}" INTERFACE_QT_META_TYPES_BUILD_FILE) + get_target_property( + backing_meta_types_file_name + "${arg_BACKING_TARGET}" INTERFACE_QT_META_TYPES_FILE_NAME) + get_target_property(backing_has_qmltypes "${arg_BACKING_TARGET}" _qt_internal_has_qmltypes) + if(backing_has_qmltypes AND NOT plugin_meta_types_file) + _qt_internal_assign_build_metatypes_files_and_properties( + "${target}" + METATYPES_FILE_NAME "${backing_meta_types_file_name}" + METATYPES_FILE_PATH "${backing_meta_types_file}" + ) + endif() + endif() + if(ANDROID) _qt_internal_get_qml_plugin_output_name(plugin_output_name ${target} BACKING_TARGET "${arg_BACKING_TARGET}" |