# How to slim down ITK install based on required functions?

**URL:** https://discourse.itk.org/t/how-to-slim-down-itk-install-based-on-required-functions/4134
**Category:** Engineering
**Tags:** cmake
**Created:** [May 14, 2021, 4:14pm UTC](https://discourse.itk.org/t/how-to-slim-down-itk-install-based-on-required-functions/4134 "2021-05-14T16:14:06Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![AshishUthama](https://discourse.itk.org/user_avatar/discourse.itk.org/ashishuthama/32/2084_2.png) [@AshishUthama](https://discourse.itk.org/u/AshishUthama)
#### Post date: [May 14, 2021, 4:14pm UTC](https://discourse.itk.org/t/how-to-slim-down-itk-install-based-on-required-functions/4134/1 "2021-05-14T16:14:06Z")

</div>

Hi  
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:  
-DITKGroup\_Registration:BOOL=ON   
-DITK\_BUILD\_DEFAULT\_MODULES:BOOL=OFF \

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?

Ashish

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [May 14, 2021, 5:52pm UTC](https://discourse.itk.org/t/how-to-slim-down-itk-install-based-on-required-functions/4134/2 "2021-05-14T17:52:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![AshishUthama](https://discourse.itk.org/user_avatar/discourse.itk.org/ashishuthama/32/2084_2.png) [@AshishUthama](https://discourse.itk.org/u/AshishUthama)
#### Post date: [May 14, 2021, 6:47pm UTC](https://discourse.itk.org/t/how-to-slim-down-itk-install-based-on-required-functions/4134/3 "2021-05-14T18:47:22Z")

</div>

@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:  
-DBUILD\_UTILITIES:BOOL=OFF   
-DBUILD\_DOCUMENTATION:BOOL=OFF   
-DBUILD\_EXAMPLES:BOOL=OFF   
-DBUILD\_TESTING:BOOL=OFF   
-DITK\_BUILD\_DEFAULT\_MODULES:BOOL=OFF   
-DITK\_USE\_GPU:BOOL=OFF   
-DITKGroup\_Compatibility:BOOL=ON   
-DITKGroup\_Core:BOOL=OFF   
-DITKGroup\_Filtering:BOOL=OFF   
-DITKGroup\_Numerics:BOOL=OFF   
-DITKGroup\_Registration:BOOL=ON   
-DITKGroup\_Segmentation:BOOL=OFF   
-DModule\_ITKTestKernel:BOOL=OFF   
-DModule\_ITKMetaIO:BOOL=OFF

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

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [May 14, 2021, 6:52pm UTC](https://discourse.itk.org/t/how-to-slim-down-itk-install-based-on-required-functions/4134/4 "2021-05-14T18:52:00Z")

</div>

> [@AshishUthama](#):
>
> ITKMetaIO, needed by [ITKSpatialObjects]

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

> [@AshishUthama](#):
>
> pulls in all the IO modules

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

---

<div class="post-metadata">

### Author: ![AshishUthama](https://discourse.itk.org/user_avatar/discourse.itk.org/ashishuthama/32/2084_2.png) [@AshishUthama](https://discourse.itk.org/u/AshishUthama)
#### Post date: [May 14, 2021, 7:03pm UTC](https://discourse.itk.org/t/how-to-slim-down-itk-install-based-on-required-functions/4134/5 "2021-05-14T19:03:39Z")

</div>

@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].  
etc…

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [May 14, 2021, 7:13pm UTC](https://discourse.itk.org/t/how-to-slim-down-itk-install-based-on-required-functions/4134/6 "2021-05-14T19:13:20Z")

</div>

> [@AshishUthama](#):
>
> ITKGroup\_Core

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.

---

<div class="post-metadata">

### Author: ![AshishUthama](https://discourse.itk.org/user_avatar/discourse.itk.org/ashishuthama/32/2084_2.png) [@AshishUthama](https://discourse.itk.org/u/AshishUthama)
#### Post date: [May 17, 2021, 3:46pm UTC](https://discourse.itk.org/t/how-to-slim-down-itk-install-based-on-required-functions/4134/7 "2021-05-17T15:46:14Z")

</div>

Here’s the process I am following now:

1. Look for headers used, e.g  
find sources/ITK/ -name itkOptimizer.h  
sources/ITK/Modules/Numerics/Optimizers/include/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:  
Module\_ITKPDEDeformable

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

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [May 17, 2021, 4:58pm UTC](https://discourse.itk.org/t/how-to-slim-down-itk-install-based-on-required-functions/4134/8 "2021-05-17T16:58:58Z")

</div>

You could/should use [WhatModulesITK.py](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Utilities/Maintenance/WhatModulesITK.py). And instead of putting them in your `find_package`'s components list in your CMakeLists, you enable them in your ITK compile configuration.

---

<div class="post-metadata">

### Author: ![AshishUthama](https://discourse.itk.org/user_avatar/discourse.itk.org/ashishuthama/32/2084_2.png) [@AshishUthama](https://discourse.itk.org/u/AshishUthama)
#### Post date: [May 17, 2021, 5:22pm UTC](https://discourse.itk.org/t/how-to-slim-down-itk-install-based-on-required-functions/4134/9 "2021-05-17T17:22:32Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [May 17, 2021, 6:01pm UTC](https://discourse.itk.org/t/how-to-slim-down-itk-install-based-on-required-functions/4134/10 "2021-05-17T18:01:07Z")

</div>

For posterity, what configuration parameters you ended up with?

---

<div class="post-metadata">

### Author: ![AshishUthama](https://discourse.itk.org/user_avatar/discourse.itk.org/ashishuthama/32/2084_2.png) [@AshishUthama](https://discourse.itk.org/u/AshishUthama)
#### Post date: [May 17, 2021, 6:12pm UTC](https://discourse.itk.org/t/how-to-slim-down-itk-install-based-on-required-functions/4134/11 "2021-05-17T18:12:19Z")

</div>

For my needs, I ended with:  
-DBUILD\_DOCUMENTATION:BOOL=OFF   
-DBUILD\_EXAMPLES:BOOL=OFF   
-DBUILD\_TESTING:BOOL=OFF   
-DITK\_BUILD\_DEFAULT\_MODULES:BOOL=OFF   
-DITKGroup\_Compatibility:BOOL=ON   
-DITKGroup\_Core:BOOL=OFF  
-DITKGroup\_Registration:BOOL=ON   
-DModule\_ITKImageFeature:BOOL=ON   
-DModule\_ITKLabelMap:BOOL=ON   
-DModule\_ITKOptimizers:BOOL=ON   
-DModule\_ITKTestKernel:BOOL=OFF   
-DModule\_ITKTransform:BOOL=ON

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