ctkMacroTargetLibraries.cmake 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. ###########################################################################
  2. #
  3. # Library: CTK
  4. #
  5. # Copyright (c) 2010 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. MACRO(ctkMacroGetTargetLibraries varname)
  24. SET(filepath ${CMAKE_CURRENT_SOURCE_DIR}/target_libraries.cmake)
  25. SET(manifestpath ${CMAKE_CURRENT_SOURCE_DIR}/manifest_headers.cmake)
  26. # Check if "target_libraries.cmake" or "manifest_headers.cmake" file exists
  27. IF(NOT EXISTS ${filepath} AND NOT EXISTS ${manifestpath})
  28. MESSAGE(FATAL_ERROR "${filepath} or ${manifestpath} doesn't exists !")
  29. ENDIF()
  30. # Make sure the variable is cleared
  31. SET(target_libraries )
  32. SET(Require-Plugin )
  33. IF(EXISTS ${filepath})
  34. # Let's make sure target_libraries contains only strings
  35. FILE(STRINGS "${filepath}" stringtocheck) # read content of 'filepath' into 'stringtocheck'
  36. STRING(REGEX MATCHALL "[^\\#]\\$\\{.*\\}" incorrect_elements ${stringtocheck})
  37. FOREACH(incorrect_element ${incorrect_elements})
  38. STRING(REGEX REPLACE "\\$|\\{|\\}" "" correct_element ${incorrect_element})
  39. MESSAGE(FATAL_ERROR "In ${filepath}, ${incorrect_element} should be replaced by ${correct_element}")
  40. ENDFOREACH()
  41. INCLUDE(${filepath})
  42. # Loop over all target library, if it does *NOT* start with "CTK",
  43. # let's resolve the variable to access its content
  44. FOREACH(target_library ${target_libraries})
  45. IF(${target_library} MATCHES "^CTK[a-zA-Z0-9]+$")
  46. LIST(APPEND ${varname} ${target_library})
  47. ELSE()
  48. LIST(APPEND ${varname} "${${target_library}}")
  49. ENDIF()
  50. ENDFOREACH()
  51. ENDIF()
  52. IF(EXISTS ${manifestpath})
  53. # Let's make sure Require-Plugins contains only strings
  54. FILE(STRINGS "${manifestpath}" stringtocheck) # read content of 'manifestpath' into 'stringtocheck'
  55. STRING(REGEX MATCHALL "[^\\#]\\$\\{.*\\}" incorrect_elements ${stringtocheck})
  56. FOREACH(incorrect_element ${incorrect_elements})
  57. STRING(REGEX REPLACE "\\$|\\{|\\}" "" correct_element ${incorrect_element})
  58. MESSAGE(FATAL_ERROR "In ${manifestpath}, ${incorrect_element} should be replaced by ${correct_element}")
  59. ENDFOREACH()
  60. INCLUDE(${manifestpath})
  61. # Loop over all plugin dependencies,
  62. FOREACH(plugin_symbolicname ${Require-Plugin})
  63. STRING(REPLACE "." "_" plugin_library ${plugin_symbolicname})
  64. LIST(APPEND ${varname} ${plugin_library})
  65. ENDFOREACH()
  66. ENDIF()
  67. ENDMACRO()
  68. #
  69. #
  70. #
  71. MACRO(ctkMacroCollectTargetLibraryNames target_dir varname)
  72. #MESSAGE(STATUS target:${target})
  73. SET(lib_targets)
  74. SET(filepath ${target_dir}/target_libraries.cmake)
  75. SET(manifestpath ${target_dir}/manifest_headers.cmake)
  76. # Check if "target_libraries.cmake" or "manifest_headers.cmake" file exists
  77. IF(NOT EXISTS ${filepath} AND NOT EXISTS ${manifestpath})
  78. MESSAGE(FATAL_ERROR "${filepath} or ${manifestpath} doesn't exists !")
  79. ENDIF()
  80. # Make sure the variable is cleared
  81. SET(target_libraries )
  82. SET(Require-Plugin )
  83. IF(EXISTS ${filepath})
  84. # Let's make sure target_libraries contains only strings
  85. FILE(STRINGS "${filepath}" stringtocheck) # read content of 'filepath' into 'stringtocheck'
  86. STRING(REGEX MATCHALL "[^\\#]\\$\\{.*\\}" incorrect_elements ${stringtocheck})
  87. FOREACH(incorrect_element ${incorrect_elements})
  88. STRING(REGEX REPLACE "\\$|\\{|\\}" "" correct_element ${incorrect_element})
  89. MESSAGE(FATAL_ERROR "In ${filepath}, ${incorrect_element} should be replaced by ${correct_element}")
  90. ENDFOREACH()
  91. INCLUDE(${filepath})
  92. LIST(APPEND ${varname} ${target_libraries})
  93. ENDIF()
  94. IF(EXISTS ${manifestpath})
  95. # Let's make sure Require-Plugins contains only strings
  96. FILE(STRINGS "${manifestpath}" stringtocheck) # read content of 'manifestpath' into 'stringtocheck'
  97. STRING(REGEX MATCHALL "[^\\#]\\$\\{.*\\}" incorrect_elements ${stringtocheck})
  98. FOREACH(incorrect_element ${incorrect_elements})
  99. STRING(REGEX REPLACE "\\$|\\{|\\}" "" correct_element ${incorrect_element})
  100. MESSAGE(FATAL_ERROR "In ${manifestpath}, ${incorrect_element} should be replaced by ${correct_element}")
  101. ENDFOREACH()
  102. INCLUDE(${manifestpath})
  103. # Loop over all plugin dependencies
  104. FOREACH(plugin_symbolicname ${Require-Plugin})
  105. STRING(REPLACE "." "_" plugin_library ${plugin_symbolicname})
  106. LIST(APPEND ${varname} ${plugin_library})
  107. ENDFOREACH()
  108. ENDIF()
  109. LIST(REMOVE_DUPLICATES ${varname})
  110. ENDMACRO()
  111. #
  112. #
  113. #
  114. MACRO(ctkMacroCollectAllTargetLibraries targets subdir varname)
  115. SET(option_prefix)
  116. IF(${subdir} STREQUAL "Libs")
  117. SET(option_prefix CTK_LIB_)
  118. ELSEIF(${subdir} STREQUAL "Plugins")
  119. SET(option_prefix CTK_PLUGIN_)
  120. ELSEIF(${subdir} STREQUAL "Applications")
  121. SET(option_prefix CTK_APP_)
  122. ELSE()
  123. MESSAGE(FATAL_ERROR "Unknown subdir:${subdir}, expected value are: 'Libs, 'Plugins' or 'Applications'")
  124. ENDIF()
  125. FOREACH(target ${targets})
  126. # Make sure the variable is cleared
  127. SET(target_libraries )
  128. SET(option_name ${option_prefix}${target})
  129. #MESSAGE(STATUS option_name:${option_name})
  130. SET(target_dir "${CTK_SOURCE_DIR}/${subdir}/${target}")
  131. #MESSAGE(STATUS target_dir:${target_dir})
  132. SET(target_libraries)
  133. # Collect target libraries only if option is ON
  134. IF(${option_name})
  135. ctkMacroCollectTargetLibraryNames(${target_dir} target_libraries)
  136. ENDIF()
  137. IF(target_libraries)
  138. LIST(APPEND ${varname} ${target_libraries})
  139. LIST(REMOVE_DUPLICATES ${varname})
  140. ENDIF()
  141. ENDFOREACH()
  142. ENDMACRO()
  143. #
  144. # Extract all library names starting with CTK uppercase or org_commontk_
  145. #
  146. MACRO(ctkMacroGetAllCTKTargetLibraries all_target_libraries varname)
  147. SET(re_ctklib "^(c|C)(t|T)(k|K)[a-zA-Z0-9]+$")
  148. SET(re_ctkplugin "^org_commontk_[a-zA-Z0-9]+$")
  149. SET(_tmp_list)
  150. LIST(APPEND _tmp_list ${all_target_libraries})
  151. ctkMacroListFilter(_tmp_list re_ctklib OUTPUT_VARIABLE ${varname})
  152. ctkMacroListFilter(_tmp_list re_ctkplugin)
  153. LIST(APPEND ${varname} ${_tmp_list})
  154. #MESSAGE(STATUS varname:${varname}:${${varname}})
  155. ENDMACRO()
  156. #
  157. # Extract all library names *NOT* starting with CTK uppercase or org_commontk_
  158. #
  159. MACRO(ctkMacroGetAllNonCTKTargetLibraries all_target_libraries varname)
  160. ctkMacroGetAllCTKTargetLibraries("${all_target_libraries}" all_ctk_libraries)
  161. SET(_tmp_list ${all_target_libraries})
  162. IF("${all_ctk_libraries}")
  163. LIST(REMOVE_ITEM _tmp_list ${all_ctk_libraries})
  164. ENDIF()
  165. SET(${varname} ${_tmp_list})
  166. #MESSAGE(STATUS varname:${varname}:${${varname}})
  167. ENDMACRO()
  168. #
  169. #
  170. #
  171. MACRO(ctkMacroShouldAddExternalProject libraries_variable_name resultvar)
  172. IF(NOT DEFINED NON_CTK_DEPENDENCIES)
  173. MESSAGE(FATAL_ERROR "Variable NON_CTK_DEPENDENCIES is undefined !")
  174. ENDIF()
  175. LIST(FIND NON_CTK_DEPENDENCIES ${libraries_variable_name} index)
  176. SET(${resultvar} FALSE)
  177. IF(${index} GREATER -1)
  178. SET(${resultvar} TRUE)
  179. ENDIF()
  180. ENDMACRO()