Reduced dependencies for ITK external modules

I would like to reduce dependencies to only the minimal ITK modules, instead of pulling in all of itk from pypi.

Since my code only depends on ITKCommon I tried using itk-core as dependency.

I did pip install itk_dissolve-1.0.3-cp39-cp39-win_amd64.whl:
Then if I try to use the package I get following error:

python -c "import itk; print(itk.dissolve_mask_image_filter)"

Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\lloyd\Downloads\WindowsWheel3.9.venv\lib\site-packages\itk\support\lazy.py”, line 132, in getattribute
base.itk_load_swig_module(module, namespace)
File “C:\Users\lloyd\Downloads\WindowsWheel3.9.venv\lib\site-packages\itk\support\base.py”, line 102, in itk_load_swig_module
itk_load_swig_module(dep, namespace)
File “C:\Users\lloyd\Downloads\WindowsWheel3.9.venv\lib\site-packages\itk\support\base.py”, line 98, in itk_load_swig_module
l_data = itk_base_global_module_data[name]
KeyError: ‘ITKImageSources’

My itk-module.cmake file contains:

itk_module(Dissolve
  DEPENDS
    ITKCommon
  COMPILE_DEPENDS
    ITKImageSources
  TEST_DEPENDS
    ITKTestKernel
    ITKMetaIO
  DESCRIPTION
    "${DOCUMENTATION}"
  EXCLUDE_FROM_DEFAULT
  ENABLE_SHARED
)

which also contains the ITKImageSources key word. What would ITKImageSources map to in terms of python modules? itk-filtering?

(I am not sure if the dependency to ITKImageSources is needed - maybe it is just a copy paste from another external module).

Yes, ImageSources are in filtering.

A way to check correctness of these dependencies is to build ITK with ITK_BUILD_DEFAULT_MODULES=OFF and ITKGroup_Core=OFF. Then only the declared dependencies will be built.

Edit: you will need to set Module_ITKCommon=ON and maybe Module_ITKImageSources=ON.

1 Like

thanks @dzenanz

@dzenanz I checked and I could set COMPILE_DEPENDS to ITKCommon and now the package works.

Out of curiosity: What is the difference between DEPENDS and COMPILE_DEPENDS?

Depends requires the modules for use, e.g. by publicly including it in header files. Compile depends indicates it is only required for compiling the module but not for using it. That makes sense only for modules which have a compiled part, i.e. modules which are not header-only.

Example where compile depends would make sense: module A is header-only, and module B’s compile part uses module A but does not expose it in its public interface. If module A had a compile part too, regular depends would be required because or requiring A’s DLL at runtime.

1 Like

Was that with static or shared libraries? If you are using ITKCommon, there is a “runtime” library dependency that is needed. Depending on the OS/compiler used the order of linking of libraries can matter. Based on @dzenanz explanation this is not a COMPILE_DEPENDS situation, so there will likely be some problems with certain configurations and systems.

1 Like

@dyoll I don’t think you need set(TopologyControl_LIBRARIES ITKCommon), as your module is header-only and you are not using any external libraries. Having ITKCommon in your module’s DEPENDS section implies linking to it.