cmake/Source/cmGraphVizWriter.cxx

514 lines
16 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2011-01-16 11:35:12 +01:00
#include "cmGraphVizWriter.h"
2016-07-09 11:21:54 +02:00
#include "cmGeneratedFileStream.h"
2016-10-30 18:24:19 +01:00
#include "cmGeneratorTarget.h"
2016-07-09 11:21:54 +02:00
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
2016-10-30 18:24:19 +01:00
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cm_auto_ptr.hxx"
#include "cmake.h"
#include <cmConfigure.h>
#include <iostream>
#include <sstream>
#include <utility>
2011-01-16 11:35:12 +01:00
2016-03-13 13:35:51 +01:00
static const char* getShapeForTarget(const cmGeneratorTarget* target)
2011-01-16 11:35:12 +01:00
{
2016-07-09 11:21:54 +02:00
if (!target) {
2011-01-16 11:35:12 +01:00
return "ellipse";
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
2016-07-09 11:21:54 +02:00
switch (target->GetType()) {
2016-03-13 13:35:51 +01:00
case cmState::EXECUTABLE:
2011-01-16 11:35:12 +01:00
return "house";
2016-03-13 13:35:51 +01:00
case cmState::STATIC_LIBRARY:
2011-01-16 11:35:12 +01:00
return "diamond";
2016-03-13 13:35:51 +01:00
case cmState::SHARED_LIBRARY:
2011-01-16 11:35:12 +01:00
return "polygon";
2016-03-13 13:35:51 +01:00
case cmState::MODULE_LIBRARY:
2011-01-16 11:35:12 +01:00
return "octagon";
default:
break;
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
return "box";
}
2016-07-09 11:21:54 +02:00
cmGraphVizWriter::cmGraphVizWriter(
const std::vector<cmLocalGenerator*>& localGenerators)
: GraphType("digraph")
, GraphName("GG")
, GraphHeader("node [\n fontsize = \"12\"\n];")
, GraphNodePrefix("node")
, LocalGenerators(localGenerators)
, GenerateForExecutables(true)
, GenerateForStaticLibs(true)
, GenerateForSharedLibs(true)
, GenerateForModuleLibs(true)
, GenerateForExternals(true)
, GeneratePerTarget(true)
, GenerateDependers(true)
, HaveTargetsAndLibs(false)
2011-01-16 11:35:12 +01:00
{
}
void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
const char* fallbackSettingsFileName)
{
cmake cm;
2015-08-17 11:37:30 +02:00
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
2016-03-13 13:35:51 +01:00
cm.GetCurrentSnapshot().SetDefaultDefinitions();
2015-08-17 11:37:30 +02:00
cmGlobalGenerator ggi(&cm);
2016-10-30 18:24:19 +01:00
CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&ggi, cm.GetCurrentSnapshot()));
CM_AUTO_PTR<cmLocalGenerator> lg(ggi.CreateLocalGenerator(mf.get()));
2011-01-16 11:35:12 +01:00
const char* inFileName = settingsFileName;
2016-07-09 11:21:54 +02:00
if (!cmSystemTools::FileExists(inFileName)) {
2011-01-16 11:35:12 +01:00
inFileName = fallbackSettingsFileName;
2016-07-09 11:21:54 +02:00
if (!cmSystemTools::FileExists(inFileName)) {
2011-01-16 11:35:12 +01:00
return;
}
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
2016-07-09 11:21:54 +02:00
if (!mf->ReadListFile(inFileName)) {
2011-01-16 11:35:12 +01:00
cmSystemTools::Error("Problem opening GraphViz options file: ",
inFileName);
return;
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
std::cout << "Reading GraphViz options file: " << inFileName << std::endl;
2016-07-09 11:21:54 +02:00
#define __set_if_set(var, cmakeDefinition) \
{ \
const char* value = mf->GetDefinition(cmakeDefinition); \
if (value) { \
2016-10-30 18:24:19 +01:00
(var) = value; \
2016-07-09 11:21:54 +02:00
} \
2011-01-16 11:35:12 +01:00
}
__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");
2016-07-09 11:21:54 +02:00
#define __set_bool_if_set(var, cmakeDefinition) \
{ \
const char* value = mf->GetDefinition(cmakeDefinition); \
if (value) { \
2016-10-30 18:24:19 +01:00
(var) = mf->IsOn(cmakeDefinition); \
2016-07-09 11:21:54 +02:00
} \
2011-01-16 11:35:12 +01:00
}
__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-06-19 15:41:06 +03:00
__set_bool_if_set(this->GenerateForModuleLibs, "GRAPHVIZ_MODULE_LIBS");
__set_bool_if_set(this->GenerateForExternals, "GRAPHVIZ_EXTERNAL_LIBS");
2014-08-03 19:52:23 +02:00
__set_bool_if_set(this->GeneratePerTarget, "GRAPHVIZ_GENERATE_PER_TARGET");
__set_bool_if_set(this->GenerateDependers, "GRAPHVIZ_GENERATE_DEPENDERS");
2011-01-16 11:35:12 +01:00
2015-04-27 22:25:09 +02:00
std::string ignoreTargetsRegexes;
2011-06-19 15:41:06 +03:00
__set_if_set(ignoreTargetsRegexes, "GRAPHVIZ_IGNORE_TARGETS");
this->TargetsToIgnoreRegex.clear();
2016-07-09 11:21:54 +02:00
if (!ignoreTargetsRegexes.empty()) {
2011-06-19 15:41:06 +03:00
std::vector<std::string> ignoreTargetsRegExVector;
cmSystemTools::ExpandListArgument(ignoreTargetsRegexes,
ignoreTargetsRegExVector);
2016-07-09 11:21:54 +02:00
for (std::vector<std::string>::const_iterator itvIt =
ignoreTargetsRegExVector.begin();
itvIt != ignoreTargetsRegExVector.end(); ++itvIt) {
2015-04-27 22:25:09 +02:00
std::string currentRegexString(*itvIt);
2011-06-19 15:41:06 +03:00
cmsys::RegularExpression currentRegex;
2016-07-09 11:21:54 +02:00
if (!currentRegex.compile(currentRegexString.c_str())) {
2011-06-19 15:41:06 +03:00
std::cerr << "Could not compile bad regex \"" << currentRegexString
<< "\"" << std::endl;
2011-01-16 11:35:12 +01:00
}
2016-07-09 11:21:54 +02:00
this->TargetsToIgnoreRegex.push_back(currentRegex);
2011-01-16 11:35:12 +01:00
}
2016-07-09 11:21:54 +02:00
}
2011-06-19 15:41:06 +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)
{
2016-10-30 18:24:19 +01:00
if (!this->GenerateDependers) {
2014-08-03 19:52:23 +02:00
return;
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
2011-06-19 15:41:06 +03:00
this->CollectTargetsAndLibs();
2016-07-09 11:21:54 +02:00
for (std::map<std::string, const cmGeneratorTarget*>::const_iterator ptrIt =
this->TargetPtrs.begin();
ptrIt != this->TargetPtrs.end(); ++ptrIt) {
2016-10-30 18:24:19 +01:00
if (ptrIt->second == CM_NULLPTR) {
2011-06-19 15:41:06 +03:00
continue;
2016-07-09 11:21:54 +02:00
}
2011-06-19 15:41:06 +03:00
2016-10-30 18:24:19 +01:00
if (!this->GenerateForTargetType(ptrIt->second->GetType())) {
2011-06-19 15:41:06 +03:00
continue;
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
2011-06-19 15:41:06 +03:00
std::string currentFilename = fileName;
currentFilename += ".";
currentFilename += ptrIt->first;
currentFilename += ".dependers";
cmGeneratedFileStream str(currentFilename.c_str());
2016-07-09 11:21:54 +02:00
if (!str) {
2011-06-19 15:41:06 +03:00
return;
2016-07-09 11:21:54 +02:00
}
2011-06-19 15:41:06 +03:00
std::set<std::string> insertedConnections;
std::set<std::string> insertedNodes;
std::cout << "Writing " << currentFilename << "..." << std::endl;
this->WriteHeader(str);
2016-07-09 11:21:54 +02:00
this->WriteDependerConnections(ptrIt->first, insertedNodes,
insertedConnections, str);
2011-06-19 15:41:06 +03:00
this->WriteFooter(str);
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
}
2011-06-19 15:41:06 +03:00
// Iterate over all targets and write for each one a graph which shows
// on which targets it depends.
2011-01-16 11:35:12 +01:00
void cmGraphVizWriter::WritePerTargetFiles(const char* fileName)
{
2016-10-30 18:24:19 +01:00
if (!this->GeneratePerTarget) {
2014-08-03 19:52:23 +02:00
return;
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
2011-01-16 11:35:12 +01:00
this->CollectTargetsAndLibs();
2016-07-09 11:21:54 +02:00
for (std::map<std::string, const cmGeneratorTarget*>::const_iterator ptrIt =
this->TargetPtrs.begin();
ptrIt != this->TargetPtrs.end(); ++ptrIt) {
2016-10-30 18:24:19 +01:00
if (ptrIt->second == CM_NULLPTR) {
2011-01-16 11:35:12 +01:00
continue;
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
2016-10-30 18:24:19 +01:00
if (!this->GenerateForTargetType(ptrIt->second->GetType())) {
2011-01-16 11:35:12 +01:00
continue;
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
std::set<std::string> insertedConnections;
std::set<std::string> insertedNodes;
std::string currentFilename = fileName;
currentFilename += ".";
currentFilename += ptrIt->first;
cmGeneratedFileStream str(currentFilename.c_str());
2016-07-09 11:21:54 +02:00
if (!str) {
2011-01-16 11:35:12 +01:00
return;
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
std::cout << "Writing " << currentFilename << "..." << std::endl;
this->WriteHeader(str);
2016-07-09 11:21:54 +02:00
this->WriteConnections(ptrIt->first, insertedNodes, insertedConnections,
str);
2011-01-16 11:35:12 +01:00
this->WriteFooter(str);
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
}
void cmGraphVizWriter::WriteGlobalFile(const char* fileName)
{
this->CollectTargetsAndLibs();
cmGeneratedFileStream str(fileName);
2016-07-09 11:21:54 +02:00
if (!str) {
2011-01-16 11:35:12 +01:00
return;
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
this->WriteHeader(str);
std::cout << "Writing " << fileName << "..." << std::endl;
std::set<std::string> insertedConnections;
std::set<std::string> insertedNodes;
2016-07-09 11:21:54 +02:00
for (std::map<std::string, const cmGeneratorTarget*>::const_iterator ptrIt =
this->TargetPtrs.begin();
ptrIt != this->TargetPtrs.end(); ++ptrIt) {
2016-10-30 18:24:19 +01:00
if (ptrIt->second == CM_NULLPTR) {
2011-01-16 11:35:12 +01:00
continue;
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
2016-10-30 18:24:19 +01:00
if (!this->GenerateForTargetType(ptrIt->second->GetType())) {
2011-01-16 11:35:12 +01:00
continue;
}
2016-07-09 11:21:54 +02:00
this->WriteConnections(ptrIt->first, insertedNodes, insertedConnections,
str);
}
2011-01-16 11:35:12 +01:00
this->WriteFooter(str);
}
void cmGraphVizWriter::WriteHeader(cmGeneratedFileStream& str) const
{
2016-03-13 13:35:51 +01:00
str << this->GraphType << " \"" << this->GraphName << "\" {" << std::endl;
2011-01-16 11:35:12 +01:00
str << this->GraphHeader << std::endl;
}
void cmGraphVizWriter::WriteFooter(cmGeneratedFileStream& str) const
{
str << "}" << std::endl;
}
2016-07-09 11:21:54 +02:00
void cmGraphVizWriter::WriteConnections(
const std::string& targetName, std::set<std::string>& insertedNodes,
std::set<std::string>& insertedConnections, cmGeneratedFileStream& str) const
2011-01-16 11:35:12 +01:00
{
2016-07-09 11:21:54 +02:00
std::map<std::string, const cmGeneratorTarget*>::const_iterator targetPtrIt =
this->TargetPtrs.find(targetName);
2011-01-16 11:35:12 +01:00
2016-07-09 11:21:54 +02:00
if (targetPtrIt == this->TargetPtrs.end()) // not found at all
{
2011-01-16 11:35:12 +01:00
return;
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
this->WriteNode(targetName, targetPtrIt->second, insertedNodes, str);
2016-10-30 18:24:19 +01:00
if (targetPtrIt->second == CM_NULLPTR) // it's an external library
2016-07-09 11:21:54 +02:00
{
2011-01-16 11:35:12 +01:00
return;
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
std::string myNodeName = this->TargetNamesNodes.find(targetName)->second;
const cmTarget::LinkLibraryVectorType* ll =
2016-07-09 11:21:54 +02:00
&(targetPtrIt->second->Target->GetOriginalLinkLibraries());
2011-01-16 11:35:12 +01:00
for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
2016-07-09 11:21:54 +02:00
llit != ll->end(); ++llit) {
2011-01-16 11:35:12 +01:00
const char* libName = llit->first.c_str();
2015-04-27 22:25:09 +02:00
std::map<std::string, std::string>::const_iterator libNameIt =
2016-07-09 11:21:54 +02:00
this->TargetNamesNodes.find(libName);
2011-01-16 11:35:12 +01:00
2011-02-19 15:09:36 +02:00
// can happen e.g. if GRAPHVIZ_TARGET_IGNORE_REGEX is used
2016-07-09 11:21:54 +02:00
if (libNameIt == this->TargetNamesNodes.end()) {
2011-02-19 15:09:36 +02:00
continue;
2016-07-09 11:21:54 +02:00
}
2011-02-19 15:09:36 +02:00
2011-01-16 11:35:12 +01:00
std::string connectionName = myNodeName;
connectionName += "-";
connectionName += libNameIt->second;
2016-07-09 11:21:54 +02:00
if (insertedConnections.find(connectionName) ==
insertedConnections.end()) {
2011-01-16 11:35:12 +01:00
insertedConnections.insert(connectionName);
this->WriteNode(libName, this->TargetPtrs.find(libName)->second,
insertedNodes, str);
2016-07-09 11:21:54 +02:00
str << " \"" << myNodeName << "\" -> \"" << libNameIt->second << "\"";
2011-01-16 11:35:12 +01:00
str << " // " << targetName << " -> " << libName << std::endl;
this->WriteConnections(libName, insertedNodes, insertedConnections, str);
}
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
}
2016-07-09 11:21:54 +02:00
void cmGraphVizWriter::WriteDependerConnections(
const std::string& targetName, std::set<std::string>& insertedNodes,
std::set<std::string>& insertedConnections, cmGeneratedFileStream& str) const
2011-06-19 15:41:06 +03:00
{
2016-07-09 11:21:54 +02:00
std::map<std::string, const cmGeneratorTarget*>::const_iterator targetPtrIt =
this->TargetPtrs.find(targetName);
2011-06-19 15:41:06 +03:00
2016-07-09 11:21:54 +02:00
if (targetPtrIt == this->TargetPtrs.end()) // not found at all
{
2011-06-19 15:41:06 +03:00
return;
2016-07-09 11:21:54 +02:00
}
2011-06-19 15:41:06 +03:00
this->WriteNode(targetName, targetPtrIt->second, insertedNodes, str);
2016-10-30 18:24:19 +01:00
if (targetPtrIt->second == CM_NULLPTR) // it's an external library
2016-07-09 11:21:54 +02:00
{
2011-06-19 15:41:06 +03:00
return;
2016-07-09 11:21:54 +02:00
}
2011-06-19 15:41:06 +03:00
std::string myNodeName = this->TargetNamesNodes.find(targetName)->second;
// now search who links against me
2016-07-09 11:21:54 +02:00
for (std::map<std::string, const cmGeneratorTarget*>::const_iterator
dependerIt = this->TargetPtrs.begin();
dependerIt != this->TargetPtrs.end(); ++dependerIt) {
2016-10-30 18:24:19 +01:00
if (dependerIt->second == CM_NULLPTR) {
2011-06-19 15:41:06 +03:00
continue;
2016-07-09 11:21:54 +02:00
}
2011-06-19 15:41:06 +03:00
2016-10-30 18:24:19 +01:00
if (!this->GenerateForTargetType(dependerIt->second->GetType())) {
2011-06-19 15:41:06 +03:00
continue;
2016-07-09 11:21:54 +02:00
}
2011-06-19 15:41:06 +03:00
// 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 =
2016-07-09 11:21:54 +02:00
&(dependerIt->second->Target->GetOriginalLinkLibraries());
2011-06-19 15:41:06 +03:00
for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
2016-07-09 11:21:54 +02:00
llit != ll->end(); ++llit) {
2015-04-27 22:25:09 +02:00
std::string libName = llit->first;
2016-07-09 11:21:54 +02:00
if (libName == targetName) {
2011-06-19 15:41:06 +03:00
// So this target links against targetName.
2015-04-27 22:25:09 +02:00
std::map<std::string, std::string>::const_iterator dependerNodeNameIt =
2016-07-09 11:21:54 +02:00
this->TargetNamesNodes.find(dependerIt->first);
2011-06-19 15:41:06 +03:00
2016-07-09 11:21:54 +02:00
if (dependerNodeNameIt != this->TargetNamesNodes.end()) {
2011-06-19 15:41:06 +03:00
std::string connectionName = dependerNodeNameIt->second;
connectionName += "-";
connectionName += myNodeName;
if (insertedConnections.find(connectionName) ==
2016-07-09 11:21:54 +02:00
insertedConnections.end()) {
2011-06-19 15:41:06 +03:00
insertedConnections.insert(connectionName);
2015-04-27 22:25:09 +02:00
this->WriteNode(dependerIt->first, dependerIt->second,
2011-06-19 15:41:06 +03:00
insertedNodes, str);
str << " \"" << dependerNodeNameIt->second << "\" -> \""
<< myNodeName << "\"";
2016-07-09 11:21:54 +02:00
str << " // " << targetName << " -> " << dependerIt->first
<< std::endl;
this->WriteDependerConnections(dependerIt->first, insertedNodes,
insertedConnections, str);
2011-06-19 15:41:06 +03:00
}
}
2016-07-09 11:21:54 +02:00
break;
2011-06-19 15:41:06 +03:00
}
}
2016-07-09 11:21:54 +02:00
}
2011-06-19 15:41:06 +03:00
}
2015-04-27 22:25:09 +02:00
void cmGraphVizWriter::WriteNode(const std::string& targetName,
2016-03-13 13:35:51 +01:00
const cmGeneratorTarget* target,
2011-01-16 11:35:12 +01:00
std::set<std::string>& insertedNodes,
cmGeneratedFileStream& str) const
{
2016-07-09 11:21:54 +02:00
if (insertedNodes.find(targetName) == insertedNodes.end()) {
2011-01-16 11:35:12 +01:00
insertedNodes.insert(targetName);
2015-04-27 22:25:09 +02:00
std::map<std::string, std::string>::const_iterator nameIt =
2016-07-09 11:21:54 +02:00
this->TargetNamesNodes.find(targetName);
2011-01-16 11:35:12 +01:00
2016-07-09 11:21:54 +02:00
str << " \"" << nameIt->second << "\" [ label=\"" << targetName
<< "\" shape=\"" << getShapeForTarget(target) << "\"];" << std::endl;
2011-01-16 11:35:12 +01:00
}
}
void cmGraphVizWriter::CollectTargetsAndLibs()
{
2016-10-30 18:24:19 +01:00
if (!this->HaveTargetsAndLibs) {
2011-01-16 11:35:12 +01:00
this->HaveTargetsAndLibs = true;
int cnt = this->CollectAllTargets();
2016-07-09 11:21:54 +02:00
if (this->GenerateForExternals) {
2011-06-19 15:41:06 +03:00
this->CollectAllExternalLibs(cnt);
2011-01-16 11:35:12 +01:00
}
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
}
int cmGraphVizWriter::CollectAllTargets()
{
int cnt = 0;
// First pass get the list of all cmake targets
for (std::vector<cmLocalGenerator*>::const_iterator lit =
2016-07-09 11:21:54 +02:00
this->LocalGenerators.begin();
lit != this->LocalGenerators.end(); ++lit) {
2016-03-13 13:35:51 +01:00
std::vector<cmGeneratorTarget*> targets = (*lit)->GetGeneratorTargets();
2016-07-09 11:21:54 +02:00
for (std::vector<cmGeneratorTarget*>::const_iterator it = targets.begin();
it != targets.end(); ++it) {
2016-03-13 13:35:51 +01:00
const char* realTargetName = (*it)->GetName().c_str();
2016-07-09 11:21:54 +02:00
if (this->IgnoreThisTarget(realTargetName)) {
2011-01-16 11:35:12 +01:00
// Skip ignored targets
continue;
2016-07-09 11:21:54 +02:00
}
2016-10-30 18:24:19 +01:00
// std::cout << "Found target: " << tit->first << std::endl;
2015-04-27 22:25:09 +02:00
std::ostringstream ostr;
2011-01-16 11:35:12 +01:00
ostr << this->GraphNodePrefix << cnt++;
this->TargetNamesNodes[realTargetName] = ostr.str();
2016-03-13 13:35:51 +01:00
this->TargetPtrs[realTargetName] = *it;
2011-01-16 11:35:12 +01:00
}
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
return cnt;
}
int cmGraphVizWriter::CollectAllExternalLibs(int cnt)
{
// Ok, now find all the stuff we link to that is not in cmake
for (std::vector<cmLocalGenerator*>::const_iterator lit =
2016-07-09 11:21:54 +02:00
this->LocalGenerators.begin();
lit != this->LocalGenerators.end(); ++lit) {
2016-03-13 13:35:51 +01:00
std::vector<cmGeneratorTarget*> targets = (*lit)->GetGeneratorTargets();
2016-07-09 11:21:54 +02:00
for (std::vector<cmGeneratorTarget*>::const_iterator it = targets.begin();
it != targets.end(); ++it) {
2016-03-13 13:35:51 +01:00
const char* realTargetName = (*it)->GetName().c_str();
2016-07-09 11:21:54 +02:00
if (this->IgnoreThisTarget(realTargetName)) {
2011-01-16 11:35:12 +01:00
// Skip ignored targets
continue;
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
const cmTarget::LinkLibraryVectorType* ll =
2016-07-09 11:21:54 +02:00
&((*it)->Target->GetOriginalLinkLibraries());
2011-01-16 11:35:12 +01:00
for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
2016-07-09 11:21:54 +02:00
llit != ll->end(); ++llit) {
2011-01-16 11:35:12 +01:00
const char* libName = llit->first.c_str();
2016-07-09 11:21:54 +02:00
if (this->IgnoreThisTarget(libName)) {
2011-01-16 11:35:12 +01:00
// Skip ignored targets
continue;
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
2016-07-09 11:21:54 +02:00
std::map<std::string, const cmGeneratorTarget*>::const_iterator tarIt =
this->TargetPtrs.find(libName);
if (tarIt == this->TargetPtrs.end()) {
2015-04-27 22:25:09 +02:00
std::ostringstream ostr;
2011-01-16 11:35:12 +01:00
ostr << this->GraphNodePrefix << cnt++;
this->TargetNamesNodes[libName] = ostr.str();
2016-10-30 18:24:19 +01:00
this->TargetPtrs[libName] = CM_NULLPTR;
// str << " \"" << ostr << "\" [ label=\"" << libName
2014-08-03 19:52:23 +02:00
// << "\" shape=\"ellipse\"];" << std::endl;
2011-01-16 11:35:12 +01:00
}
}
}
2016-07-09 11:21:54 +02:00
}
return cnt;
2011-01-16 11:35:12 +01:00
}
2015-04-27 22:25:09 +02:00
bool cmGraphVizWriter::IgnoreThisTarget(const std::string& name)
2011-01-16 11:35:12 +01:00
{
2016-07-09 11:21:54 +02:00
for (std::vector<cmsys::RegularExpression>::iterator itvIt =
this->TargetsToIgnoreRegex.begin();
itvIt != this->TargetsToIgnoreRegex.end(); ++itvIt) {
2011-06-19 15:41:06 +03:00
cmsys::RegularExpression& regEx = *itvIt;
2016-07-09 11:21:54 +02:00
if (regEx.is_valid()) {
if (regEx.find(name)) {
2011-06-19 15:41:06 +03:00
return true;
2011-01-16 11:35:12 +01:00
}
}
2016-07-09 11:21:54 +02:00
}
2011-06-19 15:41:06 +03:00
return false;
2011-01-16 11:35:12 +01:00
}
2016-07-09 11:21:54 +02:00
bool cmGraphVizWriter::GenerateForTargetType(
cmState::TargetType targetType) const
2011-01-16 11:35:12 +01:00
{
2016-07-09 11:21:54 +02:00
switch (targetType) {
2016-03-13 13:35:51 +01:00
case cmState::EXECUTABLE:
2011-01-16 11:35:12 +01:00
return this->GenerateForExecutables;
2016-03-13 13:35:51 +01:00
case cmState::STATIC_LIBRARY:
2011-01-16 11:35:12 +01:00
return this->GenerateForStaticLibs;
2016-03-13 13:35:51 +01:00
case cmState::SHARED_LIBRARY:
2011-01-16 11:35:12 +01:00
return this->GenerateForSharedLibs;
2016-03-13 13:35:51 +01:00
case cmState::MODULE_LIBRARY:
2011-01-16 11:35:12 +01:00
return this->GenerateForModuleLibs;
default:
break;
}
return false;
}