ctkFunctionGenerateProjectXml.cmake 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.apache.org/licenses/LICENSE-2.0.txt
  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. #! \ingroup CMakeUtilities
  24. function(ctkFunctionGenerateProjectXml dir name target_directories is_superbuild)
  25. if(NOT EXISTS ${dir})
  26. message(FATAL_ERROR "Directory ${dir} doesn't exist!")
  27. endif()
  28. set(xml_subprojects )
  29. if(${is_superbuild})
  30. set(xml_subprojects ${xml_subprojects} " <SubProject name=\"SuperBuild\">\n")
  31. endif()
  32. set(subproject_list)
  33. foreach(target_info ${target_directories})
  34. # extract target_dir and option_name
  35. string(REPLACE "^^" "\\;" target_info ${target_info})
  36. set(target_info_list ${target_info})
  37. list(GET target_info_list 0 target_dir)
  38. list(GET target_info_list 1 option_name)
  39. #message(STATUS target_dir:${target_dir})
  40. #message(STATUS option_name:${option_name})
  41. # make sure the directory exists
  42. if(NOT EXISTS ${target_dir}/CMakeLists.txt)
  43. message(FATAL_ERROR "Target directory ${target_dir}/CMakeLists.txt doesn't exists !")
  44. endif()
  45. # Remarks: Project.xml should contains all sub-project. That way
  46. # all dashboards should submit a similar file.
  47. #if(${${option_name}})
  48. # extract project name from CMakeLists.txt
  49. file(STRINGS "${target_dir}/CMakeLists.txt" project_string
  50. REGEX "^ *(P|p)(R|r)(O|o)(J|j)(E|e)(C|c)(T|t)\\("
  51. LIMIT_COUNT 10)
  52. string(REGEX MATCH "\\((.*)\\)" target_project_name ${project_string})
  53. string(REGEX REPLACE "\\(|\\)" "" target_project_name ${target_project_name})
  54. if(${target_project_name} STREQUAL "")
  55. message(FATAL_ERROR "Failed to extract project name from ${target_dir}/CMakeLists.txt")
  56. endif()
  57. #message(STATUS target_project_name:${target_project_name})
  58. set(xml_subprojects ${xml_subprojects} " <SubProject name=\"${target_project_name}\">\n")
  59. list(APPEND subproject_list ${target_project_name})
  60. # Make sure the variable is cleared
  61. set(dependencies )
  62. # get dependencies
  63. ctkFunctionCollectTargetLibraryNames(${target_dir} dependencies)
  64. # Make sure the variable is cleared
  65. set(ctk_dependencies)
  66. # filter dependencies starting with CTK
  67. ctkMacroGetAllProjectTargetLibraries("${dependencies}" ctk_dependencies)
  68. if(${is_superbuild})
  69. set(xml_subprojects ${xml_subprojects} " <Dependency name=\"SuperBuild\"/>\n")
  70. endif()
  71. # Generate XML related to the dependencies
  72. foreach(dependency_name ${ctk_dependencies})
  73. set(xml_subprojects ${xml_subprojects} " <Dependency name=\"${dependency_name}\"/>\n")
  74. endforeach()
  75. set(xml_subprojects ${xml_subprojects} " </SubProject>\n")
  76. #endif()
  77. endforeach()
  78. set(xml_subprojects ${xml_subprojects} " <SubProject name=\"Documentation\">\n")
  79. foreach(subproject ${subproject_list})
  80. set(xml_subprojects ${xml_subprojects} " <Dependency name=\"${subproject}\"/>\n")
  81. endforeach()
  82. set(xml_subprojects ${xml_subprojects} " </SubProject>\n")
  83. set(xml_content "<Project name=\"${name}\">\n${xml_subprojects}</Project>")
  84. set(filename "${dir}/Project.xml")
  85. file(WRITE ${filename} ${xml_content})
  86. message(STATUS "Generated: ${filename}")
  87. endfunction()