ctkFunctionGenerateProjectXml.cmake 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. ###########################################################################
  2. #
  3. # Library: CTK
  4. #
  5. # Copyright (c) Kitware Inc.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.commontk.org/LICENSE
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. ###########################################################################
  20. #
  21. #
  22. #
  23. FUNCTION(ctkFunctionGenerateProjectXml dir name target_directories is_superbuild)
  24. IF(NOT EXISTS ${dir})
  25. MESSAGE(FATAL_ERROR "Directory ${dir} doesn't exist!")
  26. ENDIF()
  27. SET(xml_subprojects )
  28. IF(${is_superbuild})
  29. SET(xml_subprojects ${xml_subprojects} " <SubProject name=\"SuperBuild\">\n")
  30. ENDIF()
  31. SET(subproject_list)
  32. FOREACH(target_info ${target_directories})
  33. # extract target_dir and option_name
  34. STRING(REPLACE "^^" "\\;" target_info ${target_info})
  35. SET(target_info_list ${target_info})
  36. LIST(GET target_info_list 0 target_dir)
  37. LIST(GET target_info_list 1 option_name)
  38. #MESSAGE(STATUS target_dir:${target_dir})
  39. #MESSAGE(STATUS option_name:${option_name})
  40. # make sure the directory exists
  41. IF(NOT EXISTS ${target_dir}/CMakeLists.txt)
  42. MESSAGE(FATAL_ERROR "Target directory ${target_dir}/CMakeLists.txt doesn't exists !")
  43. ENDIF()
  44. # Remarks: Project.xml should contains all sub-project. That way
  45. # all dashboards should submit a similar file.
  46. #IF(${${option_name}})
  47. # extract project name from CMakeLists.txt
  48. FILE(STRINGS "${target_dir}/CMakeLists.txt" project_string
  49. REGEX "^ *(P|p)(R|r)(O|o)(J|j)(E|e)(C|c)(T|t)\\("
  50. LIMIT_COUNT 10)
  51. STRING(REGEX MATCH "\\((.*)\\)" target_project_name ${project_string})
  52. STRING(REGEX REPLACE "\\(|\\)" "" target_project_name ${target_project_name})
  53. IF(${target_project_name} STREQUAL "")
  54. MESSAGE(FATAL_ERROR "Failed to extract project name from ${target_dir}/CMakeLists.txt")
  55. ENDIF()
  56. #MESSAGE(STATUS target_project_name:${target_project_name})
  57. SET(xml_subprojects ${xml_subprojects} " <SubProject name=\"${target_project_name}\">\n")
  58. LIST(APPEND subproject_list ${target_project_name})
  59. # Make sure the variable is cleared
  60. SET(dependencies )
  61. # get dependencies
  62. ctkFunctionCollectTargetLibraryNames(${target_dir} dependencies)
  63. # Make sure the variable is cleared
  64. SET(ctk_dependencies)
  65. # filter dependencies starting with CTK
  66. ctkMacroGetAllCTKTargetLibraries("${dependencies}" ctk_dependencies)
  67. IF(${is_superbuild})
  68. SET(xml_subprojects ${xml_subprojects} " <Dependency name=\"SuperBuild\"/>\n")
  69. ENDIF()
  70. # Generate XML related to the dependencies
  71. FOREACH(dependency_name ${ctk_dependencies})
  72. SET(xml_subprojects ${xml_subprojects} " <Dependency name=\"${dependency_name}\"/>\n")
  73. ENDFOREACH()
  74. SET(xml_subprojects ${xml_subprojects} " </SubProject>\n")
  75. #ENDIF()
  76. ENDFOREACH()
  77. SET(xml_subprojects ${xml_subprojects} " <SubProject name=\"Documentation\">\n")
  78. FOREACH(subproject ${subproject_list})
  79. SET(xml_subprojects ${xml_subprojects} " <Dependency name=\"${subproject}\"/>\n")
  80. ENDFOREACH()
  81. SET(xml_subprojects ${xml_subprojects} " </SubProject>\n")
  82. SET(xml_content "<Project name=\"${name}\">\n${xml_subprojects}</Project>")
  83. SET(filename "${dir}/Project.xml")
  84. FILE(WRITE ${filename} ${xml_content})
  85. MESSAGE(STATUS "Generated: ${filename}")
  86. ENDFUNCTION()