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-build-and-distribution

Module build and distribution system

The module build and distribution system uses CMake to turn ITK module choices into a configured build, a dependency-safe set of targets, and a package that other projects can use. It also supports optional remote modules and external components while keeping the same module contract across build and install trees.

Build lifecycle

The build moves from global policy to remote-module setup, module selection, target creation, and package export. Each stage supplies the information needed by the next stage, so a configuration choice affects both the build graph and the package seen by downstream projects.

flowchart TD
    A[Configure CMake] --> B[Set build policies and options]
    B --> C[Load remote module definitions]
    C --> D[Discover and select modules]
    D --> E[Resolve dependencies and order modules]
    E --> F[Create module targets]
    F --> G[Export build and install package files]
    G --> H[Downstream project finds ITK]

Global build configuration

Global configuration sets the rules shared by all modules. It chooses the language standard, library form, output and install locations, download policy, testing, wrapping, and library loading behavior before module targets are created. Install paths are relative to CMAKE_INSTALL_PREFIX, which keeps the package layout usable in both the main build and external module projects. CMakeLists.txt defines these policies and options at the start of configuration.

The configuration also defines how ITK uses resources outside its source tree. A build can use system libraries or ITK-managed components, and it can restrict downloads when all required code and data must already exist locally. These choices become part of the package contract when downstream projects use the configured ITK build.

Compiler policy adds only flags that the active compiler accepts. ITK does not add architecture-specific optimization flags by default, so built packages remain usable on more target machines. Platform flags that affect ITK clients are carried through module targets, while external module projects reuse the required flags from the ITK build.

References: CMakeLists.txt• L13-68 CMakeLists.txt• L191-227 CMakeLists.txt• L253-367 CMakeLists.txt• L394-413 CMake/ITKSetStandardCompilerFlags.cmake• L22-57 CMake/ITKSetStandardCompilerFlags.cmake• L113-136 CMake/ITKSetStandardCompilerFlags.cmake• L289-407

Module discovery and selection

Module discovery builds a catalog from the available module declarations. ITKGroups.cmake scans the module declarations under each named group, creates the group and module documentation map, and connects group options to module requests. User options and module groups then select the requested set. A selected module brings in its required dependencies, so the final set represents a usable capability rather than a list of isolated directories. The module enablement system performs discovery, selection, validation, and dependency ordering before CMake enters module directories.

Availability does not mean that a module is enabled by default. A module declaration can exclude a module from the default set while still allowing an explicit selection or a dependency to enable it. Group options request the modules that are not excluded from the default set. When ITK_BUILD_DEFAULT_MODULES is active, CMake hides those group options because the default build already requests the available modules; in a developer build, the Core group is enabled by default unless the build runs under the dashboard configuration. For example, IsotropicWavelets is available for explicit use but is excluded from the default set. It requires image, frequency, FFT, registration, convolution, and image-source capabilities. Its test support adds the test kernel and adds VTK glue only when VTK glue is enabled. The module also opts into shared-library output. AdaptiveDenoising follows the same explicit-selection pattern, while Polynomials is enabled as a normal module with its test support kept in the test dependency set. The build loads remote module definitions before it resolves the dependency graph, so a requested or required remote module can take part in normal selection instead of becoming a special case outside the main module model. See Module declaration and dependencies for the module-level contract.

Module declarations also define the public boundary that downstream code sees. ITKIOGE exposes its image IO capability with public image IO dependencies, while ITKIOMINC keeps ITKMINC private. Both declare factory names so package users can request the capability without knowing each source module. ITKIODCMTK follows the same model for its DICOM IO capability, but stays out of the default set until a user or dependency selects it. ITKTestKernel adds its Python bridge dependency only when Python wrapping is enabled.

References: CMakeLists.txt• L821-827 CMake/ITKModuleEnablement.cmake• L4-34 CMake/ITKModuleEnablement.cmake• L105-113 CMake/ITKModuleEnablement.cmake• L116-239 CMake/ITKGroups.cmake• L1-16 CMake/ITKGroups.cmake• L107-157 CMake/ITKGroups.cmake• L162-205 Modules/…/itk-module.cmake• L13-33 Modules/…/itk-module.cmake• L11-27 Modules/…/itk-module.cmake• L7-16 Modules/…/itk-module.cmake• L8-23 Modules/…/itk-module.cmake• L8-22 Modules/…/itk-module.cmake• L7-23 Modules/…/itk-module.cmake• L9-17

Dependency graph

The dependency graph is the shared model for validation and build order. CMake checks that every required module is known and stops when a dependency cycle exists. It then orders enabled modules so a dependency is ready before the module that uses it.

Dependency visibility also shapes downstream use. Public and compile dependencies travel through a module's interface target, while private dependencies remain inside the owning module. Test dependencies support the module's verification path without becoming part of its consumer link boundary. The registration v4 modules show this layered graph: ITKRegistrationMethodsv4 declares both ITKMetricsv4 and ITKOptimizersv4 as public dependencies, while its test dependencies provide GoogleTest and the test kernel. The resulting module information can be exported and loaded by a consumer without repeating the source-side dependency rules.

References: CMake/ITKModuleEnablement.cmake• L60-103 CMake/ITKModuleEnablement.cmake• L174-214 CMake/ITKModuleEnablement.cmake• L224-239 CMake/ITKModuleMacros.cmake• L35-49 CMake/ITKModuleAPI.cmake• L70-105 Modules/…/itk-module.cmake• L6-17 Modules/…/itk-module.cmake• L6-17 Modules/…/itk-module.cmake• L7-16 Modules/…/itk-module.cmake• L14-44

Module target assembly

Target assembly turns each enabled module into build targets with a common usage boundary. The module interface target carries the include, link, and dependency requirements that consuming code needs. This boundary also works for modules that provide capabilities through registration rather than through their own compiled source.

Module targets use the configured naming and namespace rules. Their interface targets are exported and installed with the same module contract, while library targets can expose the configured namespace for consumers. Module headers and supported target header sets follow the same install boundary. Header file sets require CMake 3.23 or newer when a module uses that install form.

Module declarations can add distribution rules to that common target path. IsotropicWavelets requests shared-library output while keeping its capability outside the default module set. ITKIODCMTK also requests a shared build and registers an image IO factory, so its target form and runtime capability remain visible to package users as one module contract. The same shared-target choice is used by modules such as AdaptiveDenoising, Polynomials, and RegistrationMethodsv4.

The same assembly path applies to in-tree modules, remote modules, and modules built in an external project. Module checks then extend this path with header coverage, style checks, documentation-group checks, and normal or wrapped test drivers when the matching tools and options are available. These checks keep test labels and data needs tied to the module that owns them. CTest also applies configured warning and error limits while filtering known tool and third-party diagnostics for dashboard results. See Testing and continuous integration for the wider test and dashboard flow.

The module test path can register both a standard driver and a GoogleTest driver for one module. Each named test can also declare the temporary outputs that the build removes after the test, which keeps test data separate from source files. Wrapping follows the configured image dimensions, and Python checks run only when the required wrapping, NumPy bridge, precision, and dimension settings are active. See Python wrapping for the wrapping system.

GoogleTest drivers require the module to declare ITKGoogleTest as a test dependency. CMake/ITKModuleTest.cmake gives tests a controlled cleanup path for temporary output while protecting the build from duplicate test names. In-tree duplicate names stop configuration. Collisions from remote repositories produce a warning because the source is outside this tree.

References: CMake/ITKModuleMacros.cmake• L145-180 CMake/ITKModuleMacros.cmake• L392-478 CMake/ITKModuleMacros.cmake• L750-851 CMake/ITKModuleMacros.cmake• L886-947 CMake/ITKModuleMacros.cmake• L907-956 CMake/ITKModuleAPI.cmake• L20-65 CMake/ITKModuleTest.cmake• L16-175 CMake/ITKModuleTest.cmake• L321-374 CMake/ITKModuleTest.cmake• L401-471 CMake/ITKModuleHeaderTest.cmake• L34-153 CMake/ITKModuleKWStyleTest.cmake• L17-113 CMake/ITKModuleDoxygen.cmake• L13-67 CMake/CTestCustom.cmake.in• L20-59 CMake/CTestCustom.cmake.in• L61-182 Modules/…/itk-module.cmake• L18-33 Modules/…/itk-module.cmake• L7-21 Modules/…/itk-module.cmake• L11-27 Modules/…/itk-module.cmake• L7-16 Modules/…/itk-module.cmake• L6-17 Modules/…/CMakeLists.txt• L1-47 Modules/…/CMakeLists.txt• L1-10 Modules/…/CMakeLists.txt• L1-48

External components

External components are libraries or tools that a module uses but does not own as normal ITK module code. The build can use an installed component or build an ITK-managed copy. In both cases, the module target and the installed package must describe the same include and link boundary.

System and bundled resources

System-versus-bundled selection is a build policy that controls where an external component comes from. FFTW shows how this policy supports several providers: ITK can locate an installed FFTW, use oneMKL's FFTW interface, use CUDA's CUFFT compatibility path, or fetch a pinned copy. The selected resource remains behind the module capability that needs it.

The system path finds the requested double- and single-precision components and exposes them through imported FFTW::Double and FFTW::Float targets. A caller can request either precision as a package component. The bundled path uses the same requested precisions and applies target-aware SIMD defaults. An explicit SIMD option remains authoritative, so a package builder can choose a policy that matches its target machines.

The FFTW architecture check runs as a CTest configuration check. It verifies that the default NEON, SSE, SSE2, AVX, and AVX2 choices follow the target architecture rather than the host architecture. It also checks that an explicit user option is not replaced and that universal macOS builds do not assume one architecture's defaults. CMake/…/CMakeLists.txt registers this check when testing is enabled.

References: CMakeLists.txt• L621-705 Modules/…/CMakeLists.txt• L5-40 Modules/…/CMakeLists.txt• L97-145 CMake/FindFFTW.cmake• L1-13 CMake/FindFFTW.cmake• L21-31 CMake/FindFFTW.cmake• L33-87 CMake/FindFFTW.cmake• L89-155 CMake/FindFFTW.cmake• L216-261 Modules/…/itkFFTWOptions.cmake• L9-55 CMake/…/CMakeLists.txt• L1-12 CMake/…/CMakeLists.txt• L1-88

External module settings

External module projects inherit settings that must match the ITK build. The external entry point seeds shared-library, Python, compiler-flag, build-type, and position-independent-code settings from the selected ITK build, then checks them again on later configuration runs. Boolean spellings and equivalent file paths are treated as equal, but a real mismatch stops configuration with the values needed to repair the build.

This check protects the binary and Python package boundary. It catches both cache values and normal variables, so a parent project cannot silently hide a setting that differs from ITK. The case project and its CTest wrapper cover initial seeding, equivalent values, normal-variable overrides, and combined Python mismatches. A compiler identity or version mismatch is reported as a warning because it can still affect binary compatibility.

References: CMake/ITKModuleExternal.cmake• L26-56 CMake/ITKModuleExternal.cmake• L164-204 CMake/ITKModuleExternalSettings.cmake• L1-64 CMake/…/CMakeLists.txt• L1-9 CMake/…/CMakeLists.txt• L9-63

Test data retrieval

Test data retrieval gives module tests access to large files without storing those files in the source tree. The build searches configured local object stores first and uses approved remote URL templates when downloads are allowed. It places resolved data under the build tree so test inputs remain separate from source files.

The data policy is shared by the main build and external module projects. ITK adds its source-side data store to the configured stores, disables symbolic links for Emscripten and WASI, and applies a fixed upper time limit to large downloads. The generated ExternalData configuration carries these choices into the installed package.

References: CMake/ITKExternalData.cmake• L1-35 CMake/ITKExternalData.cmake• L41-82 CMake/ITKModuleTest.cmake• L104-119 CMake/ExternalData_config.cmake.in• L1-6 CMakeLists.txt• L191-196 CMakeLists.txt• L986-989

Package configuration and distribution

ITK distributes more than compiled libraries. It exports targets, module metadata, include paths, library paths, version data, and selected build features so a downstream CMake project can use the same module set without rebuilding the dependency rules.

Build and install package views

The build tree and install tree each receive an ITK package configuration. The build view points to targets and module information in the active build. The install view derives its prefix from the installed configuration file and points to files below the installed package directory. Both views support module selection through find_package(ITK).

The package configuration loads the requested modules and their transitive dependencies. It imports exported targets and exposes factory information. It also reports build properties such as the compiler, C++ standard, shared-library mode, wrapping mode, and FFTW selection. A consumer therefore links to ITK interface targets instead of reconstructing module dependencies. The installed package also carries the FFTW finder so an external module can resolve the same system component policy.

The exported version includes a date-based tweak value in addition to the release version. This gives downstream projects a fine-grained way to compare configured ITK builds between release tags.

References: CMakeLists.txt• L70-73 CMakeLists.txt• L831-879 CMakeLists.txt• L881-944 CMake/ITKConfig.cmake.in• L24-34 CMake/ITKConfig.cmake.in• L66-112 CMake/ITKConfig.cmake.in• L120-157 CMake/ITKModuleInfo.cmake.in• L1-15 CMake/FindFFTW.cmake• L1-13

Downstream module projects

An external module project uses an existing ITK build tree as its configuration source. It reuses ITK's module rules, target names, dependency model, wrapping settings, and install layout. The external-module entry point requires ITK to be found first and rejects an install tree that does not provide the module build macros.

The external project writes its own module metadata and can install it beside the ITK package. Its install paths must remain relative to CMAKE_INSTALL_PREFIX, so the package stays relocatable and its build and install views remain consistent. The project also uses the ITK compiler and build flags, and it warns when its compiler does not match the compiler recorded by ITK.

References: CMake/ITKModuleExternal.cmake• L1-35 CMake/ITKModuleExternal.cmake• L33-56 CMake/ITKModuleExternal.cmake• L164-219 CMake/ITKModuleExternal.cmake• L238-322 CMake/ITKModuleExternalSettings.cmake• L1-64 CMakeLists.txt• L881-923 CMake/ITKModuleMacros.cmake• L744-845

Remote modules

Remote modules extend the available module set without placing all their source in the main ITK tree. Their control data identifies the source repository, the revision to use, and the level of compliance needed for normal selection.

Remote selection and fetch policy

Remote modules are normally disabled until a user choice, group, or dependency selects one. During configuration, ITK loads the selected revision and repeats module discovery. This means a remote dependency can enter the same graph as an in-tree dependency before validation and ordering finish.

The remote list applies a minimum compliance level to normal selection. Each remote declaration pins a repository and revision, while the compliance level expresses the quality threshold used by the selection policy. The current declarations include the following levels:

  • Level 5: SphinxExamples.
  • Level 3: CudaCommon, HASI, RTK, SimpleITKFilters, Ultrasound, and WebAssemblyInterface.
  • Level 1: FEM, which is unmaintained and scheduled for removal in ITK 7.

The build can restrict downloads, reuse an existing clone, or override a revision for controlled development. A missing tool, invalid revision, changed repository, or blocked download stops configuration instead of creating a partial module graph.

References: CMake/ITKModuleRemote.cmake• L1-13 CMake/ITKModuleRemote.cmake• L152-182 CMake/ITKModuleRemote.cmake• L184-212 CMake/ITKModuleRemote.cmake• L213-390 Modules/…/CMakeLists.txt• L1-32 CMake/ITKModuleEnablement.cmake• L60-80 Modules/…/CudaCommon.remote.cmake• L40-46 Modules/…/FEM.remote.cmake• L13-31 Modules/…/HASI.remote.cmake• L44-51 Modules/…/RTK.remote.cmake• L40-46 Modules/…/SimpleITKFilters.remote.cmake• L44-54 Modules/…/SphinxExamples.remote.cmake• L48-55 Modules/…/Ultrasound.remote.cmake• L44-67 Modules/…/WebAssemblyInterface.remote.cmake• L45-51

Remote module integration

After a remote module is fetched, it follows the same declaration, dependency, target, test, wrapping, and install path as an in-tree module. Only the source location differs. Its package contract remains the same, which lets downstream code use the capability without knowing where its source was obtained.

References: CMake/ITKModuleRemote.cmake• L362-390 CMake/ITKModuleEnablement.cmake• L105-113 CMake/ITKModuleEnablement.cmake• L473-480 CMake/ITKModuleExternal.cmake• L180-228

Change checklist

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

  • A change to module dependencies, default selection, or test dependencies can change graph validation, build order, exported transitive dependencies, and the modules loaded by find_package(ITK).
  • A change to group membership, group descriptions, or default-exclusion rules must keep group options, module requests, generated documentation groups, and default-build behavior aligned.
  • A change to install directories or target namespaces must stay consistent across build exports, install exports, generated module information, and external module projects.
  • A change to external component selection must update both target usage requirements and the installed package's finder and component paths.
  • A change to external-module settings must keep the seeded values, mismatch checks, installed CMake files, and validation cases aligned.
  • A change to external test-data stores, URL templates, or download restrictions must stay aligned with module test setup, external module projects, and generated ExternalData package configuration.
  • A change to FFTW provider or architecture defaults must keep precision targets, oneMKL or CUDA provider rules, bundled FFTW options, and the architecture check aligned.
  • A change to public compiler or linker options must keep in-tree module targets, exported usage requirements, and external module settings aligned.
  • A change to a remote control file must preserve its repository, revision, compliance level, and dependency discovery behavior.
  • A change to package generation must keep build-tree and install-tree configurations consistent with the exported targets and module metadata.
  • A change to module test registration must preserve unique test names, module labels, data dependencies, cleanup behavior, and the CTest warning and error policy across in-tree and remote modules.
  • A change to header, style, or documentation checks must keep their source-tree and installed-package paths usable for external module projects.

Important failure modes

TriggerConsequenceGuard
A module dependency forms a cycleConfiguration stops before targets are createdValidate the dependency graph before module assembly
A required module is missing and is not a valid remote moduleConfiguration cannot produce the requested module setKeep module names and dependency declarations aligned
A selected remote module cannot be fetched or checked outConfiguration stops before the module enters the graphProvide a valid local clone or allow a verified download
Downloads are disabled while a selected remote module is absentThe requested build cannot completePre-stage the remote source or disable the module
A user selects the retired FEM remote moduleConfiguration warns that the module is unmaintained and scheduled for removalMove dependent work to a maintained module or track the removal plan
An external module setting differs from the ITK buildConfiguration stops before incompatible targets are builtUse the reported ITK values or configure a fresh external build tree
An external module uses a different compiler from ITKConfiguration warns of a possible binary mismatchUse the compiler recorded by the ITK build
Required test data is absent from local stores while downloads are forbiddenTests that use the data cannot obtain their inputsPre-stage the object store or allow a configured data source
A configured data store or URL template is not usableData lookup fails before the affected test runsCheck local paths and approved URL templates during build setup
A required external component cannot be found or builtThe module target or downstream package cannot linkProvide the selected system component or enable the managed copy
oneMKL is selected for a 32-bit target or lacks its FFTW headersFFTW configuration stopsUse a 64-bit oneMKL setup with the required FFTW interface
An install directory is absoluteConfiguration stops before package paths are generatedSet install directories relative to CMAKE_INSTALL_PREFIX
FFTW SIMD defaults use the host instead of the target architectureA redistributed binary can fail on a supported target or lose expected SIMD supportUse the target-aware defaults and run FFTWTargetArchitecture
A macOS universal build enables one architecture's FFTW defaultsThe bundled FFTW codelets do not match both binary slicesKeep per-architecture defaults disabled or use a universal system FFTW
No module remains enabled after selectionITK produces no usable target setEnable the default modules, a group, or a specific module
A GoogleTest driver lacks the module's ITKGoogleTest test dependencyConfiguration stops before the driver is linkedDeclare ITKGoogleTest in the module test dependencies
Two modules register the same test nameIn-tree configuration fails, or a remote-module collision can race during cleanupKeep test names unique across the full test run
A module test needs its output after it finishes while cleanup is enabledThe cleanup fixture removes the output even after a failureConfigure ITK_REMOVE_TEMPORARY_TEST_FILES=OFF while debugging
A target uses a header file set with CMake older than 3.23Module installation cannot support that header setUse CMake 3.23 or newer or use the supported header install form
An external module uses an ITK install tree as its module-macro sourceConfiguration stops before the module target is createdUse an ITK build tree with the required CMake files

Key files

FileWhy to read it
CMakeLists.txtShows global options, remote-module loading, package generation, install paths, and external component policy
CMake/ITKSetStandardCompilerFlags.cmakeShows compiler feature checks, portable default flags, and options passed to ITK targets and clients
CMake/ITKGroups.cmakeShows module groups, group documentation, default exclusions, and group-driven module requests
CMake/ITKModuleEnablement.cmakeDefines module discovery, selection, dependency checks, and build order
CMake/ITKModuleMacros.cmakeShows the common target, namespace, export, install, and client compiler-option contract for enabled modules
CMake/ITKModuleAPI.cmakeExplains how build and downstream projects load module metadata
CMake/ITKConfig.cmake.inDefines the package boundary used by downstream find_package(ITK) calls
CMake/ITKModuleInfo.cmake.inDefines the compact module metadata exported to consumers
CMake/ITKModuleRemote.cmakeDefines remote module selection, revision control, and fetch behavior
CMake/ITKModuleExternal.cmakeShows how an external module project reuses an ITK build tree, compiler settings, and package layout
CMake/ITKModuleExternalSettings.cmakeDefines the settings that an external module must share with ITK
CMake/ITKModuleTest.cmakeDefines module test drivers, labels, data lookup, and output cleanup
CMake/CTestCustom.cmake.inDefines the CTest warning, error, coverage, and diagnostic filtering policy
CMake/ITKExternalData.cmakeDefines local test-data stores, remote data sources, and download limits
CMake/ExternalData_config.cmake.inCarries the configured test-data policy into downstream projects
Modules/Filtering/IsotropicWavelets/itk-module.cmakeShows an explicitly selected module with shared-library output, core processing dependencies, and conditional test support
Modules/Filtering/AdaptiveDenoising/itk-module.cmakeShows explicit module selection, shared-library output, and separated compile and test dependencies
Modules/Registration/Metricsv4/itk-module.cmakeShows a registration module's public and test dependency boundary
Modules/Registration/RegistrationMethodsv4/itk-module.cmakeShows a module that builds on the registration v4 dependency chain
Modules/IO/GE/itk-module.cmakeShows public dependencies and factory declarations for an image IO module
Modules/IO/MINC/itk-module.cmakeShows the boundary between public and private module dependencies
Modules/IO/DCMTK/itk-module.cmakeShows a shared module with a factory, a private third-party dependency, and explicit selection
Modules/Core/TestKernel/itk-module.cmakeShows conditional wrapping dependencies and test support dependencies
Modules/Numerics/NarrowBand/itk-module.cmakeShows public processing dependencies separated from test dependencies
Modules/…/CMakeLists.txtSets the remote compliance threshold and loads remote declarations
Modules/Remote/CudaCommon.remote.cmakeShows the pinned CudaCommon remote module and its compliance level
Modules/Remote/SphinxExamples.remote.cmakeShows a high-compliance remote examples module
Modules/Remote/FEM.remote.cmakeShows a retired remote module and its user warning
Modules/Remote/RTK.remote.cmakeShows the pinned RTK remote module and its compliance level
Modules/Remote/SimpleITKFilters.remote.cmakeShows a pinned remote filter collection with compliance level 3
Modules/Remote/Ultrasound.remote.cmakeShows the pinned Ultrasound remote module and its compliance level
Modules/Remote/WebAssemblyInterface.remote.cmakeShows a pinned remote module for WebAssembly pipelines with compliance level 3
CMake/…/CMakeLists.txtValidates the external module settings contract
Modules/…/CMakeLists.txtShows the system-versus-bundled FFTW choice and the exported precision targets
CMake/FindFFTW.cmakeDefines provider selection and precision-specific imported targets for system FFTW, oneMKL, and CUDA paths
Modules/ThirdParty/FFTW/itkFFTWOptions.cmakeDefines target-aware FFTW SIMD defaults
CMake/…/CMakeLists.txtChecks FFTW defaults for target and architecture combinations
CMake/ITKModuleHeaderTest.cmakeDefines generated header coverage for module include dependencies
CMake/ITKModuleKWStyleTest.cmakeDefines optional module style checks and their source file scope
CMake/ITKModuleDoxygen.cmakeDefines module documentation groups, dependency graphs, and documentation checks