ctkMacroTargetLibraries.cmake 8.0 KB

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