diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-06-10 18:55:28 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-06-18 10:45:25 +0200 |
commit | aed94b820b21ba4adaee08796e9db21fce71f671 (patch) | |
tree | 1b7db3acc1be0e4991858ce4213fa86a90d948b5 | |
parent | ac03b4b8ee9cc8d4522e0c8cf1018ff086f80c1b (diff) |
CMake: Adjust QML plugin class name auto-computing
The recent 602d26c38f3767be9bec25302c93fc155c4dce59 change in qtbase
is now requiring that CLASS_NAME is always set for qml plugins, to
ensure that in static builds we can pre-build a plugin initializer
object library.
Split out the uri escaping and class name generation code into
separate functions.
Ensure that the class name is auto-generated by
qt_internal_add_qml_plugin if it wasn't manually specified.
Pass that value to the qt_internal_add_plugin function.
Remove comment about not passing the CLASS_NAME.
Task-number: QTBUG-93257
Task-number: QTBUG-92933
Change-Id: I8aa482a7da3a59f5a2213a630ff0be70506efe11
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r-- | src/qml/Qt6QmlBuildInternals.cmake | 14 | ||||
-rw-r--r-- | src/qml/Qt6QmlMacros.cmake | 19 |
2 files changed, 22 insertions, 11 deletions
diff --git a/src/qml/Qt6QmlBuildInternals.cmake b/src/qml/Qt6QmlBuildInternals.cmake index 8bb69734aa..a9cc7ef3f7 100644 --- a/src/qml/Qt6QmlBuildInternals.cmake +++ b/src/qml/Qt6QmlBuildInternals.cmake @@ -27,12 +27,6 @@ function(qt_internal_add_qml_module target) module_multi_args ) - # We don't want to pass CLASS_NAME to qt_internal_add_plugin(), we will - # pass it to qt6_add_qml_module() to handle instead. qt_internal_add_plugin() - # would just ignore it anyway because we set TYPE to qml_plugin, but we have - # to remove it to prevent duplicates in argument parsing. - list(REMOVE_ITEM module_single_args CLASS_NAME) - set(qml_module_option_args DESIGNER_SUPPORTED NO_PLUGIN_OPTIONAL @@ -194,6 +188,14 @@ function(qt_internal_add_qml_module target) endif() if(NOT arg_NO_CREATE_PLUGIN_TARGET) + # If the qt_internal_add_qml_module call didn't specify a CLASS_NAME, we need to pre-compute + # it here and pass it along to qt_internal_add_plugin -> qt_add_plugin so that + # qt_add_qml_plugin does not complain about differing class names (the default pre-computed + # class name of a regular plugin and qml plugin are different). + if(NOT arg_CLASS_NAME) + _qt_internal_compute_qml_plugin_class_name_from_uri("${arg_URI}" arg_CLASS_NAME) + endif() + # Create plugin target now so we can set internal things list(APPEND plugin_args TYPE qml_plugin diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake index 6bbc92b972..a8b479d736 100644 --- a/src/qml/Qt6QmlMacros.cmake +++ b/src/qml/Qt6QmlMacros.cmake @@ -294,8 +294,7 @@ function(qt6_add_qml_module target) endif() endif() if(NOT arg_CLASS_NAME) - string(REGEX REPLACE "[^A-Za-z0-9]" "_" escaped_uri "${arg_URI}") - set(arg_CLASS_NAME "${escaped_uri}Plugin") + _qt_internal_compute_qml_plugin_class_name_from_uri("${arg_URI}" arg_CLASS_NAME) endif() if(TARGET ${target}) @@ -537,6 +536,16 @@ if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) endfunction() endif() +function(_qt_internal_get_escaped_uri uri out_var) + string(REGEX REPLACE "[^A-Za-z0-9]" "_" escaped_uri "${uri}") + set(${out_var} "${escaped_uri}" PARENT_SCOPE) +endfunction() + +function(_qt_internal_compute_qml_plugin_class_name_from_uri uri out_var) + _qt_internal_get_escaped_uri("${uri}" escaped_uri) + set(${out_var} "${escaped_uri}Plugin" PARENT_SCOPE) +endfunction() + macro(_qt_internal_genex_getproperty var target property) set(${var} "$<TARGET_PROPERTY:${target},${property}>") set(have_${var} "$<BOOL:${${var}}>") @@ -902,7 +911,7 @@ function(qt6_add_qml_plugin target) get_target_property(arg_URI ${arg_BACKING_TARGET} QT_QML_MODULE_URI) endif() - string(REGEX REPLACE "[^A-Za-z0-9]" "_" escaped_uri "${arg_URI}") + _qt_internal_get_escaped_uri("${arg_URI}" escaped_uri) if(TARGET ${target}) foreach(arg IN ITEMS STATIC SHARED) @@ -922,7 +931,7 @@ function(qt6_add_qml_plugin target) endif() set(arg_CLASS_NAME ${class_name}) elseif(NOT arg_CLASS_NAME) - set(arg_CLASS_NAME "${escaped_uri}Plugin") + _qt_internal_compute_qml_plugin_class_name_from_uri("${arg_URI}" arg_CLASS_NAME) endif() else() if(arg_STATIC AND arg_SHARED) @@ -938,7 +947,7 @@ function(qt6_add_qml_plugin target) endif() if(NOT arg_CLASS_NAME) - set(arg_CLASS_NAME "${escaped_uri}Plugin") + _qt_internal_compute_qml_plugin_class_name_from_uri("${arg_URI}" arg_CLASS_NAME) endif() qt6_add_plugin(${target} ${lib_type} |