Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions CMake/CTestCustom.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ set(CTEST_CUSTOM_WARNING_EXCEPTION
"Cloning into.*"
"Note: checking out.*"
"HEAD is now at.*"
# FFTW ExternalProject
".*fftw[fd]/src/fftw[fd]./*"
"libtool: install: warning: relinking .libfftw3f?_threads.la."

# Ignore clang's summary warning, assuming prior text has matched some
# other warning expression:
Expand Down
99 changes: 85 additions & 14 deletions CMake/FindFFTW.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
## various data types.
## There is a single set of include files, and then multiple libraries,
## One for each type. I.e. libfftw.a-->double, libfftwf.a-->float
##
## Usage:
## find_package(FFTW REQUIRED COMPONENTS Double Float)
## Without COMPONENTS, the precisions enabled by `ITK_USE_FFTWD` and
## `ITK_USE_FFTWF` are searched for.
##
## Imported targets (carrying include directories and link dependencies):
## FFTW::Double -- double precision FFTW (with threads support if found)
## FFTW::Float -- single precision FFTW (with threads support if found)

## The following logic belongs in the individual package
## mark_as_advanced(ITK_USE_FFTWD)
Expand Down Expand Up @@ -30,7 +39,23 @@
## to set the initial value of the CMake variable `MKLROOT` (see
## https://software.intel.com/en-us/mkl-linux-developer-guide-scripts-to-set-environment-variables).

if(ITK_USE_FFTWD OR ITK_USE_FFTWF)
set(_fftw_double ${ITK_USE_FFTWD})
set(_fftw_float ${ITK_USE_FFTWF})
if(FFTW_FIND_COMPONENTS)
set(_fftw_double OFF)
set(_fftw_float OFF)
foreach(_fftw_component IN LISTS FFTW_FIND_COMPONENTS)
if(_fftw_component STREQUAL "Double")
set(_fftw_double ON)
elseif(_fftw_component STREQUAL "Float")
set(_fftw_float ON)
else()
message(FATAL_ERROR "Unknown FFTW component: ${_fftw_component}")
endif()
endforeach()
endif()

if(_fftw_double OR _fftw_float)
if(ITK_USE_MKL)
# If the user has provided the MKL include path then search nearby for library files
if(FFTW_INCLUDE_PATH)
Expand All @@ -53,8 +78,6 @@ if(ITK_USE_FFTWD OR ITK_USE_FFTWF)
else()
set(
FFTW_INC_SEARCHPATH
${FFTW3f_INCLUDE_DIRS} # Defined in fftwf local build
${FFTW3_INCLUDE_DIRS} # Defined in fftwd local build
/sw/include
/usr/include
/usr/local/include
Expand Down Expand Up @@ -194,20 +217,17 @@ if(ITK_USE_FFTWD OR ITK_USE_FFTWF)
endif()
endforeach()
fftwd_libraries_end()
add_compile_options(${MKL_OPTIONS})
else()
get_filename_component(FFTW_INSTALL_BASE_PATH ${FFTW_INCLUDE_PATH} PATH)
set(
FFTW_LIB_SEARCHPATH
${FFTW3f_LIBRARY_DIRS} # Defined in fftwf local build
${FFTW3_LIBRARY_DIRS} # Defined in fftwd local build
${FFTW_INSTALL_BASE_PATH}/lib
${FFTW_INSTALL_BASE_PATH}/lib64
/usr/lib/fftw
/usr/local/lib/fftw
)
unset(FFTWD_FOUND)
if(ITK_USE_FFTWD)
if(_fftw_double)
mark_as_advanced(
FFTWD_BASE_LIB
FFTWD_THREADS_LIB
Expand All @@ -219,8 +239,6 @@ if(ITK_USE_FFTWD OR ITK_USE_FFTWF)
if(FFTWD_BASE_LIB)
set(FFTWD_FOUND 1)
get_filename_component(FFTW_LIBDIR ${FFTWD_BASE_LIB} PATH) #NOTE FFTWD_BASE_LIB and FFTWF_BASE_LIB must be installed in the same location
get_filename_component(FFTWD_BASE_LIB ${FFTWD_BASE_LIB} NAME)
get_filename_component(FFTWD_THREADS_LIB ${FFTWD_THREADS_LIB} NAME)
set(FFTWD_LIBRARIES ${FFTWD_BASE_LIB})
if(FFTWD_THREADS_LIB)
set(
Expand All @@ -235,7 +253,7 @@ if(ITK_USE_FFTWD OR ITK_USE_FFTWF)
endif()

unset(FFTWF_FOUND)
if(ITK_USE_FFTWF)
if(_fftw_float)
mark_as_advanced(
FFTWF_BASE_LIB
FFTWF_THREADS_LIB
Expand All @@ -247,8 +265,6 @@ if(ITK_USE_FFTWD OR ITK_USE_FFTWF)
if(FFTWF_BASE_LIB)
set(FFTWF_FOUND 1)
get_filename_component(FFTW_LIBDIR ${FFTWF_BASE_LIB} PATH) #NOTE FFTWD_BASE_LIB and FFTWF_BASE_LIB must be installed in the same location
get_filename_component(FFTWF_BASE_LIB ${FFTWF_BASE_LIB} NAME)
get_filename_component(FFTWF_THREADS_LIB ${FFTWF_THREADS_LIB} NAME)
set(FFTWF_LIBRARIES ${FFTWF_BASE_LIB})
if(FFTWF_THREADS_LIB)
set(
Expand All @@ -262,6 +278,61 @@ if(ITK_USE_FFTWD OR ITK_USE_FFTWF)
endif()
endif()
endif()
unset(FFTWD_THREADS_LIB)
unset(FFTWF_THREADS_LIB)
if(ITK_USE_MKL)
set(FFTWF_LIBRARIES ${FFTWD_LIBRARIES})
endif()
set(_fftw_required_vars FFTW_INCLUDE)
if(_fftw_double)
list(APPEND _fftw_required_vars FFTWD_LIBRARIES)
endif()
if(_fftw_float)
list(APPEND _fftw_required_vars FFTWF_LIBRARIES)
endif()
if(ITK_USE_CUFFTW)
list(
APPEND
_fftw_required_vars
CUFFT_LIB
CUFFTW_LIB
)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FFTW REQUIRED_VARS ${_fftw_required_vars})

if(FFTW_FOUND)
set(_fftw_extra_libraries "")
if(NOT ITK_USE_MKL AND NOT ITK_USE_CUFFTW)
find_package(Threads REQUIRED)
list(APPEND _fftw_extra_libraries Threads::Threads)
if(UNIX)
list(APPEND _fftw_extra_libraries m)
endif()
endif()
foreach(_fftw_precision IN ITEMS Double Float)
string(SUBSTRING ${_fftw_precision} 0 1 _fftw_suffix)
string(TOLOWER ${_fftw_precision} _fftw_selected)
if(_fftw_${_fftw_selected} AND NOT TARGET FFTW::${_fftw_precision})
add_library(FFTW::${_fftw_precision} INTERFACE IMPORTED)
target_include_directories(
FFTW::${_fftw_precision}
SYSTEM
INTERFACE
"${FFTW_INCLUDE}"
)
target_link_libraries(
FFTW::${_fftw_precision}
INTERFACE
${FFTW${_fftw_suffix}_LIBRARIES}
${_fftw_extra_libraries}
)
if(ITK_USE_MKL)
target_compile_options(
FFTW::${_fftw_precision}
INTERFACE
${MKL_OPTIONS}
)
endif()
endif()
endforeach()
endif()
endif()
8 changes: 0 additions & 8 deletions CMake/ITKConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,6 @@ include( "${ITK_CMAKE_DIR}/ITKFactoryRegistration.cmake" )
set(ITK_USE_FFTWD "@ITK_USE_FFTWD@")
set(ITK_USE_FFTWF "@ITK_USE_FFTWF@")
set(ITK_USE_SYSTEM_FFTW "@ITK_USE_SYSTEM_FFTW@")
set(ITK_FFTW_INCLUDE_PATH "@FFTW_INCLUDE_PATH@")
set(ITK_FFTW_LIBDIR "@FFTW_LIBDIR@")

# Add FFTW include and library directories
if (ITK_USE_FFTWF OR ITK_USE_FFTWD)
set(ITK_INCLUDE_DIRS ${ITK_INCLUDE_DIRS} "${ITK_FFTW_INCLUDE_PATH}")
set(ITK_LIBRARY_DIRS ${ITK_LIBRARY_DIRS} "${ITK_FFTW_LIBDIR}")
endif()

# Add configuration with GPU
set(ITK_USE_GPU "@ITK_USE_GPU@")
Expand Down
8 changes: 8 additions & 0 deletions CMake/ITKModuleMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,14 @@ endif()
# Export and install the interface library
itk_module_target_export(${itk-module}Module)
itk_module_target_install(${itk-module}Module)
# Source-less modules still export their interface library to ITKTargets.
set_property(
GLOBAL
APPEND
PROPERTY
ITKTargets_MODULES
${itk-module}
)
####
# End ITK Modules interface library creation
####
Expand Down
75 changes: 50 additions & 25 deletions CMake/Tests/FFTWTargetArchitecture/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
cmake_minimum_required(VERSION 3.22.1)
project(FFTWTargetArchitectureCheck LANGUAGES NONE)

file(READ "${CMAKE_CURRENT_LIST_DIR}/../../itkExternal_FFTW.cmake" source)
string(FIND "${source}" "set(_fftw_default_neon OFF)" selection_start)
string(FIND "${source}" "# Macro to generate library filename" selection_end)
math(EXPR selection_length "${selection_end} - ${selection_start}")
string(SUBSTRING "${source}" ${selection_start} ${selection_length} selection)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/selection.cmake" "${selection}")
include(CheckCSourceCompiles)

function(check_c_source_compiles source result)
set(${result} OFF PARENT_SCOPE)
set(${result} "${compiler_simd}" PARENT_SCOPE)
endfunction()

set(APPLE TRUE)
set(failures "")
foreach(host IN ITEMS arm64 x86_64)
set(CMAKE_SYSTEM_PROCESSOR "${host}")
if(host STREQUAL "arm64")
set(CMAKE_OSX_ARCHITECTURES x86_64)
set(expected_neon OFF)
set(expected_sse ON)
else()
set(CMAKE_OSX_ARCHITECTURES arm64)
set(expected_neon ON)
set(expected_sse OFF)
endif()
function(
check_target
processor
architectures
expected_neon
expected_sse
expected_avx
)
set(APPLE TRUE)
set(CMAKE_SYSTEM_PROCESSOR "${processor}")
set(CMAKE_OSX_ARCHITECTURES "${architectures}")
foreach(
isa
IN
Expand All @@ -38,7 +31,9 @@ foreach(host IN ITEMS arm64 x86_64)
unset(FFTW_ENABLE_${isa} CACHE)
unset(FFTW_ENABLE_${isa})
endforeach()
include("${CMAKE_CURRENT_BINARY_DIR}/selection.cmake")
include(
"${CMAKE_CURRENT_LIST_DIR}/../../../Modules/ThirdParty/FFTW/itkFFTWOptions.cmake"
)
if(
NOT
"${FFTW_ENABLE_NEON}"
Expand All @@ -54,10 +49,40 @@ foreach(host IN ITEMS arm64 x86_64)
"${FFTW_ENABLE_SSE2}"
STREQUAL
"${expected_sse}"
OR
NOT
"${FFTW_ENABLE_AVX}"
STREQUAL
"${expected_avx}"
OR
NOT
"${FFTW_ENABLE_AVX2}"
STREQUAL
"${expected_avx}"
)
list(APPEND failures "${host}->${CMAKE_OSX_ARCHITECTURES}")
message(
FATAL_ERROR
"FFTW defaults disagree with target: ${processor}->${architectures}"
)
endif()
endforeach()
if(failures)
message(FATAL_ERROR "FFTW defaults disagree with target: ${failures}")
endfunction()

set(compiler_simd OFF)
check_target(arm64 x86_64 OFF ON OFF)
check_target(x86_64 arm64 ON OFF OFF)
check_target(x86_64 "" OFF ON OFF)
check_target(aarch64 "" ON OFF OFF)
check_target(i686 "" OFF OFF OFF)
check_target(arm64 "arm64;x86_64" OFF OFF OFF)

set(compiler_simd ON)
check_target(x86_64 "" OFF ON ON)

set(FFTW_ENABLE_AVX OFF CACHE BOOL "" FORCE)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
include(
"${CMAKE_CURRENT_LIST_DIR}/../../../Modules/ThirdParty/FFTW/itkFFTWOptions.cmake"
)
if(FFTW_ENABLE_AVX)
message(FATAL_ERROR "FFTW SIMD defaults override an explicit user option")
endif()
Loading
Loading