Repository navigation
ENH: Build FFTW as an ITKFFTW third-party module with FetchContent - #6999
hjmjohnson merged 2 commits into
Conversation
|
@blowekamp I tested this locally against its base and pushed possible fixes as separate commits on top of your head (
The GPL status message is fine as is. What was tested (macOS arm64)
|
af10dea to
63242b3
Compare
|
Thanks @hjmjohnson, this was very useful. I pushed updates to this PR:
Re-tested from clean builds: static, shared, system, Python wrapping, and downstream installs. |
63242b3 to
552e988
Compare
|
Errors:
|
|
Rebased onto current @hjmjohnson, the |
hjmjohnson
left a comment
There was a problem hiding this comment.
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.
|
@greptile Please review |
[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
|
|
@blowekamp I tested this PR rebased onto 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)
The downstream Not tested: Windows (MSVC, oneMKL) and macOS. oneMKL no longer supports macOS. |
|
@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. |
|
Windows testing of #6999 and #7020 (Windows 11, MSVC 14.44 / VS 2022, CMake 4.4, Release,
A downstream project linking only
In #7020, a consumer-provided Regression: system FFTW without separate threads libraries. Not tested on Windows: Debug or multi-config Debug builds, Python wrapping, cuFFTW. AI assistanceBuilds, 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.
2298342 to
b5c5da0
Compare
|
Taking this over at @blowekamp's invitation. I rebased onto current There were two force-pushes. Fixes folded in
TestingLinux x86_64 (GCC 13.3, CMake 4.2.1).
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:
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 Not tested: Windows Debug, cuFFTW. Range-diff against the rebased original1: 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 |
|
@dzenanz thank you for the initial Windows testing in #6999 (comment). It caught a small regression the Linux runs could not: Windows verification of
DetailsCase A's environment has The consumer gets no FFTW path of its own and is built four ways against both the install tree and the build tree: One note unrelated to this PR: with a system FFTW DLL outside PATH, Not covered: Python wrapping, cuFFTW, oneMKL (#7020), Visual Studio generator. |
|
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? |
|
@blowekamp Not on the critical path, I think. Inside ITK nothing reads the 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
Proposed follow-up after this PR (tracked in #7027): wrap the exported Proposed migration guide entry for that follow-up:
|
|
@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
left a comment
There was a problem hiding this comment.
This still looks good on a glance.
Build FFTW as a standard
ITKFFTWthird-party module usingFetchContent, replacing theExternalProjectinitkExternal_FFTW.cmake. Downstream projects get FFTW throughITK::ITKFFTModuleinstead of FFTW-specificITKConfig.cmakevariables; the migration guide describes the change.Design
FFTW_ENABLE_*).FindFFTWtakesCOMPONENTS Double Floatand definesFFTW::Double/FFTW::Float. For system FFTW the module setsITKFFTW_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 setsFFTW_ROOT, and the app'sCMAKE_MODULE_PATHis restored afterward. A separate threads library is optional.ITK::namespace so no barefftw3*compatibility targets are exported.ITKFFTWwith neitherITK_USE_FFTWDnorITK_USE_FFTWFis a configure error.ITKModuleMacros.cmake: source-less modules now register inITKTargets_MODULES. Without this, an install whose only module is a system-library module exported no targets.ITK_FFTW_INCLUDE_PATH/ITK_FFTW_LIBDIRfromITKConfig.cmake(no remaining users in the tree).AI assistance
Test results
Rebased on
mainat6784c31877. Clean builds on Linux x86_64 (GCC 13), each from an empty build directory:ctest -R 'FFT|FFTW'92/92 passed in each.ITKFFTW, and FFTW disabled: passed.ITKFFTWenabled with no precision fails at configure (bundled and system).ITKFFTWalone with one precision (bundled and system): installs, and a downstream project using onlyfind_package(ITK COMPONENTS ITKFFTW)builds and runs.ITKFFTwrappers built; FFTW forward/inverse roundtrips passed in all four type/dimension combinations.ITKFFTWonly,UseITK, and a project defining its ownfftw3*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