# Find all available modules from GroupIO

**URL:** https://discourse.itk.org/t/find-all-available-modules-from-groupio/351
**Category:** Uncategorized
**Tags:** io, cmake
**Created:** [October 25, 2017, 3:08am UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351 "2017-10-25T03:08:29Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [October 25, 2017, 3:08am UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/1 "2017-10-25T03:08:29Z")

</div>

Is it possible to use any installed/available modules from [Group IO](https://itk.org/Doxygen/html/modules.html) without specifying particular Modules: `IOTIFF`, etc? Something like:

`find_package(ITK COMPONENTS ITKExternalModule ITKGroupIO ...)`

Right now I am using:

`find_package(ITK COMPONENTS IsotropicWavelets ITKIOImageBase ITKIOTIFF ITKIOPNG ITKIOJPEG REQUIRED)`

But it feels like my application shouldn’t care what IO modules the user has selected.

What do you use/recommend here? Thanks

---

<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: [October 25, 2017, 1:09pm UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/2 "2017-10-25T13:09:29Z")

</div>

The list of packages are important in the case of static libraries - the more formats you list, the bigger your compiled executable will be.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [October 25, 2017, 1:10pm UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/3 "2017-10-25T13:10:49Z")

</div>

Good question, @phcerdan.

What is needed is not necessarily the _Group IO_ modules – what is needed are all modules that provide [itk::ImageIOBase](https://itk.org/Doxygen/html/classitk_1_1ImageIOBase.html) classes for population of the factory. Some modules in _Group IO_ provide transform and mesh IO. And, there other modules that provide _ImageIOBase_ classes that are not in _Group IO_.

So, what we needed is a new parameter for the `itk_module` macro that declares what factory classes a module provides. These values can be stored in `lib/cmake/ITK-4.XX/Modules/ModuleName.cmake`, and loaded and parsed by `ITKConfig.cmake` when `find_package(ITK` is called.

---

<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: [October 25, 2017, 1:17pm UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/4 "2017-10-25T13:17:43Z")

</div>

While having improved information specified in the itk\_module, for internal and external management of the IO factories, would be an overall good thing, there are some conventions that can be currently be utilized. Currently, all IO modules names contain “IO”, so I have using the following in SimpleITK, which may work for your case too:

> <https://github.com/SimpleITK/SimpleITK/blob/81139b32ccc386c9cb27485e118b968c668e983e/Code/IO/src/CMakeLists.txt#L12-L18>

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [October 25, 2017, 9:54pm UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/5 "2017-10-25T21:54:54Z")

</div>

Thanks for the feedback! @matt.mccormick that would super helpful for external projects indeed. I’ll go for parsing `ITK_MODULES_ENABLED` for now, as @blowekamp suggested. Thanks!

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [October 25, 2017, 10:27pm UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/6 "2017-10-25T22:27:36Z")

</div>

For completeness, this is what I have used based on @blowekamp suggestion.

I had to find\_package twice to import `ITK_MODULES_ENABLED`

```auto
find_package(ITK CONFIG REQUIRED)
set(use_itk_modules IsotropicWavelets )
foreach( mod IN LISTS ITK_MODULES_ENABLED)
  if( ${mod} MATCHES "IO")
    list(APPEND use_itk_modules ${mod})
  endif()
endforeach()
find_package(ITK COMPONENTS ${use_itk_modules} REQUIRED)
#include_directories(${ITK_INCLUDE_DIRS}) # Not needed
include(${ITK_USE_FILE})

```

---

<div class="post-metadata">

### Author: ![fbudin](https://discourse.itk.org/user_avatar/discourse.itk.org/fbudin/32/14_2.png) [@fbudin](https://discourse.itk.org/u/fbudin)
#### Post date: [October 26, 2017, 2:24pm UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/7 "2017-10-26T14:24:18Z")

</div>

Another option would be to do:

```auto
# First pass to get the list of IOs available
find_package(ITK CONFIG REQUIRED)
include(${ITK_USE_FILE})

# Create list of avaialble image formats
foreach(ImageFormat ${LIST_OF_IMAGEIO_FORMATS})
  if (NOT ${ImageFormat}_image_module_name )
     list(APPEND IOList ITKIO${ImageFormat})
  endif()
endforeach()
find_package(ITK COMPONENTS IsotropicWavelets ${IOList} REQUIRED )
include(${ITK_USE_FILE})

```

I haven’t tried it, but I think it should work.

---

<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: [October 26, 2017, 2:40pm UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/8 "2017-10-26T14:40:51Z")

</div>

I thought `LIST_OF_IMAGEIO_FORMATS` and `LIST_OF_TransformIO_FORMATS` were “private” cmake variables, and not part of the public interface for of UseITK.cmake?

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [October 26, 2017, 6:50pm UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/9 "2017-10-26T18:50:21Z")

</div>

Thanks for the follow-up, @phcerdan.

> [@phcerdan](#):
>
> include\_directories({ITK\_INCLUDE\_DIRS}) include({ITK\_USE\_FILE})

Minor tweak possible here – `include_directories` is called already by `include(${ITK_USE_FILE})`, so it can be removed. This will help reduce the length of the command line calls.

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [November 4, 2017, 11:03pm UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/10 "2017-11-04T23:03:55Z")

</div>

Thanks @matt.mccormick , I commented it out.

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [February 20, 2018, 11:35pm UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/11 "2018-02-20T23:35:38Z")

</div>

Do you know if this approach is still valid in ITK-5.0?  
I cannot read 3D tiff files with the suggested workaround --it reads a 3D image, but only the first slice-- but if a hard code the ITKIOTIFF component it works.  
I am not getting a read error, it is just that the image of size 64x64x16 reads as 64x64x1.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [February 21, 2018, 1:24am UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/12 "2018-02-21T01:24:41Z")

</div>

A much better approach is available in ITK 4.13 and newer.

```auto
find_package(ITK REQUIRED COMPONENTS ITKImageIO)

```

Here `ITKImageIO` will bring in all modules that have Image IO’s, whether they are in the `IO` group or otherwise (like remote modules).

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [February 21, 2018, 1:31am UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/13 "2018-02-21T01:31:47Z")

</div>

Oh yeah, thanks!

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [April 2, 2019, 3:58pm UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/14 "2019-04-02T15:58:21Z")

</div>

> [@fbudin](#):
>
> I haven’t tried it, but I think it should work.

For completeness, I tested it and it doesn’t work. For version \< 4.13 I am sticking with [what I was using](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/6).  
Since 4.13, `ITKImageIO` is awesome 🙂  
Thanks!

---

<div class="post-metadata">

### Author: ![Sara\_Caffe](https://discourse.itk.org/user_avatar/discourse.itk.org/sara_caffe/32/974_2.png) [@Sara\_Caffe](https://discourse.itk.org/u/Sara_Caffe)
#### Post date: [November 7, 2019, 3:56am UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/15 "2019-11-07T03:56:04Z")

</div>

@matt.mccormick and @phcerdan I am wondering how we can realize which components should be added in the cmakelist. For example, once I included the `#include <itkMeshFileWriter.h>` , I was getting the `undefined reference errors` as follows:

```
CMakeFiles/3-WritePLY.dir/main.cpp.o:(.data+0xc0): undefined reference to `itk::BYUMeshIOFactoryRegister__Private()'
CMakeFiles/3-WritePLY.dir/main.cpp.o:(.data+0xc8): undefined reference to `itk::BYUMeshIOFactoryRegister__Private()'
CMakeFiles/3-WritePLY.dir/main.cpp.o:(.data+0xd0): undefined reference to `itk::FreeSurferAsciiMeshIOFactoryRegister__Private()'
CMakeFiles/3-WritePLY.dir/main.cpp.o:(.data+0xd8): undefined reference to `itk::FreeSurferAsciiMeshIOFactoryRegister__Private()'
CMakeFiles/3-WritePLY.dir/main.cpp.o:(.data+0xe0): undefined reference to `itk::FreeSurferBinaryMeshIOFactoryRegister__Private()'
CMakeFiles/3-WritePLY.dir/main.cpp.o:(.data+0xe8): undefined reference to `itk::FreeSurferBinaryMeshIOFactoryRegister__Private()'
CMakeFiles/3-WritePLY.dir/main.cpp.o:(.data+0xf0): undefined reference to `itk::GiftiMeshIOFactoryRegister__Private()'
CMakeFiles/3-WritePLY.dir/main.cpp.o:(.data+0xf8): undefined reference to `itk::GiftiMeshIOFactoryRegister__Private()'
CMakeFiles/3-WritePLY.dir/main.cpp.o:(.data+0x100): undefined reference to `itk::OBJMeshIOFactoryRegister__Private()'
CMakeFiles/3-WritePLY.dir/main.cpp.o:(.data+0x108): undefined reference to `itk::OBJMeshIOFactoryRegister__Private()'
CMakeFiles/3-WritePLY.dir/main.cpp.o:(.data+0x110): undefined reference to `itk::OFFMeshIOFactoryRegister__Private()'
CMakeFiles/3-WritePLY.dir/main.cpp.o:(.data+0x118): undefined reference to `itk::OFFMeshIOFactoryRegister__Private()'
CMakeFiles/3-WritePLY.dir/main.cpp.o:(.data+0x120): undefined reference to `itk::VTKPolyDataMeshIOFactoryRegister__Private()'

```

I just commented the include line and then could run the code. But how we can know that which component should we include in the `fine_package` in the cmake file whenever we are including any specific header file?

Is there any reference that we can get help from?

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [November 7, 2019, 7:40am UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/16 "2019-11-07T07:40:41Z")

</div>

Hey @Sara_Caffe, please do not revamp existing threads for completely new questions. Just open a new one.

ITK has a helper script [WhatModulesITK.py](https://github.com/InsightSoftwareConsortium/ITK/blob/9d1a92d1b53c2877ed0a320d3c700905109332ac/Utilities/Maintenance/WhatModulesITK.py) for finding what modules you need based on the `#include's` you have in your projects.

See [this thread](https://discourse.itk.org/t/itk-modules-a-comprehensive-list/1701) for more info about modules.

For usage, see documentation in the python script, for example:  
Single file:

```auto
 /path/src-ITK-master/Utilities/Maintenance/WhatModulesITK.py /path/ITK/src-ITK-master /path/myproject/foo.cpp)

```

List of files:

```auto
 /path/src-ITK-master/Utilities/Maintenance/WhatModulesITK.py /path/ITK/src-ITK-master $(find /path/myproject/ -type f)

```

---

<div class="post-metadata">

### Author: ![Sara\_Caffe](https://discourse.itk.org/user_avatar/discourse.itk.org/sara_caffe/32/974_2.png) [@Sara\_Caffe](https://discourse.itk.org/u/Sara_Caffe)
#### Post date: [November 20, 2019, 6:45am UTC](https://discourse.itk.org/t/find-all-available-modules-from-groupio/351/17 "2019-11-20T06:45:09Z")

</div>

Thank you Sir, This is really helpful. Sorry for asking the question here

appreciate it.
