External_ITK.cmake 4.69 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
message(STATUS "Setup ITK...")

set(proj ITK)

# Use an external version of ITK by default except on windows (ITK is not packaged in OSGeo4W)
set(DEFAULT_USE_SYSTEM_ITK OFF)

option(USE_SYSTEM_ITK "Use a system build of ITK." ${DEFAULT_USE_SYSTEM_ITK})
mark_as_advanced(USE_SYSTEM_ITK)

if(USE_SYSTEM_ITK)
  message(STATUS "  Using ITK system version")
else()
14
  SETUP_SUPERBUILD(PROJECT ${proj})
15
  
16
  # if(MSVC)
17 18
    # set(ITK_SB_SRC "C:/Temp/ITK")
    # set(ITK_SB_BUILD_DIR ${ITK_SB_SRC}/build)
19
  # endif()
20
  
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
  set(ITK_ENABLED_MODULES
    Common
    FiniteDifference
    GPUCommon
    GPUFiniteDifference
    ImageAdaptors
    ImageFunction
    Mesh
    QuadEdgeMesh
    SpatialObjects
    #TestKernel
    Transform

    AnisotropicSmoothing
    AntiAlias
    BiasCorrection
    BinaryMathematicalMorphology
    Colormap
    Convolution
    CurvatureFlow
    Deconvolution
    Denoising
    #DiffusionTensorImage
    DisplacementField
    DistanceMap
    FastMarching
    FFT
    GPUAnisotropicSmoothing
    GPUImageFilterBase
    GPUSmoothing
    GPUThresholding
    ImageCompare
    ImageCompose
    ImageFeature
    ImageFilterBase
    ImageFusion
    ImageGradient
    ImageGrid
    ImageIntensity
    ImageLabel
    ImageSources
    ImageStatistics
    LabelMap
    MathematicalMorphology
    Path
    QuadEdgeMeshFiltering
    Smoothing
    SpatialFunction
    Thresholding

    Eigen
    #FEM
    NarrowBand
    NeuralNetworks
    Optimizers
    Optimizersv4
    Polynomials
    Statistics

    RegistrationCommon
    #FEMRegistration
    GPURegistrationCommon
    GPUPDEDeformableRegistration
    Metricsv4
    PDEDeformableRegistration
    RegistrationMethodsv4

    #BioCell
    Classifiers
    ConnectedComponents
    DeformableMesh
    KLMRegionGrowing
    LabelVoting
    LevelSets
    LevelSetsv4
    #LevelSetsv4Visualization
    MarkovRandomFieldsClassifiers
    RegionGrowing
    SignedDistanceFunction
    Voronoi
    Watersheds
    )
  
  set(ITK_MODULES_CMAKE_CACHE)
  foreach(ITK_MODULE ${ITK_ENABLED_MODULES})
    list(APPEND ITK_MODULES_CMAKE_CACHE -DModule_ITK${ITK_MODULE}:BOOL=ON)
  endforeach()
  
  # By default activate FFTW, but with an external fftw build
  # These variables are used in ITK to initialize the value of the ITK_USE_FFTW_XXX options
  if (WIN32)
112 113 114 115
    set(ITK_SB_FFTW_CONFIG 
      -DUSE_FFTWF:BOOL=OFF
      -DUSE_FFTWD:BOOL=OFF
      )
116
  else()
117 118 119 120 121 122 123 124 125
    set(ITK_SB_FFTW_CONFIG 
      -DUSE_FFTWF:BOOL=ON
      -DUSE_FFTWD:BOOL=ON
      -DUSE_SYSTEM_FFTW:BOOL=ON
      )
    if (NOT USE_SYSTEM_FFTW)
      set(ITK_SB_FFTW_CONFIG ${ITK_SB_FFTW_CONFIG}
        -DFFTW_INCLUDE_PATH:PATH=${CMAKE_INSTALL_PREFIX}/include
        )
126 127
      list(APPEND ${proj}_DEPENDENCIES FFTWF)
      list(APPEND ${proj}_DEPENDENCIES FFTWD)
128
    endif()
129 130 131 132
  endif()
  
  # TODO : handle different build type (Release/Debug)
  
133
  if(USE_SYSTEM_TIFF)
134
    list(APPEND ITK_SB_CONFIG ${SYSTEM_ITK_CMAKE_CACHE})
135 136 137 138
  else()
    list(APPEND ${proj}_DEPENDENCIES TIFF)
  endif()
  
139 140
  if(USE_SYSTEM_EXPAT)
    # TODO : handle specific prefix
141 142 143 144
  else()
    list(APPEND ${proj}_DEPENDENCIES EXPAT)
  endif()
  
145 146
  if(USE_SYSTEM_PNG)
    # TODO : handle specific prefix
147 148 149 150
  else()
    list(APPEND ${proj}_DEPENDENCIES EXPAT)
  endif()
  
151 152
  if(USE_SYSTEM_ZLIB)
    # TODO : handle specific prefix
153 154 155 156 157
  else()
    list(APPEND ${proj}_DEPENDENCIES ZLIB)
  endif()
  
  if(MSVC)
158
    
159
  endif()
160 161 162 163 164
  
  ExternalProject_Add(${proj}
    PREFIX ${proj}
    URL "http://sourceforge.net/projects/itk/files/itk/4.6/InsightToolkit-4.6.1.tar.gz/download"
    URL_MD5 2c84eae50ab2452cdad32aaadced3c37
165
    SOURCE_DIR ${ITK_SB_SRC}
166 167 168 169 170 171 172 173
    BINARY_DIR ${ITK_SB_BUILD_DIR}
    INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
    CMAKE_CACHE_ARGS
      -DCMAKE_INSTALL_PREFIX:STRING=${CMAKE_INSTALL_PREFIX}
      -DCMAKE_BUILD_TYPE:STRING=Release
      -DITK_BUILD_DEFAULT_MODULES:BOOL=OFF
      ${ITK_MODULES_CMAKE_CACHE}
      -DITKGroup_Core:BOOL=OFF
174
      -DBUILD_SHARED_LIBS:BOOL=${SB_BUILD_SHARED_LIBS}
175 176
      -DBUILD_TESTING:BOOL=OFF
      -DBUILD_EXAMPLES:BOOL=OFF
177
      -DCMAKE_PREFIX_PATH:STRING=${CMAKE_INSTALL_PREFIX};${CMAKE_PREFIX_PATH}
178
      -DITK_USE_SYSTEM_EXPAT:BOOL=ON
179 180 181
      -DITK_USE_SYSTEM_ZLIB:BOOL=ON
      -DITK_USE_SYSTEM_TIFF:BOOL=ON
      -DITK_USE_SYSTEM_PNG:BOOL=ON
182
      ${ITK_SB_FFTW_CONFIG}
183
      ${ITK_SB_CONFIG}
184
    PATCH_COMMAND ${CMAKE_COMMAND} -E copy 
185
      ${CMAKE_SOURCE_DIR}/patches/ITK/hashtable.hxx.in
186
      ${ITK_SB_SRC}/Modules/ThirdParty/KWSys/src/KWSys
187
    DEPENDS ${${proj}_DEPENDENCIES}
188 189 190 191 192
    )
  
  # write patch in binary dir
  #file(WRITE ${CMAKE_BINARY_DIR}/itk_patch_1.cmake 
  #  "configure_file(${CMAKE_SOURCE_DIR}/patches_ITK/hashtable.hxx.in 
193
  #   ${ITK_SB_SRC}/Modules/ThirdParty/KWSys/src/KWSys/hashtable.hxx.in COPYONLY)")
194 195 196
  
  message(STATUS "  Using ITK SuperBuild version")
endif()