diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-03-30 09:27:04 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-03-31 01:09:20 +0200 |
commit | 734d2cdbc4ff6db6b3df8fffbb23dbbb565c076b (patch) | |
tree | 5268116893f65e888783801ce6d7e8ffeeab0693 | |
parent | c9fefcf98bdefecfec8309a5cb97471d5c50716c (diff) |
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 <joerg.bornemann@qt.io>
-rw-r--r-- | cmake/QtPluginHelpers.cmake | 44 |
1 files changed, 32 insertions, 12 deletions
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 - "$<TARGET_PROPERTY:${target},QT_PLUGIN_CLASS_NAME>" + + 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 + "$<TARGET_PROPERTY:${target},QT_PLUGIN_CLASS_NAME>" ) + 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() |