# ITK Template optimization + ITKVtkGlue
#
# Using extern template declaration to reduce compile time and memory usage of ITK 
# - see https://arne-mertz.de/2019/02/extern-template-reduce-compile-times/
# - check also ITKFilterAPI.cpp for the actual explicit declaration
# - a similar idea is used in SimpleITK, see https://github.com/SimpleITK/SimpleITK/tree/master/Code/Explicit

# Note : to determine which ITK templates are build in, for instance, itkfilters
# nm -g -C --defined-only build/lib/camitk-?.?/actions/libitkfilters.so | grep itk:: | cut -f3- -d" " | grep "^itk::" | sort -h | less > /tmp/itkfilter-templates

# ITKVtkGlue
#
# ITKVtkGlue provides
# - itkImageToVTKImageFilter.h
# - itkImageToVTKImageFilter.txx
# - itkVTKImageToImageFilter.h
# - itkVTKImageToImageFilter.txx

# FIXME trixie: ITK package (>=5.3) now comes with ITKVtkGlue
# see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1025504 (Fixed in 5.3.0-3)
#
# FIXME CI windows: the currently installed version needs to be rebuild in order to provide ITKVtkGlue
# directly in the ITK includes as well → Enable Module_ITKVtkGlue
# -DModule_ITKVtkGlue:BOOL=ON
#
# When ITKVtkGlue is provided directly by ITK:
# - remove these headers from this directory
# - remove the filename from ITKTEMPLATES_HEADERS below
# - remove NEEDS_CAMITKCORE below
# - remove NEEDS_CEP_LIBRARIES camitkitktemplates in imaging/component/itkimage/CMakeLists.txt
#
# Tag: ITK_VERSION_MAJOR 5, ITK_VERSION_MINOR 3, ITK_VERSION 5.3

#headers
set(ITKTEMPLATES_HEADERS    DefaultPixelAccessor.h
                            FixedArray.h
                            Image.h
                            ImageBase.h
                            ImageBoundaryCondition.h
                            ImageBufferRange.h
                            ImageConstIterator.h
                            ImageRegion.h
                            ImageRegionConstIterator.h
                            ImageScanlineIterator.h
                            ImageScanlineConstIterator.h
                            ImageSource.h
                            ImageToImageFilter.h
                            ImportImageContainer.h
                            InPlaceImageFilter.h
                            ItkTemplatesAPI.h
                            ItkTemplates.h
                            ITKVtkGlue.h
)

# sources files
set(ITKTEMPLATES_SOURCES    ${ITKTEMPLATES_HEADERS}
                            DefaultPixelAccessor.cpp
                            FixedArray.cpp
                            Image.cpp
                            ImageBase.cpp
                            ImageBoundaryCondition.cpp
                            ImageBufferRange.cpp
                            ImageConstIterator.cpp
                            ImageRegion.cpp
                            ImageRegionConstIterator.cpp
                            ImageScanlineIterator.cpp
                            ImageScanlineConstIterator.cpp
                            ImageSource.cpp
                            ImageToImageFilter.cpp
                            ImportImageContainer.cpp
                            InPlaceImageFilter.cpp
                            ITKVtkGlue.cpp
)

# add camitk library
camitk_library(SHARED
               PUBLIC
               LIBNAME camitkitktemplates
               SOURCES ${ITKTEMPLATES_SOURCES}
               HEADERS_TO_INSTALL ${ITKTEMPLATES_HEADERS}
               NEEDS_ITK
               NEEDS_CAMITKCORE # needed to get VTK includes which is required by ITKVtkGlue
               DEFINES COMPILE_ITKFILTER_API
)
