<filename>conanfile.py
import os
import re
import shutil

from conans import ConanFile, CMake, tools
from fnmatch import fnmatch


class LibITKConan(ConanFile):
    name = "itk"
    upstream_version = "4.13"
    upstream_patch = "2"
    package_revision = "-r4"
    version = "{0}.{1}{2}".format(upstream_version, upstream_patch, package_revision)

    generators = "cmake"
    settings = "os", "arch", "compiler", "build_type"
    options = {"shared": [True, False]}
    default_options = {"shared":True, "boost:shared": True, "zlib:shared": False}
    exports = [
        "patches/CMakeProjectWrapper.txt",
        "patches/linux.diff"
    ]
    url = "https://github.com/pollen-metrology/itk-conan"
    license = "http://www.itk.org/licensing/"
    description = "Insight Segmentation and Registration Toolkit"
    source_subfolder = "sf"
    build_subfolder = "build"
    short_paths = True

    def configure(self):
        del self.settings.compiler.libcxx
        if 'CI' not in os.environ:
            os.environ["CONAN_SYSREQUIRES_MODE"] = "verify"

    def requirements(self):

        if not tools.os_info.is_linux:
            self.requires("libjpeg/9c@bincrafters/stable")
            self.requires("libpng/1.6.37@bincrafters/stable")
            self.requires("libtiff/4.0.9@bincrafters/stable")

        if tools.os_info.is_windows:
            self.requires("Expat/2.2.6@pix4d/stable")
            self.requires("zlib/1.2.11@conan/stable")

    def build_requirements(self):
        if tools.os_info.linux_distro == "linuxmint":
            pack_names = [
                "libexpat1-dev",
                "libjpeg-turbo8-dev",
                "libtiff5-dev"
            ]
            if tools.os_info.os_version.major(fill=False) == "18":
                pack_names.append("libpng12-dev")
            elif tools.os_info.os_version.major(fill=False) == "19":
                pack_names.append("libpng-dev")
            installer = tools.SystemPackageTool()
            for p in pack_names:
                installer.install(p)

    def system_requirements(self):
        if tools.os_info.linux_distro == "linuxmint":
            pack_names = [
                "libexpat1",
                "libjpeg-turbo8",
                "libtiff5"
            ]
            if tools.os_info.os_version.major(fill=False) == "18":
                pack_names.append("libpng12-0")
            elif tools.os_info.os_version.major(fill=False) == "19":
                pack_names.append("libpng16-16")
            installer = tools.SystemPackageTool()
            for p in pack_names:
                installer.install(p)

    def source(self):
        tools.get("https://github.com/InsightSoftwareConsortium/ITK/archive/v{0}.{1}.tar.gz".format(self.upstream_version, self.upstream_patch))
        os.rename("ITK-{0}.{1}".format(self.upstream_version, self.upstream_patch), self.source_subfolder)

    def build(self):
        itk_source_dir = os.path.join(self.source_folder, self.source_subfolder)
        shutil.move("patches/CMakeProjectWrapper.txt", "CMakeLists.txt")
        tools.patch(itk_source_dir, "patches/linux.diff")

        cmake = CMake(self)
        
        # Set common flags
        #cmake.definitions["SIGHT_CMAKE_C_FLAGS"] = common.get_c_flags()
        #cmake.definitions["SIGHT_CMAKE_CXX_FLAGS"] = common.get_cxx_flags()
        
        cmake.definitions["BUILD_EXAMPLES"] = "OFF"
        cmake.definitions["BUILD_SHARED_LIBS"] = self.options.shared
        cmake.definitions["BUILD_TESTING"] = "OFF"
        cmake.definitions["BUILD_DOCUMENTATION"] = "OFF"
        cmake.definitions["ITK_USE_REVIEW"] = "ON"
        cmake.definitions["ITK_SKIP_PATH_LENGTH_CHECKS"] = "ON"

        cmake.definitions["ITK_USE_SYSTEM_DCMTK"] = "OFF"
        cmake.definitions["ITK_USE_SYSTEM_GDCM"] = "OFF"
        cmake.definitions["ITK_USE_SYSTEM_PNG"] = "ON"
        cmake.definitions["ITK_USE_SYSTEM_TIFF"] = "ON"
        cmake.definitions["ITK_USE_SYSTEM_ZLIB"] = "ON"
        cmake.definitions["ITK_USE_SYSTEM_JPEG"] = "ON"
        cmake.definitions["ITK_USE_SYSTEM_EXPAT"] = "ON"

        cmake.definitions["ITK_BUILD_DEFAULT_MODULES"] = "OFF"
        cmake.definitions["Module_ITKDeprecated"] = "OFF"
        cmake.definitions["Module_ITKMINC"] = "OFF"
        cmake.definitions["Module_ITKIOMINC"] = "OFF"
        cmake.definitions["Module_ITKV3Compatibility"] = "OFF"
        cmake.definitions["Module_ITKVideoBridgeOpenCV"] = "OFF"
        cmake.definitions["Module_ITKDCMTK"] = "OFF"
        cmake.definitions["Module_ITKIODCMTK"] = "OFF"
        cmake.definitions["Module_ITKIOHDF5"] = "OFF"
        cmake.definitions["Module_ITKIOTransformHDF5"] = "OFF"

        cmake.definitions["Module_ITKAnisotropicSmoothing"] = "ON"
        cmake.definitions["Module_ITKAntiAlias"] = "ON"
        cmake.definitions["Module_ITKBiasCorrection"] = "ON"
        cmake.definitions["Module_ITKBinaryMathematicalMorphology"] = "ON"
        cmake.definitions["Module_ITKBioCell"] = "ON"
        cmake.definitions["Module_ITKClassifiers"] = "ON"
        cmake.definitions["Module_ITKColormap"] = "ON"
        cmake.definitions["Module_ITKConnectedComponents"] = "ON"
        cmake.definitions["Module_ITKConvolution"] = "ON"
        cmake.definitions["Module_ITKCurvatureFlow"] = "ON"
        cmake.definitions["Module_ITKDeconvolution"] = "ON"
        cmake.definitions["Module_ITKDeformableMesh"] = "ON"
        cmake.definitions["Module_ITKDenoising"] = "ON"
        cmake.definitions["Module_ITKDiffusionTensorImage"] = "ON"
        cmake.definitions["Module_ITKDisplacementField"] = "ON"
        cmake.definitions["Module_ITKDistanceMap"] = "ON"
        cmake.definitions["Module_ITKEigen"] = "ON"
        cmake.definitions["Module_ITKFEM"] = "ON"
        cmake.definitions["Module_ITKFEMRegistration"] = "ON"
        cmake.definitions["Module_ITKFFT"] = "ON"
        cmake.definitions["Module_ITKFastMarching"] = "ON"
        cmake.definitions["Module_ITKGIFTI"] = "ON"
        cmake.definitions["Module_ITKGPUAnisotropicSmoothing"] = "ON"
        cmake.definitions["Module_ITKGPUImageFilterBase"] = "ON"
        cmake.definitions["Module_ITKGPUPDEDeformableRegistration"] = "ON"
        cmake.definitions["Module_ITKGPURegistrationCommon"] = "ON"
        cmake.definitions["Module_ITKGPUSmoothing"] = "ON"
        cmake.definitions["Module_ITKGPUThresholding"] = "ON"
        cmake.definitions["Module_ITKIOCSV"] = "ON"
        cmake.definitions["Module_ITKIOGE"] = "ON"
        cmake.definitions["Module_ITKIOIPL"] = "ON"
        cmake.definitions["Module_ITKIOMesh"] = "ON"
        cmake.definitions["Module_ITKIOPhilipsREC"] = "ON"
        cmake.definitions["Module_ITKIORAW"] = "ON"
        cmake.definitions["Module_ITKIOSiemens"] = "ON"
        cmake.definitions["Module_ITKIOSpatialObjects"] = "ON"
        cmake.definitions["Module_ITKIOTransformBase"] = "ON"
        cmake.definitions["Module_ITKIOTransformInsightLegacy"] = "ON"
        cmake.definitions["Module_ITKIOTransformMatlab"] = "ON"
        cmake.definitions["Module_ITKIOXML"] = "ON"
        cmake.definitions["Module_ITKImageCompare"] = "ON"
        cmake.definitions["Module_ITKImageCompose"] = "ON"
        cmake.definitions["Module_ITKImageFeature"] = "ON"
        cmake.definitions["Module_ITKImageFusion"] = "ON"
        cmake.definitions["Module_ITKImageGradient"] = "ON"
        cmake.definitions["Module_ITKImageGrid"] = "ON"
        cmake.definitions["Module_ITKImageIntensity"] = "ON"
        cmake.definitions["Module_ITKImageLabel"] = "ON"
        cmake.definitions["Module_ITKImageSources"] = "ON"
        cmake.definitions["Module_ITKImageStatistics"] = "ON"
        cmake.definitions["Module_ITKIntegratedTest"] = "ON"
        cmake.definitions["Module_ITKKLMRegionGrowing"] = "ON"
        cmake.definitions["Module_ITKLabelMap"] = "ON"
        cmake.definitions["Module_ITKLabelVoting"] = "ON"
        cmake.definitions["Module_ITKLevelSets"] = "ON"
        cmake.definitions["Module_ITKLevelSetsv4"] = "ON"

        cmake.definitions["Module_ITKMarkovRandomFieldsClassifiers"] = "ON"
        cmake.definitions["Module_ITKMathematicalMorphology"] = "ON"
        cmake.definitions["Module_ITKMetricsv4"] = "ON"
        cmake.definitions["Module_ITKNarrowBand"] = "ON"
        cmake.definitions["Module_ITKNeuralNetworks"] = "ON"
        cmake.definitions["Module_ITKOptimizers"] = "ON"
        cmake.definitions["Module_ITKOptimizersv4"] = "ON"
        cmake.definitions["Module_ITKPDEDeformableRegistration"] = "ON"
        cmake.definitions["Module_ITKPath"] = "ON"
        cmake.definitions["Module_ITKPolynomials"] = "ON"
        cmake.definitions["Module_ITKQuadEdgeMeshFiltering"] = "ON"
        cmake.definitions["Module_ITKRegionGrowing"] = "ON"
        cmake.definitions["Module_ITKRegistrationCommon"] = "ON"
        cmake.definitions["Module_ITKRegistrationMethodsv4"] = "ON"
        cmake.definitions["Module_ITKReview"] = "ON"
        cmake.definitions["Module_ITKSignedDistanceFunction"] = "ON"
        cmake.definitions["Module_ITKSmoothing"] = "ON"
        cmake.definitions["Module_ITKSpatialFunction"] = "ON"
        cmake.definitions["Module_ITKThresholding"] = "ON"

        cmake.definitions["Module_ITKVideoCore"] = "OFF"
        cmake.definitions["Module_ITKVideoFiltering"] = "OFF"
        cmake.definitions["Module_ITKVideoIO"] = "OFF"
        cmake.definitions["Module_ITKVoronoi"] = "ON"
        cmake.definitions["Module_ITKVTK"] = "OFF"
        cmake.definitions["Module_ITKWatersheds"] = "ON"
        cmake.definitions["Module_ITKDICOMParser"] = "OFF"

        # Disabled on Linux (link errors)
        cmake.definitions["Module_ITKLevelSetsv4Visualization"] = "OFF"
        cmake.definitions["Module_ITKVtkGlue"] = "OFF"

        # Disabled because Vxl vidl is not build anymore
        cmake.definitions["Module_ITKVideoBridgeVXL"] = "OFF"

        if not tools.os_info.is_windows:
            cmake.definitions["CMAKE_POSITION_INDEPENDENT_CODE"] = "ON"
        cmake.configure(build_folder=self.build_subfolder)
        cmake.build()
        cmake.install()

    def cmake_fix_macos_sdk_path(self, file_path):
        # Read in the file
        with open(file_path, 'r') as file:
            file_data = file.read()

        if file_data:
            # Replace the target string
            file_data = re.sub(
                # Match sdk path
                r';/Applications/Xcode\.app/Contents/Developer/Platforms/MacOSX\.platform/Developer/SDKs/MacOSX\d\d\.\d\d\.sdk/usr/include',
                '',
                file_data,
                re.M
            )

            # Write the file out again
            with open(file_path, 'w') as file:
                file.write(file_data)

    def cmake_fix_path(self, file_path, package_name):
        try:
            tools.replace_in_file(
                file_path,
                self.deps_cpp_info[package_name].rootpath.replace('\\', '/'),
                "${CONAN_" + package_name.upper() + "_ROOT}",
                strict=False
            )
        except:
            self.output.info("Ignoring {0}...".format(package_name))

    def package(self):
        for path, subdirs, names in os.walk(self.package_folder):
            for name in names:
                if fnmatch(name, '*.cmake'):
                    cmake_file = os.path.join(path, name)
                    
                    tools.replace_in_file(
                        cmake_file, 
                        self.package_folder.replace('\\', '/'), 
                        '${CONAN_ITK_ROOT}', 
                        strict=False
                    )
                    
                    self.cmake_fix_path(cmake_file, "gdcm")
                    self.cmake_fix_path(cmake_file, "libjpeg")
                    self.cmake_fix_path(cmake_file, "libpng")
                    self.cmake_fix_path(cmake_file, "libtiff")
                    self.cmake_fix_path(cmake_file, "zlib")
                    self.cmake_fix_path(cmake_file, "expat")

                    if tools.os_info.is_macos:
                        self.cmake_fix_macos_sdk_path(cmake_file)

    def package_info(self):
        self.cpp_info.libs = tools.collect_libs(self)
        self.cpp_info.includedirs = ['include']
        # This hack allow to include directly, for example, a vnl
        # file using `#include <vln/...>`
        # Without the hack, the vln files cannot themselves include
        # files using `#include<vnl/..>` since only <ITK-xx/vnl/...> is
        # available. More, one has to add in CMakeLists.txt
        # include_directories(${CONAN_INCLUDE_DIRS_ITK_SUB})
        # to finish the use of this hack.
        self.cpp_info.sub.includedirs = ['include/ITK-{0}'.format(self.upstream_version)]

<filename>conanfile.py
import os
import re
import shutil

from conans import ConanFile, CMake, tools
from fnmatch import fnmatch


class LibITKConan(ConanFile):
    name = "itk"
    upstream_version = "4.13"
    upstream_patch = "2"
    package_revision = "-r4"
    version = "{0}.{1}{2}".format(upstream_version, upstream_patch, package_revision)

    generators = "cmake"
    settings = "os", "arch", "compiler", "build_type"
    options = {"shared": [True, False]}
    default_options = {"shared":True, "boost:shared": True, "zlib:shared": False}
    exports = [
        "patches/CMakeProjectWrapper.txt",
        "patches/linux.diff"
    ]
    url = "https://github.com/pollen-metrology/itk-conan"
    license = "http://www.itk.org/licensing/"
    description = "Insight Segmentation and Registration Toolkit"
    source_subfolder = "sf"
    build_subfolder = "build"
    short_paths = True

    def configure(self):
        del self.settings.compiler.libcxx
        if 'CI' not in os.environ:
            os.environ["CONAN_SYSREQUIRES_MODE"] = "verify"

    def requirements(self):

        if not tools.os_info.is_linux:
            self.requires("libjpeg/9c@bincrafters/stable")
            self.requires("libpng/1.6.37@bincrafters/stable")
            self.requires("libtiff/4.0.9@bincrafters/stable")

        if tools.os_info.is_windows:
            self.requires("Expat/2.2.6@pix4d/stable")
            self.requires("zlib/1.2.11@conan/stable")

    def build_requirements(self):
        if tools.os_info.linux_distro == "linuxmint":
            pack_names = [
                "libexpat1-dev",
                "libjpeg-turbo8-dev",
                "libtiff5-dev"
            ]
            if tools.os_info.os_version.major(fill=False) == "18":
                pack_names.append("libpng12-dev")
            elif tools.os_info.os_version.major(fill=False) == "19":
                pack_names.append("libpng-dev")
            installer = tools.SystemPackageTool()
            for p in pack_names:
                installer.install(p)

    def system_requirements(self):
        if tools.os_info.linux_distro == "linuxmint":
            pack_names = [
                "libexpat1",
                "libjpeg-turbo8",
                "libtiff5"
            ]
            if tools.os_info.os_version.major(fill=False) == "18":
                pack_names.append("libpng12-0")
            elif tools.os_info.os_version.major(fill=False) == "19":
                pack_names.append("libpng16-16")
            installer = tools.SystemPackageTool()
            for p in pack_names:
                installer.install(p)

    def source(self):
        tools.get("https://github.com/InsightSoftwareConsortium/ITK/archive/v{0}.{1}.tar.gz".format(self.upstream_version, self.upstream_patch))
        os.rename("ITK-{0}.{1}".format(self.upstream_version, self.upstream_patch), self.source_subfolder)

    def build(self):
        itk_source_dir = os.path.join(self.source_folder, self.source_subfolder)
        shutil.move("patches/CMakeProjectWrapper.txt", "CMakeLists.txt")
        tools.patch(itk_source_dir, "patches/linux.diff")

        cmake = CMake(self)
        
        # Set common flags
        #cmake.definitions["SIGHT_CMAKE_C_FLAGS"] = common.get_c_flags()
        #cmake.definitions["SIGHT_CMAKE_CXX_FLAGS"] = common.get_cxx_flags()
        
        cmake.definitions["BUILD_EXAMPLES"] = "OFF"
        cmake.definitions["BUILD_SHARED_LIBS"] = self.options.shared
        cmake.definitions["BUILD_TESTING"] = "OFF"
        cmake.definitions["BUILD_DOCUMENTATION"] = "OFF"
        cmake.definitions["ITK_USE_REVIEW"] = "ON"
        cmake.definitions["ITK_SKIP_PATH_LENGTH_CHECKS"] = "ON"

        cmake.definitions["ITK_USE_SYSTEM_DCMTK"] = "OFF"
        cmake.definitions["ITK_USE_SYSTEM_GDCM"] = "OFF"
        cmake.definitions["ITK_USE_SYSTEM_PNG"] = "ON"
        cmake.definitions["ITK_USE_SYSTEM_TIFF"] = "ON"
        cmake.definitions["ITK_USE_SYSTEM_ZLIB"] = "ON"
        cmake.definitions["ITK_USE_SYSTEM_JPEG"] = "ON"
        cmake.definitions["ITK_USE_SYSTEM_EXPAT"] = "ON"

        cmake.definitions["ITK_BUILD_DEFAULT_MODULES"] = "OFF"
        cmake.definitions["Module_ITKDeprecated"] = "OFF"
        cmake.definitions["Module_ITKMINC"] = "OFF"
        cmake.definitions["Module_ITKIOMINC"] = "OFF"
        cmake.definitions["Module_ITKV3Compatibility"] = "OFF"
        cmake.definitions["Module_ITKVideoBridgeOpenCV"] = "OFF"
        cmake.definitions["Module_ITKDCMTK"] = "OFF"
        cmake.definitions["Module_ITKIODCMTK"] = "OFF"
        cmake.definitions["Module_ITKIOHDF5"] = "OFF"
        cmake.definitions["Module_ITKIOTransformHDF5"] = "OFF"

        cmake.definitions["Module_ITKAnisotropicSmoothing"] = "ON"
        cmake.definitions["Module_ITKAntiAlias"] = "ON"
        cmake.definitions["Module_ITKBiasCorrection"] = "ON"
        cmake.definitions["Module_ITKBinaryMathematicalMorphology"] = "ON"
        cmake.definitions["Module_ITKBioCell"] = "ON"
        cmake.definitions["Module_ITKClassifiers"] = "ON"
        cmake.definitions["Module_ITKColormap"] = "ON"
        cmake.definitions["Module_ITKConnectedComponents"] = "ON"
        cmake.definitions["Module_ITKConvolution"] = "ON"
        cmake.definitions["Module_ITKCurvatureFlow"] = "ON"
        cmake.definitions["Module_ITKDeconvolution"] = "ON"
        cmake.definitions["Module_ITKDeformableMesh"] = "ON"
        cmake.definitions["Module_ITKDenoising"] = "ON"
        cmake.definitions["Module_ITKDiffusionTensorImage"] = "ON"
        cmake.definitions["Module_ITKDisplacementField"] = "ON"
        cmake.definitions["Module_ITKDistanceMap"] = "ON"
        cmake.definitions["Module_ITKEigen"] = "ON"
        cmake.definitions["Module_ITKFEM"] = "ON"
        cmake.definitions["Module_ITKFEMRegistration"] = "ON"
        cmake.definitions["Module_ITKFFT"] = "ON"
        cmake.definitions["Module_ITKFastMarching"] = "ON"
        cmake.definitions["Module_ITKGIFTI"] = "ON"
        cmake.definitions["Module_ITKGPUAnisotropicSmoothing"] = "ON"
        cmake.definitions["Module_ITKGPUImageFilterBase"] = "ON"
        cmake.definitions["Module_ITKGPUPDEDeformableRegistration"] = "ON"
        cmake.definitions["Module_ITKGPURegistrationCommon"] = "ON"
        cmake.definitions["Module_ITKGPUSmoothing"] = "ON"
        cmake.definitions["Module_ITKGPUThresholding"] = "ON"
        cmake.definitions["Module_ITKIOCSV"] = "ON"
        cmake.definitions["Module_ITKIOGE"] = "ON"
        cmake.definitions["Module_ITKIOIPL"] = "ON"
        cmake.definitions["Module_ITKIOMesh"] = "ON"
        cmake.definitions["Module_ITKIOPhilipsREC"] = "ON"
        cmake.definitions["Module_ITKIORAW"] = "ON"
        cmake.definitions["Module_ITKIOSiemens"] = "ON"
        cmake.definitions["Module_ITKIOSpatialObjects"] = "ON"
        cmake.definitions["Module_ITKIOTransformBase"] = "ON"
        cmake.definitions["Module_ITKIOTransformInsightLegacy"] = "ON"
        cmake.definitions["Module_ITKIOTransformMatlab"] = "ON"
        cmake.definitions["Module_ITKIOXML"] = "ON"
        cmake.definitions["Module_ITKImageCompare"] = "ON"
        cmake.definitions["Module_ITKImageCompose"] = "ON"
        cmake.definitions["Module_ITKImageFeature"] = "ON"
        cmake.definitions["Module_ITKImageFusion"] = "ON"
        cmake.definitions["Module_ITKImageGradient"] = "ON"
        cmake.definitions["Module_ITKImageGrid"] = "ON"
        cmake.definitions["Module_ITKImageIntensity"] = "ON"
        cmake.definitions["Module_ITKImageLabel"] = "ON"
        cmake.definitions["Module_ITKImageSources"] = "ON"
        cmake.definitions["Module_ITKImageStatistics"] = "ON"
        cmake.definitions["Module_ITKIntegratedTest"] = "ON"
        cmake.definitions["Module_ITKKLMRegionGrowing"] = "ON"
        cmake.definitions["Module_ITKLabelMap"] = "ON"
        cmake.definitions["Module_ITKLabelVoting"] = "ON"
        cmake.definitions["Module_ITKLevelSets"] = "ON"
        cmake.definitions["Module_ITKLevelSetsv4"] = "ON"

        cmake.definitions["Module_ITKMarkovRandomFieldsClassifiers"] = "ON"
        cmake.definitions["Module_ITKMathematicalMorphology"] = "ON"
        cmake.definitions["Module_ITKMetricsv4"] = "ON"
        cmake.definitions["Module_ITKNarrowBand"] = "ON"
        cmake.definitions["Module_ITKNeuralNetworks"] = "ON"
        cmake.definitions["Module_ITKOptimizers"] = "ON"
        cmake.definitions["Module_ITKOptimizersv4"] = "ON"
        cmake.definitions["Module_ITKPDEDeformableRegistration"] = "ON"
        cmake.definitions["Module_ITKPath"] = "ON"
        cmake.definitions["Module_ITKPolynomials"] = "ON"
        cmake.definitions["Module_ITKQuadEdgeMeshFiltering"] = "ON"
        cmake.definitions["Module_ITKRegionGrowing"] = "ON"
        cmake.definitions["Module_ITKRegistrationCommon"] = "ON"
        cmake.definitions["Module_ITKRegistrationMethodsv4"] = "ON"
        cmake.definitions["Module_ITKReview"] = "ON"
        cmake.definitions["Module_ITKSignedDistanceFunction"] = "ON"
        cmake.definitions["Module_ITKSmoothing"] = "ON"
        cmake.definitions["Module_ITKSpatialFunction"] = "ON"
        cmake.definitions["Module_ITKThresholding"] = "ON"

        cmake.definitions["Module_ITKVideoCore"] = "OFF"
        cmake.definitions["Module_ITKVideoFiltering"] = "OFF"
        cmake.definitions["Module_ITKVideoIO"] = "OFF"
        cmake.definitions["Module_ITKVoronoi"] = "ON"
        cmake.definitions["Module_ITKVTK"] = "OFF"
        cmake.definitions["Module_ITKWatersheds"] = "ON"
        cmake.definitions["Module_ITKDICOMParser"] = "OFF"

        # Disabled on Linux (link errors)
        cmake.definitions["Module_ITKLevelSetsv4Visualization"] = "OFF"
        cmake.definitions["Module_ITKVtkGlue"] = "OFF"

        # Disabled because Vxl vidl is not build anymore
        cmake.definitions["Module_ITKVideoBridgeVXL"] = "OFF"

        if not tools.os_info.is_windows:
            cmake.definitions["CMAKE_POSITION_INDEPENDENT_CODE"] = "ON"
        cmake.configure(build_folder=self.build_subfolder)
        cmake.build()
        cmake.install()

    def cmake_fix_macos_sdk_path(self, file_path):
        # Read in the file
        with open(file_path, 'r') as file:
            file_data = file.read()

        if file_data:
            # Replace the target string
            file_data = re.sub(
                # Match sdk path
                r';/Applications/Xcode\.app/Contents/Developer/Platforms/MacOSX\.platform/Developer/SDKs/MacOSX\d\d\.\d\d\.sdk/usr/include',
                '',
                file_data,
                re.M
            )

            # Write the file out again
            with open(file_path, 'w') as file:
                file.write(file_data)

    def cmake_fix_path(self, file_path, package_name):
        try:
            tools.replace_in_file(
                file_path,
                self.deps_cpp_info[package_name].rootpath.replace('\\', '/'),
                "${CONAN_" + package_name.upper() + "_ROOT}",
                strict=False
            )
        except:
            self.output.info("Ignoring {0}...".format(package_name))

    def package(self):
        for path, subdirs, names in os.walk(self.package_folder):
            for name in names:
                if fnmatch(name, '*.cmake'):
                    cmake_file = os.path.join(path, name)
                    
                    tools.replace_in_file(
                        cmake_file, 
                        self.package_folder.replace('\\', '/'), 
                        '${CONAN_ITK_ROOT}', 
                        strict=False
                    )
                    
                    self.cmake_fix_path(cmake_file, "gdcm")
                    self.cmake_fix_path(cmake_file, "libjpeg")
                    self.cmake_fix_path(cmake_file, "libpng")
                    self.cmake_fix_path(cmake_file, "libtiff")
                    self.cmake_fix_path(cmake_file, "zlib")
                    self.cmake_fix_path(cmake_file, "expat")

                    if tools.os_info.is_macos:
                        self.cmake_fix_macos_sdk_path(cmake_file)

    def package_info(self):
        self.cpp_info.libs = tools.collect_libs(self)
        self.cpp_info.includedirs = ['include']
        # This hack allow to include directly, for example, a vnl
        # file using `#include <vln/...>`
        # Without the hack, the vln files cannot themselves include
        # files using `#include<vnl/..>` since only <ITK-xx/vnl/...> is
        # available. More, one has to add in CMakeLists.txt
        # include_directories(${CONAN_INCLUDE_DIRS_ITK_SUB})
        # to finish the use of this hack.
        self.cpp_info.sub.includedirs = ['include/ITK-{0}'.format(self.upstream_version)]

# Set common flags #cmake.definitions["SIGHT_CMAKE_C_FLAGS"] = common.get_c_flags() #cmake.definitions["SIGHT_CMAKE_CXX_FLAGS"] = common.get_cxx_flags() # Disabled on Linux (link errors) # Disabled because Vxl vidl is not build anymore # Read in the file # Replace the target string # Match sdk path # Write the file out again # This hack allow to include directly, for example, a vnl # file using `#include <vln/...>` # Without the hack, the vln files cannot themselves include # files using `#include<vnl/..>` since only <ITK-xx/vnl/...> is # available. More, one has to add in CMakeLists.txt # include_directories(${CONAN_INCLUDE_DIRS_ITK_SUB}) # to finish the use of this hack.