2010-11-09 23:37:51 +03:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
|
|
|
#include "cmGraphVizWriter.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
#include "cmGeneratedFileStream.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char* getShapeForTarget(const cmTarget* target)
|
|
|
|
{
|
|
|
|
if (!target)
|
|
|
|
{
|
|
|
|
return "ellipse";
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( target->GetType() )
|
|
|
|
{
|
|
|
|
case cmTarget::EXECUTABLE:
|
|
|
|
return "house";
|
|
|
|
case cmTarget::STATIC_LIBRARY:
|
|
|
|
return "diamond";
|
|
|
|
case cmTarget::SHARED_LIBRARY:
|
|
|
|
return "polygon";
|
|
|
|
case cmTarget::MODULE_LIBRARY:
|
|
|
|
return "octagon";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "box";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmGraphVizWriter::cmGraphVizWriter(const std::vector<cmLocalGenerator*>&
|
|
|
|
localGenerators)
|
|
|
|
:GraphType("digraph")
|
|
|
|
,GraphName("GG")
|
|
|
|
,GraphHeader("node [\n fontsize = \"12\"\n];")
|
|
|
|
,GraphNodePrefix("node")
|
2010-11-14 21:30:58 +03:00
|
|
|
,GenerateForExecutables(true)
|
|
|
|
,GenerateForStaticLibs(true)
|
|
|
|
,GenerateForSharedLibs(true)
|
|
|
|
,GenerateForModuleLibs(true)
|
2011-02-05 20:43:34 +03:00
|
|
|
,GenerateForExternals(true)
|
2014-02-10 01:58:44 +04:00
|
|
|
,GeneratePerTarget(true)
|
|
|
|
,GenerateDependers(true)
|
2010-11-09 23:37:51 +03:00
|
|
|
,LocalGenerators(localGenerators)
|
2010-11-14 21:37:03 +03:00
|
|
|
,HaveTargetsAndLibs(false)
|
2010-11-09 23:37:51 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
|
|
|
|
const char* fallbackSettingsFileName)
|
|
|
|
{
|
|
|
|
cmake cm;
|
2015-05-05 00:01:29 +03:00
|
|
|
cm.SetHomeDirectory("");
|
|
|
|
cm.SetHomeOutputDirectory("");
|
2015-05-24 12:31:14 +03:00
|
|
|
cmGlobalGenerator ggi(&cm);
|
2015-05-16 06:18:25 +03:00
|
|
|
cmsys::auto_ptr<cmLocalGenerator> lg(ggi.MakeLocalGenerator());
|
2010-11-09 23:37:51 +03:00
|
|
|
cmMakefile *mf = lg->GetMakefile();
|
|
|
|
|
|
|
|
const char* inFileName = settingsFileName;
|
|
|
|
|
|
|
|
if ( !cmSystemTools::FileExists(inFileName) )
|
|
|
|
{
|
|
|
|
inFileName = fallbackSettingsFileName;
|
|
|
|
if ( !cmSystemTools::FileExists(inFileName) )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 15:50:37 +03:00
|
|
|
if ( !mf->ReadListFile(inFileName) )
|
2010-11-09 23:37:51 +03:00
|
|
|
{
|
|
|
|
cmSystemTools::Error("Problem opening GraphViz options file: ",
|
|
|
|
inFileName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "Reading GraphViz options file: " << inFileName << std::endl;
|
|
|
|
|
|
|
|
#define __set_if_set(var, cmakeDefinition) \
|
|
|
|
{ \
|
|
|
|
const char* value = mf->GetDefinition(cmakeDefinition); \
|
|
|
|
if ( value ) \
|
|
|
|
{ \
|
|
|
|
var = value; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
__set_if_set(this->GraphType, "GRAPHVIZ_GRAPH_TYPE");
|
|
|
|
__set_if_set(this->GraphName, "GRAPHVIZ_GRAPH_NAME");
|
|
|
|
__set_if_set(this->GraphHeader, "GRAPHVIZ_GRAPH_HEADER");
|
|
|
|
__set_if_set(this->GraphNodePrefix, "GRAPHVIZ_NODE_PREFIX");
|
|
|
|
|
2010-11-14 21:30:58 +03:00
|
|
|
#define __set_bool_if_set(var, cmakeDefinition) \
|
|
|
|
{ \
|
|
|
|
const char* value = mf->GetDefinition(cmakeDefinition); \
|
|
|
|
if ( value ) \
|
|
|
|
{ \
|
|
|
|
var = mf->IsOn(cmakeDefinition); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
__set_bool_if_set(this->GenerateForExecutables, "GRAPHVIZ_EXECUTABLES");
|
|
|
|
__set_bool_if_set(this->GenerateForStaticLibs, "GRAPHVIZ_STATIC_LIBS");
|
|
|
|
__set_bool_if_set(this->GenerateForSharedLibs, "GRAPHVIZ_SHARED_LIBS");
|
2011-02-05 20:43:34 +03:00
|
|
|
__set_bool_if_set(this->GenerateForModuleLibs, "GRAPHVIZ_MODULE_LIBS");
|
|
|
|
__set_bool_if_set(this->GenerateForExternals, "GRAPHVIZ_EXTERNAL_LIBS");
|
2014-02-10 01:58:44 +04:00
|
|
|
__set_bool_if_set(this->GeneratePerTarget, "GRAPHVIZ_GENERATE_PER_TARGET");
|
|
|
|
__set_bool_if_set(this->GenerateDependers, "GRAPHVIZ_GENERATE_DEPENDERS");
|
2010-11-14 21:30:58 +03:00
|
|
|
|
2014-02-10 09:21:34 +04:00
|
|
|
std::string ignoreTargetsRegexes;
|
2011-02-05 21:09:54 +03:00
|
|
|
__set_if_set(ignoreTargetsRegexes, "GRAPHVIZ_IGNORE_TARGETS");
|
2010-11-14 21:47:28 +03:00
|
|
|
|
2011-02-05 21:09:54 +03:00
|
|
|
this->TargetsToIgnoreRegex.clear();
|
2015-01-15 02:06:11 +03:00
|
|
|
if (!ignoreTargetsRegexes.empty())
|
2010-11-09 23:37:51 +03:00
|
|
|
{
|
2011-02-05 21:09:54 +03:00
|
|
|
std::vector<std::string> ignoreTargetsRegExVector;
|
|
|
|
cmSystemTools::ExpandListArgument(ignoreTargetsRegexes,
|
|
|
|
ignoreTargetsRegExVector);
|
|
|
|
for(std::vector<std::string>::const_iterator itvIt
|
|
|
|
= ignoreTargetsRegExVector.begin();
|
|
|
|
itvIt != ignoreTargetsRegExVector.end();
|
2010-11-09 23:37:51 +03:00
|
|
|
++ itvIt )
|
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
std::string currentRegexString(*itvIt);
|
2011-02-05 21:09:54 +03:00
|
|
|
cmsys::RegularExpression currentRegex;
|
|
|
|
if (!currentRegex.compile(currentRegexString.c_str()))
|
|
|
|
{
|
|
|
|
std::cerr << "Could not compile bad regex \"" << currentRegexString
|
|
|
|
<< "\"" << std::endl;
|
|
|
|
}
|
|
|
|
this->TargetsToIgnoreRegex.push_back(currentRegex);
|
2010-11-09 23:37:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-06 20:34:48 +03:00
|
|
|
// Iterate over all targets and write for each one a graph which shows
|
|
|
|
// which other targets depend on it.
|
|
|
|
void cmGraphVizWriter::WriteTargetDependersFiles(const char* fileName)
|
|
|
|
{
|
2014-02-10 01:58:44 +04:00
|
|
|
if(this->GenerateDependers == false)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-06 20:34:48 +03:00
|
|
|
this->CollectTargetsAndLibs();
|
|
|
|
|
2014-02-10 09:21:34 +04:00
|
|
|
for(std::map<std::string, const cmTarget*>::const_iterator ptrIt =
|
2011-02-06 20:34:48 +03:00
|
|
|
this->TargetPtrs.begin();
|
|
|
|
ptrIt != this->TargetPtrs.end();
|
|
|
|
++ptrIt)
|
|
|
|
{
|
|
|
|
if (ptrIt->second == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->GenerateForTargetType(ptrIt->second->GetType()) == false)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string currentFilename = fileName;
|
|
|
|
currentFilename += ".";
|
|
|
|
currentFilename += ptrIt->first;
|
|
|
|
currentFilename += ".dependers";
|
|
|
|
|
|
|
|
cmGeneratedFileStream str(currentFilename.c_str());
|
|
|
|
if ( !str )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::set<std::string> insertedConnections;
|
|
|
|
std::set<std::string> insertedNodes;
|
|
|
|
|
|
|
|
std::cout << "Writing " << currentFilename << "..." << std::endl;
|
|
|
|
this->WriteHeader(str);
|
|
|
|
|
2014-03-11 03:04:11 +04:00
|
|
|
this->WriteDependerConnections(ptrIt->first,
|
2011-02-06 20:34:48 +03:00
|
|
|
insertedNodes, insertedConnections, str);
|
|
|
|
|
|
|
|
this->WriteFooter(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Iterate over all targets and write for each one a graph which shows
|
|
|
|
// on which targets it depends.
|
2010-11-09 23:37:51 +03:00
|
|
|
void cmGraphVizWriter::WritePerTargetFiles(const char* fileName)
|
|
|
|
{
|
2014-02-10 01:58:44 +04:00
|
|
|
if(this->GeneratePerTarget == false)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-14 21:37:03 +03:00
|
|
|
this->CollectTargetsAndLibs();
|
|
|
|
|
2014-02-10 09:21:34 +04:00
|
|
|
for(std::map<std::string, const cmTarget*>::const_iterator ptrIt =
|
2010-11-09 23:37:51 +03:00
|
|
|
this->TargetPtrs.begin();
|
|
|
|
ptrIt != this->TargetPtrs.end();
|
|
|
|
++ptrIt)
|
|
|
|
{
|
|
|
|
if (ptrIt->second == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-11-14 21:30:58 +03:00
|
|
|
if (this->GenerateForTargetType(ptrIt->second->GetType()) == false)
|
2010-11-09 23:37:51 +03:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::set<std::string> insertedConnections;
|
|
|
|
std::set<std::string> insertedNodes;
|
|
|
|
|
|
|
|
std::string currentFilename = fileName;
|
|
|
|
currentFilename += ".";
|
|
|
|
currentFilename += ptrIt->first;
|
|
|
|
cmGeneratedFileStream str(currentFilename.c_str());
|
|
|
|
if ( !str )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-14 21:33:12 +03:00
|
|
|
std::cout << "Writing " << currentFilename << "..." << std::endl;
|
2010-11-09 23:37:51 +03:00
|
|
|
this->WriteHeader(str);
|
|
|
|
|
2014-03-11 03:04:11 +04:00
|
|
|
this->WriteConnections(ptrIt->first,
|
2010-11-09 23:37:51 +03:00
|
|
|
insertedNodes, insertedConnections, str);
|
|
|
|
this->WriteFooter(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cmGraphVizWriter::WriteGlobalFile(const char* fileName)
|
|
|
|
{
|
2010-11-14 21:37:03 +03:00
|
|
|
this->CollectTargetsAndLibs();
|
|
|
|
|
2010-11-09 23:37:51 +03:00
|
|
|
cmGeneratedFileStream str(fileName);
|
|
|
|
if ( !str )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->WriteHeader(str);
|
|
|
|
|
2010-11-14 21:33:12 +03:00
|
|
|
std::cout << "Writing " << fileName << "..." << std::endl;
|
|
|
|
|
2010-11-09 23:37:51 +03:00
|
|
|
std::set<std::string> insertedConnections;
|
|
|
|
std::set<std::string> insertedNodes;
|
|
|
|
|
2014-02-10 09:21:34 +04:00
|
|
|
for(std::map<std::string, const cmTarget*>::const_iterator ptrIt =
|
2010-11-09 23:37:51 +03:00
|
|
|
this->TargetPtrs.begin();
|
|
|
|
ptrIt != this->TargetPtrs.end();
|
|
|
|
++ptrIt)
|
|
|
|
{
|
|
|
|
if (ptrIt->second == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-11-14 21:30:58 +03:00
|
|
|
if (this->GenerateForTargetType(ptrIt->second->GetType()) == false)
|
2010-11-09 23:37:51 +03:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-03-11 03:04:11 +04:00
|
|
|
this->WriteConnections(ptrIt->first,
|
2010-11-09 23:37:51 +03:00
|
|
|
insertedNodes, insertedConnections, str);
|
|
|
|
}
|
|
|
|
this->WriteFooter(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cmGraphVizWriter::WriteHeader(cmGeneratedFileStream& str) const
|
|
|
|
{
|
|
|
|
str << this->GraphType << " " << this->GraphName << " {" << std::endl;
|
|
|
|
str << this->GraphHeader << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cmGraphVizWriter::WriteFooter(cmGeneratedFileStream& str) const
|
|
|
|
{
|
|
|
|
str << "}" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-07 02:31:47 +04:00
|
|
|
void cmGraphVizWriter::WriteConnections(const std::string& targetName,
|
2010-11-09 23:37:51 +03:00
|
|
|
std::set<std::string>& insertedNodes,
|
|
|
|
std::set<std::string>& insertedConnections,
|
|
|
|
cmGeneratedFileStream& str) const
|
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, const cmTarget* >::const_iterator targetPtrIt =
|
2010-11-09 23:37:51 +03:00
|
|
|
this->TargetPtrs.find(targetName);
|
|
|
|
|
|
|
|
if (targetPtrIt == this->TargetPtrs.end()) // not found at all
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->WriteNode(targetName, targetPtrIt->second, insertedNodes, str);
|
|
|
|
|
|
|
|
if (targetPtrIt->second == NULL) // it's an external library
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string myNodeName = this->TargetNamesNodes.find(targetName)->second;
|
|
|
|
|
|
|
|
const cmTarget::LinkLibraryVectorType* ll =
|
|
|
|
&(targetPtrIt->second->GetOriginalLinkLibraries());
|
|
|
|
|
|
|
|
for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
|
|
|
|
llit != ll->end();
|
|
|
|
++ llit )
|
|
|
|
{
|
|
|
|
const char* libName = llit->first.c_str();
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, std::string>::const_iterator libNameIt =
|
2010-11-09 23:37:51 +03:00
|
|
|
this->TargetNamesNodes.find(libName);
|
|
|
|
|
2011-02-04 22:31:18 +03:00
|
|
|
// can happen e.g. if GRAPHVIZ_TARGET_IGNORE_REGEX is used
|
|
|
|
if(libNameIt == this->TargetNamesNodes.end())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-11-09 23:37:51 +03:00
|
|
|
std::string connectionName = myNodeName;
|
|
|
|
connectionName += "-";
|
|
|
|
connectionName += libNameIt->second;
|
|
|
|
if (insertedConnections.find(connectionName) == insertedConnections.end())
|
|
|
|
{
|
|
|
|
insertedConnections.insert(connectionName);
|
|
|
|
this->WriteNode(libName, this->TargetPtrs.find(libName)->second,
|
|
|
|
insertedNodes, str);
|
|
|
|
|
2014-03-11 16:35:32 +04:00
|
|
|
str << " \"" << myNodeName << "\" -> \""
|
|
|
|
<< libNameIt->second << "\"";
|
2010-11-09 23:37:51 +03:00
|
|
|
str << " // " << targetName << " -> " << libName << std::endl;
|
|
|
|
this->WriteConnections(libName, insertedNodes, insertedConnections, str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-07 02:31:47 +04:00
|
|
|
void cmGraphVizWriter::WriteDependerConnections(const std::string& targetName,
|
2011-02-06 20:34:48 +03:00
|
|
|
std::set<std::string>& insertedNodes,
|
|
|
|
std::set<std::string>& insertedConnections,
|
|
|
|
cmGeneratedFileStream& str) const
|
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, const cmTarget* >::const_iterator targetPtrIt =
|
2011-02-06 20:34:48 +03:00
|
|
|
this->TargetPtrs.find(targetName);
|
|
|
|
|
|
|
|
if (targetPtrIt == this->TargetPtrs.end()) // not found at all
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->WriteNode(targetName, targetPtrIt->second, insertedNodes, str);
|
|
|
|
|
|
|
|
if (targetPtrIt->second == NULL) // it's an external library
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string myNodeName = this->TargetNamesNodes.find(targetName)->second;
|
|
|
|
|
|
|
|
// now search who links against me
|
2014-02-10 09:21:34 +04:00
|
|
|
for(std::map<std::string, const cmTarget*>::const_iterator dependerIt =
|
2011-02-06 20:34:48 +03:00
|
|
|
this->TargetPtrs.begin();
|
|
|
|
dependerIt != this->TargetPtrs.end();
|
|
|
|
++dependerIt)
|
|
|
|
{
|
|
|
|
if (dependerIt->second == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->GenerateForTargetType(dependerIt->second->GetType()) == false)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we have a target, check whether it links against targetName.
|
|
|
|
// If so, draw a connection, and then continue with dependers on that one.
|
|
|
|
const cmTarget::LinkLibraryVectorType* ll =
|
|
|
|
&(dependerIt->second->GetOriginalLinkLibraries());
|
|
|
|
|
|
|
|
for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
|
|
|
|
llit != ll->end();
|
|
|
|
++ llit )
|
|
|
|
{
|
2014-03-11 03:04:11 +04:00
|
|
|
std::string libName = llit->first;
|
2011-02-06 20:34:48 +03:00
|
|
|
if (libName == targetName)
|
|
|
|
{
|
|
|
|
// So this target links against targetName.
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, std::string>::const_iterator dependerNodeNameIt =
|
2011-02-06 20:34:48 +03:00
|
|
|
this->TargetNamesNodes.find(dependerIt->first);
|
|
|
|
|
|
|
|
if(dependerNodeNameIt != this->TargetNamesNodes.end())
|
|
|
|
{
|
|
|
|
std::string connectionName = dependerNodeNameIt->second;
|
|
|
|
connectionName += "-";
|
|
|
|
connectionName += myNodeName;
|
|
|
|
|
|
|
|
if (insertedConnections.find(connectionName) ==
|
|
|
|
insertedConnections.end())
|
|
|
|
{
|
|
|
|
insertedConnections.insert(connectionName);
|
2014-03-11 03:04:11 +04:00
|
|
|
this->WriteNode(dependerIt->first, dependerIt->second,
|
2011-02-06 20:34:48 +03:00
|
|
|
insertedNodes, str);
|
|
|
|
|
|
|
|
str << " \"" << dependerNodeNameIt->second << "\" -> \""
|
|
|
|
<< myNodeName << "\"";
|
|
|
|
str << " // " <<targetName<< " -> " <<dependerIt->first<<std::endl;
|
2014-03-11 03:04:11 +04:00
|
|
|
this->WriteDependerConnections(dependerIt->first,
|
2011-02-06 20:34:48 +03:00
|
|
|
insertedNodes, insertedConnections, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-07 02:31:47 +04:00
|
|
|
void cmGraphVizWriter::WriteNode(const std::string& targetName,
|
2010-11-09 23:37:51 +03:00
|
|
|
const cmTarget* target,
|
|
|
|
std::set<std::string>& insertedNodes,
|
|
|
|
cmGeneratedFileStream& str) const
|
|
|
|
{
|
|
|
|
if (insertedNodes.find(targetName) == insertedNodes.end())
|
|
|
|
{
|
|
|
|
insertedNodes.insert(targetName);
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, std::string>::const_iterator nameIt =
|
2010-11-09 23:37:51 +03:00
|
|
|
this->TargetNamesNodes.find(targetName);
|
|
|
|
|
2014-03-11 16:35:32 +04:00
|
|
|
str << " \"" << nameIt->second << "\" [ label=\""
|
2010-11-09 23:37:51 +03:00
|
|
|
<< targetName << "\" shape=\"" << getShapeForTarget(target)
|
|
|
|
<< "\"];" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-14 21:37:03 +03:00
|
|
|
void cmGraphVizWriter::CollectTargetsAndLibs()
|
|
|
|
{
|
|
|
|
if (this->HaveTargetsAndLibs == false)
|
|
|
|
{
|
|
|
|
this->HaveTargetsAndLibs = true;
|
|
|
|
int cnt = this->CollectAllTargets();
|
2011-02-05 20:43:34 +03:00
|
|
|
if (this->GenerateForExternals)
|
|
|
|
{
|
|
|
|
this->CollectAllExternalLibs(cnt);
|
|
|
|
}
|
2010-11-14 21:37:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int cmGraphVizWriter::CollectAllTargets()
|
2010-11-09 23:37:51 +03:00
|
|
|
{
|
|
|
|
int cnt = 0;
|
|
|
|
// First pass get the list of all cmake targets
|
|
|
|
for (std::vector<cmLocalGenerator*>::const_iterator lit =
|
|
|
|
this->LocalGenerators.begin();
|
|
|
|
lit != this->LocalGenerators.end();
|
|
|
|
++ lit )
|
|
|
|
{
|
|
|
|
const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets());
|
|
|
|
for ( cmTargets::const_iterator tit = targets->begin();
|
|
|
|
tit != targets->end();
|
|
|
|
++ tit )
|
|
|
|
{
|
|
|
|
const char* realTargetName = tit->first.c_str();
|
|
|
|
if(this->IgnoreThisTarget(realTargetName))
|
|
|
|
{
|
|
|
|
// Skip ignored targets
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//std::cout << "Found target: " << tit->first.c_str() << std::endl;
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream ostr;
|
2010-11-09 23:37:51 +03:00
|
|
|
ostr << this->GraphNodePrefix << cnt++;
|
|
|
|
this->TargetNamesNodes[realTargetName] = ostr.str();
|
|
|
|
this->TargetPtrs[realTargetName] = &tit->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-14 21:37:03 +03:00
|
|
|
int cmGraphVizWriter::CollectAllExternalLibs(int cnt)
|
2010-11-09 23:37:51 +03:00
|
|
|
{
|
|
|
|
// Ok, now find all the stuff we link to that is not in cmake
|
|
|
|
for (std::vector<cmLocalGenerator*>::const_iterator lit =
|
|
|
|
this->LocalGenerators.begin();
|
|
|
|
lit != this->LocalGenerators.end();
|
|
|
|
++ lit )
|
|
|
|
{
|
|
|
|
const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets());
|
|
|
|
for ( cmTargets::const_iterator tit = targets->begin();
|
|
|
|
tit != targets->end();
|
|
|
|
++ tit )
|
|
|
|
{
|
|
|
|
const char* realTargetName = tit->first.c_str();
|
|
|
|
if (this->IgnoreThisTarget(realTargetName))
|
|
|
|
{
|
|
|
|
// Skip ignored targets
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const cmTarget::LinkLibraryVectorType* ll =
|
|
|
|
&(tit->second.GetOriginalLinkLibraries());
|
|
|
|
for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
|
|
|
|
llit != ll->end();
|
|
|
|
++ llit )
|
|
|
|
{
|
|
|
|
const char* libName = llit->first.c_str();
|
|
|
|
if (this->IgnoreThisTarget(libName))
|
|
|
|
{
|
|
|
|
// Skip ignored targets
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, const cmTarget*>::const_iterator tarIt =
|
2010-11-09 23:37:51 +03:00
|
|
|
this->TargetPtrs.find(libName);
|
|
|
|
if ( tarIt == this->TargetPtrs.end() )
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream ostr;
|
2010-11-09 23:37:51 +03:00
|
|
|
ostr << this->GraphNodePrefix << cnt++;
|
|
|
|
this->TargetNamesNodes[libName] = ostr.str();
|
|
|
|
this->TargetPtrs[libName] = NULL;
|
2013-09-19 21:00:58 +04:00
|
|
|
// str << " \"" << ostr.c_str() << "\" [ label=\"" << libName
|
|
|
|
// << "\" shape=\"ellipse\"];" << std::endl;
|
2010-11-09 23:37:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-07 02:31:47 +04:00
|
|
|
bool cmGraphVizWriter::IgnoreThisTarget(const std::string& name)
|
2010-11-09 23:37:51 +03:00
|
|
|
{
|
2011-02-05 21:09:54 +03:00
|
|
|
for(std::vector<cmsys::RegularExpression>::iterator itvIt
|
|
|
|
= this->TargetsToIgnoreRegex.begin();
|
|
|
|
itvIt != this->TargetsToIgnoreRegex.end();
|
|
|
|
++ itvIt )
|
2010-11-14 21:47:28 +03:00
|
|
|
{
|
2011-02-05 21:09:54 +03:00
|
|
|
cmsys::RegularExpression& regEx = *itvIt;
|
|
|
|
if (regEx.is_valid())
|
2010-11-14 21:47:28 +03:00
|
|
|
{
|
2011-02-05 21:09:54 +03:00
|
|
|
if (regEx.find(name))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2010-11-14 21:47:28 +03:00
|
|
|
}
|
|
|
|
}
|
2011-02-05 21:09:54 +03:00
|
|
|
|
|
|
|
return false;
|
2010-11-09 23:37:51 +03:00
|
|
|
}
|
2010-11-14 21:30:58 +03:00
|
|
|
|
|
|
|
|
|
|
|
bool cmGraphVizWriter::GenerateForTargetType(cmTarget::TargetType targetType)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
switch (targetType)
|
|
|
|
{
|
|
|
|
case cmTarget::EXECUTABLE:
|
|
|
|
return this->GenerateForExecutables;
|
|
|
|
case cmTarget::STATIC_LIBRARY:
|
|
|
|
return this->GenerateForStaticLibs;
|
|
|
|
case cmTarget::SHARED_LIBRARY:
|
|
|
|
return this->GenerateForSharedLibs;
|
|
|
|
case cmTarget::MODULE_LIBRARY:
|
|
|
|
return this->GenerateForModuleLibs;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|