ctkMacroGenerateDGraphInput.cmake 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #
  2. #
  3. #
  4. MACRO(ctkMacroGenerateDGraphInput dir name target_directories)
  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. # make sure the directory exists
  20. IF(NOT EXISTS ${target_dir}/CMakeLists.txt)
  21. MESSAGE(FATAL_ERROR "Target directory ${target_dir}/CMakeLists.txt doesn't exists !")
  22. ENDIF()
  23. # extract project name from CMakeLists.txt
  24. FILE(STRINGS "${target_dir}/CMakeLists.txt" project_string
  25. REGEX "^ *(P|p)(R|r)(O|o)(J|j)(E|e)(C|c)(T|t)\\("
  26. LIMIT_COUNT 10)
  27. STRING(REGEX MATCH "\\((.*)\\)" target_project_name ${project_string})
  28. STRING(REGEX REPLACE "\\(|\\)" "" target_project_name ${target_project_name})
  29. IF(${target_project_name} STREQUAL "")
  30. MESSAGE(FATAL_ERROR "Failed to extract project name from ${target_dir}/CMakeLists.txt")
  31. ENDIF()
  32. #MESSAGE(STATUS target_project_name:${target_project_name})
  33. LIST(APPEND vertices ${target_project_name})
  34. # Make sure the variable is cleared
  35. SET(dependencies )
  36. # get dependencies
  37. ctkMacroCollectTargetLibraryNames(${target_dir} ${option_name} dependencies)
  38. # Make sure the variable is cleared
  39. SET(ctk_dependencies)
  40. # filter dependencies starting with CTK
  41. ctkMacroGetAllCTKTargetLibraries("${dependencies}" ctk_dependencies)
  42. # Generate XML related to the dependencies
  43. FOREACH(dependency_name ${ctk_dependencies})
  44. LIST(APPEND edges ${dependency_name})
  45. SET(dgraph_list ${dgraph_list} "${target_project_name} ${dependency_name}\n")
  46. ENDFOREACH()
  47. ENDFOREACH()
  48. LIST(LENGTH vertices numberOfVertices)
  49. LIST(LENGTH edges numberOfEdges)
  50. SET(dgraph_list "${numberOfVertices} ${numberOfEdges}\n" ${dgraph_list})
  51. SET(filename "${dir}/DGraphInput.txt")
  52. FILE(WRITE ${filename} ${dgraph_list})
  53. MESSAGE(STATUS "Generated: ${filename}")
  54. ENDMACRO()