Browse Source

Generate a picture of module dependencies at configure time

pull/2/head
Paul Licameli 2 years ago
committed by Leland Lucius
parent
commit
5844b2090a
  1. 12
      CMakeLists.txt
  2. 43
      cmake-proxies/cmake-modules/AudacityFunctions.cmake
  3. 2
      modules/CMakeLists.txt
  4. 12
      src/CMakeLists.txt

12
CMakeLists.txt

@ -444,6 +444,18 @@ else()
configure_file( src/audacity_config.h.in src/private/configunix.h )
endif()
# Generate a picture of module dependencies
string( JOIN "\n" GRAPH_EDGES ${GRAPH_EDGES} )
# Choose edge attributes making it easy to hover at either end of edge
# and see a tooltip describing the edge, in svg image
file( WRITE "${CMAKE_CURRENT_BINARY_DIR}/modules.dot" "digraph {
graph [rankdir=LR] edge [dir=both,arrowtail=inv] \n"
"${GRAPH_EDGES}"
"\n}\n"
)
execute_process( COMMAND
dot -O -Tsvg "${CMAKE_CURRENT_BINARY_DIR}/modules.dot" )
# Uncomment what follows for symbol values.
#[[
get_cmake_property( _variableNames VARIABLES )

43
cmake-proxies/cmake-modules/AudacityFunctions.cmake

@ -221,13 +221,7 @@ function( audacity_append_common_compiler_options var )
set( ${var} "${${var}}" PARENT_SCOPE )
endfunction()
# Set up for defining a module target.
# Pass a name and sources, and a list of other targets.
# Use the interface compile definitions and include directories of the
# other targets, and link to them.
# More defines, and more target libraries (maybe generator expressions)
# may be given too.
function( audacity_module NAME SOURCES IMPORT_TARGETS
function( audacity_module_fn NAME SOURCES IMPORT_TARGETS
ADDITIONAL_DEFINES ADDITIONAL_LIBRARIES )
set( TARGET ${NAME} )
@ -294,5 +288,40 @@ function( audacity_module NAME SOURCES IMPORT_TARGETS
endif()
endforeach()
endif()
# collect dependency information
list( APPEND GRAPH_EDGES "\"${TARGET}\" [shape=box]" )
set(ACCESS PUBLIC PRIVATE INTERFACE)
foreach( IMPORT ${IMPORT_TARGETS} )
if(IMPORT IN_LIST ACCESS)
continue()
endif()
string( REGEX REPLACE "-interface\$" "" IMPORT "${IMPORT}" )
list( APPEND GRAPH_EDGES "\"${TARGET}\" -> \"${IMPORT}\"" )
endforeach()
set( GRAPH_EDGES "${GRAPH_EDGES}" PARENT_SCOPE )
endfunction()
# Set up for defining a module target.
# All modules depend on the application.
# Pass a name and sources, and a list of other targets.
# Use the interface compile definitions and include directories of the
# other targets, and link to them.
# More defines, and more target libraries (maybe generator expressions)
# may be given too.
macro( audacity_module NAME SOURCES IMPORT_TARGETS
ADDITIONAL_DEFINES ADDITIONAL_LIBRARIES )
# The extra indirection of a function call from this macro, and
# re-assignment of GRAPH_EDGES, is so that a module definition may
# call this macro, and it will (correctly) collect edges for the
# CMakeLists.txt in the directory above it; but otherwise we take
# advantage of function scoping of variables.
audacity_module_fn(
"${NAME}"
"${SOURCES}"
"${IMPORT_TARGETS}"
"${ADDITIONAL_DEFINES}"
"${ADDITIONAL_LIBRARIES}"
)
set( GRAPH_EDGES "${GRAPH_EDGES}" PARENT_SCOPE )
endmacro()

2
modules/CMakeLists.txt

@ -15,3 +15,5 @@ if( NOT CMAKE_SYSTEM_NAME MATCHES "Darwin" )
endif()
endif()
#propagate collected edges up to root CMakeLists.txt
set( GRAPH_EDGES "${GRAPH_EDGES}" PARENT_SCOPE )

12
src/CMakeLists.txt

@ -1340,3 +1340,15 @@ if( NOT "${CMAKE_GENERATOR}" MATCHES "Xcode|Visual Studio*" )
endif()
endif()
# collect dependency information for third party libraries
list( APPEND GRAPH_EDGES "Audacity [shape=house]" )
foreach( LIBRARY ${LIBRARIES} )
if (NOT LIBRARY MATCHES "PUBLIC|PRIVATE|INTERFACE")
string( REGEX REPLACE ".*>.*:(.*)>" "\\1" LIBRARY "${LIBRARY}" )
string( REGEX REPLACE "^-(l|framework )" "" LIBRARY "${LIBRARY}" )
list( APPEND GRAPH_EDGES "\"${TARGET}\" -> \"${LIBRARY}\"" )
endif()
endforeach()
#propagate collected edgets to root CMakeLists.txt
set( GRAPH_EDGES "${GRAPH_EDGES}" PARENT_SCOPE )
Loading…
Cancel
Save