From 5b46cc91d93fe52be614e75e9a08a00f121e8aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20M=C3=BCller?= Date: Mon, 18 Sep 2017 19:22:59 +0200 Subject: graphviz: distinguish target dependency types - The output graph of graphviz differs now between target link types - Updated documentation - Fixes: #17192 --- Help/release/dev/graphviz-line-styles.rst | 6 ++ Modules/CMakeGraphVizOptions.cmake | 3 + Source/cmGraphVizWriter.cxx | 103 ++++++++++++++++++++++++++++-- 3 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 Help/release/dev/graphviz-line-styles.rst diff --git a/Help/release/dev/graphviz-line-styles.rst b/Help/release/dev/graphviz-line-styles.rst new file mode 100644 index 0000000..d24f236 --- /dev/null +++ b/Help/release/dev/graphviz-line-styles.rst @@ -0,0 +1,6 @@ +graphviz-line-styles +------------------------- + +* The graphviz output now distinguishes between the different dependency types + ``PUBLIC``, ``PRIVATE`` and ``INTERFACE`` and represents them in the output graph + as solid, dashed and dotted edges. diff --git a/Modules/CMakeGraphVizOptions.cmake b/Modules/CMakeGraphVizOptions.cmake index 3976581..0d7f1d9 100644 --- a/Modules/CMakeGraphVizOptions.cmake +++ b/Modules/CMakeGraphVizOptions.cmake @@ -20,6 +20,9 @@ # * a ``foo.dot.`` file for each target, file showing on which other targets the respective target depends # * a ``foo.dot..dependers`` file, showing which other targets depend on the respective target # +# The different dependency types ``PUBLIC``, ``PRIVATE`` and ``INTERFACE`` +# are represented as solid, dashed and dotted edges. +# # This can result in huge graphs. Using the file # ``CMakeGraphVizOptions.cmake`` the look and content of the generated # graphs can be influenced. This file is searched first in diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx index 967fd2e..ca87cbf 100644 --- a/Source/cmGraphVizWriter.cxx +++ b/Source/cmGraphVizWriter.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmGraphVizWriter.h" +#include #include #include #include @@ -17,7 +18,18 @@ #include "cm_auto_ptr.hxx" #include "cmake.h" -static const char* getShapeForTarget(const cmGeneratorTarget* target) +namespace { +enum LinkLibraryScopeType +{ + LLT_SCOPE_PUBLIC, + LLT_SCOPE_PRIVATE, + LLT_SCOPE_INTERFACE +}; + +const char* const GRAPHVIZ_PRIVATE_EDEGE_STYLE = "dashed"; +const char* const GRAPHVIZ_INTERFACE_EDEGE_STYLE = "dotted"; + +const char* getShapeForTarget(const cmGeneratorTarget* target) { if (!target) { return "ellipse"; @@ -39,6 +51,76 @@ static const char* getShapeForTarget(const cmGeneratorTarget* target) return "box"; } +std::map getScopedLinkLibrariesFromTarget( + cmTarget* Target) +{ + char sep = ';'; + std::map tokens; + size_t start = 0, end = 0; + + const char* pInterfaceLinkLibraries = + Target->GetProperty("INTERFACE_LINK_LIBRARIES"); + const char* pLinkLibraries = Target->GetProperty("LINK_LIBRARIES"); + + if (!pInterfaceLinkLibraries && !pLinkLibraries) { + return tokens; // target is not linked against any other libraries + } + + // make sure we don't touch a null-ptr + auto interfaceLinkLibraries = + std::string(pInterfaceLinkLibraries ? pInterfaceLinkLibraries : ""); + auto linkLibraries = std::string(pLinkLibraries ? pLinkLibraries : ""); + + // first extract interfaceLinkLibraries + while (start < interfaceLinkLibraries.length()) { + + if ((end = interfaceLinkLibraries.find(sep, start)) == std::string::npos) { + end = interfaceLinkLibraries.length(); + } + + std::string element = interfaceLinkLibraries.substr(start, end - start); + if (std::string::npos == element.find("$& localGenerators) : GraphType("digraph") @@ -273,11 +355,10 @@ void cmGraphVizWriter::WriteConnections( } std::string myNodeName = this->TargetNamesNodes.find(targetName)->second; + std::map ll = + getScopedLinkLibrariesFromTarget(targetPtrIt->second->Target); - const cmTarget::LinkLibraryVectorType* ll = - &(targetPtrIt->second->Target->GetOriginalLinkLibraries()); - - for (auto const& llit : *ll) { + for (auto const& llit : ll) { const char* libName = llit.first.c_str(); std::map::const_iterator libNameIt = this->TargetNamesNodes.find(libName); @@ -297,6 +378,18 @@ void cmGraphVizWriter::WriteConnections( insertedNodes, str); str << " \"" << myNodeName << "\" -> \"" << libNameIt->second << "\""; + + switch (llit.second) { + case LLT_SCOPE_PRIVATE: + str << "[style = " << GRAPHVIZ_PRIVATE_EDEGE_STYLE << "]"; + break; + case LLT_SCOPE_INTERFACE: + str << "[style = " << GRAPHVIZ_INTERFACE_EDEGE_STYLE << "]"; + break; + default: + break; + } + str << " // " << targetName << " -> " << libName << std::endl; this->WriteConnections(libName, insertedNodes, insertedConnections, str); } -- cgit v0.12