# Trimming down ITK build to just used parts

**URL:** <https://discourse.itk.org/t/trimming-down-itk-build-to-just-used-parts/1995>\
**Category:** Uncategorized\
**Created:** [June 25, 2019, 6:08pm UTC](https://discourse.itk.org/t/trimming-down-itk-build-to-just-used-parts/1995 "2019-06-25T18:08:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gdevenyi](https://discourse.itk.org/user_avatar/discourse.itk.org/gdevenyi/32/355_2.png) [@gdevenyi](https://discourse.itk.org/u/gdevenyi)\
**Post date:** [June 25, 2019, 6:08pm UTC](https://discourse.itk.org/t/trimming-down-itk-build-to-just-used-parts/1995/1 "2019-06-25T18:08:17Z")

</div>

I’m investigating trimming down the ANTs superbuild to include the minimum components of ITK/VTK required for it to function.

I was wondering, can anyone suggest a method to determine which components are used so that I can cut back the build. Thanks!

---

<div class="post-metadata">

**Author:** ![bill.lorensen](https://discourse.itk.org/user_avatar/discourse.itk.org/bill.lorensen/32/66_2.png) [@bill.lorensen](https://discourse.itk.org/u/bill.lorensen)\
**Post date:** [June 26, 2019, 3:09am UTC](https://discourse.itk.org/t/trimming-down-itk-build-to-just-used-parts/1995/2 "2019-06-26T03:09:55Z")

</div>

Both VTK and ITK have a utility called:

[WhatModulesVTK.py](https://gitlab.kitware.com/vtk/vtk/blob/master/Utilities/Maintenance/WhatModulesVTK.py) and [WhatModulesITK.py](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Utilities/Maintenance/WhatModulesITK.py).

Use the versions that are in your vtk or itk checkout.

These scripts generate a list of modules referenced in your code tree.  
For VTK you should turn off these cmake variables:

```
BUILD_EXAMPLES:BOOL=OFF .  
BUILD_TESTING:BOOL=OFF
VTK_BUILD_ALL_MODULES_FOR_TESTS:BOOL=OFF
VTK_Group_Rendering:BOOL=OFF
VTK_Group_StandAlone:BOOL=OFF

```

For ITK,

```
BUILD_EXAMPLES:BOOL=OFF
BUILD_TESTING:BOOL=OFF
ITK_BUILD_DEFAULT_MODULES:BOOL=OFF
ITKGroup_Core:BOOL=OFF

```

I have used these scripts to create options for my [Open Atlas Project](https://github.com/lorensen/OpenAtlas). Here are the [External-VTK.cmake](https://github.com/lorensen/OpenAtlas/blob/master/Superbuild/External-VTK.cmake) and [External-ITK.cmake](https://github.com/lorensen/OpenAtlas/blob/master/Superbuild/External-ITK.cmake) files.

HTH,

Bill

---

<div class="post-metadata">

**Author:** ![gdevenyi](https://discourse.itk.org/user_avatar/discourse.itk.org/gdevenyi/32/355_2.png) [@gdevenyi](https://discourse.itk.org/u/gdevenyi)\
**Post date:** [June 26, 2019, 4:42pm UTC](https://discourse.itk.org/t/trimming-down-itk-build-to-just-used-parts/1995/3 "2019-06-26T16:42:53Z")

</div>

Thanks @bill.lorensen that’s exactly what I was looking for!

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [June 26, 2019, 5:02pm UTC](https://discourse.itk.org/t/trimming-down-itk-build-to-just-used-parts/1995/4 "2019-06-26T17:02:15Z")

</div>

What Bill provides is a method to reduce the number of ITK modules used in the entire project. This can also be done on a per target level. Reducing the number of include paths during compilation and libraries used during linking or runtime loading of dynamic libraries.

While CMake has a modern (newer then ITK module) system for managing target properties and interfaces. ITK still has a custom module infrastructure.

SimpleITK has a macro to mimic the CMake `target_link_libraries` interface options to enable target specific linkage and include paths.

You can file the CMake macro here:

> <https://github.com/SimpleITK/SimpleITK/blob/master/CMake/sitkTargetUseITK.cmake>

and an example usage here:

> <https://github.com/SimpleITK/SimpleITK/blob/master/Code/IO/src/CMakeLists.txt>

Using this method adds the modern CMake interface options to your libraries, so transitive properties are automatically handled by CMake.

---

<div class="post-metadata">

**Author:** ![bill.lorensen](https://discourse.itk.org/user_avatar/discourse.itk.org/bill.lorensen/32/66_2.png) [@bill.lorensen](https://discourse.itk.org/u/bill.lorensen)\
**Post date:** [June 26, 2019, 6:04pm UTC](https://discourse.itk.org/t/trimming-down-itk-build-to-just-used-parts/1995/5 "2019-06-26T18:04:14Z")

</div>

The [VTK Examples Project](https://lorensen.github.io/VTKExamples/site/) uses the _what module_ to automatically generate a CMakeLists.txt for each example.

For example, see the generated [CMakeLists.txt](https://lorensen.github.io/VTKExamples/site/Cxx/InfoVis/WordCloudDemo/#cmakeliststxt) file for the [WordCloudDemo](https://lorensen.github.io/VTKExamples/site/Cxx/InfoVis/WordCloudDemo/) example. This works for both the old and new VTK module API’s.

Bill
