-
-
Notifications
You must be signed in to change notification settings - Fork 717
Modernize ITK Module System with CMake Interface Libraries #5721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Modernize ITK Module System with CMake Interface Libraries #5721
Conversation
|
PR description sounds amazing! Now diving into the review. |
dzenanz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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.
074d9c4 to
5c53e2b
Compare
|
This is very close a couple choices made:
Options:
TODO:
This PR is just about complete is unless there are additional major requests for features, compatibility or other changes that must go in the PR and not a follow up. Additional testing and feedback is welcome. P.S. Testing ITKMontage against a ITK build, and ITKRLEImage remote as an enable module during the build and others, all working. |
|
I am building locally. |
|
Builds and tests fine locally. Let's see when I start building some applications against it. |
|
One small application builds and works. |
|
Is this PR something I should test my app against before it's merged? |
Yes, that will be helpful if you have time. Also feedback on the options, and compatibility would be appriciated. Does your applications current use the "UseITK.cmake" approach with global properties and the ITK_LIBRARIES? Can it be easily update to use the for modular interface approach in the PR description? |
I wonder if @jcfr has thoughts on this. @blowekamp can we update ITK/Examples/Installation/CMakeLists.txt? |
I build ITK with cmake, generating static libraries. My application I build with Xcode, not CMake. I just link to the static libraries. I'll clone this and give it a try.... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 24 out of 24 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I will have a look later this weekend. |
|
I tried rebuilding an existing ITK bin directory I have, but it failed to build (so didn't get as far as trying with my app): I tried with a fresh bin directory and that did build; not yet sure what setting difference is relevant... |
|
Actually, didn't take long to find... just setting ITK_USE_SYSTEM_ZLIB to YES seems to break the build. |
|
It looks like something ends up treating a path like a target. I think following the VTK pattern of always representing third party deps as a consistent target is the way to go here. It can then be backed by the vendored target or the imported target pretty easily. Note that I found it extremely precarious to try and support a target-centric world and the variable-centric world at the same time. VTK's use of generator expressions made it nigh impossible (it could probably have been done, but may have extended the development period considerably). I don't know if ITK is using them to the same extent, but if not, a compatibility bridge might be feasible. |
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.
Thank you for testing! I have updated the PR with a fix which enabled building on Ubuntu 24.04 with system libraries include lib, expact, fifth,hdf5,jpeg,png,tif.
That sounds like an ideal solution. What I implemented was just detecting if a library was a file that existed. This approach will not work when library names/flags with LIBRARY_PATH are used. Using the name and path approach for libraries has been problematic with getting the correct library before, it should be reasonable to stop supporting it. P.S. Also update the installation example. |
That seemed to fix that, great! Next thing I hit: |
|
I fixed the PhilipsREC module issues. Tested with additional internal modules successfully. Tested many level 2 remote models, and encountered and issue with the IO ones and the factories that will need further work. |
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