summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2020-01-22 14:22:19 +0100
committerAlexandru Croitor <alexandru.croitor@qt.io>2020-01-27 11:49:11 +0000
commitf67d8ae2d4339c50cf0a4ca26f25c3afebc128ea (patch)
tree72300595566d9379df09e2081fe6057abd18c87b
parentc9bea1ad62addb7582ddf0e8d790719c96a0ea90 (diff)
Fix plugin target names to be compatible with Qt 5
In Qt 5, qmake generates CMake Config files which expose the plugins as imported libraries. The name of these libraries are derived from the plugin class name. So QCocoaIntegrationPlugin, and not qcocoa. To keep compatibility between Qt5 and Qt6 CMake target names, the pro2cmake script should generate plugin target names based on the plugin class names. To avoid passing the same name in qt_add_plugin (target and CLASS_NAME), derive the class name from the target if the class name is not explicitly specified. Also add a new OUTPUT_NAME parameter which is used to change the final file name of the plugin, so that it's compatible with Qt5. For example to generate a qcocoa.dylib file, instead of QCocoaIntegrationPlugin.dylib file. The same OUTPUT_NAME value will be used for generation of plugin .prl files for qmake consumption. Change-Id: I4d53e680d7beb62befecd359cdf6bba60a34ff0d Reviewed-by: Qt CMake Build Bot Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r--cmake/QtBuild.cmake27
-rwxr-xr-xutil/cmake/pro2cmake.py28
2 files changed, 44 insertions, 11 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake
index 0070aac2d7..b2f72d9807 100644
--- a/cmake/QtBuild.cmake
+++ b/cmake/QtBuild.cmake
@@ -2145,7 +2145,7 @@ set(__qt_add_plugin_optional_args
"STATIC;EXCEPTIONS;ALLOW_UNDEFINED_SYMBOLS"
)
set(__qt_add_plugin_single_args
- "TYPE;CLASS_NAME;OUTPUT_DIRECTORY;INSTALL_DIRECTORY;ARCHIVE_INSTALL_DIRECTORY;QML_TARGET_PATH"
+ "TYPE;CLASS_NAME;OUTPUT_DIRECTORY;INSTALL_DIRECTORY;ARCHIVE_INSTALL_DIRECTORY;QML_TARGET_PATH;OUTPUT_NAME"
)
set(__qt_add_plugin_multi_args
"${__default_private_args};${__default_public_args};DEFAULT_IF"
@@ -2178,8 +2178,11 @@ function(qt_add_plugin target)
set(archive_install_directory_default "${INSTALL_QMLDIR}/${target_path}")
endif()
- if ("x${arg_CLASS_NAME}" STREQUAL "x" AND NOT "${arg_TYPE}" STREQUAL "qml_plugin")
- message(AUTHOR_WARNING "qt_add_plugin called without setting CLASS_NAME.")
+ # Derive the class name from the target name if it's not explicitly specified.
+ # Don't set it for qml plugins though.
+ set(plugin_class_name "")
+ if (NOT arg_CLASS_NAME AND NOT "${arg_TYPE}" STREQUAL "qml_plugin")
+ set(plugin_class_name "${target}")
endif()
qt_internal_check_directory_or_type(OUTPUT_DIRECTORY "${arg_OUTPUT_DIRECTORY}" "${arg_TYPE}"
@@ -2203,11 +2206,25 @@ function(qt_add_plugin target)
endif()
endif()
+ # Make sure the Qt6 plugin library names are like they were in Qt5 qmake land.
+ # Whereas the Qt6 CMake target names are like the Qt5 CMake target names.
+ set(output_name "${target}")
+ if(arg_OUTPUT_NAME)
+ set(output_name "${arg_OUTPUT_NAME}")
+ endif()
+ set_property(TARGET "${target}" PROPERTY OUTPUT_NAME "${output_name}")
+
+ # Add a custom target with the Qt5 qmake name for a more user friendly ninja experience.
+ if(arg_OUTPUT_NAME)
+ add_custom_target("${output_name}")
+ add_dependencies("${output_name}" "${target}")
+ endif()
+
if (ANDROID)
qt_android_apply_arch_suffix("${target}")
set_target_properties(${target}
PROPERTIES
- LIBRARY_OUTPUT_NAME "plugins_${arg_TYPE}_${target}"
+ LIBRARY_OUTPUT_NAME "plugins_${arg_TYPE}_${output_name}"
)
endif()
qt_internal_add_target_aliases("${target}")
@@ -2221,7 +2238,7 @@ function(qt_add_plugin target)
LIBRARY_OUTPUT_DIRECTORY "${output_directory}"
RUNTIME_OUTPUT_DIRECTORY "${output_directory}"
ARCHIVE_OUTPUT_DIRECTORY "${output_directory}"
- QT_PLUGIN_CLASS_NAME "${arg_CLASS_NAME}")
+ QT_PLUGIN_CLASS_NAME "${plugin_class_name}")
qt_handle_multi_config_output_dirs("${target}")
qt_internal_library_deprecation_level(deprecation_define)
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py
index fe2a08b71f..24dfd0ca8b 100755
--- a/util/cmake/pro2cmake.py
+++ b/util/cmake/pro2cmake.py
@@ -3259,10 +3259,30 @@ def write_example(
def write_plugin(cm_fh, scope, *, indent: int = 0) -> str:
- plugin_name = scope.TARGET
+ extra = []
+ qmake_target_name = scope.TARGET
+
+ # Forward the original Qt5 plugin target name, to correctly name the
+ # final library file name, and also for .prl generation.
+ if qmake_target_name:
+ extra.append(f"OUTPUT_NAME {qmake_target_name}")
+
+ # In Qt 6 CMake, the CMake target name for a plugin should be the
+ # same as it is in Qt5. qmake in Qt 5 derived the CMake target name
+ # from the "plugin class name", so use that.
+ # If the class name isn't empty, use that as the target name.
+ # Otherwise use the of value qmake TARGET
+ plugin_class_name = scope.get_string("PLUGIN_CLASS_NAME")
+ if plugin_class_name:
+ plugin_name = plugin_class_name
+ else:
+ plugin_name = qmake_target_name
assert plugin_name
- extra = []
+ # If the target name is derived from the class name, no need to
+ # forward the class name.
+ if plugin_class_name and plugin_class_name != plugin_name:
+ extra.append(f"CLASS_NAME {plugin_class_name}")
qmldir = None
plugin_type = scope.get_string("PLUGIN_TYPE")
@@ -3283,10 +3303,6 @@ def write_plugin(cm_fh, scope, *, indent: int = 0) -> str:
if "qmltypes" in scope.get("CONFIG"):
extra.append("GENERATE_QMLTYPES")
- plugin_class_name = scope.get_string("PLUGIN_CLASS_NAME")
- if plugin_class_name:
- extra.append(f"CLASS_NAME {plugin_class_name}")
-
if "static" in scope.get("CONFIG"):
extra.append("STATIC")