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.
This commit is contained in:
Brad King 2012-03-06 09:31:43 -05:00
parent 4ae7f3656b
commit 67734be8cf
5 changed files with 37 additions and 74 deletions

View File

@ -380,7 +380,7 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
} }
// Compute which sources need unique object computation. // Compute which sources need unique object computation.
this->ComputeObjectNameRequirements(sourceGroups); this->ComputeObjectNameRequirements(classes);
// Write the DSP file's header. // Write the DSP file's header.
this->WriteDSPHeader(fout, libName, target, sourceGroups); this->WriteDSPHeader(fout, libName, target, sourceGroups);

View File

@ -1307,7 +1307,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
} }
// Compute which sources need unique object computation. // Compute which sources need unique object computation.
this->ComputeObjectNameRequirements(sourceGroups); this->ComputeObjectNameRequirements(classes);
// open the project // open the project
this->WriteProjectStart(fout, libName, target, sourceGroups); this->WriteProjectStart(fout, libName, target, sourceGroups);

View File

@ -83,16 +83,19 @@ bool cmLocalVisualStudioGenerator::SourceFileCompiles(const cmSourceFile* sf)
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmLocalVisualStudioGenerator::CountObjectNames( void
const std::vector<cmSourceGroup>& groups, cmLocalVisualStudioGenerator::ComputeObjectNameRequirements(
std::map<cmStdString, int>& counts) std::vector<cmSourceFile*> const& sources
)
{ {
for(unsigned int i = 0; i < groups.size(); ++i) // Clear the current set of requirements.
{ this->NeedObjectName.clear();
cmSourceGroup sg = groups[i];
std::vector<const cmSourceFile*> const& srcs = sg.GetSourceFiles(); // Count the number of object files with each name. Note that
for(std::vector<const cmSourceFile*>::const_iterator s = srcs.begin(); // windows file names are not case sensitive.
s != srcs.end(); ++s) std::map<cmStdString, int> counts;
for(std::vector<cmSourceFile*>::const_iterator s = sources.begin();
s != sources.end(); ++s)
{ {
const cmSourceFile* sf = *s; const cmSourceFile* sf = *s;
if(this->SourceFileCompiles(sf)) if(this->SourceFileCompiles(sf))
@ -104,21 +107,11 @@ void cmLocalVisualStudioGenerator::CountObjectNames(
counts[objectName] += 1; counts[objectName] += 1;
} }
} }
this->CountObjectNames(sg.GetGroupChildren(), counts);
}
}
//---------------------------------------------------------------------------- // For all source files producing duplicate names we need unique
void cmLocalVisualStudioGenerator::InsertNeedObjectNames( // object name computation.
const std::vector<cmSourceGroup>& groups, for(std::vector<cmSourceFile*>::const_iterator s = sources.begin();
std::map<cmStdString, int>& count) s != sources.end(); ++s)
{
for(unsigned int i = 0; i < groups.size(); ++i)
{
cmSourceGroup sg = groups[i];
std::vector<const cmSourceFile*> const& srcs = sg.GetSourceFiles();
for(std::vector<const cmSourceFile*>::const_iterator s = srcs.begin();
s != srcs.end(); ++s)
{ {
const cmSourceFile* sf = *s; const cmSourceFile* sf = *s;
if(this->SourceFileCompiles(sf)) if(this->SourceFileCompiles(sf))
@ -126,32 +119,12 @@ void cmLocalVisualStudioGenerator::InsertNeedObjectNames(
std::string objectName = cmSystemTools::LowerCase( std::string objectName = cmSystemTools::LowerCase(
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath())); cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()));
objectName += ".obj"; objectName += ".obj";
if(count[objectName] > 1) if(counts[objectName] > 1)
{ {
this->NeedObjectName.insert(sf); this->NeedObjectName.insert(sf);
} }
} }
} }
this->InsertNeedObjectNames(sg.GetGroupChildren(), count);
}
}
//----------------------------------------------------------------------------
void cmLocalVisualStudioGenerator::ComputeObjectNameRequirements
(std::vector<cmSourceGroup> 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<cmStdString, int> objectNameCounts;
this->CountObjectNames(sourceGroups, objectNameCounts);
// For all source files producing duplicate names we need unique
// object name computation.
this->InsertNeedObjectNames(sourceGroups, objectNameCounts);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -65,12 +65,8 @@ protected:
MaybeCreateImplibDir(cmTarget& target, const char* config, bool isFortran); MaybeCreateImplibDir(cmTarget& target, const char* config, bool isFortran);
// Safe object file name generation. // Safe object file name generation.
void ComputeObjectNameRequirements(std::vector<cmSourceGroup> const&); void ComputeObjectNameRequirements(std::vector<cmSourceFile*> const&);
bool SourceFileCompiles(const cmSourceFile* sf); bool SourceFileCompiles(const cmSourceFile* sf);
void CountObjectNames(const std::vector<cmSourceGroup>& groups,
std::map<cmStdString, int>& count);
void InsertNeedObjectNames(const std::vector<cmSourceGroup>& groups,
std::map<cmStdString, int>& count);
std::set<const cmSourceFile*> NeedObjectName; std::set<const cmSourceFile*> NeedObjectName;
friend class cmVisualStudio10TargetGenerator; friend class cmVisualStudio10TargetGenerator;

View File

@ -872,9 +872,6 @@ void cmVisualStudio10TargetGenerator::WriteCLSources()
void cmVisualStudio10TargetGenerator::ComputeObjectNames() void cmVisualStudio10TargetGenerator::ComputeObjectNames()
{ {
// We may be modifying the source groups temporarily, so make a copy.
std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
// get the classes from the source lists then add them to the groups // get the classes from the source lists then add them to the groups
std::vector<cmSourceFile*>const & classes = this->Target->GetSourceFiles(); std::vector<cmSourceFile*>const & classes = this->Target->GetSourceFiles();
for(std::vector<cmSourceFile*>::const_iterator i = classes.begin(); for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
@ -886,13 +883,10 @@ void cmVisualStudio10TargetGenerator::ComputeObjectNames()
{ {
this->ModuleDefinitionFile = (*i)->GetFullPath(); this->ModuleDefinitionFile = (*i)->GetFullPath();
} }
cmSourceGroup& sourceGroup =
this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
sourceGroup.AssignSource(*i);
} }
// Compute which sources need unique object computation. // Compute which sources need unique object computation.
this->LocalGenerator->ComputeObjectNameRequirements(sourceGroups); this->LocalGenerator->ComputeObjectNameRequirements(classes);
} }
bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(