From e769bebac7cefd26d61f120098ec7c930c4015e4 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Mon, 26 Jul 2021 11:42:12 +1000 Subject: Make CLASS_NAME default match the documentation for qt6_add_qml_plugin The implementation did not obtain the class name from the backing target, but it should have. Instead, it was considering an internal target property on the plugin target itself, if it already existed. That was a leftover from earlier work where the plugin target may have been created directly by calling qt_add_plugin(), but it doesn't match the behavior we document or support. Simplify the implementation and make it match the documented behavior. Change-Id: Icd9ee1167e189715e8aff57f147734a2476f630c Reviewed-by: Fabian Kosmale Reviewed-by: Alexandru Croitor (cherry picked from commit bdcb1d702da3d27b51135e4ecc11f89b74bd96a3) Reviewed-by: Qt Cherry-pick Bot --- src/qml/Qt6QmlMacros.cmake | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake index d4109900d7..fe6078e58b 100644 --- a/src/qml/Qt6QmlMacros.cmake +++ b/src/qml/Qt6QmlMacros.cmake @@ -834,6 +834,15 @@ function(qt6_add_qml_plugin target) _qt_internal_get_escaped_uri("${arg_URI}" escaped_uri) + if(NOT arg_CLASS_NAME) + if(NOT "${arg_BACKING_TARGET}" STREQUAL "") + get_target_property(arg_CLASS_NAME ${target} QT_QML_MODULE_CLASS_NAME) + endif() + if(NOT arg_CLASS_NAME) + _qt_internal_compute_qml_plugin_class_name_from_uri("${arg_URI}" arg_CLASS_NAME) + endif() + endif() + if(TARGET ${target}) get_target_property(target_type ${target} TYPE) if(target_type STREQUAL "EXECUTABLE") @@ -846,17 +855,13 @@ function(qt6_add_qml_plugin target) ) endif() endforeach() - get_target_property(class_name ${target} QT_PLUGIN_CLASS_NAME) - if(class_name) - if(arg_CLASS_NAME AND NOT arg_CLASS_NAME STREQUAL class_name) - message(FATAL_ERROR - "CLASS_NAME was specified, but an existing target with a " - "different class name was also given" - ) - endif() - set(arg_CLASS_NAME ${class_name}) - elseif(NOT arg_CLASS_NAME) - _qt_internal_compute_qml_plugin_class_name_from_uri("${arg_URI}" arg_CLASS_NAME) + + get_target_property(existing_class_name ${target} QT_PLUGIN_CLASS_NAME) + if(existing_class_name AND NOT existing_class_name STREQUAL arg_CLASS_NAME) + message(FATAL_ERROR + "An existing target was given, but it has a different class name " + "(${existing_class_name}) to that being used here (${arg_CLASS_NAME})" + ) endif() else() if(arg_STATIC AND arg_SHARED) @@ -871,10 +876,6 @@ function(qt6_add_qml_plugin target) set(lib_type SHARED) endif() - if(NOT arg_CLASS_NAME) - _qt_internal_compute_qml_plugin_class_name_from_uri("${arg_URI}" arg_CLASS_NAME) - endif() - qt6_add_plugin(${target} ${lib_type} TYPE qml_plugin CLASS_NAME ${arg_CLASS_NAME} -- cgit v1.2.3