summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@qt.io>2021-03-19 20:04:23 +1100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-03-23 04:30:19 +0000
commitc5859822eb44a81562f0276b3c8af050ac180c78 (patch)
tree9ff9d8ea4370c90f487304241e05df6c7602f7d2 /cmake
parent466177c9112de8b7a0bd0994767e8dfb8034d67f (diff)
Add plugins to Qt tools and executables for static builds
In static builds, we cannot allow any part of the main build to make a call to find_package(Qt6...) where such a call may load a Qt6*Plugins.cmake file. That would add additional dependencies to the main module targets, setting up a circular dependency in the set of *Config.cmake files which cannot be resolved. This scenario would be triggered by per-repo builds or user projects. But Qt's tools and other executables still need to load some plugins in static builds. Sometimes a platform plugin may be enough, other times we may want all supportable plugins (e.g. Qt Designer). Therefore, add all plugins we can identify as relevant for an executable that is part of the Qt build, but add them directly to the executable without affecting the linking relationships between the main module libraries. Also remove the now unnecessary check for QT_BUILD_PROJECT_NAME in top level builds because there should be no difference between per-repo and top level builds any more (as far as linking static plugins is concerned). Examples that build as part of the main build will still build successfully after this change, but they will not run if they require a platform plugin. Examples need to be moved out to a separate build where they can call find_package(Qt6) without QT_NO_CREATE_TARGETS set to TRUE to be runnable (see QTBUG-90820). Fixes: QTBUG-91915 Change-Id: I8088baddb54e394ca111b103313596d6743570ba Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> (cherry picked from commit 5807e1ae8168a5702ad0f6890d2b35223cfebdee) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Qt3rdPartyLibraryHelpers.cmake11
-rw-r--r--cmake/QtExecutableHelpers.cmake38
-rw-r--r--cmake/QtModuleHelpers.cmake9
-rw-r--r--cmake/QtPluginHelpers.cmake11
-rw-r--r--cmake/QtPlugins.cmake.in13
5 files changed, 49 insertions, 33 deletions
diff --git a/cmake/Qt3rdPartyLibraryHelpers.cmake b/cmake/Qt3rdPartyLibraryHelpers.cmake
index d144977c7f..4d5ffb96ff 100644
--- a/cmake/Qt3rdPartyLibraryHelpers.cmake
+++ b/cmake/Qt3rdPartyLibraryHelpers.cmake
@@ -175,17 +175,6 @@ function(qt_internal_add_3rdparty_library target)
qt_autogen_tools_initial_setup(${target})
endif()
- if(NOT arg_INTERFACE)
- # This property is used for super builds with static libraries. We use
- # it in QtPlugins.cmake.in to avoid "polluting" the dependency chain
- # for the target in it's project directory.
- # E.g: When we process find_package(Qt6 ... Gui) in QtDeclarative, the
- # rules in QtPugins.cmake add all the known Gui plugins as interface
- # dependencies. This in turn causes circular dependencies on every
- # plugin which links against Gui. Plugin A -> GUI -> Plugin A ....
- set_target_properties(${target} PROPERTIES QT_BUILD_PROJECT_NAME ${PROJECT_NAME})
- endif()
-
if(NOT arg_EXCEPTIONS AND NOT arg_INTERFACE)
qt_internal_set_exceptions_flags("${target}" FALSE)
elseif(arg_EXCEPTIONS)
diff --git a/cmake/QtExecutableHelpers.cmake b/cmake/QtExecutableHelpers.cmake
index 5ab7848aae..bccab32b87 100644
--- a/cmake/QtExecutableHelpers.cmake
+++ b/cmake/QtExecutableHelpers.cmake
@@ -174,4 +174,42 @@ function(qt_internal_add_executable name)
if("Qt::Gui" IN_LIST linked_libs AND TARGET qpa_default_plugins)
add_dependencies("${name}" qpa_default_plugins)
endif()
+
+ if(NOT BUILD_SHARED_LIBS)
+ # For static builds, we need to explicitly link to plugins we want to be
+ # loaded with the executable. User projects get that automatically, but
+ # for tools built as part of Qt, we can't use that mechanism because it
+ # would pollute the targets we export as part of an install and lead to
+ # circular dependencies. The logic here is a simpler equivalent of the
+ # more dynamic logic in QtPlugins.cmake.in, but restricted to only
+ # adding plugins that are provided by the same module as the module
+ # libraries the executable links to.
+ set(libs
+ ${arg_LIBRARIES}
+ ${arg_PUBLIC_LIBRARIES}
+ ${extra_libraries}
+ Qt::PlatformCommonInternal
+ )
+ list(REMOVE_DUPLICATES libs)
+ foreach(lib IN LISTS libs)
+ if(NOT TARGET "${lib}")
+ continue()
+ endif()
+ string(MAKE_C_IDENTIFIER "${name}_plugin_imports_${lib}" out_file)
+ string(APPEND out_file .cpp)
+ set(class_names "$<GENEX_EVAL:$<TARGET_PROPERTY:${lib},QT_REPO_PLUGIN_CLASS_NAMES>>")
+ file(GENERATE OUTPUT ${out_file} CONTENT
+"// This file is auto-generated. Do not edit.
+#include <QtPlugin>
+
+Q_IMPORT_PLUGIN($<JOIN:${class_names},)\nQ_IMPORT_PLUGIN(>)
+"
+ CONDITION "$<NOT:$<STREQUAL:${class_names},>>"
+ )
+ target_sources(${name} PRIVATE
+ "$<$<NOT:$<STREQUAL:${class_names},>>:${out_file}>"
+ )
+ target_link_libraries(${name} PRIVATE "$<TARGET_PROPERTY:${lib},QT_REPO_PLUGINS>")
+ endforeach()
+ endif()
endfunction()
diff --git a/cmake/QtModuleHelpers.cmake b/cmake/QtModuleHelpers.cmake
index 6268bfe960..efd9cd9a8e 100644
--- a/cmake/QtModuleHelpers.cmake
+++ b/cmake/QtModuleHelpers.cmake
@@ -241,15 +241,6 @@ function(qt_internal_add_module target)
endif()
if(NOT arg_HEADER_MODULE)
- # This property is used for super builds with static libraries. We use
- # it in QtPlugins.cmake.in to avoid "polluting" the dependency chain
- # for the target in it's project directory.
- # E.g: When we process find_package(Qt6 ... Gui) in QtDeclarative, the
- # rules in QtPugins.cmake add all the known Gui plugins as interface
- # dependencies. This in turn causes circular dependencies on every
- # plugin which links against Gui. Plugin A -> GUI -> Plugin A ....
-
- set_target_properties(${target} PROPERTIES QT_BUILD_PROJECT_NAME ${PROJECT_NAME})
# Plugin types associated to a module
if(NOT "x${arg_PLUGIN_TYPES}" STREQUAL "x")
# Reset the variable containing the list of plugins for the given plugin type
diff --git a/cmake/QtPluginHelpers.cmake b/cmake/QtPluginHelpers.cmake
index 2df5f6e11d..deca0dd8a5 100644
--- a/cmake/QtPluginHelpers.cmake
+++ b/cmake/QtPluginHelpers.cmake
@@ -130,6 +130,17 @@ function(qt_internal_add_plugin target)
# Add the plug-in to the list of plug-ins of this module
if(TARGET "${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>"
+ )
+ endif()
endif()
# Change the configuration file install location for qml plugins into the Qml package location.
diff --git a/cmake/QtPlugins.cmake.in b/cmake/QtPlugins.cmake.in
index fd3370b9a2..d57611caec 100644
--- a/cmake/QtPlugins.cmake.in
+++ b/cmake/QtPlugins.cmake.in
@@ -35,18 +35,6 @@ function(__qt_internal_add_static_plugins_once)
# Plugin genex marker for prl processing.
set(_is_plugin_marker_genex "$<BOOL:QT_IS_PLUGIN_GENEX>")
- # In super builds the rules below pollute the dependency rule for the
- # plugin target when it's being build, causing cyclic dependencies.
- # to overcome this, we check if the current target where this rule evaluates
- # has a QT_BUILD_PROJECT_NAME equal to the current PROJECT_NAME.
- # If so we disable the injection of plugin link rules to avoid cyclic
- # dependencies.
- if (@QT_SUPERBUILD@)
- set(_build_allow_plugin_link_rules_genex "$<NOT:$<STREQUAL:$<TARGET_PROPERTY:QT_BUILD_PROJECT_NAME>,@PROJECT_NAME@>>")
- else()
- set(_build_allow_plugin_link_rules_genex 1)
- endif()
-
# The code in here uses the properties defined in qt_import_plugins (Qt6CoreMacros.cmake)
foreach(target ${_qt_plugins})
set(_plugin_target "@INSTALL_CMAKE_NAMESPACE@::${target}")
@@ -115,7 +103,6 @@ function(__qt_internal_add_static_plugins_once)
string(CONCAT _plugin_condition
"$<BOOL:$<AND:"
"${_is_plugin_marker_genex},"
- "${_build_allow_plugin_link_rules_genex},"
"$<OR:"
"${_plugin_is_whitelisted},"
"${_plugin_versionless_is_whitelisted},"