From 734d2cdbc4ff6db6b3df8fffbb23dbbb565c076b Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 30 Mar 2021 09:27:04 +0200 Subject: CMake: Semi-handle non-current repo qt modules when creating plugins In the recent refactoring of qt_internal_add_plugin, a new target existence check was added when associating a plugin with a qt module. That check didn't account for a qualified qt module target name. This failed configuration of qtsvg which checked for the existence of a namespace-less 'Gui' in a per-repo build. Make sure to prepend the Qt namespace to the qt module name and also handle aliased target names. As a drive-by, add a TODO item to figure out how to link executables to plugins who's plugin type belong to a different repo, but both the executable and plugin are built in the current repo. Amends aa4a1006cbccbc180c600f9b4dc9e882bb5ed5ca Fixes: QTBUG-92235 Pick-to: dev Change-Id: I1c0f83672ab00f4702be9bad9a66ccc35e82f5c8 Reviewed-by: Joerg Bornemann --- cmake/QtPluginHelpers.cmake | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'cmake/QtPluginHelpers.cmake') diff --git a/cmake/QtPluginHelpers.cmake b/cmake/QtPluginHelpers.cmake index e3bde9c79f..1eb800cb0b 100644 --- a/cmake/QtPluginHelpers.cmake +++ b/cmake/QtPluginHelpers.cmake @@ -145,23 +145,43 @@ function(qt_internal_add_plugin target) # Save the Qt module in the plug-in's properties and vice versa if(NOT plugin_type_escaped STREQUAL "qml_plugin") qt_internal_get_module_for_plugin("${target}" "${plugin_type_escaped}" qt_module) - if(NOT TARGET "${qt_module}") - message(FATAL_ERROR "${qt_module} is not a known CMake target") + + set(qt_module_target "${QT_CMAKE_EXPORT_NAMESPACE}::${qt_module}") + if(NOT TARGET "${qt_module_target}") + message(FATAL_ERROR "Failed to associate Qt plugin with Qt module. ${qt_module_target} is not a known CMake target") endif() + set_target_properties("${target}" PROPERTIES QT_MODULE "${qt_module}") set(plugin_install_package_suffix "${qt_module}") - set_property(TARGET "${qt_module}" APPEND PROPERTY QT_PLUGINS "${target}") - get_target_property(module_source_dir ${qt_module} SOURCE_DIR) - get_directory_property(module_project_name - DIRECTORY ${module_source_dir} - DEFINITION PROJECT_NAME - ) - if(module_project_name STREQUAL PROJECT_NAME) - set_property(TARGET ${qt_module} APPEND PROPERTY QT_REPO_PLUGINS "${target}") - set_property(TARGET ${qt_module} APPEND PROPERTY QT_REPO_PLUGIN_CLASS_NAMES - "$" + + get_target_property(aliased_target ${qt_module_target} ALIASED_TARGET) + if(aliased_target) + set(qt_module_target ${aliased_target}) + endif() + get_target_property(is_imported_qt_module ${qt_module_target} IMPORTED) + + if(NOT is_imported_qt_module) + set_property(TARGET "${qt_module_target}" APPEND PROPERTY QT_PLUGINS "${target}") + get_target_property(module_source_dir ${qt_module_target} SOURCE_DIR) + get_directory_property(module_project_name + DIRECTORY ${module_source_dir} + DEFINITION PROJECT_NAME + ) + if(module_project_name STREQUAL PROJECT_NAME) + set_property(TARGET ${qt_module_target} APPEND PROPERTY QT_REPO_PLUGINS "${target}") + set_property(TARGET ${qt_module_target} APPEND PROPERTY QT_REPO_PLUGIN_CLASS_NAMES + "$" ) + endif() + else() + # TODO: If a repo A provides an internal executable E and a plugin P, with the plugin + # type belonging to a Qt module defined in a different repo, and executable E needs to + # link to plugin P in a static build, currently that won't happen. The executable E + # will link to plugins mentioned in the Qt module's QT_REPO_PLUGINS property, but that + # property will not list P because the Qt module will be an imported target and won't + # have a SOURCE_DIR or PROJECT NAME, so the checks above will not be met. + # Figure out how to handle such a scenario. endif() endif() -- cgit v1.2.3