Modernize ITK Module System with CMake Interface Libraries#5721
Modernize ITK Module System with CMake Interface Libraries#5721hjmjohnson merged 14 commits intoInsightSoftwareConsortium:mainfrom
Conversation
|
PR description sounds amazing! Now diving into the review. |
dzenanz
left a comment
There was a problem hiding this comment.
I am glad you are working on this! Does this work? What else is needed, besides changing the rest of the examples?
hjmjohnson
left a comment
There was a problem hiding this comment.
@blowekamp AMAZING! Thank you for tackling this. It is long overdue!
|
f8488a7 configures and builds locally, in Debug and RelWithDebInfo modes, including examples. CMake 4.2.1, VS 2022. Tests in RelWithDebInfo mode succeed. |
f8488a7 to
e648c27
Compare
|
Woohoo! |
There was a problem hiding this comment.
Pull request overview
This PR modernizes the ITK module system by introducing CMake interface libraries (${ModuleName}Module) that provide target-based dependency management and proper transitive propagation of include directories and dependencies. This replaces the legacy directory-level include_directories() approach with modern target-specific target_include_directories() calls using generator expressions.
Key Changes:
- Created interface libraries for each ITK module with automatic transitive dependency linking
- Migrated from directory-level includes to target-based includes using BUILD_INTERFACE/INSTALL_INTERFACE generator expressions
- Updated 60+ filtering examples to explicitly link against specific module targets instead of the monolithic
${ITK_LIBRARIES}
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| Utilities/Maintenance/WhatModulesITK.py | Enhanced script with argparse and new --link option to generate target_link_libraries commands; improved regex pattern for module detection |
| CMake/ITKModuleMacros.cmake | Added interface library creation for modules, migrated to target-based include directories with generator expressions, added transitive dependency linking |
| CMake/ITKModuleInfo.cmake.in | Added INCLUDE2_DIRS variable to support generator expression-based include directories |
| CMake/ITKModuleHeaderTest.cmake | Updated header tests to use target-based include directories |
| CMake/ITKModuleEnablement.cmake | Created factory meta-module interface libraries (ITKImageIO, ITKMeshIO, ITKTransformIO) |
| CMake/ITKModuleAPI.cmake | Added INCLUDE2_DIRS propagation through module configuration |
| Modules/ThirdParty/MetaIO/src/CMakeLists.txt | Added directory-level includes as compatibility workaround for third-party modules |
| Modules/ThirdParty/HDF5/CMakeLists.txt | Added directory-level includes as compatibility workaround for third-party modules |
| Examples/Filtering/CMakeLists.txt | Converted all examples from ${ITK_LIBRARIES} to explicit module targets with Module suffix and factory meta-modules |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e648c27 to
4b20ef5
Compare
|
Thank you @Copilot for the thorough review! I've addressed the actionable feedback in the latest commit: Fixed:
Regarding directory-level includes in third-party modules (MetaIO/HDF5): |
|
In SimpleITK the PR SimpleITK/SimpleITK#2475 is using this branch along with cmake FetchContent with ITK. Additionally it is build ITK in a super build and separate build are using ITK from the source or from the build tree. They seem to be working. The one exception is the build with Elastic, which is encountering a Sobel filter related error 😸 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 22 out of 22 changed files in this pull request and generated 13 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4b20ef5 to
ea12c51
Compare
|
@bradking Would you be able to provide feedback on this PR? |
mathstuf
left a comment
There was a problem hiding this comment.
Some high-level recommendations based on VTK module experience:
- add alias targets for all targets that match what
find_package(ITK)users see - highly recommend exporting with
ITK::namespace (it will help with CPS support in the future) - use
EXPORT_NAMEproperty to name the post-::install target rather than the core target name (a mistake from VTK's module system because I was unaware of the property) - use
FILE_SETsource listings so that you don't even needtarget_include_directoriesand header installation Just Works™ even with subdirectories (VTK opportunistically does it, but still supports even CMake 3.12(!))
CMake/ITKModuleMacros.cmake
Outdated
| set( | ||
| itk-module-RUNTIME_LIBRARY_DIRS-install2 | ||
| "$<INSTALL_INTERFACE:\${ITK_INSTALL_PREFIX}/${ITK_INSTALL_RUNTIME_DIR}>" | ||
| ) |
There was a problem hiding this comment.
There's an open CMake feature request for runtime usage requirements like this. But it's not implemented yet.
|
Some of those recommendations might be out-of-scope for this PR. |
ea12c51 to
5f1281c
Compare
Add ITK_*_FACTORY_REGISTER_MANAGER compile definitions and factory registration header includes to factory meta-module interface targets. Use itk_generate_factory_registration in Examples to register factories.
Introduce ITK_INTERFACE_LIBRARIES variable to allow users to link to
the interface libraries with properties.
Add ITK_LIBRARY_NAMESPACE configuration (defaults to 'ITK') that enables
namespaced targets for all ITK modules (e.g., ITK::ITKCommonModule).
Introduce LIBRARIES_DEPRECATED variable alongside LIBRARIES to maintain
backward compatibility. Create INTERFACE IMPORTED wrappers for old target
names that link to new namespaced targets with DEPRECATION property set.
Update module system to use ${module-targets-namespace} throughout:
- itk_module_impl builds both deprecated and namespaced library lists
- itk_module_link_dependencies uses namespaced targets
- itk_module_test uses namespaced targets
- Factory meta-modules use namespaced targets
Update external itk_modile_config api to use ITK interface module
libraries.
Add init_module_vars() macro to set per-module namespace configuration.
Add documentation for itk_module_target_export() explaining export
mechanism and namespace handling for library targets.
For a Module's Libraries, detect non-target library file with an "EXISTS" check. This will detect full paths, but not library only filenames with library search path usages.
Update the example usage of ITK to remove "UseITK" to use the ITK's module interface libraries with the library properties.
Each time itk_generate_factory_registration, the include directories for the meta factory module is called the include paths are reset to the latest.
040a7be to
14665e6
Compare
|
Please approve or review so we can hopefully merge tomorrow. |
hjmjohnson
left a comment
There was a problem hiding this comment.
This is a very welcome update!
|
Thanks Hans! |
|
This was the only PR merged yesterday. There are a few new errors and warnings, e.g.
|
|
@dzenanz Could you please create a GH issue for these? |
This PR introduces modern CMake interface libraries for ITK modules, enabling clean target-based linking and proper transitive dependency propagation.
Key Changes
CMake Interface Libraries - Created
${ModuleName}Moduleinterface library for each ITK module with:Target-Based Includes - Replaced directory-level
include_directories()with target properties:target_include_directories()withBUILD_INTERFACE/INSTALL_INTERFACEExample Modernization - Updated examples to use specific module targets:
Enhanced Tooling - Improved
WhatModulesITK.pywith--linkoption to generate updatedtarget_link_librariescommandsFactory Registration - Properties part of factory meta-modules
Interface meta-modules for factories: ITKImageIO, ITKMeshIO, ITKTransformIO and FFTImageFilterInit factories. Factory modules will be added as dependencies to these meta-module. When itk_generate_factory_registration() is called, it adds the include directory containing the generated FactoryRegisterManager header file.
Example Usage:
or
Benefits
${ITK_LIBRARIES})Compatibility
itk_module_add_library()for automatic target properties${ITK_LIBRARIES}pattern still supported