Pro-file level support for importing plugins for static Qt builds

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>
bb10
Miikka Heikkinen 2012-12-10 15:56:29 +02:00 committed by The Qt Project
parent c9d40ef2c1
commit f166fcd3d0
2 changed files with 27 additions and 2 deletions

View 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

View 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