Skip to content

ENH: Build FFTW as an ITKFFTW third-party module with FetchContent - #6999

Merged
hjmjohnson merged 2 commits into
InsightSoftwareConsortium:mainfrom
blowekamp:ENH-FFTW-third-party-module
Oct 29, 2026
Merged

hjmjohnson merged 2 commits into
InsightSoftwareConsortium:mainfrom
blowekamp:ENH-FFTW-third-party-module

Conversation

@blowekamp

@blowekamp blowekamp commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Build FFTW as a standard ITKFFTW third-party module using FetchContent, replacing the ExternalProject in itkExternal_FFTW.cmake. Downstream projects get FFTW through ITK::ITKFFTModule instead of FFTW-specific ITKConfig.cmake variables; the migration guide describes the change.

Design
  • FFTW 3.3.10 is fetched once; float and double are added as two scoped subdirectories. Both precisions share the existing SIMD defaults (FFTW_ENABLE_*).
  • FindFFTW takes COMPONENTS Double Float and defines FFTW::Double / FFTW::Float. For system FFTW the module sets ITKFFTW_EXPORT_CODE_INSTALL/BUILD (as ZLIB/TIFF do) so downstream projects re-run the finder. The finder is seeded with the include directory and library files ITK found, unless the app sets FFTW_ROOT, and the app's CMAKE_MODULE_PATH is restored afterward. A separate threads library is optional.
  • Bundled targets use the ITK:: namespace so no bare fftw3* compatibility targets are exported.
  • Enabling ITKFFTW with neither ITK_USE_FFTWD nor ITK_USE_FFTWF is a configure error.
  • ITKModuleMacros.cmake: source-less modules now register in ITKTargets_MODULES. Without this, an install whose only module is a system-library module exported no targets.
  • Removed ITK_FFTW_INCLUDE_PATH / ITK_FFTW_LIBDIR from ITKConfig.cmake (no remaining users in the tree).
AI assistance
  • Tool: GitHub Copilot CLI
  • Role: implemented the migration, the review follow-ups, and the test matrix below; all changes were reviewed and run locally.
Test results

Rebased on main at 6784c31877. Clean builds on Linux x86_64 (GCC 13), each from an empty build directory:

  • Static, shared, and system FFTW with float+double: ctest -R 'FFT|FFTW' 92/92 passed in each.
  • Float-only and double-only ITKFFTW, and FFTW disabled: passed. ITKFFTW enabled with no precision fails at configure (bundled and system).
  • ITKFFTW alone with one precision (bundled and system): installs, and a downstream project using only find_package(ITK COMPONENTS ITKFFTW) builds and runs.
  • Python wrapping (float/double, 2D/3D): ITKFFT wrappers built; FFTW forward/inverse roundtrips passed in all four type/dimension combinations.
  • Downstream projects against build and install trees of static, shared, relocated, system, and custom-prefix FFTW installs, via imported targets, ITKFFTW only, UseITK, and a project defining its own fftw3* targets: 32/32 passed. Linked libraries were checked to be the expected FFTW in each case.

Not tested: Windows, MKL, cuFFTW. macOS arm64 and a downstream build forest were tested after the takeover; see the takeover comment.

PR Checklist

  • No API changes were made (or the changes have been approved)
  • No major design changes were made (or the changes have been approved)
  • Added test (or behavior not changed)
  • Updated API documentation (or API not changed)
  • Added license to new files (if any)
  • Added Python wrapping to new files (if any) as described in ITK Software Guide Section 9.5
  • Added ITK examples for all new major features (if any)

@github-actions github-actions Bot added type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Enhancement Improvement of existing methods or implementation type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Filtering Issues affecting the Filtering module area:ThirdParty Issues affecting the ThirdParty module area:Documentation Issues affecting the Documentation module labels Oct 23, 2026
@hjmjohnson

hjmjohnson commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

@blowekamp I tested this locally against its base and pushed possible fixes as separate commits on top of your head (af10dea2e1f): compare view. Same commits as draft hjmjohnson#19. Cherry-pick whatever you agree with.

  1. No precision selected should fail. Module_ITKFFTW=ON with neither ITK_USE_FFTWD nor ITK_USE_FFTWF currently builds double-precision FFTW. Suggested: a configure-time FATAL_ERROR (hjmjohnson/ITK@423199569fa).
  2. FFTW should always be optimized. The old ExternalProject forced Release; with add_subdirectory, a Debug ITK compiles FFTW with -g only. Suggested: use the release flags for every configuration (hjmjohnson/ITK@a4c89c95457).
  3. Duplicated logic. Precision is tested three times in Modules/ThirdParty/FFTW/CMakeLists.txt (precision list, components, library names) and the version string is separate from the hash (hjmjohnson/ITK@4e32bd759d0).
  4. ITKTargets_MODULES duplicates. The new append in ITKModuleMacros.cmake also runs for modules with sources, so 93 of 133 modules are listed twice. It's harmless today because the only reader checks for emptiness, but a one-line guard keeps it to source-less modules as the comment says (hjmjohnson/ITK@4bd00d1e035).
  5. GoogleTest instead of the C smoke test, one test per enabled precision (hjmjohnson/ITK@de4a7a7de97).
  6. Migration guide rather than ITK_LEGACY_REMOVE for the removed ITKConfig.cmake variables (hjmjohnson/ITK@6ed0cec6530); evidence below.

The GPL status message is fine as is.

What was tested (macOS arm64)
  • Base 46e45824cc2 vs this PR, with these configurations: bundled FFTW (build and install), system FFTW with FFTW_INCLUDE_PATH/FFTW*_BASE_LIB/FFTW*_THREADS_LIB hints pointing to a nonstandard copy, Debug, and no precision option.
  • Four downstream find_package(ITK) projects (${ITK_LIBRARIES}, ITK_USE_FILE, the removed variables, and the migrated form), each against both build and install trees.
  • With the fixes, Debug and both precisions: FFTW compiles with -O3 -DNDEBUG, and 73/73 ITKFFT + ITKFFTW tests pass. System FFTW: the GoogleTests pass. Install-tree consumers run with no DYLD_LIBRARY_PATH.
  • Install tree: no stray FFTW CMake package or pkg-config files; it is cleaner than the base.
  • Removed variables: no consumers found in about 120 local ecosystem repos or in GitHub code search outside copies of ITK. They were already empty in a base build tree, and a project still using them fails loudly at link time (-lfftw3).
  • FFTWD_LIB/FFTWF_LIB (the MINC/NIRAL superbuild style) never selected the base library before this PR either, so that is not a regression.
  • Bundled 3.3.10 reports fftw-3.3.9 from fftw_version(); that version is hard-coded in FFTW's own CMakeLists.

@blowekamp

Copy link
Copy Markdown
Member Author

Thanks @hjmjohnson, this was very useful. I pushed updates to this PR:

  1. Applied. ITKFFTW with no precision is now a configure error.
  2. Not taking this. It needs Windows-specific handling (build type must match ITK's runtime), and no other ThirdParty module forces its build type.
  3. Applied, folded into the main commit.
  4. Could you open this as a separate PR? The ITKTargets_MODULES guard in ITKModuleMacros.cmake is a general framework cleanup. Confirmed here: 42 of 49 modules are listed twice in a small configure, harmless today.
  5. Removed the smoke test instead of adding GoogleTest. The module doesn't need those test dependencies, and the ITKFFT tests cover FFTW.
  6. Applied, rewritten as a "link ITK::ITKFFTModule" note under the modern CMake interface libraries section.

Re-tested from clean builds: static, shared, system, Python wrapping, and downstream installs.

@blowekamp
blowekamp force-pushed the ENH-FFTW-third-party-module branch from 63242b3 to 552e988 Compare October 26, 2026 14:17
@kwrobot-v1

kwrobot-v1 Bot commented Oct 26, 2026

Copy link
Copy Markdown

Errors:

  • Failed to reserve ref 552e988 for the merge request: invalid git ref: 'no such commit'.
  • Failed to run the checks: mr utilities error: failed to list commits of 552e988400f0b13227d4604ef04f73b2ff40190d for https://github.com/InsightSoftwareConsortium/ITK/pull/6999: fatal: bad object 552e988400f0b13227d4604ef04f73b2ff40190d .

@blowekamp

Copy link
Copy Markdown
Member Author

Rebased onto current main (6784c31877) and force-pushed; no conflicts. Re-ran the clean static, shared, system, Python, and downstream-install builds on the rebased tree, all passing.

@hjmjohnson, the ITKTargets_MODULES duplicate guard is still the one suggestion left for a separate PR, if you can open it.

@hjmjohnson hjmjohnson left a comment

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.

Thanks for considering the several comments.

RE 2. I did not think about the windows optimization. Good with your solution.
RE ITKTargets_MODULES. <-- I have a note to deal with this after merging.

The failing tests are due to timing issues, not real errors, I think we could merge as is.

@hjmjohnson

Copy link
Copy Markdown
Member

@greptile Please review

@greptile-apps

greptile-apps Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5 Tier: plus

[Medium impact] The changes affect ITK builds that enable FFTW and projects that consume those builds.

Preserve custom cuFFTW paths before merging so downstream apps can configure without repeating ITK’s CUDA settings.

Findings

  1. P1 Custom CUDA paths disappear ▶

Summary

Moves FFTW into the ITKFFTW module, using one source download and separate builds for each precision.

  • ITK builds bundled FFTW inside its third-party module.
  • FFTW consumers link through precision-aware targets.
  • System-only modules appear in ITK's exported targets.
  • FFTW SIMD defaults follow the target architecture.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  FFT["ITKFFT"] --> Module["ITKFFTW"]
  Module --> Mode{"ITK_USE_SYSTEM_FFTW"}
  Mode -->|OFF| Fetch["FetchContent: FFTW 3.3.10"]
  Fetch --> Builds["Separate float and double builds"]
  Builds --> Bundled["ITK::fftw3* targets"]
  Mode -->|ON| Find["FindFFTW.cmake"]
  Find --> System["FFTW::Double / FFTW::Float"]
  System --> Export["Downstream apps repeat discovery"]
Loading

Reviews (2) · Last reviewed commit: "DOC: Add ITK 6 migration note for linkin..." · Reviewed by Greptile

Comment thread Modules/ThirdParty/FFTW/CMakeLists.txt Resolved
@hjmjohnson

hjmjohnson commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

@blowekamp I tested this PR rebased onto main and found a regression in oneMKL support. #7020 adds 1 commit on top of your work to fix it.

I think your changes are OK as they stand, with oneMKL support addressed separately in #7020. If you prefer the complete solution, feel free to incorporate the oneMKL commit from #7020 here.

Testing was Linux only, with no Windows or macOS testing.

Automated testing done (Linux x86_64, GCC 13.3)
Scenario This PR (rebased on main) With #7020
System GNU FFTW (ITK_USE_SYSTEM_FFTW), ctest -R FFT 92/92 92/92
oneMKL 2026.1, MKLROOT at the 2024+ layout (lib/) configure fails: libmkl_intel_ilp64.a not found 92/92
Installed ITK + oneMKL, downstream find_package(ITK) with no MKLROOT configure fails: re-run FindFFTW loses ITK's MKLROOT (greptile P1) builds and runs
System libfftw3-dev installed alongside oneMKL MKL libraries compiled against /usr/include/fftw3.h uses oneMKL's fftw3.h

The downstream MKLROOT failure is new with this PR, because the exported module now re-runs FindFFTW. The lib/ layout and header shadowing issues also exist on main.

Not tested: Windows (MSVC, oneMKL) and macOS. oneMKL no longer supports macOS.

@blowekamp

Copy link
Copy Markdown
Member Author

@hjmjohnson I think this is very close too. Inspecting the export ITKTargets for FFTW looks right to me for a couple of the builds I agnatically did locally. Moving these libraries into the standard third party and using the modern CMake targets is another good step with modernization of the CMake infrastructure.

However, the complication of MKL and Cuda FFT being in this same ITK module does add a bit of complexity I was not able to investigate completely. I am in favor of keeping things simple as best they can be.

Unfortunately, I am running low on tokens and have other priorities for them now. @hjmjohnson you are welcome to take over this PR, and get it across the finish line.

@dzenanz

dzenanz commented Oct 27, 2026

Copy link
Copy Markdown
Member

Windows testing of #6999 and #7020 (Windows 11, MSVC 14.44 / VS 2022, CMake 4.4, Release, ITK_USE_FFTWD=ON ITK_USE_FFTWF=ON, ctest -R FFT)

Configuration Result
#6999 bundled FFTW, static, Ninja 92/92
#6999 bundled FFTW, shared, Ninja 92/92
#7020 bundled FFTW, Visual Studio 17 2022 generator 92/92
#7020 oneMKL 2026.1 (conda-forge mkl-devel/mkl-static, lib/ layout) 92/92, links mkl_intel_ilp64/mkl_core/mkl_sequential
#6999 with the same oneMKL configure fails: mkl_intel_ilp64.lib not found (fixed by #7020)
#7020 with MKLROOT set only in the environment, as a backslash path configures correctly
#6999 system FFTW (conda-forge fftw 3.3.11) configure fails, see below

A downstream project linking only ITK::ITKFFTModule and calling the FFTW API directly, plus the FFTW filters in float and double, builds and runs against:

In #7020, a consumer-provided MKLROOT (as a CMake variable or an environment variable) takes precedence over the exported one. The installed layout is clean: libraries are lib/itkfftw3*-6.0.lib and the header is include/ITK-6.0/fftw3.h, with no stray FFTW CMake package. On Windows, the bundled FFTW is built static even when ITK is shared, so no extra DLLs need to be deployed. Under MSVC, FFTW's SIMD probes enable SSE2.

Regression: system FFTW without separate threads libraries. FindFFTW now lists FFTWD_THREADS_LIB/FFTWF_THREADS_LIB in REQUIRED_VARS. conda-forge's Windows FFTW ships only fftw3.lib/fftw3f.lib, with fftw_init_threads exported from fftw3.dll itself. The base commit 46e45824cc2 builds against it with the threads libs NOTFOUND and passes 92/92. #6999 fails with Could NOT find FFTW (missing: FFTWD_THREADS_LIB FFTWF_THREADS_LIB). Pointing FFTW*_THREADS_LIB at the main libraries works around it and gives 92/92. Suggest making the threads libraries optional again, as they were before. #7020 inherits this.

Not tested on Windows: Debug or multi-config Debug builds, Python wrapping, cuFFTW.

AI assistance

Builds, tests, and this summary were prepared with Claude Code and reviewed by me.

Replace the itkExternal_FFTW ExternalProject, which built the library
twice outside the module system, with a standard third-party module.
FFTW is fetched once and each precision is added as a subdirectory.

FindFFTW now provides FFTW::Double and FFTW::Float imported targets,
and the module re-runs it for downstream projects through the usual
EXPORT_CODE hooks. Remove the FFTW paths from ITKConfig.cmake.

Enabling ITKFFTW without ITK_USE_FFTWD or ITK_USE_FFTWF is an error.
ITKConfig.cmake no longer defines ITK_FFTW_INCLUDE_PATH or
ITK_FFTW_LIBDIR, and the bundled libraries are renamed libitkfftw3*.
Describe linking ITK::ITKFFTModule instead of naming FFTW paths and
libraries.
@hjmjohnson
hjmjohnson force-pushed the ENH-FFTW-third-party-module branch 2 times, most recently from 2298342 to b5c5da0 Compare October 27, 2026 20:53
@hjmjohnson

hjmjohnson commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Taking this over at @blowekamp's invitation. I rebased onto current main and folded 4 fixes from review and testing into the two existing commits (+44/−25). The range-diff is below. MKL and cuFFTW are left alone in this PR. #7020 handles oneMKL separately.

There were two force-pushes. 552e988 → 2298342 is a plain rebase onto main. 2298342 → b5c5da0 contains only the fixes.

Fixes folded in
  1. The consumer's CMAKE_MODULE_PATH is restored after the system-FFTW export code runs find_package(FFTW). Previously ${ITK_CMAKE_DIR} stayed prepended, so ITK's FindFFTW.cmake hid an app's own finder. Reproduced on Linux and macOS: a consumer with its own FindFFTW failed (Unknown FFTW component).
  2. Downstream projects reuse the exact FFTW files ITK found. The export code seeds the app's cache with FFTW_INCLUDE_PATH and FFTW{D,F}_{BASE,THREADS}_LIB, unless the app sets FFTW_ROOT. Previously only FFTW_ROOT=dirname(include) was passed, so explicitly named libraries such as libfftw3-3.lib were searched for again and not found.
  3. A separate FFTW threads library is optional again, as on main. FFTW built with combined threads has no fftw3_threads library, and the new REQUIRED_VARS rejected it.
  4. Build-tree consumers get only fftw3.h. It is staged in the module's binary directory instead of exposing FFTW's api/ directory, which also holds api.h and guru.h.
Testing

Linux x86_64 (GCC 13.3, CMake 4.2.1). ctest -R FFT passed in every row; 76 tests for single precision, 92 otherwise.

Scenario Result
Bundled FFTW: shared Release, static Debug, float only, double only Pass. Install tree holds only libitkfftw3* and fftw3.h, with no FFTW pkg-config or CMake package files.
System FFTW (libfftw3-dev) Pass. Install-tree and build-tree consumers configure, build, and run.
System FFTW with explicitly named, renamed libraries Pass. Consumers reuse the same files.
FFTW prefix without a threads library Configure passes. Before the fix: missing: FFTWD_THREADS_LIB.
Consumer that ships its own FindFFTW.cmake Its finder is used. Before the fix it was hidden by ITK's.
Reconfigure: none → bundled → system → bundled → off Pass at each step.
FETCHCONTENT_SOURCE_DIR_FFTW with ITK_FORBID_DOWNLOADS No FFTW download, 91/91.
-march=native AVX and AVX2 codelets enabled.
Ninja Multi-Config Pass.
IsotropicWavelets, PhaseSymmetry, Montage (C++) 542/542
ITKUltrasound (includes fftw3.h directly), bundled and system 41/41 each
Python wrapping, PythonFFT* tests 3/3, same as main (also 3/3 on macOS)

macOS arm64 (Apple clang 21, CMake 3.26.6). Shared, static Debug, system FFTW from Homebrew, reconfigure transitions, and Ninja Multi-Config all pass. All consumer variants run.

Downstream build forest (macOS, static ITK with Python wrapping and FFTW on). Builds and tests pass for RTK, VkFFTBackend, Ultrasound, BioCell, Impact, LesionSizingToolkit, Cleaver, TractographyTRX, PerformanceBenchmarking, HASI, Shape, SkullStrip, and SphinxExamples.

Not caused by this PR:

  • Montage tests fail with FFTW on macOS on main too (25/68 on both).
  • PythonFFTImageFilterTest shows a small baseline difference only in the full forest configuration on macOS. A minimal FFTW build passes 3/3 on both main and this branch.
  • IsotropicWavelets Python wrapping does not compile on current main (SetNoiseScale and an std::complex comparison in itkBridgeEigenDecompositionSignConvention.h). Its C++ tests pass with FFTW.
  • elastix and ANTs currently fail on main with vnl_determinant undeclared.
  • Shared install-tree consumers on Linux need LD_LIBRARY_PATH, because ITK sets no install RPATH; main behaves the same.

Windows: @dzenanz's report (#6999 (comment)) covers MSVC 2022 with Ninja and Visual Studio, static and shared, and oneMKL through #7020. His one regression was system FFTW without separate threads libraries (conda-forge Windows fftw3.lib). Fix 3 above addresses it; not yet re-run on Windows.

Not tested: Windows Debug, cuFFTW.

Range-diff against the rebased original
1:  5741913fc34 ! 1:  5456d9c5c75 ENH: Build FFTW as an ITKFFTW third-party module with FetchContent
    @@ CMake/FindFFTW.cmake: if(ITK_USE_FFTWD OR ITK_USE_FFTWF)
     +      CUFFT_LIB
     +      CUFFTW_LIB
     +    )
    -+  elseif(NOT ITK_USE_MKL)
    -+    if(_fftw_double)
    -+      list(APPEND _fftw_required_vars FFTWD_THREADS_LIB)
    -+    endif()
    -+    if(_fftw_float)
    -+      list(APPEND _fftw_required_vars FFTWF_THREADS_LIB)
    -+    endif()
     +  endif()
     +  include(FindPackageHandleStandardArgs)
     +  find_package_handle_standard_args(FFTW REQUIRED_VARS ${_fftw_required_vars})
    @@ Modules/ThirdParty/FFTW/CMakeLists.txt (new)
     +  find_package(FFTW REQUIRED COMPONENTS ${_fftw_components})
     +  set(ITKFFTW_NO_SRC 1)
     +
    -+  # Prefer the FFTW ITK was built with, unless the app provides FFTW_ROOT.
    -+  set(_fftw_root_code "")
    ++  # Seed the app's cache with the files ITK found, unless the app provides FFTW_ROOT.
    ++  set(_fftw_hint_code "")
     +  if(NOT ITK_USE_MKL AND NOT ITK_USE_CUFFTW)
    -+    get_filename_component(_fftw_root "${FFTW_INCLUDE}" DIRECTORY)
    ++    foreach(
    ++      _fftw_var
    ++      IN
    ++      ITEMS
    ++        FFTW_INCLUDE_PATH
    ++        FFTWD_BASE_LIB
    ++        FFTWD_THREADS_LIB
    ++        FFTWF_BASE_LIB
    ++        FFTWF_THREADS_LIB
    ++    )
    ++      if(${_fftw_var})
    ++        set(_fftw_type FILEPATH)
    ++        if(_fftw_var STREQUAL "FFTW_INCLUDE_PATH")
    ++          set(_fftw_type PATH)
    ++        endif()
    ++        string(
    ++          APPEND
    ++          _fftw_hint_code
    ++          "
    ++  set(${_fftw_var} \"${${_fftw_var}}\" CACHE ${_fftw_type} \"\")"
    ++        )
    ++      endif()
    ++    endforeach()
     +    set(
    -+      _fftw_root_code
    ++      _fftw_hint_code
     +      "
    -+if(NOT DEFINED FFTW_ROOT AND NOT DEFINED ENV{FFTW_ROOT})
    -+  set(FFTW_ROOT \"${_fftw_root}\")
    -+  set(_itk_fftw_root_default TRUE)
    ++if(NOT DEFINED FFTW_ROOT AND NOT DEFINED ENV{FFTW_ROOT})${_fftw_hint_code}
     +endif()"
     +    )
     +  endif()
    @@ Modules/ThirdParty/FFTW/CMakeLists.txt (new)
     +    _fftw_find_code
     +    "
     +set(ITK_USE_MKL ${ITK_USE_MKL})
    -+set(ITK_USE_CUFFTW ${ITK_USE_CUFFTW})
    -+list(PREPEND CMAKE_MODULE_PATH \"\${ITK_CMAKE_DIR}\")${_fftw_root_code}
    ++set(ITK_USE_CUFFTW ${ITK_USE_CUFFTW})${_fftw_hint_code}
    ++set(_itk_fftw_module_path \"\${CMAKE_MODULE_PATH}\")
    ++list(PREPEND CMAKE_MODULE_PATH \"\${ITK_CMAKE_DIR}\")
     +find_package(FFTW REQUIRED COMPONENTS ${_fftw_components})
    -+if(_itk_fftw_root_default)
    -+  unset(FFTW_ROOT)
    -+  unset(_itk_fftw_root_default)
    -+endif()
    ++set(CMAKE_MODULE_PATH \"\${_itk_fftw_module_path}\")
    ++unset(_itk_fftw_module_path)
     +"
     +  )
     +  set(ITKFFTW_EXPORT_CODE_INSTALL "${_fftw_find_code}")
    @@ Modules/ThirdParty/FFTW/CMakeLists.txt (new)
     +    itk_download_attempt_check(FFTW)
     +  endif()
     +  FetchContent_MakeAvailable(FFTW)
    -+  set(ITKFFTW_INCLUDE_DIRS "${fftw_SOURCE_DIR}/api")
    ++  # Expose only the public header, not FFTW's internal api/ headers.
    ++  configure_file(
    ++    "${fftw_SOURCE_DIR}/api/fftw3.h"
    ++    "${ITKFFTW_BINARY_DIR}/include/fftw3.h"
    ++    COPYONLY
    ++  )
    ++  set(ITKFFTW_INCLUDE_DIRS "${ITKFFTW_BINARY_DIR}/include")
     +  # Namespaced names keep ITK from exporting bare fftw3* compatibility targets.
     +  set(_fftw_ns "${ITK_MODULE_ITKFFTW_TARGETS_NAMESPACE}")
     +  foreach(_fftw_library IN LISTS _fftw_library_names)
    @@ Modules/ThirdParty/FFTW/src/CMakeLists.txt (new)
     +
     +install(
     +  FILES
    -+    "${fftw_SOURCE_DIR}/api/fftw3.h"
    ++    "${ITKFFTW_BINARY_DIR}/include/fftw3.h"
     +  DESTINATION ${ITKFFTW_INSTALL_INCLUDE_DIR}
     +  COMPONENT Development
     +)
2:  22983423416 ! 2:  b5c5da0dea9 DOC: Add ITK 6 migration note for linking FFTW through ITK targets
    @@ Documentation/docs/migration_guides/itk_6_migration_guide.md: Use the `--link` o
     +built with (`ITK_USE_FFTWF` and `ITK_USE_FFTWD`) are provided.
     +
     +When ITK is built against a system FFTW (`ITK_USE_SYSTEM_FFTW=ON`), downstream `find_package(ITK)` runs ITK's
    -+installed `FindFFTW.cmake` to locate the same FFTW. Set `FFTW_ROOT` to use a different installation. The ITK build
    -+options `FFTW_INCLUDE_PATH`, `FFTWD_BASE_LIB`, `FFTWF_BASE_LIB`, `FFTWD_THREADS_LIB`, and `FFTWF_THREADS_LIB` are still
    -+honored; the library results are now full paths rather than file names.
    ++installed `FindFFTW.cmake`, seeded with the include directory and library files ITK found. Set `FFTW_ROOT` to search
    ++for a different installation instead. The ITK build options `FFTW_INCLUDE_PATH`, `FFTWD_BASE_LIB`, `FFTWF_BASE_LIB`,
    ++`FFTWD_THREADS_LIB`, and `FFTWF_THREADS_LIB` are still honored; the library results are now full paths rather than
    ++file names. A separate FFTW threads library is optional.
     +
      
      ### Migration for ITK Modules

@hjmjohnson
hjmjohnson marked this pull request as ready for review October 28, 2026 11:47
@hjmjohnson
hjmjohnson self-requested a review October 28, 2026 11:49
Comment thread Modules/ThirdParty/FFTW/CMakeLists.txt Resolved
@hjmjohnson

Copy link
Copy Markdown
Member

@dzenanz thank you for the initial Windows testing in #6999 (comment). It caught a small regression the Linux runs could not: FindFFTW had started requiring FFTWD_THREADS_LIB/FFTWF_THREADS_LIB, which conda-forge's Windows FFTW does not ship. b5c5da0 makes the threads libraries optional again, and that fix has now been re-run on Windows.

Windows verification of b5c5da0dea (Windows 11, MSVC 19.38 / VS 2022, CMake 4.2.1, Ninja, ITK_USE_FFTWD=ON ITK_USE_FFTWF=ON, minimal ITK with Module_ITKFFT=ON and BUILD_TESTING=ON). Zero failures across all three cases.

Case Configure ctest -R FFT Install Consumer (8 runs each)
A: conda-forge fftw 3.3.11, ITK_USE_SYSTEM_FFTW=ON, shared Release pass, FFTW*_THREADS_LIB NOTFOUND 92/92 pass 8/8
B: bundled FFTW, shared Release pass 92/92 pass, only include/ITK-6.0/fftw3.h 8/8
C: bundled FFTW, static Debug pass 92/92 pass, only include/ITK-6.0/fftw3.h 8/8
Details

Case A's environment has fftw3.lib and fftw3f.lib only, no fftw3*_threads.lib, the same layout as your report. The cache after configure:

FFTWD_BASE_LIB=C:/i6999A/fftw-env/Library/lib/fftw3.lib
FFTWD_THREADS_LIB=FFTWD_THREADS_LIB-NOTFOUND
FFTWF_BASE_LIB=C:/i6999A/fftw-env/Library/lib/fftw3f.lib
FFTWF_THREADS_LIB=FFTWF_THREADS_LIB-NOTFOUND

The consumer gets no FFTW path of its own and is built four ways against both the install tree and the build tree: ITK::ITKFFTModule with FFTWForwardFFTImageFilter (double and float, DC=(64,0)) and ITK::ITKFFTWModule calling the FFTW API directly (double and float, DC=8). The B and C install trees carry no api.h, guru.h, FFTW CMake package, or pkg-config file.

One note unrelated to this PR: with a system FFTW DLL outside PATH, gtest_discover_tests fails at build time with 0xc0000135 because it runs the test driver; the DLL directory must be on PATH for the build, not only for ctest.

Not covered: Python wrapping, cuFFTW, oneMKL (#7020), Visual Studio generator.

@blowekamp

Copy link
Copy Markdown
Member Author

Related issue, not clear if it's on critical path for this PR as it mostly modifications to FindFFTW. Do we still need to support the FFTW CMake variables? Can they be removed and just the CMake targets be used?

The current CMake variables are the old names, where as the standard names (FFTW_INCLUDE_DIRS, FFTW_LIBRARIES, FFTW_VERSION) are undefined. Migrate the variable name or drop the variables?

@hjmjohnson

hjmjohnson commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

@blowekamp Not on the critical path, I think. Inside ITK nothing reads the FindFFTW result variables any more; they only feed FFTW::Double/FFTW::Float, which ITK::ITKFFTWModule links. I also searched the CMake files of 300 downstream repositories (the 47 projects in our downstream build forest plus the 253 Slicer extensions it checks out): none uses ITK's FFTW variables. That includes RTK, which only checks the ITK_USE_FFTWD/ITK_USE_FFTWF options. I'd drop them as interface rather than migrate them, and keep the input hints (FFTW_INCLUDE_PATH, FFTW{D,F}_BASE_LIB, FFTW{D,F}_THREADS_LIB), which users set for nonstandard or renamed libraries and which this PR now forwards to consumers.

This work is monitored in #7027 and drafts are being put into #7020 for review after this work is pushed.

Why not migrate to the standard names
  • With system FFTW, the exported ITKFFTW code runs ITK's FindFFTW in the consumer's scope, so standard names would overwrite a consumer's own. Plastimatch, for example, calls its own find_package(FFTW) (setting FFTW_LIBRARIES) before find_package(ITK). FFTW_FOUND already leaks this way today.
  • FFTW_VERSION can't come from headers: fftw3.h only has the runtime fftw_version string, and oneMKL and cuFFTW have their own versions.
  • Of those 300 repositories, only Plastimatch mentions any of these names, and it uses its own FindFFTW.cmake (FFTW_INCLUDE_DIR, FFTW_LIBRARIES), not ITK's results.

Proposed follow-up after this PR (tracked in #7027): wrap the exported find_package(FFTW) in a function, so only the imported targets reach consumers, and make the result variables internal.

Proposed migration guide entry for that follow-up:

The FindFFTW result variables FFTW_INCLUDE, FFTWD_LIBRARIES, FFTWF_LIBRARIES, FFTWD_FOUND, and FFTWF_FOUND are no longer set in projects that call find_package(ITK). This is unlikely to affect existing code; link ITK::ITKFFTWModule (or a module that depends on it, such as ITK::ITKFFTModule) to get FFTW's include directories and libraries. The options that locate a system FFTW (FFTW_INCLUDE_PATH, FFTWD_BASE_LIB, FFTWF_BASE_LIB, FFTWD_THREADS_LIB, FFTWF_THREADS_LIB) are unchanged.

@hjmjohnson
hjmjohnson requested a review from dzenanz October 28, 2026 18:28
@hjmjohnson

Copy link
Copy Markdown
Member

@blowekamp I think this is ready for merging. I'd like your thumbs-up confirmation if you would approve this (it's still yours, with polishing changes added).

@dzenanz dzenanz left a comment

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.

This still looks good on a glance.

@hjmjohnson
hjmjohnson merged commit 11ebcef into InsightSoftwareConsortium:main Oct 29, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Documentation Issues affecting the Documentation module area:Filtering Issues affecting the Filtering module area:ThirdParty Issues affecting the ThirdParty module type:Enhancement Improvement of existing methods or implementation type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants