From 4f1c71fdd25f33bd0cdeb2b705723db02f8fddf4 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 9 Apr 2014 01:32:14 +0200 Subject: cmTarget: Add all sources traced from custom commands at once. The AddSource method accepts one file and tries to avoiding adding it to the sources-list of the target if it already exists. This involves creating many cmSourceFileLocation objects for matching on existing files, which is an expensive operation. Avoid the searching algorithm by appending the new sources as one group. Generate-time processing of source files will ensure uniqueness. Add a new AddTracedSources for this purpose. The existing AddSources method must process the input for policy CMP0049, but as these source filenames come from cmSourceFile::GetFullPath(), we can forego that extra processing. --- Source/cmGeneratorTarget.cxx | 7 +++++-- Source/cmTarget.cxx | 27 +++++++++++++++++++++++++++ Source/cmTarget.h | 1 + 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 0d25a00..ec5ce9e 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -610,6 +610,7 @@ private: std::set SourcesQueued; typedef std::map NameMapType; NameMapType NameMap; + std::vector NewSources; void QueueSource(cmSourceFile* sf); void FollowName(std::string const& name); @@ -698,6 +699,8 @@ void cmTargetTraceDependencies::Trace() } } this->CurrentEntry = 0; + + this->Target->AddTracedSources(this->NewSources); } //---------------------------------------------------------------------------- @@ -707,8 +710,8 @@ void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf) { this->SourceQueue.push(sf); - // Make sure this file is in the target. - this->Target->AddSource(sf->GetFullPath()); + // Make sure this file is in the target at the end. + this->NewSources.push_back(sf->GetFullPath()); } } diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 4903f8b..1f8cddb 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -850,6 +850,33 @@ void cmTarget::GetSourceFiles(std::vector &files, } //---------------------------------------------------------------------------- +void cmTarget::AddTracedSources(std::vector const& srcs) +{ + std::string srcFiles; + const char* sep = ""; + for(std::vector::const_iterator i = srcs.begin(); + i != srcs.end(); ++i) + { + std::string filename = *i; + srcFiles += sep; + srcFiles += filename; + sep = ";"; + } + if (!srcFiles.empty()) + { + this->Internal->SourceFilesMap.clear(); + this->LinkImplementationLanguageIsContextDependent = true; + cmListFileBacktrace lfbt; + this->Makefile->GetBacktrace(lfbt); + cmGeneratorExpression ge(lfbt); + cmsys::auto_ptr cge = ge.Parse(srcFiles); + cge->SetEvaluateForBuildsystem(true); + this->Internal->SourceEntries.push_back( + new cmTargetInternals::TargetPropertyEntry(cge)); + } +} + +//---------------------------------------------------------------------------- void cmTarget::AddSources(std::vector const& srcs) { std::string srcFiles; diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 868e260..45ae487 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -144,6 +144,7 @@ public: * Add sources to the target. */ void AddSources(std::vector const& srcs); + void AddTracedSources(std::vector const& srcs); cmSourceFile* AddSourceCMP0049(const std::string& src); cmSourceFile* AddSource(const std::string& src); -- cgit v0.12