ctkMacroTargetLibraries.cmake 7.4 KB

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