diff --git a/cmake/DuneUtils.cmake b/cmake/DuneUtils.cmake
index da3b28a1883e45feed4083d9225049a9211ca4f3..7a93cf31854246754cd078056d5e319655bce89a 100644
--- a/cmake/DuneUtils.cmake
+++ b/cmake/DuneUtils.cmake
@@ -59,7 +59,7 @@ MACRO( DEPENDENCYCHECK )
         SET( TEST_NAME "dependenycheck_${fn}")
         TO_LIST_SPACES( MY_CXX_FLAGS TEST_NAME_FLAGS )
         SET(XARGS ${TEST_NAME_FLAGS} -DHAVE_CONFIG_H -H -c ${HEADER} -w)
-        ADD_CUSTOM_TARGET( ${TEST_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/../dune-stuff/cmake/dependencyinfo.py ${CMAKE_CXX_COMPILER} ${XARGS} ${CMAKE_CURRENT_SOURCE_DIR} ${fn}.dep)
+        ADD_CUSTOM_TARGET( ${TEST_NAME} + ${CMAKE_CURRENT_SOURCE_DIR}/../dune-stuff/cmake/dependencyinfo.py ${CMAKE_CXX_COMPILER} ${XARGS} ${CMAKE_CURRENT_SOURCE_DIR} ${fn}.dep)
         add_dependencies( dependenycheck ${TEST_NAME} )
     ENDFOREACH( HEADER )
 ENDMACRO( DEPENDENCYCHECK )
diff --git a/cmake/dependencyinfo.py b/cmake/dependencyinfo.py
index 8ffaa962a26dfb9caa61da9b2f42425881fa4c8a..95e44d0cf5d32af7343a4c76f0e871db6ab98d77 100755
--- a/cmake/dependencyinfo.py
+++ b/cmake/dependencyinfo.py
@@ -8,14 +8,18 @@ from pygraph.algorithms.cycles import find_cycle
 
 fn = sys.argv[-1]
 strip_base = sys.argv[-2]
+compiler_cmd = sys.argv[1:-3]
+
 with open(fn,'wb') as out:
-    p = subprocess.Popen(sys.argv[1:-3], shell=False, stdout=out, stderr=out)
+    p = subprocess.Popen(compiler_cmd, shell=False, stdout=out, stderr=out)
     errcode = p.wait()
-print('STRIP %s'%strip_base)
-graph = sourcetree.parse_file(strip_base, fn)
+    if errcode != 0:
+        sys.exit(errcode)
+
+(root,graph) = sourcetree.parse_file(strip_base, fn, maxdepth=100)
 cycle_nodes = find_cycle(graph)
 if cycle_nodes:
     with open(fn+'.cycles','wb') as out:
-       pp = pprint.PrettyPrinter()
-       pp.pprint(cycle_nodes, out)
+       pprint.pprint(cycle_nodes, out)
 
+sourcetree.render_graph(sourcetree.parse_file(strip_base, fn, maxdepth=3))
diff --git a/cmake/sourcetree.py b/cmake/sourcetree.py
index c23c634f9042c03e7161189d5d18f090f3b53908..09ab2f6702b3fb662e42a34278b18748bd93f90b 100644
--- a/cmake/sourcetree.py
+++ b/cmake/sourcetree.py
@@ -3,20 +3,23 @@
 import pygraph
 from pygraph.classes.graph import graph
 from pygraph.readwrite.dot import write
+from pygraph.algorithms.searching import breadth_first_search
+from pygraph.classes.digraph import digraph
 import pygraphviz as gv
 from itertools import takewhile
 
 is_dot = '.'.__eq__
 
-        
 class Node(object):
-    def __init__(self, title, graph, **attrs):
+    def __init__(self, title, graph, attrs=[]):
         self.title = title
         self.parent = None
         self.children = []
         self.graph = graph
         try:
             graph.add_node(title,attrs)
+        #gets triggered on adding an already existing node
+        #which we can ignore
         except pygraph.classes.exceptions.AdditionError:
             pass
 
@@ -51,22 +54,26 @@ class Inserter(object):
         self.node = newNode
         
 def parse_file(strip_base, outfile, maxdepth=3):
-    root = outfile[:-len('.dep')].replace(strip_base, '')
+    root = outfile[:-len('.dep')].replace(strip_base, '').strip()
     gr = graph()
-    tree = Node('ROOT__' + root, gr, color='red')
+    tree = Node(root, gr, [('color','red')])
     inserter = Inserter(tree,0)
     with open(outfile, 'rb') as gcc_out:
         for line in gcc_out:
             dots = len(list(takewhile(is_dot, line)))
-            if dots < 1 or dots > 3:
+            if dots < 1 or dots > maxdepth:
                 continue
-            fn = line[dots+1:].replace(strip_base, '')
-            #fn
-            print fn
+            fn = line[dots+1:].replace(strip_base, '').strip()
             inserter(fn, dots, gr)
-    dot = write(gr)
+    return (root, gr)
+
+def render_graph((root, gr)):
+    st, order = breadth_first_search(gr, root=root)
+    gst = digraph()
+    gst.add_spanning_tree(st)
+    dot = write(gst)
     G = gv.AGraph(dot, strict=False,directed=True)
     prog = 'dot'
     G.layout(prog=prog)
-    G.draw('%s.png'%outfile, prog=prog)
+    G.draw('include_graph_%s.png'%root, prog=prog)
     return gr
\ No newline at end of file