Skip to content

Add using ITK with CMake's FetchContent module#2475

Merged
blowekamp merged 3 commits intoSimpleITK:mainfrom
blowekamp:itk_fetch
Jan 12, 2026
Merged

Add using ITK with CMake's FetchContent module#2475
blowekamp merged 3 commits intoSimpleITK:mainfrom
blowekamp:itk_fetch

Conversation

@blowekamp
Copy link
Copy Markdown
Member

@blowekamp blowekamp commented Dec 12, 2025

Documentation on CMake's FetchContent can be found here:
https://cmake.org/cmake/help/latest/module/FetchContent.html

This is an experimental option for SimpleITK as an alternative to the Superbuild. With this change the Superbuild build of ITK still works, and the SimpleITK project still respects ITK_DIR with the FetchContent trying to use find_package(ITK) to determine if ITK needs to build built.

If ITK needs to be built with FetchContent, then ITK is downloaded, and configured during SimpleITK's configuration. And ITK shares the same CMake configuration cache with the SimpleITK project to enable consistent, and easier tuning of the ITK build through the SimpleITK project.

@blowekamp blowekamp changed the title Itk fetch Add using ITK with CMake's FetchContent module Dec 12, 2025
@blowekamp blowekamp force-pushed the itk_fetch branch 6 times, most recently from 4a79b78 to 79e5b7a Compare December 13, 2025 15:54
@blowekamp
Copy link
Copy Markdown
Member Author

There is an issue when SimpleITK_EXPLICIT_INSTANTIATION is enabled. With using ITK FetchContent, the include path as just the build, and the targets do not have installation targets. When the SimpleITK Explicit library declare a public interface with ITK, the ITK include paths are the build only.

Don't set ExternalData_SOURCE_ROOT if the default will work. This help
with using FetchContent with other projects.
@blowekamp blowekamp marked this pull request as ready for review January 12, 2026 14:31
@blowekamp blowekamp requested review from dave3d and zivy January 12, 2026 14:31
Comment thread CMake/sitkITKFetchContent.cmake Outdated
set(ITK_USE_KWSTYLE OFF)

# ITK automatically checks COMPILER_LAUNCHER variables to automatically enable ccache option.
# However additional contrains and usages are added, that are not needed for
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"ITK automatically checks COMPILER_LAUNCHER variables to automatically..." -> drop first "automatically", "ITK checks COMPILER_LAUNCHER variables to automatically..."

Second sentence is not complete, not sure about the intention ("However...").


#set(ExternalData_SOURCE_ROOT ${ITK_SOURCE_DIR})
#message(STATUS "ITK source root for ExternalData: ${ExternalData_SOURCE_ROOT}")
FetchContent_MakeAvailable(ITK)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented out code?

@blowekamp blowekamp merged commit b9a4cb4 into SimpleITK:main Jan 12, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants