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"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2010-11-09 23:37:51 +03:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmMakefile.h"
|
2010-11-09 23:37:51 +03:00
|
|
|
|
2015-10-21 22:49:41 +03:00
|
|
|
static const char* getShapeForTarget(const cmGeneratorTarget* target)
|
2010-11-09 23:37:51 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!target) {
|
2010-11-09 23:37:51 +03:00
|
|
|
return "ellipse";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-09 23:37:51 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
switch (target->GetType()) {
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::EXECUTABLE:
|
2010-11-09 23:37:51 +03:00
|
|
|
return "house";
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::STATIC_LIBRARY:
|
2010-11-09 23:37:51 +03:00
|
|
|
return "diamond";
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::SHARED_LIBRARY:
|
2010-11-09 23:37:51 +03:00
|
|
|
return "polygon";
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::MODULE_LIBRARY:
|
2010-11-09 23:37:51 +03:00
|
|
|
return "octagon";
|
|
|
|
default:
|
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-09 23:37:51 +03:00
|
|
|
|
|
|
|
return "box";
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03: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)
|
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-10-13 22:48:46 +03:00
|
|
|
cm.GetCurrentSnapshot().SetDefaultDefinitions();
|
2015-05-24 12:31:14 +03:00
|
|
|
cmGlobalGenerator ggi(&cm);
|
2016-06-28 17:17:52 +03:00
|
|
|
CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&ggi, cm.GetCurrentSnapshot()));
|
|
|
|
CM_AUTO_PTR<cmLocalGenerator> lg(ggi.CreateLocalGenerator(mf.get()));
|
2010-11-09 23:37:51 +03:00
|
|
|
|
|
|
|
const char* inFileName = settingsFileName;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileExists(inFileName)) {
|
2010-11-09 23:37:51 +03:00
|
|
|
inFileName = fallbackSettingsFileName;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileExists(inFileName)) {
|
2010-11-09 23:37:51 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-09 23:37:51 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!mf->ReadListFile(inFileName)) {
|
2010-11-09 23:37:51 +03:00
|
|
|
cmSystemTools::Error("Problem opening GraphViz options file: ",
|
|
|
|
inFileName);
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-09 23:37:51 +03:00
|
|
|
|
|
|
|
std::cout << "Reading GraphViz options file: " << inFileName << std::endl;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
#define __set_if_set(var, cmakeDefinition) \
|
|
|
|
{ \
|
|
|
|
const char* value = mf->GetDefinition(cmakeDefinition); \
|
|
|
|
if (value) { \
|
|
|
|
var = value; \
|
|
|
|
} \
|
2010-11-09 23:37:51 +03: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-05-16 17:34:04 +03:00
|
|
|
#define __set_bool_if_set(var, cmakeDefinition) \
|
|
|
|
{ \
|
|
|
|
const char* value = mf->GetDefinition(cmakeDefinition); \
|
|
|
|
if (value) { \
|
|
|
|
var = mf->IsOn(cmakeDefinition); \
|
|
|
|
} \
|
2010-11-14 21:30:58 +03: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-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();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!ignoreTargetsRegexes.empty()) {
|
2011-02-05 21:09:54 +03:00
|
|
|
std::vector<std::string> ignoreTargetsRegExVector;
|
|
|
|
cmSystemTools::ExpandListArgument(ignoreTargetsRegexes,
|
|
|
|
ignoreTargetsRegExVector);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator itvIt =
|
|
|
|
ignoreTargetsRegExVector.begin();
|
|
|
|
itvIt != ignoreTargetsRegExVector.end(); ++itvIt) {
|
2014-02-10 09:21:34 +04:00
|
|
|
std::string currentRegexString(*itvIt);
|
2011-02-05 21:09:54 +03:00
|
|
|
cmsys::RegularExpression currentRegex;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!currentRegex.compile(currentRegexString.c_str())) {
|
2011-02-05 21:09:54 +03:00
|
|
|
std::cerr << "Could not compile bad regex \"" << currentRegexString
|
|
|
|
<< "\"" << std::endl;
|
2010-11-09 23:37:51 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->TargetsToIgnoreRegex.push_back(currentRegex);
|
2010-11-09 23:37:51 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
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)
|
|
|
|
{
|
2016-06-02 00:29:53 +03:00
|
|
|
if (!this->GenerateDependers) {
|
2014-02-10 01:58:44 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-02-10 01:58:44 +04:00
|
|
|
|
2011-02-06 20:34:48 +03:00
|
|
|
this->CollectTargetsAndLibs();
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<std::string, const cmGeneratorTarget*>::const_iterator ptrIt =
|
|
|
|
this->TargetPtrs.begin();
|
|
|
|
ptrIt != this->TargetPtrs.end(); ++ptrIt) {
|
2016-06-27 23:44:16 +03:00
|
|
|
if (ptrIt->second == CM_NULLPTR) {
|
2011-02-06 20:34:48 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-02-06 20:34:48 +03:00
|
|
|
|
2016-06-02 00:29:53 +03:00
|
|
|
if (!this->GenerateForTargetType(ptrIt->second->GetType())) {
|
2011-02-06 20:34:48 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-02-06 20:34:48 +03:00
|
|
|
|
|
|
|
std::string currentFilename = fileName;
|
|
|
|
currentFilename += ".";
|
|
|
|
currentFilename += ptrIt->first;
|
|
|
|
currentFilename += ".dependers";
|
|
|
|
|
|
|
|
cmGeneratedFileStream str(currentFilename.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!str) {
|
2011-02-06 20:34:48 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-02-06 20:34:48 +03:00
|
|
|
|
|
|
|
std::set<std::string> insertedConnections;
|
|
|
|
std::set<std::string> insertedNodes;
|
|
|
|
|
|
|
|
std::cout << "Writing " << currentFilename << "..." << std::endl;
|
|
|
|
this->WriteHeader(str);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->WriteDependerConnections(ptrIt->first, insertedNodes,
|
|
|
|
insertedConnections, str);
|
2011-02-06 20:34:48 +03:00
|
|
|
|
|
|
|
this->WriteFooter(str);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-02-06 20:34:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
2016-06-02 00:29:53 +03:00
|
|
|
if (!this->GeneratePerTarget) {
|
2014-02-10 01:58:44 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-02-10 01:58:44 +04:00
|
|
|
|
2010-11-14 21:37:03 +03:00
|
|
|
this->CollectTargetsAndLibs();
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<std::string, const cmGeneratorTarget*>::const_iterator ptrIt =
|
|
|
|
this->TargetPtrs.begin();
|
|
|
|
ptrIt != this->TargetPtrs.end(); ++ptrIt) {
|
2016-06-27 23:44:16 +03:00
|
|
|
if (ptrIt->second == CM_NULLPTR) {
|
2010-11-09 23:37:51 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-09 23:37:51 +03:00
|
|
|
|
2016-06-02 00:29:53 +03:00
|
|
|
if (!this->GenerateForTargetType(ptrIt->second->GetType())) {
|
2010-11-09 23:37:51 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-09 23:37:51 +03: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-05-16 17:34:04 +03:00
|
|
|
if (!str) {
|
2010-11-09 23:37:51 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-09 23:37:51 +03:00
|
|
|
|
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);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->WriteConnections(ptrIt->first, insertedNodes, insertedConnections,
|
|
|
|
str);
|
2010-11-09 23:37:51 +03:00
|
|
|
this->WriteFooter(str);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-09 23:37:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!str) {
|
2010-11-09 23:37:51 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-09 23:37:51 +03:00
|
|
|
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;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<std::string, const cmGeneratorTarget*>::const_iterator ptrIt =
|
|
|
|
this->TargetPtrs.begin();
|
|
|
|
ptrIt != this->TargetPtrs.end(); ++ptrIt) {
|
2016-06-27 23:44:16 +03:00
|
|
|
if (ptrIt->second == CM_NULLPTR) {
|
2010-11-09 23:37:51 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-09 23:37:51 +03:00
|
|
|
|
2016-06-02 00:29:53 +03:00
|
|
|
if (!this->GenerateForTargetType(ptrIt->second->GetType())) {
|
2010-11-09 23:37:51 +03:00
|
|
|
continue;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
|
|
|
|
this->WriteConnections(ptrIt->first, insertedNodes, insertedConnections,
|
|
|
|
str);
|
|
|
|
}
|
2010-11-09 23:37:51 +03:00
|
|
|
this->WriteFooter(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGraphVizWriter::WriteHeader(cmGeneratedFileStream& str) const
|
|
|
|
{
|
2015-12-09 20:15:52 +03:00
|
|
|
str << this->GraphType << " \"" << this->GraphName << "\" {" << std::endl;
|
2010-11-09 23:37:51 +03:00
|
|
|
str << this->GraphHeader << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGraphVizWriter::WriteFooter(cmGeneratedFileStream& str) const
|
|
|
|
{
|
|
|
|
str << "}" << std::endl;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGraphVizWriter::WriteConnections(
|
|
|
|
const std::string& targetName, std::set<std::string>& insertedNodes,
|
|
|
|
std::set<std::string>& insertedConnections, cmGeneratedFileStream& str) const
|
2010-11-09 23:37:51 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::map<std::string, const cmGeneratorTarget*>::const_iterator targetPtrIt =
|
|
|
|
this->TargetPtrs.find(targetName);
|
2010-11-09 23:37:51 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (targetPtrIt == this->TargetPtrs.end()) // not found at all
|
|
|
|
{
|
2010-11-09 23:37:51 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-09 23:37:51 +03:00
|
|
|
|
|
|
|
this->WriteNode(targetName, targetPtrIt->second, insertedNodes, str);
|
|
|
|
|
2016-06-27 23:44:16 +03:00
|
|
|
if (targetPtrIt->second == CM_NULLPTR) // it's an external library
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2010-11-09 23:37:51 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-09 23:37:51 +03:00
|
|
|
|
|
|
|
std::string myNodeName = this->TargetNamesNodes.find(targetName)->second;
|
|
|
|
|
|
|
|
const cmTarget::LinkLibraryVectorType* ll =
|
2016-05-16 17:34:04 +03:00
|
|
|
&(targetPtrIt->second->Target->GetOriginalLinkLibraries());
|
2010-11-09 23:37:51 +03:00
|
|
|
|
|
|
|
for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
llit != ll->end(); ++llit) {
|
2010-11-09 23:37:51 +03:00
|
|
|
const char* libName = llit->first.c_str();
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, std::string>::const_iterator libNameIt =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->TargetNamesNodes.find(libName);
|
2010-11-09 23:37:51 +03:00
|
|
|
|
2011-02-04 22:31:18 +03:00
|
|
|
// can happen e.g. if GRAPHVIZ_TARGET_IGNORE_REGEX is used
|
2016-05-16 17:34:04 +03:00
|
|
|
if (libNameIt == this->TargetNamesNodes.end()) {
|
2011-02-04 22:31:18 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-02-04 22:31:18 +03:00
|
|
|
|
2010-11-09 23:37:51 +03:00
|
|
|
std::string connectionName = myNodeName;
|
|
|
|
connectionName += "-";
|
|
|
|
connectionName += libNameIt->second;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (insertedConnections.find(connectionName) ==
|
|
|
|
insertedConnections.end()) {
|
2010-11-09 23:37:51 +03:00
|
|
|
insertedConnections.insert(connectionName);
|
|
|
|
this->WriteNode(libName, this->TargetPtrs.find(libName)->second,
|
|
|
|
insertedNodes, str);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
str << " \"" << myNodeName << "\" -> \"" << libNameIt->second << "\"";
|
2010-11-09 23:37:51 +03:00
|
|
|
str << " // " << targetName << " -> " << libName << std::endl;
|
|
|
|
this->WriteConnections(libName, insertedNodes, insertedConnections, str);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-09 23:37:51 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGraphVizWriter::WriteDependerConnections(
|
|
|
|
const std::string& targetName, std::set<std::string>& insertedNodes,
|
|
|
|
std::set<std::string>& insertedConnections, cmGeneratedFileStream& str) const
|
2011-02-06 20:34:48 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::map<std::string, const cmGeneratorTarget*>::const_iterator targetPtrIt =
|
|
|
|
this->TargetPtrs.find(targetName);
|
2011-02-06 20:34:48 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (targetPtrIt == this->TargetPtrs.end()) // not found at all
|
|
|
|
{
|
2011-02-06 20:34:48 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-02-06 20:34:48 +03:00
|
|
|
|
|
|
|
this->WriteNode(targetName, targetPtrIt->second, insertedNodes, str);
|
|
|
|
|
2016-06-27 23:44:16 +03:00
|
|
|
if (targetPtrIt->second == CM_NULLPTR) // it's an external library
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2011-02-06 20:34:48 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-02-06 20:34:48 +03:00
|
|
|
|
|
|
|
std::string myNodeName = this->TargetNamesNodes.find(targetName)->second;
|
|
|
|
|
|
|
|
// now search who links against me
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<std::string, const cmGeneratorTarget*>::const_iterator
|
|
|
|
dependerIt = this->TargetPtrs.begin();
|
|
|
|
dependerIt != this->TargetPtrs.end(); ++dependerIt) {
|
2016-06-27 23:44:16 +03:00
|
|
|
if (dependerIt->second == CM_NULLPTR) {
|
2011-02-06 20:34:48 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-02-06 20:34:48 +03:00
|
|
|
|
2016-06-02 00:29:53 +03:00
|
|
|
if (!this->GenerateForTargetType(dependerIt->second->GetType())) {
|
2011-02-06 20:34:48 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-02-06 20:34:48 +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-05-16 17:34:04 +03:00
|
|
|
&(dependerIt->second->Target->GetOriginalLinkLibraries());
|
2011-02-06 20:34:48 +03:00
|
|
|
|
|
|
|
for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
llit != ll->end(); ++llit) {
|
2014-03-11 03:04:11 +04:00
|
|
|
std::string libName = llit->first;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (libName == targetName) {
|
2011-02-06 20:34:48 +03:00
|
|
|
// So this target links against targetName.
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, std::string>::const_iterator dependerNodeNameIt =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->TargetNamesNodes.find(dependerIt->first);
|
2011-02-06 20:34:48 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (dependerNodeNameIt != this->TargetNamesNodes.end()) {
|
2011-02-06 20:34:48 +03:00
|
|
|
std::string connectionName = dependerNodeNameIt->second;
|
|
|
|
connectionName += "-";
|
|
|
|
connectionName += myNodeName;
|
|
|
|
|
|
|
|
if (insertedConnections.find(connectionName) ==
|
2016-05-16 17:34:04 +03:00
|
|
|
insertedConnections.end()) {
|
2011-02-06 20:34:48 +03:00
|
|
|
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 << "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
str << " // " << targetName << " -> " << dependerIt->first
|
|
|
|
<< std::endl;
|
|
|
|
this->WriteDependerConnections(dependerIt->first, insertedNodes,
|
|
|
|
insertedConnections, str);
|
2011-02-06 20:34:48 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
break;
|
2011-02-06 20:34:48 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-02-06 20:34:48 +03:00
|
|
|
}
|
|
|
|
|
2014-02-07 02:31:47 +04:00
|
|
|
void cmGraphVizWriter::WriteNode(const std::string& targetName,
|
2015-10-21 22:49:41 +03:00
|
|
|
const cmGeneratorTarget* target,
|
2010-11-09 23:37:51 +03:00
|
|
|
std::set<std::string>& insertedNodes,
|
|
|
|
cmGeneratedFileStream& str) const
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (insertedNodes.find(targetName) == insertedNodes.end()) {
|
2010-11-09 23:37:51 +03:00
|
|
|
insertedNodes.insert(targetName);
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, std::string>::const_iterator nameIt =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->TargetNamesNodes.find(targetName);
|
2010-11-09 23:37:51 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
str << " \"" << nameIt->second << "\" [ label=\"" << targetName
|
|
|
|
<< "\" shape=\"" << getShapeForTarget(target) << "\"];" << std::endl;
|
2010-11-09 23:37:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-14 21:37:03 +03:00
|
|
|
void cmGraphVizWriter::CollectTargetsAndLibs()
|
|
|
|
{
|
2016-06-02 00:29:53 +03:00
|
|
|
if (!this->HaveTargetsAndLibs) {
|
2010-11-14 21:37:03 +03:00
|
|
|
this->HaveTargetsAndLibs = true;
|
|
|
|
int cnt = this->CollectAllTargets();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->GenerateForExternals) {
|
2011-02-05 20:43:34 +03:00
|
|
|
this->CollectAllExternalLibs(cnt);
|
2010-11-14 21:37:03 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
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 =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->LocalGenerators.begin();
|
|
|
|
lit != this->LocalGenerators.end(); ++lit) {
|
2015-10-21 22:49:41 +03:00
|
|
|
std::vector<cmGeneratorTarget*> targets = (*lit)->GetGeneratorTargets();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmGeneratorTarget*>::const_iterator it = targets.begin();
|
|
|
|
it != targets.end(); ++it) {
|
2015-10-21 22:49:41 +03:00
|
|
|
const char* realTargetName = (*it)->GetName().c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IgnoreThisTarget(realTargetName)) {
|
2010-11-09 23:37:51 +03:00
|
|
|
// Skip ignored targets
|
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-06-07 00:53:32 +03:00
|
|
|
// std::cout << "Found target: " << tit->first << 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();
|
2015-10-21 22:49:41 +03:00
|
|
|
this->TargetPtrs[realTargetName] = *it;
|
2010-11-09 23:37:51 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-09 23:37:51 +03:00
|
|
|
|
|
|
|
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 =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->LocalGenerators.begin();
|
|
|
|
lit != this->LocalGenerators.end(); ++lit) {
|
2015-10-21 22:49:41 +03:00
|
|
|
std::vector<cmGeneratorTarget*> targets = (*lit)->GetGeneratorTargets();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmGeneratorTarget*>::const_iterator it = targets.begin();
|
|
|
|
it != targets.end(); ++it) {
|
2015-10-21 22:49:41 +03:00
|
|
|
const char* realTargetName = (*it)->GetName().c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IgnoreThisTarget(realTargetName)) {
|
2010-11-09 23:37:51 +03:00
|
|
|
// Skip ignored targets
|
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-09 23:37:51 +03:00
|
|
|
const cmTarget::LinkLibraryVectorType* ll =
|
2016-05-16 17:34:04 +03:00
|
|
|
&((*it)->Target->GetOriginalLinkLibraries());
|
2010-11-09 23:37:51 +03:00
|
|
|
for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
llit != ll->end(); ++llit) {
|
2010-11-09 23:37:51 +03:00
|
|
|
const char* libName = llit->first.c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IgnoreThisTarget(libName)) {
|
2010-11-09 23:37:51 +03:00
|
|
|
// Skip ignored targets
|
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-09 23:37:51 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::map<std::string, const cmGeneratorTarget*>::const_iterator tarIt =
|
|
|
|
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();
|
2016-06-27 23:44:16 +03:00
|
|
|
this->TargetPtrs[libName] = CM_NULLPTR;
|
2016-06-07 00:53:32 +03:00
|
|
|
// str << " \"" << ostr << "\" [ label=\"" << libName
|
2013-09-19 21:00:58 +04:00
|
|
|
// << "\" shape=\"ellipse\"];" << std::endl;
|
2010-11-09 23:37:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
return cnt;
|
2010-11-09 23:37:51 +03:00
|
|
|
}
|
|
|
|
|
2014-02-07 02:31:47 +04:00
|
|
|
bool cmGraphVizWriter::IgnoreThisTarget(const std::string& name)
|
2010-11-09 23:37:51 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmsys::RegularExpression>::iterator itvIt =
|
|
|
|
this->TargetsToIgnoreRegex.begin();
|
|
|
|
itvIt != this->TargetsToIgnoreRegex.end(); ++itvIt) {
|
2011-02-05 21:09:54 +03:00
|
|
|
cmsys::RegularExpression& regEx = *itvIt;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (regEx.is_valid()) {
|
|
|
|
if (regEx.find(name)) {
|
2011-02-05 21:09:54 +03:00
|
|
|
return true;
|
2010-11-14 21:47:28 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +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
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmGraphVizWriter::GenerateForTargetType(
|
|
|
|
cmState::TargetType targetType) const
|
2010-11-14 21:30:58 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
switch (targetType) {
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::EXECUTABLE:
|
2010-11-14 21:30:58 +03:00
|
|
|
return this->GenerateForExecutables;
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::STATIC_LIBRARY:
|
2010-11-14 21:30:58 +03:00
|
|
|
return this->GenerateForStaticLibs;
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::SHARED_LIBRARY:
|
2010-11-14 21:30:58 +03:00
|
|
|
return this->GenerateForSharedLibs;
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::MODULE_LIBRARY:
|
2010-11-14 21:30:58 +03:00
|
|
|
return this->GenerateForModuleLibs;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|