Files
MINGW-packages/mingw-w64-cmake-git/0002-Implement-Qt5-static-plugin-support.patch
T

174 lines
7.1 KiB
Diff

From 3e14f4ba2c5d0dbaec88daa1034605f02154dabd 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 2/3] 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 | 74 +++++++++++++++++++++++++++++++--
Source/cmTarget.cxx | 2 +
3 files changed, 74 insertions(+), 3 deletions(-)
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index a1764a3..7448c0c 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -1352,6 +1352,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 dd19760..38c7199 100644
--- a/Source/cmQtAutoGeneratorInitializer.cxx
+++ b/Source/cmQtAutoGeneratorInitializer.cxx
@@ -20,6 +20,7 @@
#include <sys/stat.h>
#include <cmsys/FStream.hxx>
+#include <cmGeneratedFileStream.h>
#if defined(_WIN32) && !defined(__CYGWIN__)
#include "cmGlobalVisualStudioGenerator.h"
@@ -28,7 +29,7 @@
static std::string GetAutogenTargetName(cmGeneratorTarget const* target)
{
std::string autogenTargetName = target->GetName();
- autogenTargetName += "_automoc";
+ autogenTargetName += "_autogen";
return autogenTargetName;
}
@@ -164,6 +165,65 @@ static void SetupSourceFiles(cmGeneratorTarget const* target,
fileIt != newRccFiles.end(); ++fileIt) {
const_cast<cmGeneratorTarget*>(target)->AddSource(*fileIt);
}
+
+ /* 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(
@@ -748,6 +808,12 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
if (target->GetPropertyAsBool("AUTORCC")) {
toolNames.push_back("rcc");
}
+ /* 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. */
+ if (!toolNames.size()) {
+ return;
+ }
std::string tools = toolNames[0];
toolNames.erase(toolNames.begin());
@@ -920,9 +986,11 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget(
if (target->GetPropertyAsBool("AUTOMOC") ||
target->GetPropertyAsBool("AUTOUIC") ||
- target->GetPropertyAsBool("AUTORCC")) {
+ target->GetPropertyAsBool("AUTORCC") ||
+ ( target->GetPropertyAsBool("AUTOSTATICPLUGINS")
+ && target->GetType() == cmState::EXECUTABLE))
SetupSourceFiles(target, skipMoc, mocSources, mocHeaders, skipUic);
- }
+
makefile->AddDefinition(
"_cpp_files",
cmOutputConverter::EscapeForCMake(cmJoin(mocSources, ";")).c_str());
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 5e0d2b7..bea321d 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -127,6 +127,7 @@ void cmTarget::SetMakefile(cmMakefile* mf)
this->SetPropertyDefault("AUTOMOC", 0);
this->SetPropertyDefault("AUTOUIC", 0);
this->SetPropertyDefault("AUTORCC", 0);
+ this->SetPropertyDefault("AUTOSTATICPLUGINS", 0);
this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
this->SetPropertyDefault("AUTOUIC_OPTIONS", 0);
this->SetPropertyDefault("AUTORCC_OPTIONS", 0);
@@ -741,6 +742,7 @@ static bool whiteListedInterfaceProperty(const std::string& prop)
builtIns.insert("IMPORTED");
builtIns.insert("NAME");
builtIns.insert("TYPE");
+ builtIns.insert("STATIC_PLUGINS");
}
if (builtIns.count(prop)) {
--
2.8.2