ENH: add project to target map, not used yet, but created

This commit is contained in:
Bill Hoffman 2007-03-13 14:23:08 -04:00
parent d720036e61
commit 5891ba16ce
5 changed files with 139 additions and 19 deletions

View File

@ -1055,6 +1055,116 @@ void cmGlobalGenerator::FillProjectMap()
}
while (lg);
}
// now create project to target map
// This will make sure that targets have all the
// targets they depend on as part of the build.
this->FillProjectToTargetMap();
}
// Build a map that contains a the set of targets used by each project
void cmGlobalGenerator::FillProjectToTargetMap()
{
// loop over each project in the build
for(std::map<cmStdString,
std::vector<cmLocalGenerator*> >::iterator m =
this->ProjectMap.begin();
m != this->ProjectMap.end(); ++m)
{
std::vector<cmLocalGenerator*>& lgs = m->second;
if(lgs.size() == 0)
{
continue;
}
cmStdString const & projectName = m->first;
cmMakefile* projectMakefile = lgs[0]->GetMakefile();
// get the current EXCLUDE_FROM_ALL value from projectMakefile
const char* exclude = 0;
std::string excludeSave;
bool chain = false;
exclude =
projectMakefile->GetProperties().
GetPropertyValue("EXCLUDE_FROM_ALL",
cmProperty::DIRECTORY, chain);
if(exclude)
{
excludeSave = exclude;
}
// Set EXCLUDE_FROM_ALL to FALSE for the top level makefile because
// in the current project nothing is excluded yet
projectMakefile->SetProperty("EXCLUDE_FROM_ALL", "FALSE");
// now loop over all cmLocalGenerators in this project and pull
// out all the targets that depend on each other, even if those
// targets come from a target that is excluded.
for(std::vector<cmLocalGenerator*>::iterator lg =
lgs.begin(); lg != lgs.end(); ++lg)
{
cmMakefile* mf = (*lg)->GetMakefile();
cmTargets& targets = mf->GetTargets();
for(cmTargets::iterator t = targets.begin();
t != targets.end(); ++t)
{
cmTarget& target = t->second;
// if the target is in all then add it to the project
if(!target.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
{
// add this target to the project
this->ProjectToTargetMap[projectName].insert(&target);
// now get all the targets that link to this target and
// add them
cmTarget::LinkLibraryVectorType::const_iterator j, jend;
j = target.GetLinkLibraries().begin();
jend = target.GetLinkLibraries().end();
for(;j!= jend; ++j)
{
cmTarget* depTarget = this->FindTarget(0, j->first.c_str());
if(depTarget)
{
this->ProjectToTargetMap[projectName].insert(depTarget);
}
}
// Now add any utility targets used by this target
std::set<cmStdString>::const_iterator i, end;
i = target.GetUtilities().begin();
end = target.GetUtilities().end();
for(;i!= end; ++i)
{
cmTarget* depTarget = this->FindTarget(0, i->c_str());
if(depTarget)
{
this->ProjectToTargetMap[projectName].insert(depTarget);
}
}
}
}
}
// Now restore the EXCLUDE_FROM_ALL property on the project top
// makefile
if(exclude)
{
exclude = excludeSave.c_str();
}
projectMakefile->SetProperty("EXCLUDE_FROM_ALL", exclude);
}
// dump the map for debug purposes
// right now this map is not being used, but it was
// checked in to avoid constant conflicts.
// It is also the first step to creating sub projects
// that contain all of the targets they need.
#if 0
std::map<cmStdString, std::set<cmTarget*> >::iterator i =
this->ProjectToTargetMap.begin();
for(; i != this->ProjectToTargetMap.end(); ++i)
{
std::cerr << i->first << "\n";
std::set<cmTarget*>::iterator t = i->second.begin();
for(; t != i->second.end(); ++t)
{
cmTarget* target = *t;
std::cerr << "\t" << target->GetName() << "\n";
}
}
#endif
}

View File

@ -198,7 +198,7 @@ protected:
// has been populated.
void FillProjectMap();
bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen);
void FillProjectToTargetMap();
void CreateDefaultGlobalTargets(cmTargets* targets);
cmTarget CreateGlobalTarget(const char* name, const char* message,
const cmCustomCommandLines* commandLines,
@ -214,6 +214,7 @@ protected:
std::vector<cmLocalGenerator *> LocalGenerators;
// map from project name to vector of local generators in that project
std::map<cmStdString, std::vector<cmLocalGenerator*> > ProjectMap;
std::map<cmStdString, std::set<cmTarget*> > ProjectToTargetMap;
// Set of named installation components requested by the project.
std::set<cmStdString> InstallComponents;

View File

@ -1120,8 +1120,10 @@ void cmMakefile::AddSubDirectory(const char* srcPath, const char *binPath,
// set the subdirs start dirs
lg2->GetMakefile()->SetStartDirectory(srcPath);
lg2->GetMakefile()->SetStartOutputDirectory(binPath);
lg2->GetMakefile()->SetProperty("EXCLUDE_FROM_ALL",
(excludeFromAll) ? "TRUE" : "FALSE");
if(excludeFromAll)
{
lg2->GetMakefile()->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
}
lg2->GetMakefile()->SetPreOrder(preorder);
if (immediate)
@ -1342,8 +1344,10 @@ void cmMakefile::AddLibrary(const char* lname, int shared,
// over changes in CMakeLists.txt, making the information stale and
// hence useless.
target.ClearDependencyInformation( *this, lname );
target.SetProperty("EXCLUDE_FROM_ALL",
(excludeFromAll) ? "TRUE" : "FALSE");
if(excludeFromAll)
{
target.SetProperty("EXCLUDE_FROM_ALL", "TRUE");
}
target.GetSourceLists() = srcs;
this->AddGlobalLinkInformation(lname, target);
cmTargets::iterator it =
@ -1358,8 +1362,10 @@ cmTarget* cmMakefile::AddExecutable(const char *exeName,
cmTarget target;
target.SetType(cmTarget::EXECUTABLE, exeName);
target.SetMakefile(this);
target.SetProperty("EXCLUDE_FROM_ALL",
(excludeFromAll) ?"TRUE" : "FALSE");
if(excludeFromAll)
{
target.SetProperty("EXCLUDE_FROM_ALL", "TRUE");
}
target.GetSourceLists() = srcs;
this->AddGlobalLinkInformation(exeName, target);
cmTargets::iterator it =
@ -2600,11 +2606,6 @@ void cmMakefile::SetProperty(const char* prop, const char* value)
{
return;
}
if (!value)
{
value = "NOTFOUND";
}
this->Properties.SetProperty(prop,value,cmProperty::DIRECTORY);
}
@ -2653,6 +2654,11 @@ const char *cmMakefile::GetProperty(const char* prop,
this->Properties.GetPropertyValue(prop, scope, chain);
if (chain)
{
if(this->LocalGenerator->GetParent())
{
return this->LocalGenerator->GetParent()->GetMakefile()->
GetProperty(prop, scope);
}
return this->GetCMakeInstance()->GetProperty(prop,scope);
}
@ -2782,5 +2788,6 @@ void cmMakefile::DefineProperties(cmake *cm)
"A property on a target that indicates if the target is excluded "
"from the default build target. If it is not, then with a Makefile "
"for example typing make will couse this target to be built as well. "
"The same concept applies to the default build of other generators.");
"The same concept applies to the default build of other generators.",
true);
}

View File

@ -43,7 +43,11 @@ void cmPropertyMap::SetProperty(const char *name, const char *value,
{
return;
}
if(!value)
{
this->erase(name);
return;
}
#ifdef CMAKE_STRICT
if (!this->CMakeInstance)
{
@ -89,7 +93,7 @@ const char *cmPropertyMap
::GetPropertyValue(const char *name,
cmProperty::ScopeType scope,
bool &chain) const
{
{
chain = false;
if (!name)
{
@ -142,7 +146,6 @@ const char *cmPropertyMap
}
return 0;
}
return it->second.GetValue();
}

View File

@ -122,7 +122,8 @@ void cmTarget::DefineProperties(cmake *cm)
"A property on a target that indicates if the target is excluded "
"from the default build target. If it is not, then with a Makefile "
"for example typing make will couse this target to be built as well. "
"The same concept applies to the default build of other generators.");
"The same concept applies to the default build of other generators.",
true);
cm->DefineProperty
("INSTALL_NAME_DIR", cmProperty::TARGET,
@ -1313,7 +1314,6 @@ const char *cmTarget::GetProperty(const char* prop,
}
return 0;
}
bool chain = false;
const char *retVal =
this->Properties.GetPropertyValue(prop, scope, chain);
@ -1321,7 +1321,6 @@ const char *cmTarget::GetProperty(const char* prop,
{
return this->Makefile->GetProperty(prop,scope);
}
return retVal;
}