diff options
author | Sebastian Holtermann <sebholt@xwmw.org> | 2019-02-21 10:18:17 (GMT) |
---|---|---|
committer | Sebastian Holtermann <sebholt@xwmw.org> | 2019-02-21 17:27:21 (GMT) |
commit | 84819c79e7efde0155dbb8431d0a205b325ce1cc (patch) | |
tree | bb964ec3d72ee7cad28cde1cfbaed63f997884e0 /Source/cmQtAutoGenInitializer.cxx | |
parent | d9893fb594c904605b3b9ebf3548d2f48793f788 (diff) | |
download | CMake-84819c79e7efde0155dbb8431d0a205b325ce1cc.zip CMake-84819c79e7efde0155dbb8431d0a205b325ce1cc.tar.gz CMake-84819c79e7efde0155dbb8431d0a205b325ce1cc.tar.bz2 |
Autogen: Refactor cmQtAutoGenInitializer::AddGeneratedSource method
In AUTOGEN pass the abstract cmQtAutoGenInitializer::GenVarsT to methods
to identify the generator (moc/uic/rcc).
Diffstat (limited to 'Source/cmQtAutoGenInitializer.cxx')
-rw-r--r-- | Source/cmQtAutoGenInitializer.cxx | 124 |
1 files changed, 59 insertions, 65 deletions
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 1095dad..7c70dc4 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -53,58 +53,6 @@ static std::size_t GetParallelCPUCount() return count; } -static bool AddToSourceGroup(cmMakefile* makefile, std::string const& fileName, - cmQtAutoGen::GenT genType) -{ - cmSourceGroup* sourceGroup = nullptr; - // Acquire source group - { - std::string property; - std::string groupName; - { - std::array<std::string, 2> props; - // Use generator specific group name - switch (genType) { - case cmQtAutoGen::GenT::MOC: - props[0] = "AUTOMOC_SOURCE_GROUP"; - break; - case cmQtAutoGen::GenT::RCC: - props[0] = "AUTORCC_SOURCE_GROUP"; - break; - default: - props[0] = "AUTOGEN_SOURCE_GROUP"; - break; - } - props[1] = "AUTOGEN_SOURCE_GROUP"; - for (std::string& prop : props) { - const char* propName = makefile->GetState()->GetGlobalProperty(prop); - if ((propName != nullptr) && (*propName != '\0')) { - groupName = propName; - property = std::move(prop); - break; - } - } - } - // Generate a source group on demand - if (!groupName.empty()) { - sourceGroup = makefile->GetOrCreateSourceGroup(groupName); - if (sourceGroup == nullptr) { - std::ostringstream ost; - ost << cmQtAutoGen::GeneratorNameUpper(genType); - ost << ": " << property; - ost << ": Could not find or create the source group "; - ost << cmQtAutoGen::Quoted(groupName); - cmSystemTools::Error(ost.str()); - return false; - } - } - } - if (sourceGroup != nullptr) { - sourceGroup->AddGroupFile(fileName); - } - return true; -} - static void AddCleanFile(cmMakefile* makefile, std::string const& fileName) { makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", fileName.c_str(), @@ -969,7 +917,7 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() // Files provided by the autogen target std::vector<std::string> autogenProvides; if (this->Moc.Enabled) { - this->AddGeneratedSource(this->Moc.MocsCompilation, GenT::MOC, true); + this->AddGeneratedSource(this->Moc.MocsCompilation, this->Moc, true); autogenProvides.push_back(this->Moc.MocsCompilation); } @@ -1122,7 +1070,7 @@ bool cmQtAutoGenInitializer::InitRccTargets() // Register info file as generated by CMake makefile->AddCMakeOutputFile(qrc.InfoFile); // Register file at target - this->AddGeneratedSource(qrc.RccFile, GenT::RCC); + this->AddGeneratedSource(qrc.RccFile, this->Rcc); std::vector<std::string> ccOutput; ccOutput.push_back(qrc.RccFile); @@ -1360,22 +1308,68 @@ bool cmQtAutoGenInitializer::SetupWriteRccInfo() return true; } -void cmQtAutoGenInitializer::AddGeneratedSource(std::string const& filename, - GenT genType, bool prepend) +void cmQtAutoGenInitializer::RegisterGeneratedSource( + std::string const& filename) { - // Register source file in makefile cmMakefile* makefile = this->Target->Target->GetMakefile(); - { - cmSourceFile* gFile = makefile->GetOrCreateSource(filename, true); - gFile->SetProperty("GENERATED", "1"); - gFile->SetProperty("SKIP_AUTOGEN", "On"); - } - - // Add source file to source group - AddToSourceGroup(makefile, filename, genType); + cmSourceFile* gFile = makefile->GetOrCreateSource(filename, true); + gFile->SetProperty("GENERATED", "1"); + gFile->SetProperty("SKIP_AUTOGEN", "1"); +} +bool cmQtAutoGenInitializer::AddGeneratedSource(std::string const& filename, + GenVarsT const& genVars, + bool prepend) +{ + // Register source at makefile + this->RegisterGeneratedSource(filename); // Add source file to target this->Target->AddSource(filename, prepend); + // Add source file to source group + return this->AddToSourceGroup(filename, genVars.GenNameUpper); +} + +bool cmQtAutoGenInitializer::AddToSourceGroup(std::string const& fileName, + std::string const& genNameUpper) +{ + cmMakefile* makefile = this->Target->Target->GetMakefile(); + cmSourceGroup* sourceGroup = nullptr; + // Acquire source group + { + std::string property; + std::string groupName; + { + // Prefer generator specific source group name + std::array<std::string, 2> props{ { genNameUpper + "_SOURCE_GROUP", + "AUTOGEN_SOURCE_GROUP" } }; + for (std::string& prop : props) { + const char* propName = makefile->GetState()->GetGlobalProperty(prop); + if ((propName != nullptr) && (*propName != '\0')) { + groupName = propName; + property = std::move(prop); + break; + } + } + } + // Generate a source group on demand + if (!groupName.empty()) { + sourceGroup = makefile->GetOrCreateSourceGroup(groupName); + if (sourceGroup == nullptr) { + std::string err; + err += genNameUpper; + err += " error in "; + err += property; + err += ": Could not find or create the source group "; + err += cmQtAutoGen::Quoted(groupName); + cmSystemTools::Error(err); + return false; + } + } + } + if (sourceGroup != nullptr) { + sourceGroup->AddGroupFile(fileName); + } + return true; } static unsigned int CharPtrToUInt(const char* const input) |