From 67734be8cf4cb7fa1c29ec62a19ef04dd898a08c Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 6 Mar 2012 09:31:43 -0500 Subject: VS: Simplify object name computation Simplify cmLocalVisualStudioGenerator::ComputeObjectNameRequirements to loop over the original vector of source files instead of recursively traversing source groups just to find the same files. Drop from cmVisualStudio10TargetGenerator::ComputeObjectNames temporary source group calculation now that it is not needed for computing object names. --- Source/cmLocalVisualStudio6Generator.cxx | 2 +- Source/cmLocalVisualStudio7Generator.cxx | 2 +- Source/cmLocalVisualStudioGenerator.cxx | 87 +++++++++++------------------- Source/cmLocalVisualStudioGenerator.h | 6 +-- Source/cmVisualStudio10TargetGenerator.cxx | 8 +-- 5 files changed, 34 insertions(+), 71 deletions(-) diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx index 56b9869..dd51a2d 100644 --- a/Source/cmLocalVisualStudio6Generator.cxx +++ b/Source/cmLocalVisualStudio6Generator.cxx @@ -380,7 +380,7 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout, } // Compute which sources need unique object computation. - this->ComputeObjectNameRequirements(sourceGroups); + this->ComputeObjectNameRequirements(classes); // Write the DSP file's header. this->WriteDSPHeader(fout, libName, target, sourceGroups); diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 7ff8892..ee5d407 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1307,7 +1307,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, } // Compute which sources need unique object computation. - this->ComputeObjectNameRequirements(sourceGroups); + this->ComputeObjectNameRequirements(classes); // open the project this->WriteProjectStart(fout, libName, target, sourceGroups); diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx index de1ac30..f389b35 100644 --- a/Source/cmLocalVisualStudioGenerator.cxx +++ b/Source/cmLocalVisualStudioGenerator.cxx @@ -83,77 +83,50 @@ bool cmLocalVisualStudioGenerator::SourceFileCompiles(const cmSourceFile* sf) } //---------------------------------------------------------------------------- -void cmLocalVisualStudioGenerator::CountObjectNames( - const std::vector& groups, - std::map& counts) +void +cmLocalVisualStudioGenerator::ComputeObjectNameRequirements( + std::vector const& sources + ) { - for(unsigned int i = 0; i < groups.size(); ++i) + // Clear the current set of requirements. + this->NeedObjectName.clear(); + + // Count the number of object files with each name. Note that + // windows file names are not case sensitive. + std::map counts; + for(std::vector::const_iterator s = sources.begin(); + s != sources.end(); ++s) { - cmSourceGroup sg = groups[i]; - std::vector const& srcs = sg.GetSourceFiles(); - for(std::vector::const_iterator s = srcs.begin(); - s != srcs.end(); ++s) + const cmSourceFile* sf = *s; + if(this->SourceFileCompiles(sf)) { - const cmSourceFile* sf = *s; - if(this->SourceFileCompiles(sf)) - { - std::string objectName = cmSystemTools::LowerCase( - cmSystemTools::GetFilenameWithoutLastExtension( - sf->GetFullPath())); - objectName += ".obj"; - counts[objectName] += 1; - } + std::string objectName = cmSystemTools::LowerCase( + cmSystemTools::GetFilenameWithoutLastExtension( + sf->GetFullPath())); + objectName += ".obj"; + counts[objectName] += 1; } - this->CountObjectNames(sg.GetGroupChildren(), counts); } -} -//---------------------------------------------------------------------------- -void cmLocalVisualStudioGenerator::InsertNeedObjectNames( - const std::vector& groups, - std::map& count) -{ - for(unsigned int i = 0; i < groups.size(); ++i) + // For all source files producing duplicate names we need unique + // object name computation. + for(std::vector::const_iterator s = sources.begin(); + s != sources.end(); ++s) { - cmSourceGroup sg = groups[i]; - std::vector const& srcs = sg.GetSourceFiles(); - for(std::vector::const_iterator s = srcs.begin(); - s != srcs.end(); ++s) + const cmSourceFile* sf = *s; + if(this->SourceFileCompiles(sf)) { - const cmSourceFile* sf = *s; - if(this->SourceFileCompiles(sf)) + std::string objectName = cmSystemTools::LowerCase( + cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath())); + objectName += ".obj"; + if(counts[objectName] > 1) { - std::string objectName = cmSystemTools::LowerCase( - cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath())); - objectName += ".obj"; - if(count[objectName] > 1) - { - this->NeedObjectName.insert(sf); - } + this->NeedObjectName.insert(sf); } } - this->InsertNeedObjectNames(sg.GetGroupChildren(), count); } } - -//---------------------------------------------------------------------------- -void cmLocalVisualStudioGenerator::ComputeObjectNameRequirements -(std::vector const& sourceGroups) -{ - // Clear the current set of requirements. - this->NeedObjectName.clear(); - - // Count the number of object files with each name. Note that - // windows file names are not case sensitive. - std::map objectNameCounts; - this->CountObjectNames(sourceGroups, objectNameCounts); - - // For all source files producing duplicate names we need unique - // object name computation. - this->InsertNeedObjectNames(sourceGroups, objectNameCounts); -} - //---------------------------------------------------------------------------- const char* cmLocalVisualStudioGenerator::ReportErrorLabel() const { diff --git a/Source/cmLocalVisualStudioGenerator.h b/Source/cmLocalVisualStudioGenerator.h index fcf1f21..e58c757 100644 --- a/Source/cmLocalVisualStudioGenerator.h +++ b/Source/cmLocalVisualStudioGenerator.h @@ -65,12 +65,8 @@ protected: MaybeCreateImplibDir(cmTarget& target, const char* config, bool isFortran); // Safe object file name generation. - void ComputeObjectNameRequirements(std::vector const&); + void ComputeObjectNameRequirements(std::vector const&); bool SourceFileCompiles(const cmSourceFile* sf); - void CountObjectNames(const std::vector& groups, - std::map& count); - void InsertNeedObjectNames(const std::vector& groups, - std::map& count); std::set NeedObjectName; friend class cmVisualStudio10TargetGenerator; diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 9418761..c3629f9 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -872,9 +872,6 @@ void cmVisualStudio10TargetGenerator::WriteCLSources() void cmVisualStudio10TargetGenerator::ComputeObjectNames() { - // We may be modifying the source groups temporarily, so make a copy. - std::vector sourceGroups = this->Makefile->GetSourceGroups(); - // get the classes from the source lists then add them to the groups std::vectorconst & classes = this->Target->GetSourceFiles(); for(std::vector::const_iterator i = classes.begin(); @@ -886,13 +883,10 @@ void cmVisualStudio10TargetGenerator::ComputeObjectNames() { this->ModuleDefinitionFile = (*i)->GetFullPath(); } - cmSourceGroup& sourceGroup = - this->Makefile->FindSourceGroup(source.c_str(), sourceGroups); - sourceGroup.AssignSource(*i); } // Compute which sources need unique object computation. - this->LocalGenerator->ComputeObjectNameRequirements(sourceGroups); + this->LocalGenerator->ComputeObjectNameRequirements(classes); } bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( -- cgit v0.12