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:
parent
4ae7f3656b
commit
67734be8cf
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -83,75 +83,48 @@ bool cmLocalVisualStudioGenerator::SourceFileCompiles(const cmSourceFile* sf)
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmLocalVisualStudioGenerator::CountObjectNames(
|
||||
const std::vector<cmSourceGroup>& groups,
|
||||
std::map<cmStdString, int>& counts)
|
||||
{
|
||||
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;
|
||||
if(this->SourceFileCompiles(sf))
|
||||
{
|
||||
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<cmSourceGroup>& groups,
|
||||
std::map<cmStdString, int>& count)
|
||||
{
|
||||
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;
|
||||
if(this->SourceFileCompiles(sf))
|
||||
{
|
||||
std::string objectName = cmSystemTools::LowerCase(
|
||||
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()));
|
||||
objectName += ".obj";
|
||||
if(count[objectName] > 1)
|
||||
{
|
||||
this->NeedObjectName.insert(sf);
|
||||
}
|
||||
}
|
||||
}
|
||||
this->InsertNeedObjectNames(sg.GetGroupChildren(), count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmLocalVisualStudioGenerator::ComputeObjectNameRequirements
|
||||
(std::vector<cmSourceGroup> const& sourceGroups)
|
||||
void
|
||||
cmLocalVisualStudioGenerator::ComputeObjectNameRequirements(
|
||||
std::vector<cmSourceFile*> const& sources
|
||||
)
|
||||
{
|
||||
// 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);
|
||||
std::map<cmStdString, int> counts;
|
||||
for(std::vector<cmSourceFile*>::const_iterator s = sources.begin();
|
||||
s != sources.end(); ++s)
|
||||
{
|
||||
const cmSourceFile* sf = *s;
|
||||
if(this->SourceFileCompiles(sf))
|
||||
{
|
||||
std::string objectName = cmSystemTools::LowerCase(
|
||||
cmSystemTools::GetFilenameWithoutLastExtension(
|
||||
sf->GetFullPath()));
|
||||
objectName += ".obj";
|
||||
counts[objectName] += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// For all source files producing duplicate names we need unique
|
||||
// object name computation.
|
||||
this->InsertNeedObjectNames(sourceGroups, objectNameCounts);
|
||||
for(std::vector<cmSourceFile*>::const_iterator s = sources.begin();
|
||||
s != sources.end(); ++s)
|
||||
{
|
||||
const cmSourceFile* sf = *s;
|
||||
if(this->SourceFileCompiles(sf))
|
||||
{
|
||||
std::string objectName = cmSystemTools::LowerCase(
|
||||
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()));
|
||||
objectName += ".obj";
|
||||
if(counts[objectName] > 1)
|
||||
{
|
||||
this->NeedObjectName.insert(sf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
@ -65,12 +65,8 @@ protected:
|
|||
MaybeCreateImplibDir(cmTarget& target, const char* config, bool isFortran);
|
||||
|
||||
// Safe object file name generation.
|
||||
void ComputeObjectNameRequirements(std::vector<cmSourceGroup> const&);
|
||||
void ComputeObjectNameRequirements(std::vector<cmSourceFile*> const&);
|
||||
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;
|
||||
friend class cmVisualStudio10TargetGenerator;
|
||||
|
||||
|
|
|
@ -872,9 +872,6 @@ void cmVisualStudio10TargetGenerator::WriteCLSources()
|
|||
|
||||
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
|
||||
std::vector<cmSourceFile*>const & classes = this->Target->GetSourceFiles();
|
||||
for(std::vector<cmSourceFile*>::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(
|
||||
|
|
Loading…
Reference in New Issue