Commit 02fe6fa6 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'static-plugins' into 'master'

Enable optional static linkage of plugins. (Useful for profiling.)



See merge request !32
parents d8fbcb9f f9f9e792
Pipeline #105 skipped
......@@ -255,6 +255,9 @@ endif()
# start with an empty plugin list
acg_set (OPENFLIPPER_PLUGINS "")
acg_set (OPENFLIPPER_STATIC_PLUGINS "")
acg_set (OPENFLIPPER_STATIC_PLUGIN_FILES "")
acg_set (OPENFLIPPER_STATIC_PLUGIN_NAMES "")
foreach (package ${PREFOUND_PACKAGES})
find_package(${package})
......
......@@ -71,6 +71,9 @@
#include <QtScript/QScriptValueIterator>
#include <QThread>
#include <QMutexLocker>
#if QT_VERSION >= 0x050000
#include <QStaticPlugin>
#endif
#include <QPluginLoader>
#include "OpenFlipper/BasePlugin/BaseInterface.hh"
......@@ -122,6 +125,8 @@
*/
static const int PRELOAD_THREADS_COUNT = (QThread::idealThreadCount() != -1) ? QThread::idealThreadCount() : 8;
namespace cmake { extern const char *static_plugins; };
class PreloadAggregator {
public:
PreloadAggregator() : expectedLoaders_(0) {}
......@@ -342,6 +347,26 @@ void Core::loadPlugins()
// Prepend the additional Plugins to the plugin list
pluginlist = additionalPlugins << pluginlist;
#if QT_VERSION >= 0x050000
/*
* 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;
}
}
}
#endif
/*
* Note: This call is not necessary, anymore. Initialization order
* is determined later.
......@@ -436,6 +461,26 @@ void Core::loadPlugins()
delete *it;
}
#if QT_VERSION >= 0x050000
/*
* 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;
}
}
#endif
emit log(LOGINFO, tr("Total time needed to load plugins was %1 ms.").arg(time.elapsed()));
splashMessage_ = "";
......
......@@ -100,6 +100,24 @@ if ( EXISTS ${CMAKE_SOURCE_DIR}/branding/branding.qrc )
endif()
endif()
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")
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")
if (WIN32)
# add app icon rc file to windows build
acg_add_executable (${OPENFLIPPER_PRODUCT_STRING} WIN32 ${CMAKE_CURRENT_SOURCE_DIR}/CoreApp.rc ${uic_targets} ${sources} ${headers} ${moc_targets} ${RC_SRC})
......@@ -206,6 +224,7 @@ target_link_libraries (${OPENFLIPPER_PRODUCT_STRING}
${GLEW_LIBRARY}
${GLUT_LIBRARIES}
${COREAPP_ADDITIONAL_LINK_LIBRARIES}
${OPENFLIPPER_STATIC_PLUGINS}
)
if (APPLE)
......
......@@ -595,11 +595,20 @@ function (_build_openflipper_plugin plugin)
add_library (Plugin-${plugin} MODULE ${uic_targets} ${sources} ${headers} ${moc_targets} ${qrc_targets} ${${_PLUGIN}_ADDSRC})
# add this plugin to build plugin list for dependency tracking
acg_set (OPENFLIPPER_PLUGINS "${OPENFLIPPER_PLUGINS};Plugin-${plugin}")
acg_set (OPENFLIPPER_${_PLUGIN}_BUILD "1")
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 ()
# append compiler and linker flags from plugin dependencies
list(APPEND ${_PLUGIN}_DEPS_COMPILE_DEFINITIONS ${${_PLUGIN}_CDEFINITIONSADD} )
......@@ -771,6 +780,14 @@ macro (openflipper_plugin)
OFF
)
set (
STATIC_PLUGIN_${_PLUGIN}
""
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})
_build_openflipper_plugin (${_plugin} ${ARGN})
set(LOADED_PACKAGES ${LOADED_PACKAGES} PARENT_SCOPE)
......
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