How to slim down ITK install based on required functions?

I am trying to build ITK WITHOUT any of the IO modules. I cant seem to figure out the required cmake switches to do this.

Lets say I only need registration functions:

This still pulls in:
– Enabled ITKMetaIO, needed by [ITKSpatialObjects].
which then pulls in all the IO modules (zlib/etc).

ITKSpatialObjects is required by ITKRegistrationCommon.

Does this mean there is no way to have an ITK build without the IO modules?


If you set BUILD_TESTING to OFF, that will greatly reduce dependent IO modules, as tests use a lot of IOs.

@dzenanz - thanks for the quick reply.

I had that, didnt seem like it mattered for the transitive closure of dependencies I listed above.

I tried this:

But it still resulted in the IO libs/GPU libs getting pulled in.

This might not be necessary. Is that right @Stephen_Aylward?

MetaIO needs zlib, and common IO stuff such as imageIObase, but it should not require all the IO modules (NRRD, nifti, HDF5, etc).

@dzenanz - yes, you are right. For the config I listed, only ZLIB gets pulled, not the others.

I am still trying to work backwards from my list of functions to modules to see the slimmest possible ITK I can have. Do you have any suggestions for a rigorous process to follow for this? e.g ITKGroup_Core seems like something I HAVE to enable, which results in:
– Enabled ITKTestKernel, needed by [ITKGroup_Core].
Which then results in all the other IO’s getting pulled in:
– Enabled ITKIOJPEG, needed by [ITKTestKernel].
– Enabled ITKIOBMP, needed by [ITKTestKernel].

The entire groups is not necessary. In fact, you could disable it and rely on module interdependencies to only bring in the required ones. That will be ITKCommon and maybe some others, but almost certainly not ITKTestKernel, which is usually only needed by tests. ITKTestKernel brings in most IOs.

Here’s the process I am following now:

  1. Look for headers used, e.g
    find sources/ITK/ -name itkOptimizer.h
  2. Use -DModule_ITKOptimizers to pick Optimizers/ dir or -DITK_Group_Numerics to pick Numerics dir

Is that the right approach? Appears to work for the above example.

  1. But in the result, e.g sources/ITK/Modules/Registration/PDEDeformable. Choosing -DModule_ITKPDEDeformable to pick the module results in:

Manually-specified variables were not used by the project:

And the required header is missing in the install.
So I am now using DITKGroup_Registration instead…

You could/should use And instead of putting them in your find_package's components list in your CMakeLists, you enable them in your ITK compile configuration.

1 Like

Thank you @dzenanz for the helpful replies, I am all set.

1 Like

For posterity, what configuration parameters you ended up with?

For my needs, I ended with:

I am yet to explore the need for Compatibility.
And I was unable to narrow down Group_Registration down to one of its modules.

1 Like