ctkMacroTargetLibraries.cmake 5.1 KB

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