From d8d064abbc10239cf61655da31d3e6a4a46298e7 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Aug 2017 23:13:10 +0200 Subject: Autogen: Use the same algorithm for RCC and UIC option merging --- Source/cmQtAutoGen.cxx | 77 +++++++++++++++++++++++++++++++++ Source/cmQtAutoGen.h | 10 +++++ Source/cmQtAutoGeneratorInitializer.cxx | 42 +----------------- Source/cmQtAutoGenerators.cxx | 39 +---------------- Source/cmQtAutoGenerators.h | 1 - 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 #include #include @@ -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& baseOpts, + const std::vector& newOpts, + const std::vector& valueOpts, bool isQt5) +{ + typedef std::vector::iterator Iter; + typedef std::vector::const_iterator CIter; + if (newOpts.empty()) { + return; + } + if (baseOpts.empty()) { + baseOpts = newOpts; + return; + } + + std::vector 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& baseOpts, + const std::vector& newOpts, + bool isQt5) +{ + static const std::vector valueOpts = { + "tr", "translate", "postfix", "generator", + "include", // Since Qt 5.3 + "g" + }; + MergeOptions(baseOpts, newOpts, valueOpts, isQt5); +} + +void cmQtAutoGen::RccMergeOptions(std::vector& baseOpts, + const std::vector& newOpts, + bool isQt5) +{ + static const std::vector 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& baseOpts, + const std::vector& newOpts, + bool isQt5); + + /// @brief Merges newOpts into baseOpts + static void RccMergeOptions(std::vector& baseOpts, + const std::vector& 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& opts, - const std::vector& fileOpts, - bool isQt5) -{ - typedef std::vector::iterator Iter; - typedef std::vector::const_iterator CIter; - static const char* valueOptions[4] = { "name", "root", "compress", - "threshold" }; - - std::vector 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 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 #include -#include #include #include -#include #include #include @@ -201,40 +199,6 @@ static std::string JoinOptionsMap( return result; } -static void UicMergeOptions(std::vector& opts, - const std::vector& fileOpts, - bool isQt5) -{ - static const char* valueOptions[] = { "tr", "translate", - "postfix", "generator", - "include", // Since Qt 5.3 - "g" }; - std::vector extraOpts; - for (std::vector::const_iterator it = fileOpts.begin(); - it != fileOpts.end(); ++it) { - std::vector::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 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 #include #include -#include #include class cmMakefile; -- cgit v0.12