ctkMacroGenerateDGraphInput.cmake 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #
  2. # Generate a DGrapgh input file expected by DGraph executable.
  3. #
  4. MACRO(ctkMacroGenerateDGraphInput dir target_directories with_option)
  5. IF(NOT EXISTS ${dir})
  6. MESSAGE(FATAL_ERROR "Directory ${dir} doesn't exist!")
  7. ENDIF()
  8. SET(dgraph_list )
  9. SET(edges)
  10. SET(vertices)
  11. FOREACH(target_info ${target_directories})
  12. # extract target_dir and option_name
  13. STRING(REPLACE "^^" "\\;" target_info ${target_info})
  14. SET(target_info_list ${target_info})
  15. LIST(GET target_info_list 0 target_dir)
  16. LIST(GET target_info_list 1 option_name)
  17. #MESSAGE(STATUS target_dir:${target_dir})
  18. #MESSAGE(STATUS option_name:${option_name})
  19. #MESSAGE(STATUS option_name-value:${${option_name}})
  20. # make sure the directory exists
  21. IF(NOT EXISTS ${target_dir}/CMakeLists.txt)
  22. MESSAGE(FATAL_ERROR "Target directory ${target_dir}/CMakeLists.txt doesn't exists !")
  23. ENDIF()
  24. SET(include_dep 1)
  25. IF(${with_option})
  26. SET(include_dep ${${option_name}})
  27. ENDIF()
  28. IF(${include_dep})
  29. # extract project name from CMakeLists.txt
  30. FILE(STRINGS "${target_dir}/CMakeLists.txt" project_string
  31. REGEX "^ *(P|p)(R|r)(O|o)(J|j)(E|e)(C|c)(T|t)\\("
  32. LIMIT_COUNT 10)
  33. STRING(REGEX MATCH "\\((.*)\\)" target_project_name ${project_string})
  34. STRING(REGEX REPLACE "\\(|\\)" "" target_project_name ${target_project_name})
  35. IF(${target_project_name} STREQUAL "")
  36. MESSAGE(FATAL_ERROR "Failed to extract project name from ${target_dir}/CMakeLists.txt")
  37. ENDIF()
  38. #MESSAGE(STATUS target_project_name:${target_project_name})
  39. LIST(APPEND vertices ${target_project_name})
  40. # Make sure the variable is cleared
  41. SET(dependencies )
  42. # get dependencies
  43. ctkMacroCollectTargetLibraryNames(${target_dir} dependencies)
  44. # Make sure the variable is cleared
  45. SET(ctk_dependencies)
  46. # filter dependencies starting with CTK
  47. ctkMacroGetAllCTKTargetLibraries("${dependencies}" ctk_dependencies)
  48. # Generate XML related to the dependencies
  49. FOREACH(dependency_name ${ctk_dependencies})
  50. LIST(APPEND edges ${dependency_name})
  51. SET(dgraph_list ${dgraph_list} "${target_project_name} ${dependency_name}\n")
  52. ENDFOREACH()
  53. ENDIF()
  54. ENDFOREACH()
  55. LIST(LENGTH vertices numberOfVertices)
  56. LIST(LENGTH edges numberOfEdges)
  57. SET(dgraph_list "${numberOfVertices} ${numberOfEdges}\n" ${dgraph_list})
  58. IF(${with_option})
  59. SET(filename "${dir}/DGraphInput.txt")
  60. ELSE()
  61. SET(filename "${dir}/DGraphInput-alldep.txt")
  62. ENDIF()
  63. FILE(WRITE ${filename} ${dgraph_list})
  64. MESSAGE(STATUS "Generated: ${filename}")
  65. ENDMACRO()