Factor out duplicate VS target dependency code

Compute VS target dependencies in cmGlobalVisualStudioGenerator when the
main global dependency analysis is done.  Use these results in each of
the VS generators instead of duplicating the analysis.
This commit is contained in:
Brad King 2010-08-24 18:39:36 -04:00
parent 6bea84353c
commit 325bdb2a92
5 changed files with 96 additions and 135 deletions

View File

@ -274,42 +274,14 @@ void cmGlobalVisualStudio6Generator::WriteProject(std::ostream& fout,
fout << "Package=<5>\n{{{\n}}}\n\n"; fout << "Package=<5>\n{{{\n}}}\n\n";
fout << "Package=<4>\n"; fout << "Package=<4>\n";
fout << "{{{\n"; fout << "{{{\n";
VSDependSet const& depends = this->VSTargetDepends[&target];
// insert Begin Project Dependency Project_Dep_Name project stuff here for(VSDependSet::const_iterator di = depends.begin();
if (target.GetType() != cmTarget::STATIC_LIBRARY) di != depends.end(); ++di)
{ {
cmTarget::LinkLibraryVectorType::const_iterator j, jend; const char* name = di->c_str();
j = target.GetLinkLibraries().begin(); fout << "Begin Project Dependency\n";
jend = target.GetLinkLibraries().end(); fout << "Project_Dep_Name " << GetVS6TargetName(name) << "\n";
for(;j!= jend; ++j) fout << "End Project Dependency\n";
{
if(j->first != dspname)
{
// is the library part of this DSW ? If so add dependency
if(this->FindTarget(0, j->first.c_str()))
{
fout << "Begin Project Dependency\n";
fout << "Project_Dep_Name "
<< GetVS6TargetName(j->first.c_str()) << "\n";
fout << "End Project Dependency\n";
}
}
}
}
std::set<cmStdString>::const_iterator i, end;
// write utility dependencies.
i = target.GetUtilities().begin();
end = target.GetUtilities().end();
for(;i!= end; ++i)
{
if(*i != dspname)
{
std::string depName = this->GetUtilityForTarget(target, i->c_str());
fout << "Begin Project Dependency\n";
fout << "Project_Dep_Name " << GetVS6TargetName(depName) << "\n";
fout << "End Project Dependency\n";
}
} }
fout << "}}}\n\n"; fout << "}}}\n\n";
} }

View File

@ -185,59 +185,21 @@ cmGlobalVisualStudio71Generator
const char* dspname, const char* dspname,
const char*, cmTarget& target) const char*, cmTarget& target)
{ {
#if 0 VSDependSet const& depends = this->VSTargetDepends[&target];
// Create inter-target dependencies in the solution file. For VS for(VSDependSet::const_iterator di = depends.begin();
// 7.1 and below we cannot let static libraries depend directly on di != depends.end(); ++di)
// targets to which they "link" because the librarian tool will copy
// the targets into the static library. See
// cmGlobalVisualStudioGenerator::FixUtilityDependsForTarget for a
// work-around. VS 8 and above do not have this problem.
if (!this->VSLinksDependencies() ||
target.GetType() != cmTarget::STATIC_LIBRARY);
#else
if (target.GetType() != cmTarget::STATIC_LIBRARY)
#endif
{ {
cmTarget::LinkLibraryVectorType::const_iterator j, jend; const char* name = di->c_str();
j = target.GetLinkLibraries().begin(); std::string guid = this->GetGUID(name);
jend = target.GetLinkLibraries().end(); if(guid.size() == 0)
for(;j!= jend; ++j)
{ {
if(j->first != dspname) std::string m = "Target: ";
{ m += target.GetName();
// is the library part of this SLN ? If so add dependency m += " depends on unknown target: ";
// find target anywhere because all depend libraries are m += name;
// brought in as well cmSystemTools::Error(m.c_str());
if(this->FindTarget(0, j->first.c_str()))
{
fout << "\t\t{" << this->GetGUID(j->first.c_str()) << "} = {"
<< this->GetGUID(j->first.c_str()) << "}\n";
}
}
}
}
std::set<cmStdString>::const_iterator i, end;
// write utility dependencies.
i = target.GetUtilities().begin();
end = target.GetUtilities().end();
for(;i!= end; ++i)
{
if(*i != dspname)
{
std::string name = this->GetUtilityForTarget(target, i->c_str());
std::string guid = this->GetGUID(name.c_str());
if(guid.size() == 0)
{
std::string m = "Target: ";
m += target.GetName();
m += " depends on unknown target: ";
m += name;
cmSystemTools::Error(m.c_str());
}
fout << "\t\t{" << guid << "} = {" << guid << "}\n";
} }
fout << "\t\t{" << guid << "} = {" << guid << "}\n";
} }
} }

View File

@ -422,59 +422,23 @@ cmGlobalVisualStudio7Generator
const char*, cmTarget& target) const char*, cmTarget& target)
{ {
int depcount = 0; int depcount = 0;
// insert Begin Project Dependency Project_Dep_Name project stuff here std::string dspguid = this->GetGUID(dspname);
if (target.GetType() != cmTarget::STATIC_LIBRARY) VSDependSet const& depends = this->VSTargetDepends[&target];
for(VSDependSet::const_iterator di = depends.begin();
di != depends.end(); ++di)
{ {
cmTarget::LinkLibraryVectorType::const_iterator j, jend; const char* name = di->c_str();
j = target.GetLinkLibraries().begin(); std::string guid = this->GetGUID(name);
jend = target.GetLinkLibraries().end(); if(guid.size() == 0)
for(;j!= jend; ++j)
{ {
if(j->first != dspname) std::string m = "Target: ";
{ m += target.GetName();
// is the library part of this SLN ? If so add dependency m += " depends on unknown target: ";
if(this->FindTarget(0, j->first.c_str())) m += name;
{ cmSystemTools::Error(m.c_str());
std::string guid = this->GetGUID(j->first.c_str());
if(guid.size() == 0)
{
std::string m = "Target: ";
m += dspname;
m += " depends on unknown target: ";
m += j->first.c_str();
cmSystemTools::Error(m.c_str());
}
fout << "\t\t{" << this->GetGUID(dspname) << "}."
<< depcount << " = {" << guid << "}\n";
depcount++;
}
}
}
}
std::set<cmStdString>::const_iterator i, end;
// write utility dependencies.
i = target.GetUtilities().begin();
end = target.GetUtilities().end();
for(;i!= end; ++i)
{
if(*i != dspname)
{
std::string name = this->GetUtilityForTarget(target, i->c_str());
std::string guid = this->GetGUID(name.c_str());
if(guid.size() == 0)
{
std::string m = "Target: ";
m += dspname;
m += " depends on unknown target: ";
m += name.c_str();
cmSystemTools::Error(m.c_str());
}
fout << "\t\t{" << this->GetGUID(dspname) << "}." << depcount << " = {"
<< guid << "}\n";
depcount++;
} }
fout << "\t\t{" << dspguid << "}." << depcount << " = {" << guid << "}\n";
depcount++;
} }
} }

View File

@ -352,6 +352,64 @@ cmGlobalVisualStudioGenerator::CreateUtilityDependTarget(cmTarget& target)
} }
} }
//----------------------------------------------------------------------------
bool cmGlobalVisualStudioGenerator::ComputeTargetDepends()
{
if(!this->cmGlobalGenerator::ComputeTargetDepends())
{
return false;
}
std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
{
std::vector<cmLocalGenerator*>& gen = it->second;
for(std::vector<cmLocalGenerator*>::iterator i = gen.begin();
i != gen.end(); ++i)
{
cmTargets& targets = (*i)->GetMakefile()->GetTargets();
for(cmTargets::iterator ti = targets.begin();
ti != targets.end(); ++ti)
{
this->ComputeVSTargetDepends(ti->second);
}
}
}
return true;
}
//----------------------------------------------------------------------------
void cmGlobalVisualStudioGenerator::ComputeVSTargetDepends(cmTarget& target)
{
if(this->VSTargetDepends.find(&target) != this->VSTargetDepends.end())
{
return;
}
VSDependSet& vsTargetDepend = this->VSTargetDepends[&target];
if(target.GetType() != cmTarget::STATIC_LIBRARY)
{
cmTarget::LinkLibraryVectorType const& libs = target.GetLinkLibraries();
for(cmTarget::LinkLibraryVectorType::const_iterator j = libs.begin();
j != libs.end(); ++j)
{
if(j->first != target.GetName() &&
this->FindTarget(0, j->first.c_str()))
{
vsTargetDepend.insert(j->first);
}
}
}
std::set<cmStdString> const& utils = target.GetUtilities();
for(std::set<cmStdString>::const_iterator i = utils.begin();
i != utils.end(); ++i)
{
if(*i != target.GetName())
{
std::string name = this->GetUtilityForTarget(target, i->c_str());
vsTargetDepend.insert(name);
}
}
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmGlobalVisualStudioGenerator::CheckTargetLinks(cmTarget& target, bool cmGlobalVisualStudioGenerator::CheckTargetLinks(cmTarget& target,
const char* name) const char* name)

View File

@ -93,6 +93,11 @@ protected:
virtual void GetTargetSets(TargetDependSet& projectTargets, virtual void GetTargetSets(TargetDependSet& projectTargets,
TargetDependSet& originalTargets, TargetDependSet& originalTargets,
cmLocalGenerator* root, GeneratorVector const&); cmLocalGenerator* root, GeneratorVector const&);
virtual bool ComputeTargetDepends();
class VSDependSet: public std::set<cmStdString> {};
class VSDependMap: public std::map<cmTarget*, VSDependSet> {};
VSDependMap VSTargetDepends;
void ComputeVSTargetDepends(cmTarget&);
bool CheckTargetLinks(cmTarget& target, const char* name); bool CheckTargetLinks(cmTarget& target, const char* name);
private: private: