Introducing a new way to review your PRs.

Read the announcement

insightsoftwareconsortium / itk

Insight Toolkit (ITK) -- Official Repository. ITK builds on a proven, spatially-oriented architecture for processing, segmentation, and registration of scientific images in two, three, or more dimensions.

View on GitHub

19 documents · Updated Nov 23, 2026

docs / module-declaration-and-dependencies

Module declaration and dependency resolution

ITK modules use shared CMake metadata to describe library capabilities and required relationships. The build turns that metadata into an ordered, selectable module set, then publishes the same dependency and target information to in-tree tests, external modules, and downstream package users. This page complements Module build and distribution, Python wrapping, Testing and continuous integration, and I/O format integration.

Module metadata

Module declarations

An itk-module.cmake file defines the contract for one module. It identifies the module and records the dependencies, description, factory formats, and build choices that other parts of the build use. The dependency roles remain separate because each role has a different effect:

  • Public dependencies form part of the module's user-facing link contract.
  • Private dependencies support the module implementation without becoming part of that contract.
  • Compile dependencies must be available first but are not linked by the module. This role is deprecated in favor of public or private dependencies.
  • Test dependencies apply to the module's test targets.

The declaration can also define factory formats. A factory format lets a group such as image I/O select a provider by capability instead of by each provider module name. A declaration can also enable shared-library support for the module, as ITKIOMeshBase does while declaring its mesh and image I/O dependencies. The ITKIOGE and ITKIOMINC declarations show how image providers expose factory names while keeping implementation-only dependencies private when needed. ITKIOStimulate shows the same image-provider contract with a public image I/O dependency, shared-library support, test support, and an ImageIO::Stimulate factory name. The FFT declarations show how a provider can be conditional: ITKFFT always exposes PocketFFT, and adds the ITKFFTW dependency and FFTW factory when single- or double-precision FFTW is requested. ITKFFTW is a separate GPL-licensed module that is excluded from the default selection. IsotropicWavelets shows a shared module with several public processing dependencies, optional VTK glue for tests, and explicit exclusion from the default selection. Other declarations show the same contract across different module roles: ITKTestKernel gathers test support and optional Python wrapping support, ITKIODCMTK exposes a DCMTK image provider without default enablement, and ITKNarrowBand relies on image-processing and finite-difference capabilities while adding shared test support.

The SmoothingRecursiveYvvGaussianFilter declaration shows how one module adds optional GPU support without changing its base role. When GPU use is enabled, its dependency set includes the GPU smoothing and common modules; its test set also includes GPU common support. The module stays out of the default selection because it is marked EXCLUDE_FROM_DEFAULT.

References: CMake/ITKModuleMacros.cmake• L15-49 Modules/…/itk-module.cmake• L17-35 Modules/…/itk-module.cmake• L1-45 Modules/…/itk-module.cmake• L1-15 Modules/…/itk-module.cmake• L1-23 Modules/…/itk-module.cmake• L1-23 Modules/…/itk-module.cmake• L1-22 Modules/…/itk-module.cmake• L1-24 Modules/…/itk-module.cmake• L1-19 Modules/…/itk-module.cmake• L1-17 Modules/…/itk-module.cmake• L8-40 Modules/…/itk-module.cmake• L1-36 Modules/…/itk-module.cmake• L1-7 Modules/…/itk-module.cmake• L10-27 Modules/…/itk-module.cmake• L1-33 Modules/…/itk-module.cmake• L7-16 Modules/…/itk-module.cmake• L6-17 Modules/…/itk-module.cmake• L6-17 Modules/…/itk-module.cmake• L10-32

When a module has tests, the build connects the test area to its parent module. This keeps test code in the same dependency model without changing the library's public interface. Shared test support adds the module label and can arrange cleanup for temporary outputs.

References: CMake/ITKModuleMacros.cmake• L51-137 CMake/ITKModuleEnablement.cmake• L20-34 CMake/ITKModuleTest.cmake• L103-175 CMake/ITKModuleTest.cmake• L401-471

Module metadata records

After a module is assembled, the build writes a metadata record for it. The record gives later build steps and consumers a stable view of the module's identity, dependencies, targets, include paths, library paths, and factory formats. Consumers load this record by module name instead of parsing the source declaration again.

References: CMake/ITKModuleInfo.cmake.in• L1-15 CMake/ITKModuleAPI.cmake• L70-105

Dependency graph

Graph discovery

The build discovers module declarations before it selects modules. It checks that dependency names are declared and rejects invalid relationships, including cycles. The result is a directed acyclic graph, or DAG, that gives the build a valid order for compilation and downstream use.

References: CMake/ITKModuleEnablement.cmake• L4-113

The graph also separates normal modules from restricted areas such as deprecated, review, and integrated-test modules. A dependency is valid only when its declaration belongs to an area that permits that relationship. The v4 registration declarations illustrate how related capabilities form a graph: ITKRegistrationMethodsv4 depends on ITKMetricsv4 and ITKOptimizersv4, while ITKMetricsv4 also depends on ITKRegistrationCommon.

References: CMake/ITKModuleEnablement.cmake• L20-58 Modules/…/itk-module.cmake• L6-17 Modules/…/itk-module.cmake• L6-17

This diagram shows how declarations become an ordered build and reusable package data.

flowchart LR
    D[Module declarations] --> G[Dependency graph]
    G --> V[Validation and cycle checks]
    V --> E[Module enablement]
    E --> O[Dependency order]
    O --> B[Module targets]
    B --> M[Build and install metadata]
    M --> C[Consumer configuration]

Dependency resolution

When the build enables a module, it enables the modules required by that module. The final set therefore includes direct requests, group or default selections, and transitive dependencies. At package use time, itk_module_config resolves that transitive set into one consumer view of libraries, interface targets, include paths, library paths, run-time paths, and factory formats.

References: CMake/ITKModuleEnablement.cmake• L174-235 CMake/ITKModuleAPI.cmake• L20-65 CMake/ITKModuleAPI.cmake• L107-173

Module selection

Default enablement

The default build selects modules unless their declarations mark them EXCLUDE_FROM_DEFAULT. For example, AdaptiveDenoising, VariationalRegistration, IsotropicWavelets, ITKIODCMTK, and ITKFFTW are available for explicit selection but do not enter a default build. ITKFFT remains selectable with PocketFFT by default; enabling either FFTW precision option adds the FFTW provider dependency. A user can request one module with Module_<name> or a capability group with ITKGroup_<group>. Dependency resolution then adds the modules needed to satisfy the request.

References: CMake/ITKModuleEnablement.cmake• L115-172 CMake/ITKModuleEnablement.cmake• L216-235 Modules/…/itk-module.cmake• L11-27 Modules/…/itk-module.cmake• L18-33 Modules/…/itk-module.cmake• L7-23 Modules/…/itk-module.cmake• L34-40 Modules/…/itk-module.cmake• L11-25 Modules/…/itk-module.cmake• L1-7

Module groups

Groups provide a product-level selection surface for related capabilities. The build scans the module declarations under each named group, removes modules marked for exclusion from the default selection, and maps an enabled ITKGroup_<group> option to requests for the remaining modules. The dependency graph then supplies lower-level modules that those capabilities need, so group selection expresses the desired feature set rather than replacing dependency resolution.

References: CMake/ITKGroups.cmake• L1-16 CMake/ITKGroups.cmake• L107-127 CMake/ITKGroups.cmake• L162-205 CMake/ITKModuleEnablement.cmake• L268-280

The build tracks why each module is enabled. A module can enter the build through a direct request, a group or default choice, or another module's dependency. This distinction helps explain why a module appears even when the user did not name it.

References: CMake/ITKModuleEnablement.cmake• L268-280

Remote and external modules

Remote module handling

Remote modules extend ITK from outside the main source tree. A remote declaration identifies the module, its source repository, revision, description, and compliance level. Remote modules are off by default, and the configured compliance threshold controls whether a declaration is eligible.

References: Modules/…/CMakeLists.txt• L1-22 CMake/ITKModuleRemote.cmake• L184-259 Modules/…/SCIFIO.remote.cmake• L44-50

The build loads remote declarations while it forms the graph. If a dependency is missing and does not use an ITK module name, the build treats it as a possible remote module and requests the source before it completes module selection. An enabled remote module is then cloned or updated at its requested revision unless download policy or freeze settings prevent that action. The current declarations pin revisions and assign compliance levels: RTK and Ultrasound use level 3, LesionSizingToolkit uses level 2, and FEM uses level 1.

References: CMakeLists.txt• L776-787 CMake/ITKModuleEnablement.cmake• L60-113 CMake/ITKModuleRemote.cmake• L61-182 CMake/ITKModuleRemote.cmake• L276-369 Modules/…/FEM.remote.cmake• L13-31 Modules/…/LesionSizingToolkit.remote.cmake• L44-50 Modules/…/RTK.remote.cmake• L40-46 Modules/…/Ultrasound.remote.cmake• L44-67

External module handling

An external module is built in a separate project while using an ITK build tree as its host. CMake/ITKModuleExternal.cmake checks that the host is compatible, then aligns the external project with ITK's build settings, module search path, target records, install layout, tests, and optional wrapping. This lets an external module use the same declaration and consumer contract as an in-tree module.

References: CMake/ITKModuleExternal.cmake• L4-31 CMake/ITKModuleExternal.cmake• L65-107 CMake/ITKModuleExternal.cmake• L142-220

The external project can add its tests and wrapping only when the matching ITK features and source areas are available. Its host must be an ITK build tree because the module assembly support and build-context target data are not supplied by a plain install tree.

References: CMake/ITKModuleExternal.cmake• L26-31 CMake/ITKModuleExternal.cmake• L222-301

External build settings

External projects must keep selected build settings equal to the ITK host. CMake/ITKModuleExternalSettings.cmake seeds missing settings from ITK and stops configuration when shared-library or Python settings differ. This prevents an external module from producing targets that do not match the host ABI or wrapping setup.

References: CMake/ITKModuleExternalSettings.cmake• L1-34 CMake/ITKModuleExternalSettings.cmake• L36-63 CMake/ITKModuleExternal.cmake• L33-56

Generated configuration

Module configuration records

The build writes module records for both the build context and the install context. They preserve the same module meaning while using paths suitable for each context. The install records travel with the package so a later consumer can resolve the installed module set.

References: CMake/ITKModuleMacros.cmake• L483-581 CMake/ITKModuleInfo.cmake.in• L1-15

Package configuration

The generated ITKConfig.cmake is the entry point for a consumer. It locates the module records, imports ITK targets, loads the module API, and resolves requested components or factories. A factory request selects providers by capability, while a module request selects a named module and its required graph.

References: CMakeLists.txt• L792-839 CMake/ITKConfig.cmake.in• L8-15 CMake/ITKConfig.cmake.in• L66-103 CMake/ITKModuleAPI.cmake• L37-59

CMake assembly macros

Module target assembly

itk_module_impl assembles one enabled module. It loads the declaration, prepares dependency use, adds the module source area, creates the module interface, and writes metadata. itk_module_add_library then creates the implementation target, connects it to its public and private dependencies, and applies the export and install contract.

References: CMake/ITKModuleMacros.cmake• L145-183 CMake/ITKModuleMacros.cmake• L391-478 CMake/ITKModuleMacros.cmake• L892-945

The module interface is the stable boundary for users. It carries the module's libraries and include paths, exposes public and compile dependencies as interface links, and keeps private dependencies on the implementation target. A consumer can therefore use the selected module interface without rebuilding the graph by hand.

References: CMake/ITKModuleMacros.cmake• L391-422 CMake/ITKModuleMacros.cmake• L585-618

Factory assembly

Factory meta-modules collect providers for a capability such as image input and output or transforms. A provider declares its formats, and the assembly step connects its interface to the matching factory interface. For FFT, ITKFFT exposes PocketFFT by default and conditionally adds FFTW; when FFTW is enabled, its declaration places that provider first. This makes a factory request resolve to the matching provider through one consumer contract.

References: CMake/ITKModuleEnablement.cmake• L434-471 CMake/ITKModuleMacros.cmake• L424-474 Modules/…/itk-module.cmake• L11-35 Modules/…/itk-module.cmake• L1-7

Module quality checks

The module macros can add checks that protect the dependency contract and the public module surface. Header tests compile generated source that includes the module headers, while Doxygen checks verify that public headers belong to the module's documentation group. KWStyle checks apply the shared style rules or a module-specific override.

References: CMake/ITKModuleHeaderTest.cmake• L42-151 CMake/ITKModuleDoxygen.cmake• L13-67 CMake/ITKModuleKWStyleTest.cmake• L45-113

These checks are part of module assembly support rather than separate product features. Header tests expose missing dependencies, Doxygen checks keep public documentation grouped, and KWStyle checks keep source files within the shared style contract.

References: CMake/ITKModuleHeaderTest.cmake• L1-5 CMake/ITKModuleDoxygen.cmake• L19-41 CMake/ITKModuleKWStyleTest.cmake• L15-43

Change checklist

When these files or sections are changed, remember to consider these:

  • A public, private, or compile dependency change affects both graph order and the link data exposed to consumers.
  • A conditional dependency must keep its feature guard aligned with the module's build and test needs.
  • A factory format change must remain aligned with provider declarations, conditional backend dependencies, factory interfaces, and generated registration data.
  • An optional third-party backend must keep its default-selection policy and licensing notice aligned with the feature switch that enables it.
  • A group or default-selection change must account for excluded modules and the final dependency order.
  • A remote dependency change must keep its declaration name, revision, compliance level, and download policy aligned.
  • An external-module change must preserve the build-tree host requirement, the build/install target records, and the settings matched by CMake/ITKModuleExternalSettings.cmake.
  • A module header or source layout change can affect generated header-test inputs and KWStyle file lists.
  • A test registration change must preserve unique names, module labels, and cleanup fixture behavior.
  • A path or export change must work in both build-tree and install-tree module records.

Important failure modes

TriggerConsequenceGuard
A module names an undeclared or invalid dependencyConfiguration cannot form a valid graphKeep dependency names aligned with loaded declarations and allowed module areas
The dependency graph contains a cycleConfiguration fails before module targets are assembledKeep dependencies one-way and remove the reported cycle
A conditional GPU dependency is requested without the matching GPU module setThe module cannot resolve its enabled dependency graphKeep ITK_USE_GPU and the GPU modules available in the same build
An FFTW precision option is enabled without an available ITKFFTW moduleThe FFTW provider cannot enter the dependency graph or factory setMake the third-party module available and let dependency resolution enable it
The FFTW backend is used without GPL license reviewDistribution can violate the backend's license termsTreat FFTW as an optional provider and check GPL obligations before distribution
A remote module fails the compliance threshold or cannot be downloadedThe requested module cannot enter the buildUse an eligible revision and allow downloads or provide the source locally
An external project changes a setting that must match its ITK hostConfiguration stops before module assemblyUse the host's shared-library and Python settings or configure a fresh external build tree
An external module uses an ITK install tree as its hostExternal module setup stops before assemblyUse an ITK build tree with module build support
Two configured tests use the same nameIn-tree configuration fails and remote tests may race during cleanupGive tests unique names across the configured build
A header list or style file list is staleA quality check can miss a changed public file or fail on an invalid input setRegenerate the list through the module check configuration
Temporary test cleanup is disabled or miswiredLarge test outputs remain and can fill build storageKeep cleanup enabled and pass exact output paths to the cleanup fixture
A consumer requests a module or factory absent from the packageComponent resolution does not produce the expected interfaceBuild and install the requested module or provider set

Key files

FileWhy to read it
CMake/ITKModuleMacros.cmakeDefines module declarations and the macros that assemble, link, export, install, and describe module targets.
CMake/ITKModuleEnablement.cmakeShows graph discovery, validation, selection, dependency ordering, and factory enablement.
CMake/ITKModuleAPI.cmakeShows how build and downstream consumers load module records and resolve dependencies.
CMake/ITKModuleInfo.cmake.inDefines the generated per-module metadata contract.
CMake/ITKGroups.cmakeDefines group names, discovers group members, and maps group options to module requests.
CMake/ITKModuleRemote.cmakeDefines remote module compliance, revision, and fetch behavior.
CMake/ITKModuleExternal.cmakeDefines the build-tree boundary and shared setup for modules outside the source tree.
CMake/ITKModuleExternalSettings.cmakeDefines the build settings that an external project must match with its ITK host.
CMake/ITKModuleTest.cmakeDefines test drivers, test registration, labels, duplicate-name checks, and output cleanup.
CMake/ITKModuleDoxygen.cmakeDefines module documentation groups and dependency diagrams.
CMake/ITKModuleHeaderTest.cmakeDefines generated public-header coverage checks.
CMake/ITKModuleKWStyleTest.cmakeDefines module source style checks and override behavior.
CMake/ITKConfig.cmake.inShows how installed consumers request modules and factories.
CMakeLists.txtShows the top-level order for remote loading, module enablement, and package configuration.
Modules/Core/TestKernel/itk-module.cmakeShows a test-support module with public, private, compile, test, and conditional Python dependencies.
Modules/Filtering/SmoothingRecursiveYvvGaussianFilter/itk-module.cmakeShows a module with conditional GPU dependencies, separate test dependencies, and explicit exclusion from the default build.
Modules/IO/DCMTK/itk-module.cmakeShows a shared-library image provider with a private third-party dependency, a factory name, and explicit exclusion from the default build.
Modules/Numerics/NarrowBand/itk-module.cmakeShows a numerics module whose public processing dependencies are distinct from its test dependencies.
Modules/Filtering/FFT/itk-module.cmakeShows conditional FFT provider selection and the relationship between feature settings, dependencies, and factory names.
Modules/ThirdParty/FFTW/itk-module.cmakeShows an optional third-party module that is excluded from the default build and carries a GPL license description.
Modules/Filtering/AdaptiveDenoising/itk-module.cmakeShows a shared module with public, compile-only, and test-only dependencies that is excluded from the default build.
Modules/Filtering/IsotropicWavelets/itk-module.cmakeShows a shared processing module with optional VTK glue for tests and explicit exclusion from the default build.
Modules/Numerics/Polynomials/itk-module.cmakeShows a small numerics module with a public base dependency and separate test support.
Modules/Registration/Metricsv4/itk-module.cmakeShows how a v4 registration metric module depends on the common and optimizer layers.
Modules/Registration/RegistrationMethodsv4/itk-module.cmakeShows how a v4 registration method module builds on metrics and optimizers.
Modules/IO/MeshBase/itk-module.cmakeShows a module declaration with shared-library support, mesh and image I/O dependencies, and test dependencies.
Modules/IO/Stimulate/itk-module.cmakeShows an image I/O provider with shared-library support, an image I/O dependency, test support, and a factory name.
Modules/IO/Bruker/itk-module.cmakeShows a declaration with a public dependency, test dependencies, and a factory format.
Modules/IO/GE/itk-module.cmakeShows an image I/O provider with shared-library support and more than one factory format.
Modules/IO/MINC/itk-module.cmakeShows the boundary between a public image I/O dependency and a private implementation dependency.
Modules/Registration/VariationalRegistration/itk-module.cmakeShows a module that has many public dependencies, keeps image I/O dependencies private, requires test support, and is excluded from the default build.
Modules/Remote/FEM.remote.cmakeShows a low-compliance remote module with a user warning about its retired status.
Modules/Remote/LesionSizingToolkit.remote.cmakeShows a pinned remote module with a lower compliance level and a focused product description.
Modules/Remote/RTK.remote.cmakeShows a pinned remote module with a declared compliance level and repository source.
Modules/Remote/Ultrasound.remote.cmakeShows a remote module with a longer product description and a pinned source revision.