Skip to content

WIP: Require ITK 6 and request modules as find_package COMPONENTS - #481

Closed
hjmjohnson wants to merge 12 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:comp-require-itk6
Closed

hjmjohnson wants to merge 12 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:comp-require-itk6

Conversation

@hjmjohnson

@hjmjohnson hjmjohnson commented Sep 12, 2026

Copy link
Copy Markdown
Member

Request the ITK modules each example uses as find_package COMPONENTS.
Link lines are unchanged: each example keeps its explicit
ITK::<Name>Module targets.

Stacked on #479 and #482 — review the last 10 commits.

What this buys

Components are derived from the ITK headers each example includes, resolved through an index of 3282 headers across ITK's 167 modules. Naming them means a missing or disabled module fails at configure time with No such module: X, rather than as a missing target at generate time.

Link lines keep the explicit module targets rather than ${ITK_INTERFACE_LIBRARIES}: these examples are teaching material, and ITK::ITKThresholdingModule on the link line tells a reader which module provides the class the example demonstrates.

Why the components are not narrowed to specific IO formats

Requesting the exact format an example reads (ITKIOPNG instead of the ITKImageIO meta-module) shrinks the built examples from 5.26 GB to 0.72 GB, because only the requested factory is registered.

That is not usable here yet: itk_generate_factory_registration() records the generated header's include directory on the shared ITK::ITKImageIO target, so in an aggregate build the last example configured wins and the others compile against its registration header. Measured on this repository, per-format narrowing produced 62 new test failures for that reason. Reported as InsightSoftwareConsortium/ITK#6860; once registration attaches per target, the narrowing becomes available.

Six examples still name a format module — the GDCM, TIFF, and factory-registration examples — because they include itkGDCMImageIO.h, itkTIFFImageIO.h, or itkPNGImageIOFactory.h directly and need it on the include path.

Verification

Built against ITK main with Module_ITKVtkGlue=ON and Python wrapping enabled:

before after
build 0 failed targets, 365 executables 0 failed targets, 365 executables
tests 2 failures of 558 2 failures of 558

No new failures and none fixed. The two remaining failures are unrelated to this change: ConvolveImageWithKernelTestPython needs matplotlib, and ComputeFFTInOneDimensionPhaseBaselineComparisonPython fails a baseline image comparison.

@github-actions github-actions Bot added the type:Enhancement Improvement of existing methods or implementation label Sep 12, 2026
@hjmjohnson
hjmjohnson force-pushed the comp-require-itk6 branch 2 times, most recently from 18403e0 to c76bf1d Compare September 12, 2026 18:38
@hjmjohnson hjmjohnson changed the title ENH: Require ITK 6 and request modules as find_package COMPONENTS WIP: Require ITK 6 and request modules as find_package COMPONENTS Sep 12, 2026
hjmjohnson and others added 12 commits September 13, 2026 12:26
Python 3.12 removed distutils, so every example guarding its minimum ITK
version with distutils.version.StrictVersion fails at import:

    ModuleNotFoundError: No module named 'distutils'

Compare the dotted version components as a tuple instead, which needs no
import at all and keeps each example's existing minimum.

SegmentBloodVessels and
SegmentBloodVesselsWithMultiScaleHessianBasedMeasure called sys.exit()
in that guard without importing sys; add the import.
Every example links ITK::...Module interface targets, which ITK 5.x does
not export, so against ITK 5.4 configure fails with one missing-target
error per example (346 in all). Requiring ITK 6 stops at the first
find_package with a single version error instead.

Examples for ITK 5.x now live on the release-5.4 branch.
Name the ITK modules behind each example's includes and link targets as
find_package COMPONENTS, so configure fails with "No such module" when a
module is missing rather than with a missing target at generate time.

Link lines are unchanged: each example keeps its explicit
ITK::<Name>Module targets, which show a reader which module provides
which class.

Follows the COMPONENTS approach proposed in InsightSoftwareConsortium#470.

Co-Authored-By: Bradley Lowekamp <blowekamp@mail.nih.gov>
Name the ITK modules behind each example's includes and link targets as
find_package COMPONENTS, so configure fails with "No such module" when a
module is missing rather than with a missing target at generate time.

Link lines are unchanged: each example keeps its explicit
ITK::<Name>Module targets, which show a reader which module provides
which class.

Follows the COMPONENTS approach proposed in InsightSoftwareConsortium#470.

Co-Authored-By: Bradley Lowekamp <blowekamp@mail.nih.gov>
Name the ITK modules behind each example's includes and link targets as
find_package COMPONENTS, so configure fails with "No such module" when a
module is missing rather than with a missing target at generate time.

Link lines are unchanged: each example keeps its explicit
ITK::<Name>Module targets, which show a reader which module provides
which class.

Follows the COMPONENTS approach proposed in InsightSoftwareConsortium#470.

Co-Authored-By: Bradley Lowekamp <blowekamp@mail.nih.gov>
Name the ITK modules behind each example's includes and link targets as
find_package COMPONENTS, so configure fails with "No such module" when a
module is missing rather than with a missing target at generate time.

Link lines are unchanged: each example keeps its explicit
ITK::<Name>Module targets, which show a reader which module provides
which class.

Follows the COMPONENTS approach proposed in InsightSoftwareConsortium#470.

Co-Authored-By: Bradley Lowekamp <blowekamp@mail.nih.gov>
Name the ITK modules behind each example's includes and link targets as
find_package COMPONENTS, so configure fails with "No such module" when a
module is missing rather than with a missing target at generate time.

Link lines are unchanged: each example keeps its explicit
ITK::<Name>Module targets, which show a reader which module provides
which class.

Follows the COMPONENTS approach proposed in InsightSoftwareConsortium#470.

Co-Authored-By: Bradley Lowekamp <blowekamp@mail.nih.gov>
Name the ITK modules behind each example's includes and link targets as
find_package COMPONENTS, so configure fails with "No such module" when a
module is missing rather than with a missing target at generate time.

Link lines are unchanged: each example keeps its explicit
ITK::<Name>Module targets, which show a reader which module provides
which class.

Follows the COMPONENTS approach proposed in InsightSoftwareConsortium#470.

Co-Authored-By: Bradley Lowekamp <blowekamp@mail.nih.gov>
Name the ITK modules behind each example's includes and link targets as
find_package COMPONENTS, so configure fails with "No such module" when a
module is missing rather than with a missing target at generate time.

Link lines are unchanged: each example keeps its explicit
ITK::<Name>Module targets, which show a reader which module provides
which class.

Follows the COMPONENTS approach proposed in InsightSoftwareConsortium#470.

Co-Authored-By: Bradley Lowekamp <blowekamp@mail.nih.gov>
Name the ITK modules behind each example's includes and link targets as
find_package COMPONENTS, so configure fails with "No such module" when a
module is missing rather than with a missing target at generate time.

Link lines are unchanged: each example keeps its explicit
ITK::<Name>Module targets, which show a reader which module provides
which class.

Follows the COMPONENTS approach proposed in InsightSoftwareConsortium#470.

Co-Authored-By: Bradley Lowekamp <blowekamp@mail.nih.gov>
Name the ITK modules behind each example's includes and link targets as
find_package COMPONENTS, so configure fails with "No such module" when a
module is missing rather than with a missing target at generate time.

Link lines are unchanged: each example keeps its explicit
ITK::<Name>Module targets, which show a reader which module provides
which class.

Follows the COMPONENTS approach proposed in InsightSoftwareConsortium#470.

Co-Authored-By: Bradley Lowekamp <blowekamp@mail.nih.gov>
Name the ITK modules behind each example's includes and link targets as
find_package COMPONENTS, so configure fails with "No such module" when a
module is missing rather than with a missing target at generate time.

Link lines are unchanged: each example keeps its explicit
ITK::<Name>Module targets, which show a reader which module provides
which class.

Follows the COMPONENTS approach proposed in InsightSoftwareConsortium#470.

Co-Authored-By: Bradley Lowekamp <blowekamp@mail.nih.gov>
@github-actions github-actions Bot removed the type:Enhancement Improvement of existing methods or implementation label Sep 13, 2026
@blowekamp

Copy link
Copy Markdown
Member

What was the prior behavior here for these examples? Was every example just linked to everything in ITK and all ImageIO's loaded?

It appears a motivation for using only the needed ImageIO is to reduce the binary size. I would be interested in how the size of a share library build is by comparison to the other options.

I think finding the "ImageIO" package is the best approach, which is now done here.

@dzenanz

dzenanz commented Sep 14, 2026

Copy link
Copy Markdown
Member

Was every example just linked to everything in ITK and all ImageIO's loaded?

This is quite possible. The examples' build directory was big: 30-40 GB with statically built libraries.

@dzenanz dzenanz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good

Comment thread src/Bridge/VtkGlue/ConvertvtkImageDataToAnitkImage/CMakeLists.txt
@hjmjohnson

Copy link
Copy Markdown
Member Author

Closing: once #479, #482, and #488 are in, requesting modules as COMPONENTS shows no measured benefit, so there is nothing left worth merging here.

What was the prior behavior here for these examples? Was every example just linked to everything in ITK and all ImageIO's loaded?

All ImageIOs, not all of ITK. Each example links explicit ITK::<Name>Module targets, and 247 of them include ITK::ITKImageIO, which registers every enabled image IO factory. A bare find_package(ITK REQUIRED) loads every module's config but links none of them.

I would be interested in how the size of a share library build is by comparison to the other options.

With ITKImageIO requested, COMPONENTS changes nothing in the output. I agree that requesting the ITKImageIO package is the right choice.

Measurements (static ITK main, macOS arm64)

One standalone example (MedianFilteringOfAnImage), bare find_package(ITK REQUIRED) compared with COMPONENTS ITKCommon ITKSmoothing ITKImageIO:

bare COMPONENTS
configure time (warm) 3.96 s 3.90 s
image IO factories registered 24 24
binary size 23.73 MB 23.73 MB
missing module configure error configure error

Across the aggregate build, bin/ is 5.42 GB for 372 executables with or without COMPONENTS.

The only size win is narrowing to specific formats (e.g. ITKIOPNG). That cut the built examples from 5.26 GB to 0.72 GB, but it produced 62 test failures. The cause is ITK#6860: the factory registration include directory is set on the shared ITK::ITKImageIO target, so the last example configured wins. Revisit once that is fixed.

A shared-library comparison has not been measured.

@hjmjohnson hjmjohnson closed this Sep 15, 2026
hjmjohnson added a commit that referenced this pull request Sep 16, 2026
ITK's VtkGlue requires VTK 9.1, so the VTK_VERSION VERSION_LESS
"8.90.0" branches can never be taken. Drop the VTK_USE_FILE includes
and the _vtk_prefix component prefix, and call vtk_module_autoinit
unconditionally.

Suggested in review of #481.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants