From 78eccc7836e068652ea772ec65614bc446f23b14 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Tue, 2 Apr 2019 18:58:58 +0200 Subject: Autogen: Remove lowercase generator name from generator variables class The lowercase `Auto*` generator name in `cmQtAutoGenInitializer::GenVarsT` is never user. Remove it from the class. --- Source/cmQtAutoGenInitializer.h | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Source/cmQtAutoGenInitializer.h b/Source/cmQtAutoGenInitializer.h index 1f4087f..e7e5db2 100644 --- a/Source/cmQtAutoGenInitializer.h +++ b/Source/cmQtAutoGenInitializer.h @@ -62,7 +62,6 @@ public: bool Enabled = false; // Generator type/name GenT Gen; - std::string const& GenName; std::string const& GenNameUpper; // Executable std::string ExecutableTargetName; @@ -71,11 +70,9 @@ public: bool ExecutableExists = false; /// @brief Constructor - GenVarsT(GenT gen, std::string const& genName, - std::string const& genNameUpper) + GenVarsT(GenT gen) : Gen(gen) - , GenName(genName) - , GenNameUpper(genNameUpper){}; + , GenNameUpper(cmQtAutoGen::GeneratorNameUpper(gen)){}; }; /// @brief Writes a CMake info file @@ -213,8 +210,7 @@ private: /// @brief Constructor MocT() - : GenVarsT(cmQtAutoGen::GenT::MOC, cmQtAutoGen::GenAutoMoc, - cmQtAutoGen::GenAUTOMOC){}; + : GenVarsT(GenT::MOC){}; } Moc; /// @brief Uic only variables @@ -229,8 +225,7 @@ private: /// @brief Constructor UicT() - : GenVarsT(cmQtAutoGen::GenT::UIC, cmQtAutoGen::GenAutoUic, - cmQtAutoGen::GenAUTOUIC){}; + : GenVarsT(GenT::UIC){}; } Uic; /// @brief Rcc only variables @@ -242,8 +237,7 @@ private: /// @brief Constructor RccT() - : GenVarsT(cmQtAutoGen::GenT::RCC, cmQtAutoGen::GenAutoRcc, - cmQtAutoGen::GenAUTORCC){}; + : GenVarsT(GenT::RCC){}; } Rcc; }; -- cgit v0.12 From 5431395d68a44d42149fb93692636f4138ddf6ed Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Tue, 2 Apr 2019 18:53:34 +0200 Subject: Autogen: Add cmQtAutogenGlobalInitializer::Keywords class The new `cmQtAutogenGlobalInitializer::Keywords` class instance is bound to the lifetime of the `cmQtAutogenGlobalInitializer` instance. Global static const strings would be allocated at program start and deallocated at program end. Keeping keyword strings alive only in the context where they're needed helps to reduce the memory footprint. --- Source/cmQtAutoGenGlobalInitializer.cxx | 7 +++++++ Source/cmQtAutoGenGlobalInitializer.h | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index 7bd0e52..994cfc8 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -20,6 +20,13 @@ #include #include +cmQtAutoGenGlobalInitializer::Keywords::Keywords() + : AUTOMOC("AUTOMOC") + , AUTOUIC("AUTOUIC") + , AUTORCC("AUTORCC") +{ +} + cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer( std::vector const& localGenerators) { diff --git a/Source/cmQtAutoGenGlobalInitializer.h b/Source/cmQtAutoGenGlobalInitializer.h index 74184a0..6cddf16 100644 --- a/Source/cmQtAutoGenGlobalInitializer.h +++ b/Source/cmQtAutoGenGlobalInitializer.h @@ -18,10 +18,24 @@ class cmQtAutoGenInitializer; class cmQtAutoGenGlobalInitializer { public: + /// @brief Collection of QtAutogen related keywords + class Keywords + { + public: + Keywords(); + + std::string AUTOMOC; + std::string AUTOUIC; + std::string AUTORCC; + }; + +public: cmQtAutoGenGlobalInitializer( std::vector const& localGenerators); ~cmQtAutoGenGlobalInitializer(); + Keywords const* kw() const { return Keywords_.get(); }; + bool generate(); private: @@ -48,6 +62,7 @@ private: std::map GlobalAutoGenTargets_; std::map GlobalAutoRccTargets_; std::unordered_map ExecutableTestOutputs_; + std::unique_ptr Keywords_; }; #endif -- cgit v0.12 From b32e18fb88434d3f9d58447212ee33a51430c144 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Tue, 2 Apr 2019 19:11:19 +0200 Subject: Autogen: Remove static const generator name strings from cmQtAutoGen --- Source/cmQtAutoGen.cxx | 46 ++++++++++++++++----------------- Source/cmQtAutoGen.h | 9 ------- Source/cmQtAutoGenGlobalInitializer.cxx | 6 ++--- Source/cmQtAutoGenGlobalInitializer.h | 4 +-- 4 files changed, 28 insertions(+), 37 deletions(-) diff --git a/Source/cmQtAutoGen.cxx b/Source/cmQtAutoGen.cxx index 87ef112..d71d82f 100644 --- a/Source/cmQtAutoGen.cxx +++ b/Source/cmQtAutoGen.cxx @@ -73,44 +73,44 @@ void MergeOptions(std::vector& baseOpts, unsigned int const cmQtAutoGen::ParallelMax = 64; std::string const cmQtAutoGen::ListSep = "<<>>"; -std::string const cmQtAutoGen::GenAutoGen = "AutoGen"; -std::string const cmQtAutoGen::GenAutoMoc = "AutoMoc"; -std::string const cmQtAutoGen::GenAutoUic = "AutoUic"; -std::string const cmQtAutoGen::GenAutoRcc = "AutoRcc"; - -std::string const cmQtAutoGen::GenAUTOGEN = "AUTOGEN"; -std::string const cmQtAutoGen::GenAUTOMOC = "AUTOMOC"; -std::string const cmQtAutoGen::GenAUTOUIC = "AUTOUIC"; -std::string const cmQtAutoGen::GenAUTORCC = "AUTORCC"; - std::string const& cmQtAutoGen::GeneratorName(GenT genType) { + static const std::string AutoGen("AutoGen"); + static const std::string AutoMoc("AutoMoc"); + static const std::string AutoUic("AutoUic"); + static const std::string AutoRcc("AutoRcc"); + switch (genType) { case GenT::GEN: - return GenAutoGen; + return AutoGen; case GenT::MOC: - return GenAutoMoc; + return AutoMoc; case GenT::UIC: - return GenAutoUic; + return AutoUic; case GenT::RCC: - return GenAutoRcc; + return AutoRcc; } - return GenAutoGen; + return AutoGen; } std::string const& cmQtAutoGen::GeneratorNameUpper(GenT genType) { + static const std::string AUTOGEN("AUTOGEN"); + static const std::string AUTOMOC("AUTOMOC"); + static const std::string AUTOUIC("AUTOUIC"); + static const std::string AUTORCC("AUTORCC"); + switch (genType) { case GenT::GEN: - return GenAUTOGEN; + return AUTOGEN; case GenT::MOC: - return GenAUTOMOC; + return AUTOMOC; case GenT::UIC: - return GenAUTOUIC; + return AUTOUIC; case GenT::RCC: - return GenAUTORCC; + return AUTORCC; } - return GenAUTOGEN; + return AUTOGEN; } std::string cmQtAutoGen::Tools(bool moc, bool uic, bool rcc) @@ -118,13 +118,13 @@ std::string cmQtAutoGen::Tools(bool moc, bool uic, bool rcc) std::string res; std::vector lst; if (moc) { - lst.emplace_back(GenAUTOMOC); + lst.emplace_back("AUTOMOC"); } if (uic) { - lst.emplace_back(GenAUTOUIC); + lst.emplace_back("AUTOUIC"); } if (rcc) { - lst.emplace_back(GenAUTORCC); + lst.emplace_back("AUTORCC"); } switch (lst.size()) { case 1: diff --git a/Source/cmQtAutoGen.h b/Source/cmQtAutoGen.h index 6cc8df1..d127a71 100644 --- a/Source/cmQtAutoGen.h +++ b/Source/cmQtAutoGen.h @@ -51,15 +51,6 @@ public: /// @brief Nested lists separator static std::string const ListSep; - // Generator names - static std::string const GenAutoGen; - static std::string const GenAutoMoc; - static std::string const GenAutoUic; - static std::string const GenAutoRcc; - static std::string const GenAUTOGEN; - static std::string const GenAUTOMOC; - static std::string const GenAUTOUIC; - static std::string const GenAUTORCC; /// @brief Maximum number of parallel threads/processes in a generator static unsigned int const ParallelMax; diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index 994cfc8..ab51570 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -81,9 +81,9 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer( continue; } - bool const moc = target->GetPropertyAsBool(cmQtAutoGen::GenAUTOMOC); - bool const uic = target->GetPropertyAsBool(cmQtAutoGen::GenAUTOUIC); - bool const rcc = target->GetPropertyAsBool(cmQtAutoGen::GenAUTORCC); + bool const moc = target->GetPropertyAsBool(kw().AUTOMOC); + bool const uic = target->GetPropertyAsBool(kw().AUTOUIC); + bool const rcc = target->GetPropertyAsBool(kw().AUTORCC); if (moc || uic || rcc) { std::string const mocExec = target->GetSafeProperty("AUTOMOC_EXECUTABLE"); diff --git a/Source/cmQtAutoGenGlobalInitializer.h b/Source/cmQtAutoGenGlobalInitializer.h index 6cddf16..76ed76b 100644 --- a/Source/cmQtAutoGenGlobalInitializer.h +++ b/Source/cmQtAutoGenGlobalInitializer.h @@ -34,7 +34,7 @@ public: std::vector const& localGenerators); ~cmQtAutoGenGlobalInitializer(); - Keywords const* kw() const { return Keywords_.get(); }; + Keywords const& kw() const { return Keywords_; }; bool generate(); @@ -62,7 +62,7 @@ private: std::map GlobalAutoGenTargets_; std::map GlobalAutoRccTargets_; std::unordered_map ExecutableTestOutputs_; - std::unique_ptr Keywords_; + Keywords const Keywords_; }; #endif -- cgit v0.12 From 5fb122ff75f0fac2c421a6cba6c78a2123e3fd49 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Tue, 2 Apr 2019 19:14:27 +0200 Subject: Autogen: Add `AUTO*_EXECUTABLE` strings to Keywords class --- Source/cmQtAutoGenGlobalInitializer.cxx | 9 ++++++--- Source/cmQtAutoGenGlobalInitializer.h | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index ab51570..45a21f5 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -24,6 +24,9 @@ cmQtAutoGenGlobalInitializer::Keywords::Keywords() : AUTOMOC("AUTOMOC") , AUTOUIC("AUTOUIC") , AUTORCC("AUTORCC") + , AUTOMOC_EXECUTABLE("AUTOMOC_EXECUTABLE") + , AUTOUIC_EXECUTABLE("AUTOUIC_EXECUTABLE") + , AUTORCC_EXECUTABLE("AUTORCC_EXECUTABLE") { } @@ -86,11 +89,11 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer( bool const rcc = target->GetPropertyAsBool(kw().AUTORCC); if (moc || uic || rcc) { std::string const mocExec = - target->GetSafeProperty("AUTOMOC_EXECUTABLE"); + target->GetSafeProperty(kw().AUTOMOC_EXECUTABLE); std::string const uicExec = - target->GetSafeProperty("AUTOUIC_EXECUTABLE"); + target->GetSafeProperty(kw().AUTOUIC_EXECUTABLE); std::string const rccExec = - target->GetSafeProperty("AUTORCC_EXECUTABLE"); + target->GetSafeProperty(kw().AUTORCC_EXECUTABLE); // We support Qt4, Qt5 and Qt6 auto qtVersion = cmQtAutoGenInitializer::GetQtVersion(target); diff --git a/Source/cmQtAutoGenGlobalInitializer.h b/Source/cmQtAutoGenGlobalInitializer.h index 76ed76b..abff589 100644 --- a/Source/cmQtAutoGenGlobalInitializer.h +++ b/Source/cmQtAutoGenGlobalInitializer.h @@ -27,6 +27,10 @@ public: std::string AUTOMOC; std::string AUTOUIC; std::string AUTORCC; + + std::string AUTOMOC_EXECUTABLE; + std::string AUTOUIC_EXECUTABLE; + std::string AUTORCC_EXECUTABLE; }; public: -- cgit v0.12 From 18f7b2ed2111ff9dac5ef83d8bbf20b826b8bbe9 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Tue, 2 Apr 2019 19:22:35 +0200 Subject: Autogen: Add more frequently used keywords to Keywords class --- Source/cmQtAutoGenGlobalInitializer.cxx | 8 ++++++ Source/cmQtAutoGenGlobalInitializer.h | 11 +++++++++ Source/cmQtAutoGenInitializer.cxx | 43 +++++++++++++-------------------- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index 45a21f5..59e17d7 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -27,6 +27,14 @@ cmQtAutoGenGlobalInitializer::Keywords::Keywords() , AUTOMOC_EXECUTABLE("AUTOMOC_EXECUTABLE") , AUTOUIC_EXECUTABLE("AUTOUIC_EXECUTABLE") , AUTORCC_EXECUTABLE("AUTORCC_EXECUTABLE") + , SKIP_AUTOGEN("SKIP_AUTOGEN") + , SKIP_AUTOMOC("SKIP_AUTOMOC") + , SKIP_AUTOUIC("SKIP_AUTOUIC") + , SKIP_AUTORCC("SKIP_AUTORCC") + , AUTOUIC_OPTIONS("AUTOUIC_OPTIONS") + , AUTORCC_OPTIONS("AUTORCC_OPTIONS") + , qrc("qrc") + , ui("ui") { } diff --git a/Source/cmQtAutoGenGlobalInitializer.h b/Source/cmQtAutoGenGlobalInitializer.h index abff589..77429b7 100644 --- a/Source/cmQtAutoGenGlobalInitializer.h +++ b/Source/cmQtAutoGenGlobalInitializer.h @@ -31,6 +31,17 @@ public: std::string AUTOMOC_EXECUTABLE; std::string AUTOUIC_EXECUTABLE; std::string AUTORCC_EXECUTABLE; + + std::string SKIP_AUTOGEN; + std::string SKIP_AUTOMOC; + std::string SKIP_AUTOUIC; + std::string SKIP_AUTORCC; + + std::string AUTOUIC_OPTIONS; + std::string AUTORCC_OPTIONS; + + std::string qrc; + std::string ui; }; public: diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index ef8fe73..d80aaa2 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -606,28 +606,19 @@ bool cmQtAutoGenInitializer::InitRcc() bool cmQtAutoGenInitializer::InitScanFiles() { cmMakefile* makefile = this->Target->Target->GetMakefile(); + auto const& kw = this->GlobalInitializer->kw(); - // String constants - std::string const SKIP_AUTOGEN_str = "SKIP_AUTOGEN"; - std::string const SKIP_AUTOMOC_str = "SKIP_AUTOMOC"; - std::string const SKIP_AUTOUIC_str = "SKIP_AUTOUIC"; - std::string const SKIP_AUTORCC_str = "SKIP_AUTORCC"; - std::string const AUTOUIC_OPTIONS_str = "AUTOUIC_OPTIONS"; - std::string const AUTORCC_OPTIONS_str = "AUTORCC_OPTIONS"; - std::string const qrc_str = "qrc"; - std::string const ui_str = "ui"; - - auto makeMUFile = [&](cmSourceFile* sf, std::string const& fullPath, - bool muIt) -> MUFileHandle { + auto makeMUFile = [this, &kw](cmSourceFile* sf, std::string const& fullPath, + bool muIt) -> MUFileHandle { MUFileHandle muf = cm::make_unique(); muf->RealPath = cmSystemTools::GetRealPath(fullPath); muf->SF = sf; muf->Generated = sf->GetIsGenerated(); - bool const skipAutogen = sf->GetPropertyAsBool(SKIP_AUTOGEN_str); + bool const skipAutogen = sf->GetPropertyAsBool(kw.SKIP_AUTOGEN); muf->SkipMoc = this->Moc.Enabled && - (skipAutogen || sf->GetPropertyAsBool(SKIP_AUTOMOC_str)); + (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOMOC)); muf->SkipUic = this->Uic.Enabled && - (skipAutogen || sf->GetPropertyAsBool(SKIP_AUTOUIC_str)); + (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOUIC)); if (muIt) { muf->MocIt = this->Moc.Enabled && !muf->SkipMoc; muf->UicIt = this->Uic.Enabled && !muf->SkipUic; @@ -678,8 +669,8 @@ bool cmQtAutoGenInitializer::InitScanFiles() // Register rcc enabled files if (this->Rcc.Enabled) { - if ((ext == qrc_str) && !sf->GetPropertyAsBool(SKIP_AUTOGEN_str) && - !sf->GetPropertyAsBool(SKIP_AUTORCC_str)) { + if ((ext == kw.qrc) && !sf->GetPropertyAsBool(kw.SKIP_AUTOGEN) && + !sf->GetPropertyAsBool(kw.SKIP_AUTORCC)) { // Register qrc file Qrc qrc; qrc.QrcFile = cmSystemTools::GetRealPath(fullPath); @@ -688,7 +679,7 @@ bool cmQtAutoGenInitializer::InitScanFiles() qrc.Generated = sf->GetIsGenerated(); // RCC options { - std::string const opts = sf->GetSafeProperty(AUTORCC_OPTIONS_str); + std::string const opts = sf->GetSafeProperty(kw.AUTORCC_OPTIONS); if (!opts.empty()) { cmSystemTools::ExpandListArgument(opts, qrc.Options); } @@ -798,15 +789,15 @@ bool cmQtAutoGenInitializer::InitScanFiles() this->AutogenTarget.Sources.emplace(sf, std::move(muf)); } } - } else if (this->Uic.Enabled && (ext == ui_str)) { + } else if (this->Uic.Enabled && (ext == kw.ui)) { // .ui file std::string realPath = cmSystemTools::GetRealPath(fullPath); - bool const skipAutogen = sf->GetPropertyAsBool(SKIP_AUTOGEN_str); + bool const skipAutogen = sf->GetPropertyAsBool(kw.SKIP_AUTOGEN); bool const skipUic = - (skipAutogen || sf->GetPropertyAsBool(SKIP_AUTOUIC_str)); + (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOUIC)); if (!skipUic) { // Check if the .ui file has uic options - std::string const uicOpts = sf->GetSafeProperty(AUTOUIC_OPTIONS_str); + std::string const uicOpts = sf->GetSafeProperty(kw.AUTOUIC_OPTIONS); if (!uicOpts.empty()) { this->Uic.FileFiles.push_back(std::move(realPath)); std::vector optsVec; @@ -834,11 +825,11 @@ bool cmQtAutoGenInitializer::InitScanFiles() msg += '\n'; std::string property; if (this->Moc.Enabled && this->Uic.Enabled) { - property = "SKIP_AUTOGEN"; + property = kw.SKIP_AUTOGEN; } else if (this->Moc.Enabled) { - property = "SKIP_AUTOMOC"; + property = kw.SKIP_AUTOMOC; } else if (this->Uic.Enabled) { - property = "SKIP_AUTOUIC"; + property = kw.SKIP_AUTOUIC; } msg += "For compatibility, CMake is excluding the GENERATED source " "file(s):\n"; @@ -866,7 +857,7 @@ bool cmQtAutoGenInitializer::InitScanFiles() // Target rcc options std::vector optionsTarget; cmSystemTools::ExpandListArgument( - this->Target->GetSafeProperty("AUTORCC_OPTIONS"), optionsTarget); + this->Target->GetSafeProperty(kw.AUTORCC_OPTIONS), optionsTarget); // Check if file name is unique for (Qrc& qrc : this->Rcc.Qrcs) { -- cgit v0.12