You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Factory registration include directory collides between targets in one project #6860
itk_generate_factory_registration() stores the generated header's include directory on the shared ITK::ITKImageIO target, so in a project with more than one target requesting different IO components the last call wins and the other targets compile against the wrong registration header.
# png_example/CMakeLists.txt (meta_example is identical with ITKIOMeta)project(png_example CXX)
find_package(ITKREQUIREDCOMPONENTSITKCommonITKIOImageBaseITKIOPNG)
itk_generate_factory_registration()
add_executable(png_exampleprog.cxx)
target_link_libraries(png_examplePRIVATEITK::ITKCommonModuleITK::ITKImageIO)
prog.cxx writes a 4x4 image to argv[1] with itk::WriteImage.
Observed
target
components requested
factories in binary
runtime
png_example
ITKIOPNG
Meta
fails to write .png
meta_example
ITKIOMeta
Meta
writes .mha
png_example fails with Could not create IO object for writing file, because it was compiled against meta_example's registration header.
Expected
Each target registers the factories for the components it requested.
Cause
_itk_configure_FactoryRegisterManager in CMake/ITKFactoryRegistration.cmake writes the header to ${CMAKE_CURRENT_BINARY_DIR}/ITKFactoryRegistration and then points the meta-module target at it:
The property is overwritten on each call. Two sibling subdirectories that each call find_package(ITK) themselves are unaffected, because each gets its own imported target; the collision appears once a parent scope calls find_package(ITK) and the subdirectories inherit that target.
Impact
Per-target narrowing of IO components is not usable in a single-project build. In ITKSphinxExamples, narrowing each example to the formats it reads reduces the built examples from 5.26 GB to 0.72 GB, but only works when each example is configured as its own project; in the aggregate build 62 of 558 tests fail this way.
Verified against ITK main (6.0.0) on macOS with AppleClang.
Once this is fixed, revisit per-format IO narrowing in ITKSphinxExamples (InsightSoftwareConsortium/ITKSphinxExamples#481, now closed). Narrowing examples to the IO formats they use cut the built examples from 5.26 GB to 0.72 GB, but hit this bug in the aggregate build.
I think it is a longstanding issue that would be nice to have, and would have been the expected behavior for someone trying to narrowly limit exposure in a binary, but not often encountered.
I think it is a longstanding issue that would be nice to have, and would have been the expected behavior for someone trying to narrowly limit exposure in a binary, but not often encountered.
To be clear, ITK::ITKImageIO and other meta-modules for factories are global, beyond even the project scope. This is a hard constrain based on how CMake works. The way I interpret the request is that the "ITKImageIO" should change with different find_package calls, is not achievable.
Would an explicit call to a cmake function for this special case meet the requirements?
Activity
blowekamp commentedon Sep 14, 2026
The
ITK::ITKImageIOis a CMake target which are essentially global. So I don't think there is a way to do per directory configuration with the target.Some of the functions may need to be manually called, and new options or features added around here:
ITK/CMake/ITKFactoryRegistration.cmake
Lines 286 to 296 in fd3b0b4
Alternatively the example could explicitly do the registration or create the ImageIO themselves.
dzenanz commentedon Sep 14, 2026
Does this problem affect Slicer? It has many modules which use ITK, some of which are probably providing a list of modules they want.
blowekamp commentedon Sep 14, 2026
Was it possible in ITKv5 to specify which ImageIOs to use in different parts of the project? And was is respected?
Is this a regression or a new feature/issue?
hjmjohnson commentedon Sep 15, 2026
Once this is fixed, revisit per-format IO narrowing in ITKSphinxExamples (InsightSoftwareConsortium/ITKSphinxExamples#481, now closed). Narrowing examples to the IO formats they use cut the built examples from 5.26 GB to 0.72 GB, but hit this bug in the aggregate build.
hjmjohnson commentedon Sep 16, 2026
I think it is a longstanding issue that would be nice to have, and would have been the expected behavior for someone trying to narrowly limit exposure in a binary, but not often encountered.
blowekamp commentedon Sep 16, 2026
To be clear,
ITK::ITKImageIOand other meta-modules for factories are global, beyond even the project scope. This is a hard constrain based on how CMake works. The way I interpret the request is that the "ITKImageIO" should change with different find_package calls, is not achievable.Would an explicit call to a cmake function for this special case meet the requirements?