Avoid non-root copies of root-only targets

In cmGlobalGenerator::GetTargetSets we collect targets from all local
generators in a tree or subtree corresponding to a project() command.
Some targets, such as ALL_BUILD, are duplicated in each subdirectory
with a project() command.  For such targets we should keep only the copy
for the top-most (root) local generator.

Previously this filtering was done in each VS IDE generator, but it is
easier to do it in one place when the targets are first encountered.
This also fixes bad ALL_BUILD dependencies generated for VS 7.0 because
the cmGlobalVisualStudio7Generator::WriteTargetDepends method was not
filtering out duplicates.  Now we avoid duplicates from the start.
This commit is contained in:
Brad King 2009-10-06 13:30:00 -04:00
parent d8efcfc787
commit 9000b5a4de
5 changed files with 34 additions and 48 deletions

View File

@ -1953,6 +1953,11 @@ void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets,
for (cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l) for (cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
{ {
cmTarget* target = &l->second; cmTarget* target = &l->second;
if(this->IsRootOnlyTarget(target) &&
target->GetMakefile() != root->GetMakefile())
{
continue;
}
// put the target in the set of original targets // put the target in the set of original targets
originalTargets.insert(target); originalTargets.insert(target);
// Get the set of targets that depend on target // Get the set of targets that depend on target
@ -1961,6 +1966,13 @@ void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets,
} }
} }
//----------------------------------------------------------------------------
bool cmGlobalGenerator::IsRootOnlyTarget(cmTarget* target)
{
return (target->GetType() == cmTarget::GLOBAL_TARGET ||
strcmp(target->GetName(), this->GetAllTargetName()) == 0);
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmGlobalGenerator::AddTargetDepends(cmTarget* target, void cmGlobalGenerator::AddTargetDepends(cmTarget* target,
TargetDependSet& projectTargets) TargetDependSet& projectTargets)

View File

@ -265,6 +265,7 @@ 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 IsRootOnlyTarget(cmTarget* target);
void AddTargetDepends(cmTarget* target, TargetDependSet& projectTargets); void AddTargetDepends(cmTarget* target, TargetDependSet& projectTargets);
void SetLanguageEnabledFlag(const char* l, cmMakefile* mf); void SetLanguageEnabledFlag(const char* l, cmMakefile* mf);
void SetLanguageEnabledMaps(const char* l, cmMakefile* mf); void SetLanguageEnabledMaps(const char* l, cmMakefile* mf);

View File

@ -213,27 +213,10 @@ void cmGlobalVisualStudio6Generator
} }
else else
{ {
bool skip = false; std::string dspname = GetVS6TargetName(target->GetName());
// if it is a global target or the check build system target std::string dir = target->GetMakefile()->GetStartOutputDirectory();
// or the all_build target dir = root->Convert(dir.c_str(), cmLocalGenerator::START_OUTPUT);
// then only use the one that is for the root this->WriteProject(fout, dspname.c_str(), dir.c_str(), *target);
if(target->GetType() == cmTarget::GLOBAL_TARGET
|| !strcmp(target->GetName(), this->GetAllTargetName()))
{
if(target->GetMakefile() != root->GetMakefile())
{
skip = true;
}
}
// if not skipping the project then write it into the
// solution
if(!skip)
{
std::string dspname = GetVS6TargetName(target->GetName());
std::string dir = target->GetMakefile()->GetStartOutputDirectory();
dir = root->Convert(dir.c_str(), cmLocalGenerator::START_OUTPUT);
this->WriteProject(fout, dspname.c_str(), dir.c_str(), *target);
}
} }
} }

View File

@ -289,34 +289,16 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
} }
else else
{ {
bool skip = false; const char *vcprojName =
// if it is a global target or the check build system target target->GetProperty("GENERATOR_FILE_NAME");
// or the all_build target if(vcprojName)
// then only use the one that is for the root
if(target->GetType() == cmTarget::GLOBAL_TARGET
|| !strcmp(target->GetName(), CMAKE_CHECK_BUILD_SYSTEM_TARGET)
|| !strcmp(target->GetName(), this->GetAllTargetName()))
{ {
if(target->GetMakefile() != root->GetMakefile()) cmMakefile* tmf = target->GetMakefile();
{ std::string dir = tmf->GetStartOutputDirectory();
skip = true; dir = root->Convert(dir.c_str(),
} cmLocalGenerator::START_OUTPUT);
} this->WriteProject(fout, vcprojName, dir.c_str(),
// if not skipping the project then write it into the *target);
// solution
if(!skip)
{
const char *vcprojName =
target->GetProperty("GENERATOR_FILE_NAME");
if(vcprojName)
{
cmMakefile* tmf = target->GetMakefile();
std::string dir = tmf->GetStartOutputDirectory();
dir = root->Convert(dir.c_str(),
cmLocalGenerator::START_OUTPUT);
this->WriteProject(fout, vcprojName, dir.c_str(),
*target);
}
} }
} }
} }
@ -633,6 +615,13 @@ cmGlobalVisualStudio7Generator
} }
} }
//----------------------------------------------------------------------------
bool cmGlobalVisualStudio7Generator::IsRootOnlyTarget(cmTarget* target)
{
return (this->cmGlobalVisualStudioGenerator::IsRootOnlyTarget(target) ||
strcmp(target->GetName(), CMAKE_CHECK_BUILD_SYSTEM_TARGET) == 0);
}
bool cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(const char* project, bool cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(const char* project,
cmTarget* target) cmTarget* target)
{ {

View File

@ -133,6 +133,7 @@ protected:
std::string ConvertToSolutionPath(const char* path); std::string ConvertToSolutionPath(const char* path);
virtual bool IsRootOnlyTarget(cmTarget* target);
bool IsPartOfDefaultBuild(const char* project, bool IsPartOfDefaultBuild(const char* project,
cmTarget* target); cmTarget* target);
std::vector<std::string> Configurations; std::vector<std::string> Configurations;