diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-05-03 17:51:33 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-05-26 18:58:34 +0200 |
commit | 2d929d01162e0ca191e220b03c61ec7e215e75e1 (patch) | |
tree | 8a9ade0f4dee1ef47252f36699fa2b7d95c88ffe | |
parent | Blacklist tst_QGestureRecognizer::panGesture (diff) | |
download | qtbase-2d929d01162e0ca191e220b03c61ec7e215e75e1.tar.xz qtbase-2d929d01162e0ca191e220b03c61ec7e215e75e1.zip |
CMake: Fix automatic default linking of static svg plugins
When a qmake project links to the static QSvg module, qmake will
automatically link the svg plugins into the executable.
This was not the case for CMake projects, due to an incorrect genex
check of the QT_PLUGIN_EXTENDS property.
Instead of checking against the CMAKE_MODULE_NAME value, we should
check for the modules listed in the qmake PLUGIN_EXTENDS variable.
Note that the CMake behavior is still off compared to the qmake one.
In a qmake project, the svg plugins will only be linked if there's
a QT += svg clause (find and link against svg module). If there's only
a QT += gui, the svg plugins will not be linked in.
In contrast, in CMake it's enough to only do find_package(Qt5Gui)
without finding Svg, and that will already link in the svg plugins.
This is somewhat incorrect, but shouldn't lead to any issues.
Not linking at all was worse.
Implementing this properly is much harder. A new bug report was filed
to track that for Qt 6.
Fixes: QTBUG-82037
Task-number: QTBUG-93501
Change-Id: I69715081839f9493329d12a88207daeab81218fc
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
-rw-r--r-- | mkspecs/features/create_cmake.prf | 9 | ||||
-rw-r--r-- | mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in | 9 |
2 files changed, 12 insertions, 6 deletions
diff --git a/mkspecs/features/create_cmake.prf b/mkspecs/features/create_cmake.prf index 24ed125f12..64639f177d 100644 --- a/mkspecs/features/create_cmake.prf +++ b/mkspecs/features/create_cmake.prf @@ -170,6 +170,9 @@ qtConfig(debug_and_release) { } contains(CONFIG, plugin) { + CMAKE_PLUGIN_NAME = $$PLUGIN_CLASS_NAME + + plugin_genex_check = equals(PLUGIN_EXTENDS, -) { CMAKE_PLUGIN_EXTENDS = - } else { @@ -177,8 +180,13 @@ contains(CONFIG, plugin) { for (p, PLUGIN_EXTENDS) { m = $$cmakeModuleName($$p) list_plugin_extends += Qt::$$m + + # CMake introduced $<IN_LIST:> in 3.12 which is too new for Qt, so manually + # unroll each module check with an STREQUAL genex + plugin_genex_check += \"$<STREQUAL:$<TARGET_PROPERTY:Qt5::$${CMAKE_PLUGIN_NAME},QT_PLUGIN_EXTENDS>,Qt::$${m}>,\" } CMAKE_PLUGIN_EXTENDS = $$join(list_plugin_extends, ";") + CMAKE_PLUGIN_EXTENDS_GENEX_CHECK = $$join(plugin_genex_check, "$$escape_expand(\\n) ") } PLUGIN_MODULE_NAME = @@ -207,7 +215,6 @@ contains(CONFIG, plugin) { CMAKE_MODULE_NAME = $$cmakeModuleName($$PLUGIN_MODULE_NAME) - CMAKE_PLUGIN_NAME = $$PLUGIN_CLASS_NAME CMAKE_PLUGIN_TYPE = $$PLUGIN_TYPE CMAKE_PLUGIN_TYPE_ESCAPED = $$replace(PLUGIN_TYPE, [-/], _) diff --git a/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in b/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in index b550a52c60..2e23109167 100644 --- a/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in +++ b/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in @@ -86,15 +86,14 @@ string(CONCAT _plugin_genex \"${_user_specified_genex_versionless},\" # Add this plugin if all of the following are true: # 1) the list of explicitly included plugin types is empty - # 2) the QT_PLUGIN_EXTENDS property for the plugin is empty or equal to the current - # module name + # 2) the QT_PLUGIN_EXTENDS property for the plugin is empty or equal to one of the modules + # listed in the plugin's PLUGIN_EXTEND qmake variable # 3) the user hasn\'t explicitly excluded the plugin. + # TODO: Note that the current implementation of (2) is not entirely correct QTBUG-93501 \"$<AND:\" \"$<STREQUAL:${_plugin_type_genex},>,\" \"$<OR:\" - # FIXME: The value of CMAKE_MODULE_NAME seems to be wrong (e.g for Svg plugin - # it should be Qt::Svg instead of Qt::Gui). - \"$<STREQUAL:$<TARGET_PROPERTY:Qt5::$${CMAKE_PLUGIN_NAME},QT_PLUGIN_EXTENDS>,Qt::$${CMAKE_MODULE_NAME}>,\" + $${CMAKE_PLUGIN_EXTENDS_GENEX_CHECK} \"$<STREQUAL:$<TARGET_PROPERTY:Qt5::$${CMAKE_PLUGIN_NAME},QT_PLUGIN_EXTENDS>,>\" \">,\" \"$<NOT:$<IN_LIST:Qt5::$${CMAKE_PLUGIN_NAME},${_no_plugins_genex}>>,\" |