Pro-file level support for importing plugins for static Qt builds
authorMiikka Heikkinen <miikka.heikkinen@digia.com>
Mon, 10 Dec 2012 13:56:29 +0000 (15:56 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 10 Dec 2012 14:33:45 +0000 (15:33 +0100)
Platform plugin is needed always when gui is linked to an application.
This is tedious to do manually for static builds, so provide support
for generating a source file that imports static plugins for
application projects.

"CONFIG += import_plugins" statement in application .pro file will
generate required import statements for all plugins specified with
QTPLUGIN variable.

The plugin class names are found from plugin's module pri generated
automatically when plugin is built, as long as the plugin specifies
the PLUGIN_CLASS_NAME in the plugin .pro file before loading
qt_plugin.prf.

Task-number: QTBUG-28131
Change-Id: I19f8ea48a3c1e9b5c81f4399c4b5d439a6d4bea1
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
mkspecs/features/qt.prf
mkspecs/features/qt_plugin.prf

index 443914e..6b2833b 100644 (file)
@@ -36,7 +36,30 @@ plugin { #Qt plugins
 }
 
 QT_PLUGIN_VERIFY = DEPLOYMENT_PLUGIN
-contains(QT_CONFIG, static): QT_PLUGIN_VERIFY += QTPLUGIN
+
+contains(QT_CONFIG, static) {
+    QT_PLUGIN_VERIFY += QTPLUGIN
+    contains(TEMPLATE, .*app) {
+        import_plugins:!isEmpty(QTPLUGIN) {
+            IMPORT_FILE_CONT = \
+                "// This file is autogenerated by qmake. It imports static plugin classes for" \
+                "// static plugins specified using QTPLUGIN and QT_PLUGIN_CLASS.<plugin> variables." \
+                "$${LITERAL_HASH}include <QtPlugin>"
+            for(IMPORT_PLUG, $$list($$unique(QTPLUGIN))) {
+                PLUG_CLASS = $$eval(QT_PLUGIN.$${IMPORT_PLUG}.CLASS_NAME)
+                !isEmpty(PLUG_CLASS): \
+                    IMPORT_FILE_CONT += "Q_IMPORT_PLUGIN($$PLUG_CLASS)"
+                else: \
+                    warning("Plugin class name could not be determined for $$IMPORT_PLUG plugin.")
+            }
+            IMPORT_CPP = $$OUT_PWD/$$lower($$basename(TARGET))_plugin_import.cpp
+            write_file($$IMPORT_CPP, IMPORT_FILE_CONT)|error("Aborting.")
+            SOURCES += $$IMPORT_CPP
+            QMAKE_DISTCLEAN += $$IMPORT_CPP
+        }
+    }
+}
+
 for(QT_CURRENT_VERIFY, $$list($$QT_PLUGIN_VERIFY)) {
     for(QTPLUG, $$list($$lower($$unique($$QT_CURRENT_VERIFY)))) {
        # Check if the plugin is known to Qt. We can use this to determine
index e09e5d0..f547e2d 100644 (file)
@@ -26,7 +26,9 @@ else:CONFIG += shared
     MODULE_PRI = $$MODULE_QMAKE_OUTDIR/mkspecs/modules/qt_plugin_$${MODULE}.pri
 
     MODULE_PRI_CONT = \
-        "QT_PLUGIN.$${MODULE}.TYPE = $$PLUGIN_TYPE"
+        "QT_PLUGIN.$${MODULE}.TYPE = $$PLUGIN_TYPE" \
+        "QT_PLUGIN.$${MODULE}.CLASS_NAME = $$PLUGIN_CLASS_NAME"
+
     write_file($$MODULE_PRI, MODULE_PRI_CONT)|error("Aborting.")
 
     pritarget.path = $$[QT_HOST_DATA]/mkspecs/modules