ctkMacroCheckExternalProjectDependency.cmake 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. if(NOT EXISTS "${EXTERNAL_PROJECT_DIR}")
  21. set(EXTERNAL_PROJECT_DIR ${${CMAKE_PROJECT_NAME}_SOURCE_DIR}/SuperBuild)
  22. endif()
  23. if(NOT DEFINED EXTERNAL_PROJECT_FILE_PREFIX)
  24. set(EXTERNAL_PROJECT_FILE_PREFIX "External_")
  25. endif()
  26. macro(ctk_include_once)
  27. # Make sure this file is included only once
  28. get_filename_component(CMAKE_CURRENT_LIST_FILENAME ${CMAKE_CURRENT_LIST_FILE} NAME_WE)
  29. if(${CMAKE_CURRENT_LIST_FILENAME}_FILE_INCLUDED)
  30. return()
  31. endif()
  32. set(${CMAKE_CURRENT_LIST_FILENAME}_FILE_INCLUDED 1)
  33. endmacro()
  34. macro(_epd_status txt)
  35. if(NOT __epd_first_pass)
  36. message(STATUS ${txt})
  37. endif()
  38. endmacro()
  39. macro(ctkMacroCheckExternalProjectDependency proj)
  40. # Set indent variable if needed
  41. if(NOT DEFINED __indent)
  42. set(__indent "")
  43. else()
  44. set(__indent "${__indent} ")
  45. endif()
  46. # Sanity checks
  47. if(NOT DEFINED ${proj}_DEPENDENCIES)
  48. message(FATAL_ERROR "${__indent}${proj}_DEPENDENCIES variable is NOT defined !")
  49. endif()
  50. # Keep track of the projects
  51. list(APPEND __epd_${CMAKE_PROJECT_NAME}_projects ${proj})
  52. # Is this the first run ? (used to set the <CMAKE_PROJECT_NAME>_USE_SYSTEM_* variables)
  53. if(${proj} STREQUAL ${CMAKE_PROJECT_NAME} AND NOT DEFINED __epd_first_pass)
  54. message(STATUS "SuperBuild - First pass")
  55. set(__epd_first_pass TRUE)
  56. endif()
  57. # Set message strings
  58. set(__${proj}_indent ${__indent})
  59. set(__${proj}_superbuild_message "SuperBuild - ${__indent}${proj}[OK]")
  60. if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
  61. set(__${proj}_superbuild_message "${__${proj}_superbuild_message} (SYSTEM)")
  62. endif()
  63. # Display dependency of project being processed
  64. if("${${proj}_DEPENDENCIES}" STREQUAL "")
  65. _epd_status(${__${proj}_superbuild_message})
  66. else()
  67. set(dependency_str " ")
  68. foreach(dep ${${proj}_DEPENDENCIES})
  69. if(${EXTERNAL_PROJECT_FILE_PREFIX}${dep}_FILE_INCLUDED)
  70. set(dependency_str "${dependency_str}${dep}[INCLUDED], ")
  71. else()
  72. set(dependency_str "${dependency_str}${dep}, ")
  73. endif()
  74. endforeach()
  75. _epd_status("SuperBuild - ${__indent}${proj} => Requires${dependency_str}")
  76. endif()
  77. foreach(dep ${${proj}_DEPENDENCIES})
  78. if(${${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj}})
  79. set(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${dep} ${${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj}})
  80. endif()
  81. #if(__epd_first_pass)
  82. # message("${CMAKE_PROJECT_NAME}_USE_SYSTEM_${dep} set to [${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj}:${${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj}}]")
  83. #endif()
  84. endforeach()
  85. # Include dependencies
  86. foreach(dep ${${proj}_DEPENDENCIES})
  87. if(NOT External_${dep}_FILE_INCLUDED)
  88. # XXX - Refactor - Add a single variable named 'EXTERNAL_PROJECT_DIRS'
  89. if(EXISTS "${EXTERNAL_PROJECT_DIR}/${EXTERNAL_PROJECT_FILE_PREFIX}${dep}.cmake")
  90. include(${EXTERNAL_PROJECT_DIR}/${EXTERNAL_PROJECT_FILE_PREFIX}${dep}.cmake)
  91. elseif(EXISTS "${${dep}_FILEPATH}")
  92. include(${${dep}_FILEPATH})
  93. elseif(EXISTS "${EXTERNAL_PROJECT_ADDITIONAL_DIR}/${EXTERNAL_PROJECT_FILE_PREFIX}${dep}.cmake")
  94. include(${EXTERNAL_PROJECT_ADDITIONAL_DIR}/${EXTERNAL_PEXCLUDEDROJECT_FILE_PREFIX}${dep}.cmake)
  95. else()
  96. message(FATAL_ERROR "Can't find ${EXTERNAL_PROJECT_FILE_PREFIX}${dep}.cmake")
  97. endif()
  98. endif()
  99. endforeach()
  100. # If project being process has dependencies, indicates it has also been added.
  101. if(NOT "${${proj}_DEPENDENCIES}" STREQUAL "")
  102. _epd_status(${__${proj}_superbuild_message})
  103. endif()
  104. # Update indent variable
  105. string(LENGTH "${__indent}" __indent_length)
  106. math(EXPR __indent_length "${__indent_length}-2")
  107. if(NOT ${__indent_length} LESS 0)
  108. string(SUBSTRING "${__indent}" 0 ${__indent_length} __indent)
  109. endif()
  110. if(${proj} STREQUAL ${CMAKE_PROJECT_NAME} AND __epd_first_pass)
  111. message(STATUS "SuperBuild - First pass - done")
  112. unset(__indent)
  113. if(${CMAKE_PROJECT_NAME}_SUPERBUILD)
  114. set(__epd_first_pass FALSE)
  115. endif()
  116. unset(${CMAKE_PROJECT_NAME}_DEPENDENCIES) # XXX - Refactor
  117. foreach(possible_proj ${__epd_${CMAKE_PROJECT_NAME}_projects})
  118. if(NOT ${possible_proj} STREQUAL ${CMAKE_PROJECT_NAME})
  119. unset(${EXTERNAL_PROJECT_FILE_PREFIX}${possible_proj}_FILE_INCLUDED)
  120. # XXX - Refactor - The following code should be re-organized
  121. if(DEFINED ${possible_proj}_enabling_variable)
  122. ctkMacroShouldAddExternalproject(${${possible_proj}_enabling_variable} add_project)
  123. if(${add_project})
  124. list(APPEND ${CMAKE_PROJECT_NAME}_DEPENDENCIES ${possible_proj})
  125. else()
  126. # XXX HACK
  127. if(${possible_proj} STREQUAL "VTK"
  128. AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
  129. list(APPEND ${CMAKE_PROJECT_NAME}_DEPENDENCIES VTK)
  130. else()
  131. unset(${${possible_proj}_enabling_variable}_INCLUDE_DIRS)
  132. unset(${${possible_proj}_enabling_variable}_LIBRARY_DIRS)
  133. unset(${${possible_proj}_enabling_variable}_FIND_PACKAGE_CMD)
  134. if(${CMAKE_PROJECT_NAME}_SUPERBUILD)
  135. message(STATUS "SuperBuild - ${possible_proj}[OPTIONAL]")
  136. endif()
  137. endif()
  138. endif()
  139. else()
  140. list(APPEND ${CMAKE_PROJECT_NAME}_DEPENDENCIES ${possible_proj})
  141. endif()
  142. # XXX
  143. else()
  144. endif()
  145. endforeach()
  146. list(REMOVE_DUPLICATES ${CMAKE_PROJECT_NAME}_DEPENDENCIES)
  147. if(${CMAKE_PROJECT_NAME}_SUPERBUILD)
  148. ctkMacroCheckExternalProjectDependency(${CMAKE_PROJECT_NAME})
  149. endif()
  150. endif()
  151. if(__epd_first_pass)
  152. return()
  153. endif()
  154. endmacro()