Files
MINGW-packages/mingw-w64-cmake-git/0004-Implement-Qt5-static-plugin-support.patch
2017-02-14 09:44:30 -06:00

168 lines
7.0 KiB
Diff

From 239703a5bcaf5df957f56fe21c610f50288af396 Mon Sep 17 00:00:00 2001
From: Ray Donnelly <mingw.android@gmail.com>
Date: Mon, 3 Aug 2015 22:00:16 +0100
Subject: [PATCH 4/8] Implement Qt5 static plugin support
Enabled via a new target property "AUTOSTATICPLUGINS".
At CMake execution time, a C++ file is created to link the
static plugins. For this to work, patches for Qt5-static
from [1] are necessary [2], [3] and [4]
[1] https://github.com/Alexpux/MINGW-packages/tree/master/mingw-w64-qt5-static
[2] 0038-qt-5.4.0-Make-it-possible-to-use-static-builds-of-Qt-with-CMa.patch
[3] 0039-qt-5.4.0-Generate-separated-libraries-in-prl-files-for-CMake.patch
[4] 0041-qt-5.4.0-static-cmake-also-link-plugins-and-plugin-deps.patch
.. and also some more minor ones that aren't strictly related to Qt5 static
CMake but are necessary for this to work on MinGW-w64 (0040- for example).
---
Source/cmGlobalGenerator.cxx | 1 +
Source/cmQtAutoGeneratorInitializer.cxx | 70 ++++++++++++++++++++++++++++++++-
Source/cmTarget.cxx | 1 +
Source/cmTargetPropertyComputer.cxx | 1 +
4 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index f11825083e..e8a07361c0 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -1409,6 +1409,7 @@ cmGlobalGenerator::CreateQtAutoGeneratorsTargets()
}
if ((!(*ti)->GetPropertyAsBool("AUTOMOC") &&
!(*ti)->GetPropertyAsBool("AUTOUIC") &&
+ !(*ti)->GetPropertyAsBool("AUTOSTATICPLUGINS") &&
!(*ti)->GetPropertyAsBool("AUTORCC")) ||
(*ti)->IsImported()) {
continue;
diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx
index 825eba0e1d..61652b80b1 100644
--- a/Source/cmQtAutoGeneratorInitializer.cxx
+++ b/Source/cmQtAutoGeneratorInitializer.cxx
@@ -26,6 +26,7 @@
#include <cmConfigure.h>
#include <cmsys/FStream.hxx>
#include <cmsys/RegularExpression.hxx>
+#include <cmGeneratedFileStream.h>
#include <map>
#include <set>
#include <sstream>
@@ -160,6 +161,65 @@ static void SetupSourceFiles(cmGeneratorTarget const* target,
}
}
}
+
+ /* in qt5-static/lib/cmake/Qt5Core/Qt5CoreConfig.cmake,
+ * macro(_populate_Core_plugin_properties ..), we'd have:
+ * set_property(TARGET PROPERTY AUTOSTATICPLUGINS True) // Not currently need
+ * as defaults to "ON"
+ * set_property(TARGET Qt5::Core APPEND PROPERTY STATIC_PLUGINS ${Plugin})
+ */
+ if (target->GetPropertyAsBool("AUTOSTATICPLUGINS")) {
+ std::vector<const cmGeneratorTarget*> libTargets =
+ target->GetLinkImplementationClosure("");
+ std::vector<cmGeneratorTarget const*>::const_iterator li;
+ std::vector<std::string> staticPlugins;
+ for (li = libTargets.begin(); li != libTargets.end(); ++li) {
+ cmGeneratorTarget const* tgt = *li;
+ const char* staticPluginsProp = tgt->GetProperty("STATIC_PLUGINS");
+ if (staticPluginsProp) {
+ std::vector<std::string> staticPluginsTgt =
+ cmSystemTools::tokenize(staticPluginsProp, ";");
+ for (std::vector<std::string>::const_iterator spti =
+ staticPluginsTgt.begin();
+ spti != staticPluginsTgt.end(); ++spti) {
+ if (std::find(staticPlugins.begin(), staticPlugins.end(), *spti) ==
+ staticPlugins.end()) {
+ staticPlugins.push_back(*spti);
+ }
+ }
+ }
+ }
+
+ if (staticPlugins.size()) {
+ std::string static_plugins_output_dir = target->GetSupportDirectory();
+ cmSystemTools::MakeDirectory(static_plugins_output_dir.c_str());
+ std::string static_plugins_output_file = static_plugins_output_dir;
+ static_plugins_output_file +=
+ "/" + target->GetName() + "_plugin_import.cpp";
+ cmGeneratedFileStream staticPluginsFileStream(
+ static_plugins_output_file.c_str());
+ if (staticPluginsFileStream) {
+ staticPluginsFileStream << "// This file is autogenerated by cmake. "
+ "It imports static plugin classes for"
+ << std::endl;
+ staticPluginsFileStream
+ << "// static plugins specified using QTPLUGIN and "
+ "QT_PLUGIN_CLASS.<plugin> variables."
+ << std::endl;
+ staticPluginsFileStream << "#include <QtPlugin>" << std::endl;
+ for (std::vector<std::string>::const_iterator spti =
+ staticPlugins.begin();
+ spti != staticPlugins.end(); ++spti) {
+ staticPluginsFileStream << "Q_IMPORT_PLUGIN(" << *spti << ")"
+ << std::endl;
+ }
+ staticPluginsFileStream.Close();
+ makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
+ static_plugins_output_file.c_str(), false);
+ const_cast<cmGeneratorTarget*>(target)->AddSource(static_plugins_output_file);
+ }
+ }
+ }
}
static void GetCompileDefinitionsAndDirectories(
@@ -742,7 +802,13 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
}
if (toolNames.size() == 1) {
tools += " and " + toolNames[0];
+ } else if (toolNames.size() == 0) {
+ /* AUTOSTATICPLUGINS .cpp files are created at cmake execution time,
+ * and not at build time, so in that case it is possible to get here
+ * with no toolNames. */
+ return;
}
+
autogenComment = "Automatic " + tools + " for target " + target->GetName();
}
@@ -894,7 +960,9 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget(
if (target->GetPropertyAsBool("AUTOMOC") ||
target->GetPropertyAsBool("AUTOUIC") ||
- target->GetPropertyAsBool("AUTORCC")) {
+ target->GetPropertyAsBool("AUTORCC") ||
+ ( target->GetPropertyAsBool("AUTOSTATICPLUGINS")
+ && target->GetType() == cmStateEnums::EXECUTABLE)) {
SetupSourceFiles(target, mocUicSources, mocUicHeaders, skipMoc, skipUic);
}
makefile->AddDefinition(
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index fe3472d5d7..dcfdfcbd32 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -245,6 +245,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
this->SetPropertyDefault("AUTOMOC", CM_NULLPTR);
this->SetPropertyDefault("AUTOUIC", CM_NULLPTR);
this->SetPropertyDefault("AUTORCC", CM_NULLPTR);
+ this->SetPropertyDefault("AUTOSTATICPLUGINS", CM_NULLPTR);
this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", CM_NULLPTR);
this->SetPropertyDefault("AUTOUIC_OPTIONS", CM_NULLPTR);
this->SetPropertyDefault("AUTORCC_OPTIONS", CM_NULLPTR);
diff --git a/Source/cmTargetPropertyComputer.cxx b/Source/cmTargetPropertyComputer.cxx
index a57bc5aea5..b12bd2dea8 100644
--- a/Source/cmTargetPropertyComputer.cxx
+++ b/Source/cmTargetPropertyComputer.cxx
@@ -58,6 +58,7 @@ bool cmTargetPropertyComputer::WhiteListedInterfaceProperty(
builtIns.insert("EXPORT_NAME");
builtIns.insert("IMPORTED");
builtIns.insert("NAME");
+ builtIns.insert("STATIC_PLUGINS");
builtIns.insert("TYPE");
}
--
2.11.0