1################################################################################
2# Macro definitions for creating proper Swig input files from *.wrap
3# files.
4# This file includes definitions for the macros to call from a CMakeList file
5# to cause *.wrap files to be turned into CXX files, and definitions for
6# the macros to use in the *.wrap files themselves to declare that certain
7# 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
14set(WRAPPER_LIBRARY_itk_wrap_modules_STATUS "NOT_EXECUTED" CACHE INTERNAL "status var used to avoid the use of itk_wrap_modules in simple contributions.")
15
16macro(itk_wrap_modules)
17  set(WRAPPER_LIBRARY_itk_wrap_modules_STATUS "EXECUTED" CACHE INTERNAL "status var used to avoid the use of itk_wrap_modules in simple contributions.")
18  itk_wrap_modules_all_generators()
19endmacro()
20
21macro(itk_end_wrap_modules)
22  itk_end_wrap_modules_all_generators()
23endmacro()
24
25
26
27# Support for additional include directories of each module
28# WARNING: Each module must set this variable BEFORE calling itk_wrap_module
29# TODO: is this the place place for this?
30set(WRAPPER_LIBRARY_INCLUDE_DIRECTORIES "" CACHE INTERNAL "additional include directories for each module")
31
32###############################################################################
33# Define fundamental wrapping macro which sets up the global variables used
34# across all of the wrapping macros included at the end of this file.
35# All variables set here are optional and have sensible default values.
36# Also define some other global defaults like WRAPPER_MASTER_INDEX_OUTPUT_DIR.
37###############################################################################
38macro(itk_wrap_module library_name)
39  set(WRAPPER_LIBRARY_NAME "${library_name}")
40
41  message(STATUS "${WRAPPER_LIBRARY_NAME}: Creating module.")
42
43  # Mark the current source dir for inclusion because it may contain header files.
44  include_directories(BEFORE "${CMAKE_CURRENT_SOURCE_DIR}")
45  include_directories(BEFORE ${WRAPPER_LIBRARY_INCLUDE_DIRECTORIES})
46
47  # WRAPPER_LIBRARY_INCLUDE_DIRECTORIES. List of other include directories that
48  # contain the desired header files.
49  #set(WRAPPER_LIBRARY_INCLUDE_DIRECTORIES )
50
51  # WRAPPER_LIBRARY_SOURCE_DIR. Directory to be scanned for *.wrap files.
52  set(WRAPPER_LIBRARY_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
53
54  # WRAPPER_LIBRARY_OUTPUT_DIR. Directory in which generated cxx, xml, and idx
55  # files will be placed.
56  set(WRAPPER_LIBRARY_OUTPUT_DIR "${ITK_DIR}/Wrapping")
57
58  # WRAPPER_LIBRARY_DEPENDS. List of names of other wrapper libraries that
59  # define symbols used by this wrapper library.
60  INTERSECTION(WRAPPER_LIBRARY_DEPENDS "${ITK_MODULE_${library_name}_DEPENDS}" "${WRAP_ITK_MODULES}")
61  # set(WRAPPER_LIBRARY_DEPENDS ${ITK_MODULE_${library_name}_DEPENDS})
62
63  # WRAPPER_LIBRARY_LINK_LIBRARIES. List of other libraries that should
64  # be linked to the wrapper library.
65  set(WRAPPER_LIBRARY_LINK_LIBRARIES ${ITK_LIBRARIES} ${${itk-module}_LIBRARIES})
66
67  # WRAPPER_SUBMODULE_ORDER. List of *.wrap submodules in the source dir
68  # that should be included/wrapped before the rest in the given order.
69  # Just the submodule group name is needed, not the full path or file name.
70  set(WRAPPER_SUBMODULE_ORDER )
71  # WRAPPER_LIBRARY_GROUPS is a deprecated variable for this specification.
72  unset(WRAPPER_LIBRARY_GROUPS )
73
74  # WRAPPER_LIBRARY_SWIG_INPUTS. List of C++ source files to be used
75  # as input for Swig. This list is then appended to by
76  # WRAPPER_LIBRARY_AUTO_INCLUDE_WRAP_FILES. A full path to each input is required.
77  set(WRAPPER_LIBRARY_SWIG_INPUTS )
78
79  # WRAPPER_SWIG_LIBRARY_FILES. List of swig .swg files to pass to cswig to control
80  # type handling and so forth. A full path to each include is required.
81  # The itk.swg file and the library file for the current library are implicitly added.
82  set(WRAPPER_SWIG_LIBRARY_FILES )
83
84  # WRAPPER_LIBRARY_CXX_SOURCES. C++ sources to be compiled and linked in
85  # to the wrapper library (with no prior processing by swig, etc.)
86  # A full path to each input is required.
87  set(WRAPPER_LIBRARY_CXX_SOURCES )
88
89  if("${ARGC}" EQUAL 2)
90    foreach(lang ${WRAP_ITK_GENERATORS})
91      string(TOUPPER ${lang} LANG)
92      set(WRAPPER_LIBRARY_${LANG} OFF)
93    endforeach()
94    foreach(lang ${ARGV1})
95      string(TOUPPER ${lang} LANG)
96      set(WRAPPER_LIBRARY_${LANG} ON)
97    endforeach()
98  else()
99    foreach(lang ${WRAP_ITK_GENERATORS})
100      string(TOUPPER ${lang} LANG)
101      set(WRAPPER_LIBRARY_${LANG} ON)
102    endforeach()
103  endif()
104
105  if("${WRAPPER_LIBRARY_itk_wrap_modules_STATUS}" STREQUAL "NOT_EXECUTED")
106    itk_wrap_modules()
107    # change the status of WRAPPER_LIBRARY_itk_wrap_modules_STATUS, so we can call itk_end_wrap_modules when
108    # itk_end_wrap_module will be called
109    set(WRAPPER_LIBRARY_itk_wrap_modules_STATUS "EXECUTED_IN_itk_wrap_module" CACHE INTERNAL "status var used to avoid the use of itk_wrap_modules in simple contributions.")
110  endif()
111
112  # Call the language support initialization function
113  itk_wrap_module_all_generators("${library_name}")
114
115endmacro()
116
117
118macro(itk_end_wrap_module)
119  if("${WRAPPER_LIBRARY_itk_wrap_modules_STATUS}" STREQUAL "EXECUTED_IN_itk_wrap_module")
120    itk_end_wrap_modules()
121  endif()
122
123  itk_end_wrap_module_all_generators()
124  # Add testing
125  set(wrapping_test_directory ${CMAKE_CURRENT_SOURCE_DIR}/test)
126  if(BUILD_TESTING AND EXISTS ${wrapping_test_directory}/CMakeLists.txt)
127    add_subdirectory(${wrapping_test_directory})
128  endif()
129endmacro()
130
131
132macro(INCLUDE_LIBRARY library)
133  # TODO: that macro is buggy !!!!
134  # it doesn't store the vars where in the lib sub dir
135
136  itk_wrap_module("${library}")
137  # change some default values
138
139  # WRAPPER_LIBRARY_SOURCE_DIR. Directory to be scanned for *.wrap files.
140  set(WRAPPER_LIBRARY_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${library}")
141
142  # WRAPPER_LIBRARY_OUTPUT_DIR. Directory in which generated cxx, xml, idx,
143  # and mdx files will be placed.
144  set(WRAPPER_LIBRARY_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/${library}")
145
146  add_subdirectory("${library}")
147  itk_end_wrap_module()
148endmacro()
149
150
151################################################################################
152# Macros for finding and processing *.wrap files.
153################################################################################
154
155macro(itk_auto_load_submodules)
156
157  # Include the *.wrap files in WRAPPER_LIBRARY_SOURCE_DIR. This causes
158  # corresponding wrap_*.cxx files to be generated WRAPPER_LIBRARY_OUTPUT_DIR,
159  # and added to the WRAPPER_LIBRARY_SWIG_INPUTS list.
160  # In addition, this causes the other required wrap_*.cxx files for the entire
161  # library and each wrapper language to be created.
162  # Finally, this macro causes the language support files for the templates and
163  # library here defined to be created.
164
165  # For backwards compatibility
166  if(WRAPPER_LIBRARY_GROUPS)
167    set(WRAPPER_SUBMODULE_ORDER ${WRAPPER_LIBRARY_GROUPS})
168  endif()
169
170  # Next, include modules already in WRAPPER_SUBMODULE_ORDER, because those are
171  # guaranteed to be processed first.
172  foreach(module ${WRAPPER_SUBMODULE_ORDER})
173    itk_load_submodule("${module}")
174  endforeach()
175
176  # Now search for other *.wrap files to include
177  file(GLOB wrap_cmake_files "${WRAPPER_LIBRARY_SOURCE_DIR}/*.wrap")
178  # sort the list of files so we are sure to always get the same order on all system
179  # and for all builds. That's important for several reasons:
180  # - the order is important for the order of creation of python template
181  # - the typemaps files are always the same, and the rebuild can be avoided
182  list(SORT wrap_cmake_files)
183  foreach(_file ${wrap_cmake_files})
184    # get the module name from module.wrap
185    get_filename_component(module "${_file}" NAME_WE)
186
187    # if the module is already in the list, it means that it is already included
188    # ... and do not include excluded modules
189    set(will_include 1)
190    foreach(already_included ${WRAPPER_SUBMODULE_ORDER})
191      if("${already_included}" STREQUAL "${module}")
192        set(will_include 0)
193      endif()
194    endforeach()
195
196    if(${will_include})
197      # Add the module name to the list. WRITE_MODULE_FILES uses this list
198      # to create the master library wrapper file.
199      list(APPEND WRAPPER_SUBMODULE_ORDER "${module}")
200      itk_load_submodule("${module}")
201    endif()
202  endforeach()
203endmacro()
204
205
206macro(itk_load_submodule module)
207  # include a cmake module file and generate the associated wrap_*.cxx file.
208  # This basically sets the global vars that will be added to or modified
209  # by the commands in the included *.wrap module.
210  #
211  # Global vars used: none
212  # Global vars modified: WRAPPER_MODULE_NAME WRAPPER_TYPEDEFS
213  #                       WRAPPER_INCLUDE_FILES WRAPPER_AUTO_INCLUDE_HEADERS
214
215  itk_wrap_submodule(${module})
216
217  # Now include the file.
218  if(EXISTS "${WRAPPER_LIBRARY_SOURCE_DIR}/${module}.wrap")
219      include("${WRAPPER_LIBRARY_SOURCE_DIR}/${module}.wrap")
220  else()
221    # for backward compatibility
222    if(EXISTS "${WRAPPER_LIBRARY_SOURCE_DIR}/wrap_${module}.cmake")
223        include("${WRAPPER_LIBRARY_SOURCE_DIR}/wrap_${module}.cmake")
224    else()
225      message(SEND_ERROR "Module ${WRAPPER_LIBRARY_SOURCE_DIR}/${module}.wrap or ${WRAPPER_LIBRARY_SOURCE_DIR}/wrap_${module}.cmake not found.")
226    endif()
227  endif()
228
229  # Call generator specific macros
230  itk_end_wrap_submodule_all_generators("${WRAPPER_MODULE_NAME}")
231
232endmacro()
233
234macro(itk_wrap_submodule module)
235
236  message(STATUS "${WRAPPER_LIBRARY_NAME}: Creating ${module} submodule.")
237
238  # We run into some trouble if there's a module with the same name as the
239  # wrapper library. Fix this.
240  string(TOUPPER "${module}" upper_module)
241  string(TOUPPER "${WRAPPER_LIBRARY_NAME}" upper_lib)
242  if("${upper_module}" STREQUAL "${upper_lib}")
243    message(FATAL_ERROR "The module ${module} can't have the same name than its library. Note that the names are not case sensitive.")
244  endif()
245
246  # preset the vars before include the file
247  set(WRAPPER_MODULE_NAME "${module}")
248
249  # call generators specific macros
250  itk_wrap_submodule_all_generators("${module}")
251
252  set(WRAPPER_INCLUDE_FILES )
253  foreach(inc ${WRAPPER_DEFAULT_INCLUDE})
254    itk_wrap_include("${inc}")
255  endforeach()
256  set(WRAPPER_AUTO_INCLUDE_HEADERS ON)
257
258endmacro()
259
260################################################################################
261# Macros to be used in the *.wrap files themselves.
262# These macros specify that a class is to be wrapped, that certain itk headers
263# are to be included, and what specific template instatiations are to be wrapped.
264################################################################################
265
266macro(itk_wrap_class class)
267  # Wraps the c++ class 'class'. This parameter must be a fully-qualified c++
268  # name.
269  # The class will be named in the SWIG wrappers as the top-level namespace
270  # concatenated to the base class name. E.g. itk::Image -> itkImage or
271  # itk::Statistics::Sample -> itkSample.
272  # If the top-level namespace is 'itk' and WRAPPER_AUTO_INCLUDE_HEADERS is ON
273  # then the appropriate itk header for this class will be included. Otherwise
274  # itk_wrap_include should be manually called from the *.wrap file that calls
275  # this macro.
276  # Lastly, this class takes an optional 'wrap method' parameter. Valid values are:
277  # POINTER POINTER_WITH_CONST_POINTER POINTER_WITH_SUPERCLASS POINTER_WITH_2_SUPERCLASSES
278  # EXPLICIT_SPECIALIZATION POINTER_WITH_EXPLICIT_SPECIALIZATION ENUM AUTOPOINTER
279  #
280  # Global vars used: none
281  # Global vars modified: WRAPPER_INCLUDE_FILES
282  # drop the namespace prefix
283  if("${class}" MATCHES "::")
284    # there's at least one namespace in the name
285    string(REGEX REPLACE ".*::" "" base_name "${class}")
286    string(REGEX REPLACE "^([^:]*::)?.+" "\\1" top_namespace "${class}")
287    string(REGEX REPLACE "::" "" top_namespace "${top_namespace}") # drop the :: from the namespace
288    set(swig_name "${top_namespace}${base_name}")
289  else()
290    # no namespaces
291    set(swig_name "${class}")
292  endif()
293
294  # Call the itk_wrap_named_class macro, including any optional arguments
295  itk_wrap_named_class("${class}" "${swig_name}" ${ARGN})
296
297  # and include the class's header
298  if(WRAPPER_AUTO_INCLUDE_HEADERS)
299    itk_wrap_include("${swig_name}.h")
300  endif()
301
302  itk_wrap_class_all_generators("${class}")
303endmacro()
304
305macro(itk_wrap_named_class class swig_name)
306  # Begin the wrapping of a new templated class. The 'class' parameter is a
307  # fully-qualified C++ type name, including the namespace. Between itk_wrap_class
308  # and itk_end_wrap_class various macros should be called to cause certain template
309  # instances to be automatically added to the wrap_*.cxx file. itk_end_wrap_class
310  # actually parses through the template instaces that have been recorded and
311  # creates the content of that cxx file. itk_wrap_simple_class should be used
312  # to create a definition for a non-templated class. (Note that internally,
313  # itk_wrap_simple_class eventually calls this macro. This macro should never
314  # be called directly for a non-templated class though.)
315  #
316  # The second parameter of this macro is the name that the class should be given
317  # in SWIG (with template definitions providing additional mangled suffixes to this name)
318  #
319  # Lastly, this class takes an optional 'wrap method' parameter. Valid values are:
320  # POINTER POINTER_WITH_CONST_POINTER POINTER_WITH_SUPERCLASS POINTER_WITH_2_SUPERCLASSES
321  # EXPLICIT_SPECIALIZATION POINTER_WITH_EXPLICIT_SPECIALIZATION ENUM AUTOPOINTER
322  # If no parameter is given, the class is simply wrapped as-is. If the parameter
323  # is "POINTER" then the class is wrapped and so is the SmartPointer template type
324  # that is typedef'd as class::Pointer.
325  # If POINTER_WITH_SUPERCLASS is given, class, class::Pointer, class::Superclass,
326  # and class::Superclass::Pointer are wrapped. This requires that the class
327  # has a typedef'd "Superclass" and that that superclass has Pointer and Self
328  # typedefs.
329  #
330  # Global vars used: none
331  # Global vars modified: WRAPPER_CLASS WRAPPER_TEMPLATES WRAPPER_INCLUDE_FILES
332  #                       WRAPPER_WRAP_METHOD WRAPPER_SWIG_NAME
333
334  # first, we must be sure the wrap method is valid
335  if("${ARGC}" EQUAL 2)
336    # store the wrap method
337    set(WRAPPER_WRAP_METHOD "")
338  endif()
339
340  if("${ARGC}" EQUAL 3)
341    set(WRAPPER_WRAP_METHOD "${ARGV2}")
342    set(ok 0)
343    foreach(opt POINTER POINTER_WITH_CONST_POINTER POINTER_WITH_SUPERCLASS POINTER_WITH_2_SUPERCLASSES EXPLICIT_SPECIALIZATION POINTER_WITH_EXPLICIT_SPECIALIZATION ENUM AUTOPOINTER)
344      if("${opt}" STREQUAL "${WRAPPER_WRAP_METHOD}")
345        set(ok 1)
346      endif()
347    endforeach()
348    if(ok EQUAL 0)
349      message(SEND_ERROR "itk_wrap_class: Invalid option '${WRAPPER_WRAP_METHOD}'. Possible values are POINTER, POINTER_WITH_CONST_POINTER, POINTER_WITH_SUPERCLASS, POINTER_WITH_2_SUPERCLASSES, EXPLICIT_SPECIALIZATION, POINTER_WITH_EXPLICIT_SPECIALIZATION, ENUM and AUTOPOINTER")
350    endif()
351  endif()
352
353  if("${ARGC}" GREATER 3)
354    message(SEND_ERROR "Too many arguments")
355  endif()
356
357  set(WRAPPER_CLASS "${class}")
358  set(WRAPPER_SWIG_NAME "${swig_name}")
359  set(WRAPPER_WARN_ABOUT_NO_TEMPLATE ON)
360  # clear the wrap parameters
361  # TODO: It shouldn't be used with the new architecture!!
362  set(WRAPPER_TEMPLATES)
363
364  itk_wrap_named_class_all_generators("${class}" "${swig_name}")
365endmacro()
366
367macro(itk_wrap_simple_class class)
368  # Similar to itk_wrap_class in that it generates typedefs for Swig input.
369  # However, since no templates need to be declared, there's no need for
370  # itk_wrap_class ... (declare templates) .. itk_end_wrap_class. Instead
371  # itk_wrap_simple_class takes care of it all.
372  # A fully-qualified 'class' parameter is required as above. The swig name for
373  # this class is generated as in itk_wrap_class.
374  # Lastly, this class takes an optional 'wrap method' parameter. Valid values are:
375  # POINTER POINTER_WITH_CONST_POINTER and POINTER_WITH_SUPERCLASS.
376
377  itk_wrap_class("${class}" ${ARGN})
378  # to avoid useless warning: no template can be defined in
379  set(WRAPPER_WARN_ABOUT_NO_TEMPLATE OFF)
380  itk_wrap_one_type("${WRAPPER_WRAP_METHOD}" "${WRAPPER_CLASS}" "${WRAPPER_SWIG_NAME}")
381  itk_end_wrap_class()
382
383  itk_wrap_simple_class_all_generators(${class})
384endmacro()
385
386
387macro(itk_wrap_named_simple_class class swig_name)
388  # Similar to itk_wrap_named_class in that it generates typedefs for Swig input.
389  # However, since no templates need to be declared, there's no need for
390  # itk_wrap_class ... (declare templates) .. itk_end_wrap_class. Instead
391  # itk_wrap_named_simple_class takes care of it all.
392  # A fully-qualified 'class' parameter is required as above. The swig name for
393  # this class is provided by the second parameter.
394  # Lastly, this class takes an optional 'wrap method' parameter. Valid values are:
395  # POINTER POINTER_WITH_CONST_POINTER and POINTER_WITH_SUPERCLASS.
396
397  itk_wrap_named_class("${class}" "${swig_name}" ${ARGN})
398  # to avoid useless warning: no template can be defined in
399  set(WRAPPER_WARN_ABOUT_NO_TEMPLATE OFF)
400  itk_wrap_one_type("${WRAPPER_WRAP_METHOD}" "${WRAPPER_CLASS}" "${WRAPPER_SWIG_NAME}")
401
402  itk_wrap_named_simple_class_all_generators("${class}" "${swig_name}")
403endmacro()
404
405
406macro(itk_wrap_include include_file)
407  # Add a header file to the list of files to be #included in the final cxx file.
408  # Global vars used: WRAPPER_INCLUDE_FILES
409  # Global vars modified: WRAPPER_INCLUDE_FILES
410  set(already_included 0)
411  foreach(included ${WRAPPER_INCLUDE_FILES})
412    if("${include_file}" STREQUAL "${included}")
413      set(already_included 1)
414    endif()
415  endforeach()
416
417  if(NOT already_included)
418    # include order IS important. Default values must be before the other ones
419    set(WRAPPER_INCLUDE_FILES
420      ${WRAPPER_INCLUDE_FILES}
421      ${include_file}
422    )
423    itk_wrap_include_all_generators("${include_file}")
424  endif()
425endmacro()
426
427macro(itk_end_wrap_class)
428  # Parse through the list of WRAPPER_TEMPLATES set up by the macros at the bottom
429  # of this file, turning them into proper C++ type definitions suitable for
430  # input to Swig. The C++ definitions are stored in WRAPPER_TYPEDEFS.
431  #
432  # Global vars used: WRAPPER_CLASS WRAPPER_WRAP_METHOD WRAPPER_TEMPLATES WRAPPER_SWIG_NAME
433  # Global vars modified: WRAPPER_TYPEDEFS
434
435  # the regexp used to get the values separated by a #
436  if(NOT "${WRAPPER_TEMPLATES}" STREQUAL "")
437    set(sharp_regexp "([0-9A-Za-z_]*)[ ]*#[ ]*(.*)")
438    foreach(wrap ${WRAPPER_TEMPLATES})
439      string(REGEX REPLACE "${sharp_regexp}" "\\1" mangled_suffix "${wrap}")
440      string(REGEX REPLACE "${sharp_regexp}" "\\2" template_params "${wrap}")
441      itk_wrap_one_type("${WRAPPER_WRAP_METHOD}" "${WRAPPER_CLASS}" "${WRAPPER_SWIG_NAME}${mangled_suffix}" "${template_params}")
442    endforeach()
443  else()
444    if(WRAPPER_WARN_ABOUT_NO_TEMPLATE AND NOT EXTERNAL_WRAP_ITK_PROJECT)
445      # display a warning if the class is empty
446      message("Warning: No template declared for ${WRAPPER_CLASS}. Perhaps you should turn on more WRAP_* options?")
447    endif()
448  endif()
449
450  itk_end_wrap_class_all_generators()
451endmacro()
452
453
454macro(itk_wrap_simple_type wrap_class swig_name)
455  # Add a typedef, without support for any option
456  itk_wrap_simple_type_all_generators("${wrap_class}" "${swig_name}")
457endmacro()
458
459
460macro(itk_wrap_one_type wrap_method wrap_class swig_name)
461  # Add one  typedef to WRAPPER_TYPEDEFS
462  # 'wrap_method' is the one of the valid WRAPPER_WRAP_METHODS from itk_wrap_class,
463  # 'wrap_class' is the fully-qualified C++ name of the class
464  # 'swig_name' is what the swigged class should be called
465  # The optional last argument is the template parameters that should go between
466  # the < > brackets in the C++ template definition.
467  # Only pass 3 parameters to wrap a non-templated class
468  #
469  # Global vars used: none
470  # Global vars modified: WRAPPER_TYPEDEFS
471
472  # get the base C++ class name (no namespaces) from wrap_class:
473  string(REGEX REPLACE "(.*::)" "" base_name "${wrap_class}")
474
475  set(wrap_pointer 0)
476  set(template_parameters "${ARGV3}")
477  if(template_parameters)
478    set(full_class_name "${wrap_class}< ${template_parameters} >")
479  else()
480    set(full_class_name "${wrap_class}")
481  endif()
482
483  itk_wrap_one_type_all_generators("${wrap_method}" "${wrap_class}" "${swig_name}" "${ARGV3}")
484
485  # Add a typedef for the class. We have this funny looking full_name::base_name
486  # thing (it expands to, for example "typedef itk::Foo<baz, 2>::Foo"), to
487  # trick castxml into creating code for the class. If we left off the trailing
488  # base_name, then castxml wouldn't see the typedef as a class instantiation,
489  # and thus wouldn't create XML for any of the methods, etc.
490
491  if("${wrap_method}" MATCHES "2_SUPERCLASSES")
492    itk_wrap_simple_type("${full_class_name}::Superclass::Superclass" "${swig_name}_Superclass_Superclass")
493    itk_wrap_simple_type("${full_class_name}::Superclass::Superclass::Pointer" "${swig_name}_Superclass_Superclass_Pointer")
494  endif()
495
496  if("${wrap_method}" MATCHES "SUPERCLASS")
497    itk_wrap_simple_type("${full_class_name}::Superclass" "${swig_name}_Superclass")
498    itk_wrap_simple_type("${full_class_name}::Superclass::Pointer" "${swig_name}_Superclass_Pointer")
499  endif()
500
501  if("${wrap_method}" MATCHES "CONST_POINTER")
502    # add a const pointer typedef if we are so asked
503    itk_wrap_simple_type("${full_class_name}::ConstPointer" "${swig_name}_ConstPointer")
504  endif()
505
506  itk_wrap_simple_type("${full_class_name}" "${swig_name}")
507
508  if("${wrap_method}" MATCHES "POINTER")
509    if("${wrap_method}" STREQUAL "AUTOPOINTER")
510      # add a pointer typedef if we are so asked
511      itk_wrap_simple_type("${full_class_name}::SelfAutoPointer" "${swig_name}_AutoPointer")
512    else()
513      # add a pointer typedef if we are so asked
514      itk_wrap_simple_type("${full_class_name}::Pointer" "${swig_name}_Pointer")
515    endif()
516  endif()
517
518endmacro()
519
520
521
522################################################################################
523# Macros which cause one or more template instantiations to be added to the
524# WRAPPER_TEMPLATES list. This list is initialized by the macro itk_wrap_class above,
525# and used by the macro itk_end_wrap_class to produce the wrap_xxx.cxx files with
526# the correct templates. These cxx files serve as the Swig inputs.
527################################################################################
528
529macro(itk_wrap_template name types)
530  # This is the fundamental macro for adding a template to be wrapped.
531  # 'name' is a mangled suffix to be added to the class name (defined in itk_wrap_class)
532  # to uniquely identify this instantiation.
533  # 'types' is a comma-separated list of the template parameters (in C++ form),
534  # some common parameters (e.g. for images) are stored in variables by
535  # WrapBasicTypes.cmake and WrapITKTypes.cmake.
536  #
537  # The format of the WRAPPER_TEMPLATES list is a series of "name # types" strings
538  # (because there's no CMake support for nested lists, name and types are
539  # separated out from the strings with a regex).
540  #
541  # Global vars used: WRAPPER_TEMPLATES
542  # Global vars modified: WRAPPER_TEMPLATES
543
544#   list(APPEND WRAPPER_TEMPLATES "${name} # ${types}")
545  set(WRAPPER_WARN_ABOUT_NO_TEMPLATE OFF)
546  itk_wrap_one_type("${WRAPPER_WRAP_METHOD}" "${WRAPPER_CLASS}" "${WRAPPER_SWIG_NAME}${name}" "${types}")
547  itk_wrap_template_all_generators("${name}" "${types}")
548endmacro()
549
550###################################
551# Macros for wrapping image filters
552###################################
553
554# First, a set of convenience macros for wrapping an image filter with all
555# user-selected image types of a given class. These macros take a 'param_count'
556# parameter which indicates how many template parameters the current image filter
557# takes. The parameters are filled with the exact same image type. To wrap image
558# filters which take different image types as different template parameters, use
559# itk_wrap_image_filter_types or itk_wrap_image_filter_combinations.
560# These macros also take an optional second parameter which is a "dimensionality
561# condition" to restrict the dimensions that theis filter will be instantiated
562# for. The condition can either be a single number indicating the one dimension
563# allowed, a list of dimensions that are allowed (either as a single ;-delimited
564# string or just a set of separate parameters), or something of the form "n+"
565# (where n is a number) indicating that instantiations are allowed for dimension
566# n and above.
567
568macro(itk_wrap_image_filter param_types param_count)
569  # itk_wrap_image_filter is a more general macro for wrapping image filters that
570  # need one or more image parameters of the same type. The first parameter to this
571  # macro is a list of image pixel types for which filter instantiations should be
572  # created. The second is a 'param_count' parameter which controls how many image
573  # template parameters are created (see above). The optional third parameter is
574  # a dimensionality condition (see above also).
575  #
576  # E.g. itk_wrap_image_filter("${WRAP_ITK_ALL}" 2) will create template instantiations
577  # of the filter for every pixel type that the user has selected.
578
579  set(have_dim_cond OFF)
580  if(NOT "${ARGN}" STREQUAL "")
581    set(have_dim_cond ON)
582  endif()
583
584  foreach(param_type ${param_types})
585    set(param_list "")
586    foreach(i RANGE 1 ${param_count})
587      list(APPEND param_list ${param_type})
588    endforeach()
589    if(have_dim_cond)
590      itk_wrap_image_filter_types(${param_list} "${ARGN}")
591    else()
592      itk_wrap_image_filter_types(${param_list})
593    endif()
594  endforeach()
595endmacro()
596
597macro(itk_wrap_image_filter_combinations)
598  # itk_wrap_image_filter_combinations takes a variable number of parameters. Each
599  # parameter is a list of image pixel types. Filter instantiations are created
600  # for every combination of different pixel types in different parameters.
601  # A dimensionality condition may be optionally specified as the last parameter.
602  #
603  # E.g. itk_wrap_image_filter_combinations("UC;US" "UC;US") will create:
604  # filter<itk::Image<unsigned char, d>, itk::Image<unsigned char, d> >
605  # filter<itk::Image<unsigned char, d>, itk::Image<unsigned short, d> >
606  # filter<itk::Image<unsigned short, d>, itk::Image<unsigned char, d> >
607  # filter<itk::Image<unsigned short, d>, itk::Image<unsigned short, d> >
608  # where 'd' is the image dimension, for each selected image dimension.
609
610  # First, store the variable args in real varables, not the macro parameters.
611  # Parameters can't be looked up like this: ${ARGV${num}} because they are
612  # textually substituted before the macro is evaluated.
613  set(arg0 ${ARGV0})
614  set(arg1 ${ARGV1})
615  set(arg2 ${ARGV2})
616  set(arg3 ${ARGV3})
617  set(arg4 ${ARGV4})
618  set(arg5 ${ARGV5})
619  set(arg6 ${ARGV6})
620  set(arg7 ${ARGV7})
621  set(arg8 ${ARGV8})
622  set(arg9 ${ARGV9})
623  DECREMENT(last_arg_number ${ARGC})
624
625  # Now see if we have a dimension condition, and if so, note it and remove it
626  # from the list of args that we will process later
627  set(have_dim_cond OFF)
628  set(last_arg "${arg${last_arg_number}}")
629  if("${last_arg}" MATCHES "^[0-9]")
630    # We have a dimensionality condition
631    set(have_dim_cond ON)
632    DECREMENT(last_arg_number ${last_arg_number})
633  endif()
634
635  # Build up a list of all of the combinations of all of the elements in each
636  # argument. Each combinarion is stored as a #-delimited list of pixel types.
637  # The #-delimiter is needed because CMake can't store nested lists.
638  # Also note the need to check for empty lists and note invalidity if so.
639  set(all_args_valid ON)
640  if(NOT arg0)
641    set(all_args_valid OFF)
642  else()
643    set(template_combinations ${arg0})
644  endif()
645
646  foreach(num RANGE 1 ${last_arg_number})
647    set(types "${arg${num}}")
648    if(NOT types)
649      set(all_args_valid OFF)
650    else()
651      set(temp "")
652      foreach(type_list ${template_combinations})
653        foreach(type ${types})
654          list(APPEND temp "${type_list}#${type}")
655        endforeach()
656      endforeach()
657      set(template_combinations ${temp})
658    endif()
659  endforeach()
660
661  if(all_args_valid)
662    foreach(param_set ${template_combinations})
663      # Each param_set is a #-delimited list of pixel types. First thing, we unpack
664      # param_set back to a CMake list (;-delimited). Then we instantiate the filter
665      # for that combination of image pixel types.
666      string(REPLACE "#" ";" param_list "${param_set}")
667      if(have_dim_cond)
668        itk_wrap_image_filter_types(${param_list} "${last_arg}")
669      else()
670        itk_wrap_image_filter_types(${param_list})
671      endif()
672    endforeach()
673  endif()
674endmacro()
675
676
677macro(itk_wrap_image_filter_types)
678  # itk_wrap_image_filter_types creates template instantiations of the current image
679  # filter, for all the selected dimensions (or dimensions that meet the optional
680  # dimensionality condition). This macro takes a variable number of arguments,
681  # which should correspond to the image pixel types of the images in the filter's
682  # template parameter list. The optional dimensionality condition should be
683  # placed in the last parameter.
684
685  # First, store the variable args in real varables, not the macro parameters.
686  # Parameters can't be looked up like this: ${ARGV${num}} because they are
687  # textually substituted before the macro is evaluated.
688  set(arg0 ${ARGV0})
689  set(arg1 ${ARGV1})
690  set(arg2 ${ARGV2})
691  set(arg3 ${ARGV3})
692  set(arg4 ${ARGV4})
693  set(arg5 ${ARGV5})
694  set(arg6 ${ARGV6})
695  set(arg7 ${ARGV7})
696  set(arg8 ${ARGV8})
697  set(arg9 ${ARGV9})
698  DECREMENT(last_arg_number ${ARGC})
699
700  set(last_arg "${arg${last_arg_number}}")
701  if("${last_arg}" MATCHES "^[0-9]")
702    # We have a dimensionality condition
703    itk_wrap_filter_dims(dims "${last_arg}")
704    DECREMENT(last_arg_number ${last_arg_number})
705  else()
706    set(dims ${ITK_WRAP_IMAGE_DIMS})
707  endif()
708
709  set(vec_dims 1)
710  foreach(num RANGE 0 ${last_arg_number})
711    set(type "${arg${num}}")
712    if("${WRAP_ITK_VECTOR}" MATCHES "(^|;)${type}(;|$)")
713      set(vec_dims ${ITK_WRAP_VECTOR_COMPONENTS})
714    endif()
715  endforeach()
716
717  foreach(vec_dim ${vec_dims})
718    foreach(d ${dims})
719      set(template_params "")
720      set(mangled_name "")
721      set(comma "") # Don't add a comma before the first template param!
722      foreach(num RANGE 0 ${last_arg_number})
723        set(type "${arg${num}}")
724        if("${WRAP_ITK_VECTOR}" MATCHES "(^|;)${type}(;|$)")
725          set(type "${type}${vec_dim}")
726        endif()
727        set(image_type ${ITKT_I${type}${d}})
728        set(mangle_type ${ITKM_I${type}${d}})
729        if(NOT DEFINED image_type)
730          message(FATAL_ERROR "Wrapping ${WRAPPER_CLASS}: No image type for '${type}' pixels is known.")
731        endif()
732
733        set(template_params "${template_params}${comma}${image_type}")
734        set(mangled_name "${mangled_name}${mangle_type}")
735        set(comma ", ") # now add commas after the subsequent template params
736      endforeach()
737      itk_wrap_template("${mangled_name}" "${template_params}")
738    endforeach()
739  endforeach()
740endmacro()
741
742
743macro(itk_wrap_filter_dims var_name dimension_condition)
744  # itk_wrap_filter_dims processes a dimension_condition and returns a list of the dimensions
745  # that (a) meet the condition, and (b) were selected to be wrapped. Recall
746  # that the condition is either a CMake list of dimensions, or a string of the
747  # form "n+" where n is a number.
748
749  if("${dimension_condition}" MATCHES "^[0-9]+\\+$")
750    # The condition is of the form "n+". Make a list of the
751    # selected wrapping dims that are >= that number.
752    string(REGEX REPLACE "^([0-9]+)\\+$" "\\1" min_dim "${dimension_condition}")
753    DECREMENT(max_disallowed ${min_dim})
754    set(${var_name} "")
755    foreach(d ${ITK_WRAP_IMAGE_DIMS})
756      if("${d}" GREATER "${max_disallowed}")
757        set(${var_name} ${${var_name}} ${d})
758      endif()
759    endforeach()
760  else()
761    # The condition is just a list of dims. Return the intersection of these
762    # dims with the selected ones.
763    INTERSECTION(${var_name} "${dimension_condition}" "${ITK_WRAP_IMAGE_DIMS}")
764  endif()
765endmacro()
766