PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Utilities/ITK/Wrapping/ExplicitITK/CreateExplicitInstantiations.cmake

https://github.com/paniwani/OTB
CMake | 287 lines | 181 code | 42 blank | 64 comment | 0 complexity | 21dd90318953e8ce3ca5c148f1e071c9 MD5 | raw file
  1. ################################################################################
  2. # Macro definitions for creating proper Explicit Instantiation files
  3. # from wrap_*.cmake files.
  4. # This file includes definitions for the macros to call from a CMakeList file
  5. # to cause wrap_*.cmake files to be turned into H and XX files, and definitions
  6. # for the macros to use in the wrap_*.cmake files themselves to declare that
  7. # certain classes and template instantiations be wrapped.
  8. # Note on convention: variable names in ALL_CAPS are global, and shared between
  9. # macros or between CMake and files that are configured. Variable names in
  10. # lower_case are local to a given macro.
  11. ################################################################################
  12. ################################################################################
  13. # Macros for finding and processing wrap_*.cmake files.
  14. ################################################################################
  15. MACRO(WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE type)
  16. SET(itk_Wrap_${type}_temp ${itk_Wrap_${type}})
  17. SET(itk_Wrap_${type} ${itk_Wrap_Explicit_${type}})
  18. ENDMACRO(WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE)
  19. MACRO(WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE type)
  20. SET(itk_Wrap_${type} ${itk_Wrap_${type}_temp})
  21. ENDMACRO(WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE)
  22. MACRO(WRAPPER_LIBRARY_CREATE_EXPLICIT_INSTANTIATION_FILES library_name)
  23. # Store the WrapTypes to restore them after generation
  24. WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE(Image)
  25. WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE(Offset)
  26. WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE(Vector)
  27. WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE(CovariantVector)
  28. WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE(ContinuousIndex)
  29. WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE(Array)
  30. WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE(Array2D)
  31. WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE(FixedArray)
  32. WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE(RGBPixel)
  33. WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE(VectorImage)
  34. WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE(VariableLengthVector)
  35. WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE(Point)
  36. WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE(LevelSetNode)
  37. WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE(StructuringElement)
  38. WRAPPER_LIBRARY_STORE_CURRENT_WRAP_TYPE(SpatialObject)
  39. # Include the wrap_*.cmake files in WRAPPER_LIBRARY_SOURCE_DIR. This causes
  40. # corresponding wrap_*.cxx files to be generated WRAPPER_LIBRARY_OUTPUT_DIR,
  41. # and added to the WRAPPER_LIBRARY_CABLESWIG_INPUTS list.
  42. # In addition, this causes the other required wrap_*.cxx files for the entire
  43. # library and each wrapper language to be created.
  44. # Finally, this macro causes the language support files for the templates and
  45. # library here defined to be created.
  46. SET(WRAPPER_EXPLICIT_LIBRARY_NAME "ITK${library_name}")
  47. SET(WRAPPER_LIBRARY_OUTPUT_DIR "${ITK_BINARY_DIR}/Code/${library_name}/Templates")
  48. # WRAPPER_LIBRARY_OUTPUT_DIR. Directory in which generated cxx, xml, and idx
  49. # files will be placed.
  50. SET(WRAPPER_LIBRARY_OUTPUT_DIR "${WRAPPER_LIBRARY_OUTPUT_DIR}")
  51. INCLUDE_DIRECTORIES("${ITK_BINARY_DIR}/Code/${library_name}")
  52. SET(WRAPPER_EXPLICIT_INSTANTIATION_SOURCES)
  53. # Next, include modules already in WRAPPER_LIBRARY_GROUPS, because those are
  54. # guaranteed to be processed first.
  55. FOREACH(module ${WRAPPER_LIBRARY_GROUPS})
  56. # EXISTS test is to allow groups to be declared in WRAPPER_LIBRARY_GROUPS
  57. # which aren't represented by cmake files: e.g. groups that are created in
  58. # custom cableswig cxx inputs stored in WRAPPER_LIBRARY_CABLESWIG_INPUTS.
  59. IF(EXISTS "${WRAPPER_LIBRARY_SOURCE_DIR}/wrap_${module}.cmake")
  60. IF("${module}" STREQUAL "SwigExtras")
  61. ELSE("${module}" STREQUAL "SwigExtras")
  62. INCLUDE_EXPLICIT_INSTANTIATION_CMAKE("${module}" "${library_name}")
  63. ENDIF("${module}" STREQUAL "SwigExtras")
  64. ENDIF(EXISTS "${WRAPPER_LIBRARY_SOURCE_DIR}/wrap_${module}.cmake")
  65. ENDFOREACH(module)
  66. # Now search for other wrap_*.cmake files to include
  67. FILE(GLOB wrap_cmake_files "${WRAPPER_LIBRARY_SOURCE_DIR}/wrap_*.cmake")
  68. # sort the list of files so we are sure to always get the same order on all system
  69. # and for all builds. That's important for several reasons:
  70. # - the order is important for the order of creation of python template
  71. # - the typemaps files are always the same, and the rebuild can be avoided
  72. SORT(sorted_cmake_files "${wrap_cmake_files}")
  73. FOREACH(file ${sorted_cmake_files})
  74. # get the module name from wrap_module.cmake
  75. GET_FILENAME_COMPONENT(module "${file}" NAME_WE)
  76. STRING(REGEX REPLACE "^wrap_" "" module "${module}")
  77. # if the module is already in the list, it means that it is already included
  78. # ... and do not include excluded modules
  79. SET(will_include 1)
  80. FOREACH(already_included ${WRAPPER_LIBRARY_GROUPS})
  81. IF("${already_included}" STREQUAL "${module}")
  82. SET(will_include 0)
  83. ENDIF("${already_included}" STREQUAL "${module}")
  84. ENDFOREACH(already_included)
  85. IF("${module}" STREQUAL "SwigExtras")
  86. SET(will_include 0)
  87. ENDIF("${module}" STREQUAL "SwigExtras")
  88. IF(${will_include})
  89. # Add the module name to the list. WRITE_MODULE_FILES uses this list
  90. # to create the master library wrapper file.
  91. SET(WRAPPER_LIBRARY_GROUPS ${WRAPPER_LIBRARY_GROUPS} "${module}")
  92. INCLUDE_EXPLICIT_INSTANTIATION_CMAKE("${module}" "${library_name}")
  93. ENDIF(${will_include})
  94. ENDFOREACH(file)
  95. # Restore the current state of the variables for other wrapping
  96. WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE(Image)
  97. WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE(Offset)
  98. WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE(Vector)
  99. WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE(CovariantVector)
  100. WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE(ContinuousIndex)
  101. WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE(Array)
  102. WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE(Array2D)
  103. WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE(FixedArray)
  104. WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE(RGBPixel)
  105. WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE(VectorImage)
  106. WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE(VariableLengthVector)
  107. WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE(Point)
  108. WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE(LevelSetNode)
  109. WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE(StructuringElement)
  110. WRAPPER_LIBRARY_RESTORE_CURRENT_WRAP_TYPE(SpatialObject)
  111. ENDMACRO(WRAPPER_LIBRARY_CREATE_EXPLICIT_INSTANTIATION_FILES)
  112. MACRO(INCLUDE_EXPLICIT_INSTANTIATION_CMAKE module library_name)
  113. # include a cmake module file and generate the associated wrap_*.cxx file.
  114. # This basically sets the global vars that will be added to or modified
  115. # by the commands in the included wrap_*.cmake module.
  116. #
  117. # Global vars used: none
  118. # Global vars modified: WRAPPER_MODULE_NAME WRAPPER_TYPEDEFS
  119. # WRAPPER_INCLUDE_FILES WRAPPER_AUTO_INCLUDE_HEADERS
  120. # WRAPPER_DO_NOT_CREATE_CXX
  121. MESSAGE(STATUS "${WRAPPER_EXPLICIT_LIBRARY_NAME}: Creating ${module} explicit instantiation.")
  122. # We run into some trouble if there's a module with the same name as the
  123. # wrapper library. Fix this.
  124. STRING(TOUPPER "${module}" upper_module)
  125. STRING(TOUPPER "${WRAPPER_LIBRARY_NAME}" upper_lib)
  126. IF("${upper_module}" STREQUAL "${upper_lib}")
  127. SET(module "${module}_module")
  128. ENDIF("${upper_module}" STREQUAL "${upper_lib}")
  129. # preset the vars before include the file
  130. SET(WRAPPER_MODULE_NAME "${module}")
  131. SET(WRAPPER_TYPEDEFS)
  132. SET(WRAPPER_EXPLICIT_INSTANTIATION_INCLUDES)
  133. SET(WRAPPER_INCLUDE_FILES ${WRAPPER_DEFAULT_INCLUDE})
  134. SET(WRAPPER_AUTO_INCLUDE_HEADERS ON)
  135. SET(WRAPPER_DO_NOT_CREATE_CXX OFF)
  136. # Now include the file.
  137. INCLUDE("${WRAPPER_LIBRARY_SOURCE_DIR}/wrap_${module}.cmake")
  138. # Write the file, inless the included cmake file told us not to.
  139. # A file might declare WRAPPER_DO_NOT_CREATE_CXX if that cmake file
  140. # provides a custom wrap_*.cxx file and manually appends it to the
  141. # WRAPPER_LIBRARY_CABLESWIG_INPUTS list; thus that file would not
  142. # need or want any cxx file generated.
  143. IF(NOT WRAPPER_DO_NOT_CREATE_CXX)
  144. WRITE_EXPLICIT_INSTANTIATION_H_CXX("${module}")
  145. WRITE_EXPLICIT_INSTANTIATION_FILE("${module}" "${library_name}")
  146. ENDIF(NOT WRAPPER_DO_NOT_CREATE_CXX)
  147. ENDMACRO(INCLUDE_EXPLICIT_INSTANTIATION_CMAKE)
  148. # Keep a list of files that shouldn't be included
  149. MACRO(WRAP_NO_INCLUDE type_name)
  150. SET(EXPLICIT_ITK_NO_INCLUDES ${EXPLICIT_ITK_NO_INCLUDES} ${WRAPPER_MODULE_NAME}${type_name})
  151. ENDMACRO(WRAP_NO_INCLUDE module_name)
  152. MACRO(WRITE_EXPLICIT_INSTANTIATION_H_CXX module_name)
  153. SET(CONFIG_MODULE_NAME "${WRAPPER_MODULE_NAME}")
  154. FOREACH(wrap ${WRAPPER_TEMPLATES})
  155. STRING(REGEX REPLACE "${sharp_regexp}" "\\1" mangled_suffix "${wrap}")
  156. STRING(REGEX REPLACE "${sharp_regexp}" "\\2" template_params "${wrap}")
  157. STRING(REGEX REPLACE "itk" "" class_name "${module_name}")
  158. SET(CONFIG_MANGLED_SUFFIX ${mangled_suffix})
  159. SET(CONFIG_TEMPLATE_PARAMETERS ${template_params})
  160. SET(CONFIG_CLASS_NAME ${class_name})
  161. # Add extra includes if the templates has already been defined
  162. STRING(REGEX REPLACE "," ";" template_params_list "${template_params}")
  163. STRING(REGEX REPLACE "Templates::" "" template_params_list "${template_params_list}")
  164. SET(CONFIG_EXTRA_INCLUDES "")
  165. FOREACH(param ${template_params_list})
  166. STRING(REGEX REPLACE " " "" param_nospace "${param}")
  167. IF(${param_nospace} MATCHES "Image*")
  168. SET(CONFIG_EXTRA_INCLUDES "${CONFIG_EXTRA_INCLUDES}#include \"Templates/itk${param_nospace}.h\"\n")
  169. ENDIF(${param_nospace} MATCHES "Image*")
  170. IF(${param_nospace} MATCHES "Vector*")
  171. SET(CONFIG_EXTRA_INCLUDES "${CONFIG_EXTRA_INCLUDES}#include \"Templates/itk${param_nospace}.h\"\n")
  172. ENDIF(${param_nospace} MATCHES "Vector*")
  173. IF(${param_nospace} MATCHES "Pixel*")
  174. SET(CONFIG_EXTRA_INCLUDES "${CONFIG_EXTRA_INCLUDES}#include \"Templates/itk${param_nospace}.h\"\n")
  175. ENDIF(${param_nospace} MATCHES "Pixel*")
  176. IF(${param_nospace} MATCHES "Point*")
  177. SET(CONFIG_EXTRA_INCLUDES "${CONFIG_EXTRA_INCLUDES}#include \"Templates/itk${param_nospace}.h\"\n")
  178. ENDIF(${param_nospace} MATCHES "Point*")
  179. IF(${param_nospace} MATCHES "Matrix*")
  180. SET(CONFIG_EXTRA_INCLUDES "${CONFIG_EXTRA_INCLUDES}#include \"Templates/itk${param_nospace}.h\"\n")
  181. ENDIF(${param_nospace} MATCHES "Matrix*")
  182. IF(${param_nospace} MATCHES "FixedArray*")
  183. SET(CONFIG_EXTRA_INCLUDES "${CONFIG_EXTRA_INCLUDES}#include \"Templates/itk${param_nospace}.h\"\n")
  184. ENDIF(${param_nospace} MATCHES "FixedArray*")
  185. IF(${param_nospace} MATCHES "Neighborhood*")
  186. SET(CONFIG_EXTRA_INCLUDES "${CONFIG_EXTRA_INCLUDES}#include \"Templates/itk${param_nospace}.h\"\n")
  187. ENDIF(${param_nospace} MATCHES "Neighborhood*")
  188. IF(${param_nospace} MATCHES "TreeContainer*")
  189. SET(CONFIG_EXTRA_INCLUDES "${CONFIG_EXTRA_INCLUDES}#include \"Templates/itk${param_nospace}.h\"\n")
  190. ENDIF(${param_nospace} MATCHES "TreeContainer*")
  191. IF(${param_nospace} MATCHES "EllipsoidInteriorExteriorSpatialFunction*")
  192. SET(CONFIG_EXTRA_INCLUDES "${CONFIG_EXTRA_INCLUDES}#include \"Templates/itk${param_nospace}.h\"\n")
  193. ENDIF(${param_nospace} MATCHES "EllipsoidInteriorExteriorSpatialFunction*")
  194. IF(${param_nospace} MATCHES "ZeroFluxNeumann*")
  195. SET(CONFIG_EXTRA_INCLUDES "${CONFIG_EXTRA_INCLUDES}#include \"Templates/itk${param_nospace}.h\"\n")
  196. ENDIF(${param_nospace} MATCHES "ZeroFluxNeumann*")
  197. IF(${param_nospace} MATCHES "Item*")
  198. SET(CONFIG_EXTRA_INCLUDES "${CONFIG_EXTRA_INCLUDES}#include \"Templates/itk${param_nospace}.h\"\n")
  199. ENDIF(${param_nospace} MATCHES "Item*")
  200. IF(${param_nospace} MATCHES "BloxBoundaryPoint*")
  201. SET(CONFIG_EXTRA_INCLUDES "${CONFIG_EXTRA_INCLUDES}#include \"Templates/itk${param_nospace}.h\"\n")
  202. ENDIF(${param_nospace} MATCHES "BloxBoundaryPoint*")
  203. ENDFOREACH(param ${template_params_list})
  204. # Create the h file.
  205. SET(h_file "${WRAPPER_LIBRARY_OUTPUT_DIR}/${module_name}${mangled_suffix}.h")
  206. CONFIGURE_FILE("${EXPLICIT_ITK_CONFIG_DIR}/explicit_.h.in"
  207. "${h_file}" @ONLY IMMEDIATE)
  208. # Create the cxx file.
  209. SET(cxx_file "${WRAPPER_LIBRARY_OUTPUT_DIR}/${module_name}${mangled_suffix}.cxx")
  210. CONFIGURE_FILE("${EXPLICIT_ITK_CONFIG_DIR}/explicit_.cxx.in"
  211. "${cxx_file}" @ONLY IMMEDIATE)
  212. SET(add_to_include 1)
  213. FOREACH(no_include ${EXPLICIT_ITK_NO_INCLUDES})
  214. SET(word ${module_name}${mangled_suffix})
  215. IF(${word} MATCHES ${no_include})
  216. SET(add_to_include 0)
  217. ENDIF(${word} MATCHES ${no_include})
  218. ENDFOREACH(no_include ${EXPLICIT_ITK_NO_INCLUDES})
  219. # And add the h file to the list of includes.
  220. IF(add_to_include)
  221. SET(WRAPPER_EXPLICIT_INSTANTIATION_INCLUDES
  222. ${WRAPPER_EXPLICIT_INSTANTIATION_INCLUDES} "${module_name}${mangled_suffix}.h")
  223. ENDIF(add_to_include)
  224. # Add the source
  225. SET(WRAPPER_EXPLICIT_INSTANTIATION_SOURCES
  226. ${WRAPPER_EXPLICIT_INSTANTIATION_SOURCES} ${cxx_file})
  227. ENDFOREACH(wrap)
  228. ENDMACRO(WRITE_EXPLICIT_INSTANTIATION_H_CXX)
  229. MACRO(WRITE_EXPLICIT_INSTANTIATION_FILE module_name library_name)
  230. SET(CONFIG_WRAPPER_INCLUDES)
  231. FOREACH(include_file ${WRAPPER_EXPLICIT_INSTANTIATION_INCLUDES})
  232. SET(new_include "#include \"${include_file}\"\n")
  233. SET(CONFIG_WRAPPER_INCLUDES ${CONFIG_WRAPPER_INCLUDES}${new_include})
  234. ENDFOREACH(include_file)
  235. # Create the +-.h file.
  236. SET(file "${WRAPPER_LIBRARY_OUTPUT_DIR}/${module_name}+-.h")
  237. CONFIGURE_FILE("${EXPLICIT_ITK_CONFIG_DIR}/explicit_+-.h.in" "${file}" @ONLY IMMEDIATE)
  238. INSTALL_FILES("${ITK_INSTALL_INCLUDE_DIR}/${library_name}/Templates" FILES "${file}")
  239. ENDMACRO(WRITE_EXPLICIT_INSTANTIATION_FILE)
  240. MACRO(WRAPPER_LIBRARY_CREATE_EXPLICIT_INSTANTIATION_LIBRARY)
  241. ADD_LIBRARY(${WRAPPER_LIBRARY_NAME}Explicit ${WRAPPER_EXPLICIT_INSTANTIATION_SOURCES})
  242. ENDMACRO(WRAPPER_LIBRARY_CREATE_EXPLICIT_INSTANTIATION_LIBRARY)
  243. MACRO(WRAPPER_LIBRARY_CREATE_EXPLICIT_INSTANTIATION_SOURCES)
  244. SET(WRAPPER_EXPLICIT_${WRAPPER_LIBRARY_NAME}_SRCS ${WRAPPER_EXPLICIT_INSTANTIATION_SOURCES})
  245. ENDMACRO(WRAPPER_LIBRARY_CREATE_EXPLICIT_INSTANTIATION_SOURCES)