CMAKE: Migrate to ITK 6 modern interface library targets#1435
CMAKE: Migrate to ITK 6 modern interface library targets#1435blowekamp wants to merge 1 commit intoSuperElastix:mainfrom
Conversation
Replace legacy include(${ITK_USE_FILE}) and ${ITK_LIBRARIES} patterns
with modern CMake target-based dependencies using ITK::<Module>Module interface
library targets. Backward compatibility with ITK 5.4.1+ is preserved via
version-conditional logic.
New file: CMake/ElastixITKDeps.cmake
- elastix_link_itk() macro: expands to ITK::<Mod>Module targets (ITK 6+)
or ${ITK_LIBRARIES} (ITK 5.x).
- ELASTIX_ITK_EXECUTABLE_LIBRARIES: IO factory meta-module targets
(ITK::ITKImageIO, ITK::ITKTransformIO, ITK::ITKMeshIO) that carry factory
registration include dirs and compile definitions via INTERFACE properties.
- ELASTIX_ITK_TEST_LIBRARIES: ITK::ITKTestKernelModule for test-only utilities.
- ELASTIX_ITK_ALL_LIBRARIES: full ${ITK_INTERFACE_LIBRARIES} + factory
meta-modules, for standalone executables without elxCommon transitive deps.
Top-level CMakeLists.txt:
- ITK 6+: call itk_generate_factory_registration() before add_subdirectory().
- ITK 5.x: keep include(${ITK_USE_FILE}).
- include(ElastixITKDeps) to load the helper.
Library target updates (elastix_link_itk() with WhatModulesITK.py-verified lists):
- param: ITKCommon
- elxCommon: 25 specific ITK::*Module targets (ITKCommon, ITKDisplacementField,
ITKDistanceMap, ITKImageCompose, ITKImageFilterBase, ITKImageFunction,
ITKImageGradient, ITKImageGrid, ITKImageIntensity, ITKImageStatistics,
ITKIOImageBase, ITKIOMeshBase, ITKIOMeta, ITKIOTransformBase, ITKIOXML,
ITKMathematicalMorphology, ITKMesh, ITKOptimizers, ITKRegistrationCommon,
ITKSmoothing, ITKSpatialObjects, ITKStatistics, ITKThresholding,
ITKTransform, ITKTransformFactory)
- mevisdcmtiff: ITKCommon, ITKGDCM, ITKIOImageBase
- elxOpenCL: ITKCommon, ITKGPUCommon, ITKTransform, ITKImageGrid,
ITKSmoothing, ITKImageFunction
- KNNlib: ITKCommon, ITKStatistics, ITKSpatialObjects
Components/Core/Tests:
- elxLinkLibs: ITK 6+ = elxCore only (all ITK deps come transitively via
elxCommon PUBLIC link chain); ITK 5.x = elxCore + ${ITK_LIBRARIES}.
- ELASTIX_TARGET_LINK_LIBRARIES: uses ELASTIX_ITK_EXECUTABLE_LIBRARIES.
- Test macro and utility targets: ELASTIX_ITK_EXECUTABLE_LIBRARIES +
ELASTIX_ITK_TEST_LIBRARIES. GTest targets: ELASTIX_ITK_EXECUTABLE_LIBRARIES.
Config/downstream:
- ElastixConfig.cmake.in: calls itk_generate_factory_registration() for ITK 6+.
- UseElastix.cmake.in: note recommending direct target linking for ITK 6+.
- dox/externalproject: ITK 6+ links only elastix_lib (all ITK deps transitive).
Verified with ITK 6.0.0: 159/163 tests pass (4 pre-existing failures unrelated
to this change: numerical baseline mismatches vs ITK 5 baselines, missing Python
itk module in test environment).
|
Relates to: SimpleITK/SimpleITK#2569 |
|
@N-Dekker This is a AI driven patch. Please let me know what you think of the general approach of adding the cmake function to fill in the gap between the ITK versions or other opinions on the app read before I look at things more closely. |
|
@N-Dekker Any thought on this PR, and how you might want this type if change implemented? |
|
Thanks @blowekamp I'll have a look! I very much appreciate your help with CMake. And I realize that the CMake code of elastix may be outdated. Would it be possible to do such a migration with less lines of code? I see now that your draft adds 200+ lines. In general, I would expect modernization to reduce the number of lines of code, instead. 🤷 |
There are two primary things done.
There some other AI written comment/documentation that could be reduced to. I'm not sure if they help or hinder the review process. |
|
@N-Dekker Do you have any preference or specific requests to move this PR forward? |
Replace legacy include(${ITK_USE_FILE}) and ${ITK_LIBRARIES} patterns with modern CMake target-based dependencies using ITK::Module interface library targets. Backward compatibility with ITK 5.4.1+ is preserved via version-conditional logic.
New file: CMake/ElastixITKDeps.cmake
Top-level CMakeLists.txt:
Library target updates (elastix_link_itk() with WhatModulesITK.py-verified lists):
Components/Core/Tests:
Config/downstream:
Verified with ITK 6.0.0: 159/163 tests pass (4 pre-existing failures unrelated to this change: numerical baseline mismatches vs ITK 5 baselines, missing Python itk module in test environment).