Commit 146a4e5e authored by Hans-Christian Ebke's avatar Hans-Christian Ebke

Got statically linked plugins working.

parent 6e32b402
......@@ -345,18 +345,20 @@ void Core::loadPlugins()
pluginlist = additionalPlugins << pluginlist;
/*
* Get list of static plugins.
* Remove static plugins from dynamically loaded list.
*/
QSet<QString> staticPlugins = QSet<QString>::fromList(
QString::fromUtf8(cmake::static_plugins).split("\n"));
for (int i = 0; i < pluginlist.size(); ) {
const QString bn = QFileInfo(pluginlist[i]).fileName();
if (staticPlugins.contains(bn)) {
emit log(LOGOUT, trUtf8("Not loading dynamic %1 as it is statically "
"linked against OpenFlipper.").arg(bn));
pluginlist.removeAt(i);
} else {
++i;
{
QSet<QString> staticPlugins = QSet<QString>::fromList(
QString::fromUtf8(cmake::static_plugins).split("\n"));
for (int i = 0; i < pluginlist.size(); ) {
const QString bn = QFileInfo(pluginlist[i]).fileName();
if (staticPlugins.contains(bn)) {
emit log(LOGOUT, trUtf8("Not loading dynamic %1 as it is statically "
"linked against OpenFlipper.").arg(bn));
pluginlist.removeAt(i);
} else {
++i;
}
}
}
......@@ -454,6 +456,24 @@ void Core::loadPlugins()
delete *it;
}
/*
* Initialize static plugins.
*/
QVector<QStaticPlugin> staticPlugins = QPluginLoader::staticPlugins();
for (QVector<QStaticPlugin>::iterator it = staticPlugins.begin();
it != staticPlugins.end(); ++it) {
QObject *instance = it->instance();
BaseInterface* basePlugin = qobject_cast< BaseInterface * >(instance);
if (basePlugin) {
QString fakeName = QString::fromUtf8("<Statically Linked>::/%1.%2")
.arg(basePlugin->name())
.arg(OpenFlipper::Options::isWindows() ? "dll" : "so");
QString pluginLicenseText = "";
loadPlugin(fakeName, true, pluginLicenseText, instance);
licenseTexts += pluginLicenseText;
}
}
emit log(LOGINFO, tr("Total time needed to load plugins was %1 ms.").arg(time.elapsed()));
splashMessage_ = "";
......
......@@ -100,10 +100,20 @@ if ( EXISTS ${CMAKE_SOURCE_DIR}/branding/branding.qrc )
endif()
endif()
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/static_plugins.cc" "namespace cmake {\nconst char *static_plugins = \"\"\n")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/static_plugins.cc" "#include <QtPlugin>\n\n")
foreach (plugin ${OPENFLIPPER_STATIC_PLUGIN_NAMES})
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/static_plugins.cc" "Q_IMPORT_PLUGIN(${plugin});\n")
endforeach()
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/static_plugins.cc" "\nnamespace cmake {\n")
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/static_plugins.cc" "\nconst char *static_plugins = \"\"\n")
foreach (plugin ${OPENFLIPPER_STATIC_PLUGIN_FILES})
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/static_plugins.cc" "\"${plugin}\\n\"\n")
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/static_plugins.cc" "\"${plugin}\\n\"\n")
endforeach()
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/static_plugins.cc" ";\n} /* namespace cmake */\n")
list(APPEND RC_SRC "${CMAKE_CURRENT_BINARY_DIR}/static_plugins.cc")
......
......@@ -601,9 +601,11 @@ function (_build_openflipper_plugin plugin)
if (STATIC_PLUGIN_${_PLUGIN})
add_library (Plugin-Static-${plugin} STATIC ${uic_targets} ${sources} ${headers} ${moc_targets} ${qrc_targets} ${${_PLUGIN}_ADDSRC})
set_target_properties(Plugin-Static-${plugin} PROPERTIES COMPILE_DEFINITIONS "QT_STATICPLUGIN")
get_target_property(PLUGIN_OUTPUT_FILENAME Plugin-${plugin} LOCATION)
get_filename_component(PLUGIN_OUTPUT_FILENAME "${PLUGIN_OUTPUT_FILENAME}" NAME)
acg_set (OPENFLIPPER_STATIC_PLUGINS "${OPENFLIPPER_STATIC_PLUGINS};Plugin-Static-${plugin}")
acg_set (OPENFLIPPER_STATIC_PLUGIN_NAMES "${OPENFLIPPER_STATIC_PLUGIN_NAMES};${STATIC_PLUGIN_${_PLUGIN}}")
acg_set (OPENFLIPPER_STATIC_PLUGIN_FILES "${OPENFLIPPER_STATIC_PLUGIN_FILES};${PLUGIN_OUTPUT_FILENAME}")
endif ()
......@@ -778,10 +780,12 @@ macro (openflipper_plugin)
OFF
)
option (
set (
STATIC_PLUGIN_${_PLUGIN}
"Link plugin \"${_plugin}\" statically into the OpenFlipper binary."
OFF
""
CACHE
STRING
"Set this variable to the name of the plugin class in order to link it statically into the OpenFlipper binary."
)
if (NOT DISABLE_PLUGIN_${_PLUGIN})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment