ENH: Add a way to overwrite some preferences and ignore certain targets

This commit is contained in:
Andy Cedilnik 2006-03-07 15:31:05 -05:00
parent 6d4b7425fd
commit ccac9542b1
2 changed files with 80 additions and 12 deletions

View File

@ -0,0 +1 @@
SET(GRAPHVIZ_IGNORE_TARGETS "tartest;testSystemTools;testRegistry;testProcess;testIOS;testHashSTL;testFail;testCommandLineArguments;xrtest;LIBCURL;foo")

View File

@ -2008,10 +2008,60 @@ void cmake::GenerateGraphViz(const char* fileName)
{ {
return; return;
} }
str << "digraph G {" << std::endl; cmake cm;
str << "node [" << std::endl; cmGlobalGenerator ggi;
str << " fontsize = \"12\"" << std::endl; ggi.SetCMakeInstance(&cm);
str << "];" << std::endl; std::auto_ptr<cmLocalGenerator> lg(ggi.CreateLocalGenerator());
lg->SetGlobalGenerator(&ggi);
cmMakefile *mf = lg->GetMakefile();
std::string infile = this->GetHomeOutputDirectory();
infile += "/CMakeGraphVizOptions.cmake";
if ( !cmSystemTools::FileExists(infile.c_str()) )
{
infile = this->GetHomeDirectory();
infile += "/CMakeGraphVizOptions.cmake";
if ( !cmSystemTools::FileExists(infile.c_str()) )
{
infile = "";
}
}
if ( !infile.empty() )
{
if ( !mf->ReadListFile(0, infile.c_str()) )
{
cmSystemTools::Error("Problem opening GraphViz options file: ", infile.c_str());
return;
}
std::cout << "Read GraphViz options file: " << infile.c_str() << std::endl;
}
#define __set_if_not_set(var, value, cmakeDefinition) \
const char* var = mf->GetDefinition(cmakeDefinition); \
if ( !var ) \
{ \
var = value; \
}
__set_if_not_set(graphType, "digraph", "GRAPHVIZ_GRAPH_TYPE");
__set_if_not_set(graphName, "GG", "GRAPHVIZ_GRAPH_NAME");
__set_if_not_set(graphHeader, "node [\n fontsize = \"12\"\n];", "GRAPHVIZ_GRAPH_HEADER");
__set_if_not_set(graphNodePrefix, "node", "GRAPHVIZ_NODE_PREFIX");
const char* ignoreTargets = mf->GetDefinition("GRAPHVIZ_IGNORE_TARGETS");
std::set<cmStdString> ignoreTargetsSet;
if ( ignoreTargets )
{
std::vector<std::string> ignoreTargetsVector;
cmSystemTools::ExpandListArgument(ignoreTargets,ignoreTargetsVector);
std::vector<std::string>::iterator itvIt;
for ( itvIt = ignoreTargetsVector.begin(); itvIt != ignoreTargetsVector.end(); ++ itvIt )
{
ignoreTargetsSet.insert(itvIt->c_str());
}
}
str << graphType << " " << graphName << " {" << std::endl;
str << graphHeader << std::endl;
cmGlobalGenerator* gg = this->GetGlobalGenerator(); cmGlobalGenerator* gg = this->GetGlobalGenerator();
std::vector<cmLocalGenerator*> localGenerators; std::vector<cmLocalGenerator*> localGenerators;
@ -2033,10 +2083,16 @@ void cmake::GenerateGraphViz(const char* fileName)
cmTargets::iterator tit; cmTargets::iterator tit;
for ( tit = targets->begin(); tit != targets->end(); ++ tit ) for ( tit = targets->begin(); tit != targets->end(); ++ tit )
{ {
const char* realTargetName = tit->first.c_str();
if ( ignoreTargetsSet.find(realTargetName) != ignoreTargetsSet.end() )
{
// Skip ignored targets
continue;
}
//std::cout << "Found target: " << tit->first.c_str() << std::endl; //std::cout << "Found target: " << tit->first.c_str() << std::endl;
sprintf(tgtName, "node%d", cnt++); sprintf(tgtName, "%s%d", graphNodePrefix, cnt++);
targetNamesNodes[tit->first.c_str()] = tgtName; targetNamesNodes[realTargetName] = tgtName;
targetPtrs[tit->first.c_str()] = &tit->second; targetPtrs[realTargetName] = &tit->second;
//str << " \"" << tgtName << "\" [ label=\"" << tit->first.c_str() << "\" shape=\"box\"];" << std::endl; //str << " \"" << tgtName << "\" [ label=\"" << tit->first.c_str() << "\" shape=\"box\"];" << std::endl;
} }
} }
@ -2049,17 +2105,28 @@ void cmake::GenerateGraphViz(const char* fileName)
{ {
const cmTarget::LinkLibraries* ll = &(tit->second.GetOriginalLinkLibraries()); const cmTarget::LinkLibraries* ll = &(tit->second.GetOriginalLinkLibraries());
cmTarget::LinkLibraries::const_iterator llit; cmTarget::LinkLibraries::const_iterator llit;
const char* realTargetName = tit->first.c_str();
if ( ignoreTargetsSet.find(realTargetName) != ignoreTargetsSet.end() )
{
// Skip ignored targets
continue;
}
if ( ll->size() > 0 ) if ( ll->size() > 0 )
{ {
targetDeps[tit->first.c_str()] = 1; targetDeps[realTargetName] = 1;
} }
for ( llit = ll->begin(); llit != ll->end(); ++ llit ) for ( llit = ll->begin(); llit != ll->end(); ++ llit )
{ {
const char* libName = llit->first.c_str(); const char* libName = llit->first.c_str();
std::map<cmStdString, cmStdString>::iterator tarIt = targetNamesNodes.find(libName); std::map<cmStdString, cmStdString>::iterator tarIt = targetNamesNodes.find(libName);
if ( ignoreTargetsSet.find(libName) != ignoreTargetsSet.end() )
{
// Skip ignored targets
continue;
}
if ( tarIt == targetNamesNodes.end() ) if ( tarIt == targetNamesNodes.end() )
{ {
sprintf(tgtName, "node%d", cnt++); sprintf(tgtName, "%s%d", graphNodePrefix, cnt++);
targetDeps[libName] = 2; targetDeps[libName] = 2;
targetNamesNodes[libName] = tgtName; targetNamesNodes[libName] = tgtName;
//str << " \"" << tgtName << "\" [ label=\"" << libName << "\" shape=\"ellipse\"];" << std::endl; //str << " \"" << tgtName << "\" [ label=\"" << libName << "\" shape=\"ellipse\"];" << std::endl;
@ -2085,7 +2152,7 @@ void cmake::GenerateGraphViz(const char* fileName)
if ( tarIt == targetNamesNodes.end() ) if ( tarIt == targetNamesNodes.end() )
{ {
// We should not be here. // We should not be here.
std::cout << "Cannot find library: " << newTargetName << " even though it was added in the previous pass" << std::endl; std::cout << __LINE__ << " Cannot find library: " << newTargetName << " even though it was added in the previous pass" << std::endl;
abort(); abort();
} }
@ -2096,7 +2163,7 @@ void cmake::GenerateGraphViz(const char* fileName)
if ( tarTypeIt == targetPtrs.end() ) if ( tarTypeIt == targetPtrs.end() )
{ {
// We should not be here. // We should not be here.
std::cout << "Cannot find library: " << newTargetName << " even though it was added in the previous pass" << std::endl; std::cout << __LINE__ << " Cannot find library: " << newTargetName << " even though it was added in the previous pass" << std::endl;
abort(); abort();
} }
cmTarget* tg = tarTypeIt->second; cmTarget* tg = tarTypeIt->second;
@ -2147,7 +2214,7 @@ void cmake::GenerateGraphViz(const char* fileName)
if ( tarIt == targetNamesNodes.end() ) if ( tarIt == targetNamesNodes.end() )
{ {
// We should not be here. // We should not be here.
std::cout << "Cannot find library: " << libName << " even though it was added in the previous pass" << std::endl; std::cout << __LINE__ << " Cannot find library: " << libName << " even though it was added in the previous pass" << std::endl;
abort(); abort();
} }
str << " \"" << cmakeTarIt->second.c_str() << "\" -> \"" << tarIt->second.c_str() << "\"" << std::endl; str << " \"" << cmakeTarIt->second.c_str() << "\" -> \"" << tarIt->second.c_str() << "\"" << std::endl;