ctkMacroTargetLibraries.cmake 8.2 KB

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