From a42b700cc254e284892821dea06ac265744a0939 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Thu, 17 Jan 2019 11:14:38 +0100 Subject: cmTarget,cmGeneratorTarget: Add optional `before` parameter to AddSource The new optional `before` parameter in `cmTarget::AddSource` and `cmGeneratorTarget::AddSource` allows to prepend a source file to the sources list instead of appending it. --- Source/cmGeneratorTarget.cxx | 20 ++++++++++---------- Source/cmGeneratorTarget.h | 4 ++-- Source/cmTarget.cxx | 12 +++++++++--- Source/cmTarget.h | 2 +- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 6515dfa..24d04b1 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -355,20 +355,22 @@ void cmGeneratorTarget::ClearSourcesCache() this->Objects.clear(); } -void cmGeneratorTarget::AddSourceCommon(const std::string& src) +void cmGeneratorTarget::AddSourceCommon(const std::string& src, bool before) { cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); cmGeneratorExpression ge(lfbt); std::unique_ptr cge = ge.Parse(src); cge->SetEvaluateForBuildsystem(true); - this->SourceEntries.push_back(new TargetPropertyEntry(std::move(cge))); + this->SourceEntries.insert(before ? this->SourceEntries.begin() + : this->SourceEntries.end(), + new TargetPropertyEntry(std::move(cge))); this->ClearSourcesCache(); } -void cmGeneratorTarget::AddSource(const std::string& src) +void cmGeneratorTarget::AddSource(const std::string& src, bool before) { - this->Target->AddSource(src); - this->AddSourceCommon(src); + this->Target->AddSource(src, before); + this->AddSourceCommon(src, before); } void cmGeneratorTarget::AddTracedSources(std::vector const& srcs) @@ -387,12 +389,10 @@ void cmGeneratorTarget::AddIncludeDirectory(const std::string& src, cmGeneratorExpression ge(lfbt); std::unique_ptr cge = ge.Parse(src); cge->SetEvaluateForBuildsystem(true); - // Insert before begin/end - std::vector::iterator pos = before - ? this->IncludeDirectoriesEntries.begin() - : this->IncludeDirectoriesEntries.end(); this->IncludeDirectoriesEntries.insert( - pos, new TargetPropertyEntry(std::move(cge))); + before ? this->IncludeDirectoriesEntries.begin() + : this->IncludeDirectoriesEntries.end(), + new TargetPropertyEntry(std::move(cge))); } std::vector const* cmGeneratorTarget::GetSourceDepends( diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index cfd1df0..d9221f0 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -536,7 +536,7 @@ public: */ void ClearSourcesCache(); - void AddSource(const std::string& src); + void AddSource(const std::string& src, bool before = false); void AddTracedSources(std::vector const& srcs); /** @@ -694,7 +694,7 @@ public: const char* GetSourcesProperty() const; private: - void AddSourceCommon(const std::string& src); + void AddSourceCommon(const std::string& src, bool before = false); std::string CreateFortranModuleDirectory( std::string const& working_dir) const; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index a94cf6a..25f021b 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -662,7 +662,7 @@ public: } }; -cmSourceFile* cmTarget::AddSource(const std::string& src) +cmSourceFile* cmTarget::AddSource(const std::string& src, bool before) { cmSourceFileLocation sfl(this->Makefile, src, cmSourceFileLocationKind::Known); @@ -671,8 +671,14 @@ cmSourceFile* cmTarget::AddSource(const std::string& src) TargetPropertyEntryFinder(sfl)) == this->Internal->SourceEntries.end()) { cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); - this->Internal->SourceEntries.push_back(src); - this->Internal->SourceBacktraces.push_back(lfbt); + this->Internal->SourceEntries.insert( + before ? this->Internal->SourceEntries.begin() + : this->Internal->SourceEntries.end(), + src); + this->Internal->SourceBacktraces.insert( + before ? this->Internal->SourceBacktraces.begin() + : this->Internal->SourceBacktraces.end(), + lfbt); } if (cmGeneratorExpression::Find(src) != std::string::npos) { return nullptr; diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 655cefd..24b3742 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -123,7 +123,7 @@ public: void AddSources(std::vector const& srcs); void AddTracedSources(std::vector const& srcs); cmSourceFile* AddSourceCMP0049(const std::string& src); - cmSourceFile* AddSource(const std::string& src); + cmSourceFile* AddSource(const std::string& src, bool before = false); //* how we identify a library, by name and type typedef std::pair LibraryID; -- cgit v0.12 From 1ed4d48dcf71df4e8a352bc476262a79d75e299a Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Thu, 17 Jan 2019 11:19:42 +0100 Subject: Autogen: Prepend instead of append `mocs_compilation.cpp` to the sources list `mocs_compilation.cpp` easily takes a long time to compile when it contains multiple `moc` files. When it was appended like before we ran into the situation that all smaller sources were already compiled when `mocs_compilation.cpp` got compiled at last. In that case a single core was busy but all remaining cores stayed idle. To optimize CPU core utilization we now prepend `mocs_compilation.cpp` to the sources list instead of appending it. This allows smaller source files to get compiled *while* the long lasting `mocs_compilation.cpp` gets compiled. Closes #18793 --- Source/cmQtAutoGenInitializer.cxx | 7 ++++--- Source/cmQtAutoGenInitializer.h | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 9fa8a89..3ae6d9a 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -963,7 +963,7 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() // Files provided by the autogen target std::vector autogenProvides; if (this->Moc.Enabled) { - this->AddGeneratedSource(this->Moc.MocsCompilation, GeneratorT::MOC); + this->AddGeneratedSource(this->Moc.MocsCompilation, GeneratorT::MOC, true); autogenProvides.push_back(this->Moc.MocsCompilation); } @@ -1356,7 +1356,8 @@ bool cmQtAutoGenInitializer::SetupWriteRccInfo() } void cmQtAutoGenInitializer::AddGeneratedSource(std::string const& filename, - GeneratorT genType) + GeneratorT genType, + bool prepend) { // Register source file in makefile cmMakefile* makefile = this->Target->Target->GetMakefile(); @@ -1370,7 +1371,7 @@ void cmQtAutoGenInitializer::AddGeneratedSource(std::string const& filename, AddToSourceGroup(makefile, filename, genType); // Add source file to target - this->Target->AddSource(filename); + this->Target->AddSource(filename, prepend); } static unsigned int CharPtrToInt(const char* const input) diff --git a/Source/cmQtAutoGenInitializer.h b/Source/cmQtAutoGenInitializer.h index 47f157c..eefbaf0 100644 --- a/Source/cmQtAutoGenInitializer.h +++ b/Source/cmQtAutoGenInitializer.h @@ -102,7 +102,8 @@ private: bool SetupWriteAutogenInfo(); bool SetupWriteRccInfo(); - void AddGeneratedSource(std::string const& filename, GeneratorT genType); + void AddGeneratedSource(std::string const& filename, GeneratorT genType, + bool prepend = false); bool GetMocExecutable(); bool GetUicExecutable(); -- cgit v0.12