summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorSebastian Holtermann <sebholt@xwmw.org>2017-08-30 21:13:10 (GMT)
committerSebastian Holtermann <sebholt@xwmw.org>2017-09-07 15:53:19 (GMT)
commitd8d064abbc10239cf61655da31d3e6a4a46298e7 (patch)
treebccc6ce5924ba62aa1e249eabb3a5a8389648206 /Source
parent37714f884be3c37fbbcbf7bbef0ceb3b44cc5961 (diff)
downloadCMake-d8d064abbc10239cf61655da31d3e6a4a46298e7.zip
CMake-d8d064abbc10239cf61655da31d3e6a4a46298e7.tar.gz
CMake-d8d064abbc10239cf61655da31d3e6a4a46298e7.tar.bz2
Autogen: Use the same algorithm for RCC and UIC option merging
Diffstat (limited to 'Source')
-rw-r--r--Source/cmQtAutoGen.cxx77
-rw-r--r--Source/cmQtAutoGen.h10
-rw-r--r--Source/cmQtAutoGeneratorInitializer.cxx42
-rw-r--r--Source/cmQtAutoGenerators.cxx39
-rw-r--r--Source/cmQtAutoGenerators.h1
5 files changed, 90 insertions, 79 deletions
diff --git a/Source/cmQtAutoGen.cxx b/Source/cmQtAutoGen.cxx
index 98dbdd2..cdd41ca 100644
--- a/Source/cmQtAutoGen.cxx
+++ b/Source/cmQtAutoGen.cxx
@@ -7,6 +7,7 @@
#include "cmsys/FStream.hxx"
#include "cmsys/RegularExpression.hxx"
+#include <algorithm>
#include <sstream>
#include <stddef.h>
@@ -19,6 +20,60 @@ const std::string genNameRcc = "AutoRcc";
// - Static functions
+/// @brief Merges newOpts into baseOpts
+/// @arg valueOpts list of options that accept a value
+void MergeOptions(std::vector<std::string>& baseOpts,
+ const std::vector<std::string>& newOpts,
+ const std::vector<std::string>& valueOpts, bool isQt5)
+{
+ typedef std::vector<std::string>::iterator Iter;
+ typedef std::vector<std::string>::const_iterator CIter;
+ if (newOpts.empty()) {
+ return;
+ }
+ if (baseOpts.empty()) {
+ baseOpts = newOpts;
+ return;
+ }
+
+ std::vector<std::string> extraOpts;
+ for (CIter fit = newOpts.begin(), fitEnd = newOpts.end(); fit != fitEnd;
+ ++fit) {
+ const std::string& newOpt = *fit;
+ Iter existIt = std::find(baseOpts.begin(), baseOpts.end(), newOpt);
+ if (existIt != baseOpts.end()) {
+ if (newOpt.size() >= 2) {
+ // Acquire the option name
+ std::string optName;
+ {
+ auto oit = newOpt.begin();
+ if (*oit == '-') {
+ ++oit;
+ if (isQt5 && (*oit == '-')) {
+ ++oit;
+ }
+ optName.assign(oit, newOpt.end());
+ }
+ }
+ // Test if this is a value option and change the existing value
+ if (!optName.empty() && (std::find(valueOpts.begin(), valueOpts.end(),
+ optName) != valueOpts.end())) {
+ const Iter existItNext(existIt + 1);
+ const CIter fitNext(fit + 1);
+ if ((existItNext != baseOpts.end()) && (fitNext != fitEnd)) {
+ *existItNext = *fitNext;
+ ++fit;
+ }
+ }
+ }
+ } else {
+ extraOpts.push_back(newOpt);
+ }
+ }
+ // Append options
+ baseOpts.insert(baseOpts.end(), extraOpts.begin(), extraOpts.end());
+}
+
static std::string utilStripCR(std::string const& line)
{
// Strip CR characters rcc may have printed (possibly more than one!).
@@ -218,6 +273,28 @@ std::string cmQtAutoGen::Quoted(const std::string& text)
return res;
}
+void cmQtAutoGen::UicMergeOptions(std::vector<std::string>& baseOpts,
+ const std::vector<std::string>& newOpts,
+ bool isQt5)
+{
+ static const std::vector<std::string> valueOpts = {
+ "tr", "translate", "postfix", "generator",
+ "include", // Since Qt 5.3
+ "g"
+ };
+ MergeOptions(baseOpts, newOpts, valueOpts, isQt5);
+}
+
+void cmQtAutoGen::RccMergeOptions(std::vector<std::string>& baseOpts,
+ const std::vector<std::string>& newOpts,
+ bool isQt5)
+{
+ static const std::vector<std::string> valueOpts = { "name", "root",
+ "compress",
+ "threshold" };
+ MergeOptions(baseOpts, newOpts, valueOpts, isQt5);
+}
+
bool cmQtAutoGen::RccListInputs(const std::string& qtMajorVersion,
const std::string& rccCommand,
const std::string& fileName,
diff --git a/Source/cmQtAutoGen.h b/Source/cmQtAutoGen.h
index 88fd0fc..4cd5e32 100644
--- a/Source/cmQtAutoGen.h
+++ b/Source/cmQtAutoGen.h
@@ -34,6 +34,16 @@ public:
///
static std::string Quoted(const std::string& text);
+ /// @brief Merges newOpts into baseOpts
+ static void UicMergeOptions(std::vector<std::string>& baseOpts,
+ const std::vector<std::string>& newOpts,
+ bool isQt5);
+
+ /// @brief Merges newOpts into baseOpts
+ static void RccMergeOptions(std::vector<std::string>& baseOpts,
+ const std::vector<std::string>& newOpts,
+ bool isQt5);
+
/// @brief Reads the resource files list from from a .qrc file
/// @arg fileName Must be the absolute path of the .qrc file
/// @return True if the rcc file was successfully parsed
diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx
index 79bb99b..d04e5b7 100644
--- a/Source/cmQtAutoGeneratorInitializer.cxx
+++ b/Source/cmQtAutoGeneratorInitializer.cxx
@@ -562,46 +562,6 @@ static std::string RccGetExecutable(cmGeneratorTarget const* target,
return rccExec;
}
-static void RccMergeOptions(std::vector<std::string>& opts,
- const std::vector<std::string>& fileOpts,
- bool isQt5)
-{
- typedef std::vector<std::string>::iterator Iter;
- typedef std::vector<std::string>::const_iterator CIter;
- static const char* valueOptions[4] = { "name", "root", "compress",
- "threshold" };
-
- std::vector<std::string> extraOpts;
- for (CIter fit = fileOpts.begin(), fitEnd = fileOpts.end(); fit != fitEnd;
- ++fit) {
- Iter existIt = std::find(opts.begin(), opts.end(), *fit);
- if (existIt != opts.end()) {
- const char* optName = fit->c_str();
- if (*optName == '-') {
- ++optName;
- if (isQt5 && *optName == '-') {
- ++optName;
- }
- }
- // Test if this is a value option and change the existing value
- if ((optName != fit->c_str()) &&
- std::find_if(cmArrayBegin(valueOptions), cmArrayEnd(valueOptions),
- cmStrCmp(optName)) != cmArrayEnd(valueOptions)) {
- const Iter existItNext(existIt + 1);
- const CIter fitNext(fit + 1);
- if ((existItNext != opts.end()) && (fitNext != fitEnd)) {
- *existItNext = *fitNext;
- ++fit;
- }
- }
- } else {
- extraOpts.push_back(*fit);
- }
- }
- // Append options
- opts.insert(opts.end(), extraOpts.begin(), extraOpts.end());
-}
-
static void SetupAutoTargetRcc(const cmQtAutoGenDigest& digest)
{
cmGeneratorTarget const* target = digest.Target;
@@ -871,7 +831,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
{
std::vector<std::string> opts = optionsTarget;
if (!qrcDigest.Options.empty()) {
- RccMergeOptions(opts, qrcDigest.Options, QtV5);
+ cmQtAutoGen::RccMergeOptions(opts, qrcDigest.Options, QtV5);
}
qrcDigest.Options = std::move(opts);
}
diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx
index 7f1443e..4e3ec96 100644
--- a/Source/cmQtAutoGenerators.cxx
+++ b/Source/cmQtAutoGenerators.cxx
@@ -7,10 +7,8 @@
#include "cmsys/Terminal.h"
#include <algorithm>
#include <array>
-#include <assert.h>
#include <list>
#include <sstream>
-#include <stdlib.h>
#include <string.h>
#include <utility>
@@ -201,40 +199,6 @@ static std::string JoinOptionsMap(
return result;
}
-static void UicMergeOptions(std::vector<std::string>& opts,
- const std::vector<std::string>& fileOpts,
- bool isQt5)
-{
- static const char* valueOptions[] = { "tr", "translate",
- "postfix", "generator",
- "include", // Since Qt 5.3
- "g" };
- std::vector<std::string> extraOpts;
- for (std::vector<std::string>::const_iterator it = fileOpts.begin();
- it != fileOpts.end(); ++it) {
- std::vector<std::string>::iterator existingIt =
- std::find(opts.begin(), opts.end(), *it);
- if (existingIt != opts.end()) {
- const char* o = it->c_str();
- if (*o == '-') {
- ++o;
- }
- if (isQt5 && *o == '-') {
- ++o;
- }
- if (std::find_if(cmArrayBegin(valueOptions), cmArrayEnd(valueOptions),
- cmStrCmp(*it)) != cmArrayEnd(valueOptions)) {
- assert(existingIt + 1 != opts.end());
- *(existingIt + 1) = *(it + 1);
- ++it;
- }
- } else {
- extraOpts.push_back(*it);
- }
- }
- opts.insert(opts.end(), extraOpts.begin(), extraOpts.end());
-}
-
// -- Class methods
cmQtAutoGenerators::cmQtAutoGenerators()
@@ -1580,7 +1544,8 @@ bool cmQtAutoGenerators::UicGenerateFile(const std::string& realName,
if (optionIt != this->UicOptions.end()) {
std::vector<std::string> fileOpts;
cmSystemTools::ExpandListArgument(optionIt->second, fileOpts);
- UicMergeOptions(allOpts, fileOpts, (this->QtMajorVersion == "5"));
+ cmQtAutoGen::UicMergeOptions(allOpts, fileOpts,
+ (this->QtMajorVersion == "5"));
}
cmd.insert(cmd.end(), allOpts.begin(), allOpts.end());
}
diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h
index 5421408..2084a81 100644
--- a/Source/cmQtAutoGenerators.h
+++ b/Source/cmQtAutoGenerators.h
@@ -12,7 +12,6 @@
#include <map>
#include <set>
#include <string>
-#include <utility>
#include <vector>
class cmMakefile;