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