depgraph.cmake 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Component dependency graph generation helpers.
  2. # To enable this functionality, add:
  3. # idf_build_set_property(__BUILD_COMPONENT_DEPGRAPH_ENABLED 1)
  4. # in the project CMakeLists.txt file between include(project.cmake) and project(name) calls.
  5. #
  6. # Graphviz file component_deps.dot will be produced in the build directory.
  7. # To change the template, see component_deps.dot.in.
  8. # depgraph_add_edge
  9. #
  10. # @brief Record an edge in the component dependency graph (dependent -> dependency)
  11. #
  12. # @param[in] dep_from dependent name
  13. # @param[in] dep_to dependency name
  14. # @param[in, optional] REQUIRES if given, record this as "REQUIRES" (public/interface) dependency
  15. # @param[in, optional] PRIV_REQUIRES if given, record this as "PRIV_REQUIRES" (private) dependency
  16. #
  17. function(depgraph_add_edge dep_from dep_to)
  18. cmake_parse_arguments(_ "REQUIRES;PRIV_REQUIRES" "" "" ${ARGN})
  19. idf_build_get_property(depgraph_enabled __BUILD_COMPONENT_DEPGRAPH_ENABLED)
  20. if(NOT depgraph_enabled)
  21. return()
  22. endif()
  23. idf_build_get_property(common_reqs __COMPONENT_REQUIRES_COMMON)
  24. set(attr)
  25. if(__REQUIRES)
  26. set(attr "[class=\"requires\"]")
  27. elseif(__PRIV_REQUIRES)
  28. set(attr "[class=\"priv_requires\" style=\"dotted\"]")
  29. endif()
  30. if(dep_to IN_LIST common_reqs)
  31. # Don't record graph edges leading to "common" components, since every component has these dependencies.
  32. # However, show which components are "common" by adding an edge from a node named "common".
  33. # If necessary, add a new build property to customize this behavior.
  34. if(NOT dep_from IN_LIST common_reqs)
  35. idf_build_set_property(__BUILD_COMPONENT_DEPGRAPH "common -> ${dep_to}" APPEND)
  36. endif()
  37. else()
  38. idf_build_set_property(__BUILD_COMPONENT_DEPGRAPH "${dep_from} -> ${dep_to} ${attr}" APPEND)
  39. endif()
  40. endfunction()
  41. # depgraph_generate
  42. #
  43. # @brief Write the collected component dependency graph to a file. The file is in Graphviz (.dot) format.
  44. #
  45. # @param[in] out_path name of the output file
  46. #
  47. function(depgraph_generate out_path)
  48. idf_build_get_property(depgraph_enabled __BUILD_COMPONENT_DEPGRAPH_ENABLED)
  49. if(NOT depgraph_enabled)
  50. return()
  51. endif()
  52. idf_build_get_property(depgraph __BUILD_COMPONENT_DEPGRAPH)
  53. list(REMOVE_DUPLICATES depgraph)
  54. string(REPLACE ";" ";\n" depgraph "${depgraph}")
  55. configure_file("${IDF_PATH}/tools/cmake/component_deps.dot.in"
  56. "${out_path}")
  57. endfunction()