ctkMacroGenerateDGraphInput.cmake 2.3 KB

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