|
From: <kin...@us...> - 2025-08-29 16:59:43
|
Revision: 7335
http://sourceforge.net/p/teem/code/7335
Author: kindlmann
Date: 2025-08-29 16:59:41 +0000 (Fri, 29 Aug 2025)
Log Message:
-----------
more comments on chatgpt-assisted cmake code
Modified Paths:
--------------
teem/trunk/CMake/FindFFTW3.cmake
Added Paths:
-----------
teem/trunk/CMake/FindFFTW3-multiprec.cmake
Added: teem/trunk/CMake/FindFFTW3-multiprec.cmake
===================================================================
--- teem/trunk/CMake/FindFFTW3-multiprec.cmake (rev 0)
+++ teem/trunk/CMake/FindFFTW3-multiprec.cmake 2025-08-29 16:59:41 UTC (rev 7335)
@@ -0,0 +1,156 @@
+# NOTE: this was written entirely by ChatFPT, and it has not been used or tested.
+# It suggested these as precedent:
+# https://github.com/acoustid/chromaprint/blob/master/cmake/modules/FindFFTW3.cmake
+# https://github.com/egpbos/findFFTW
+
+# - Find the FFTW3 library (Fastest Fourier Transform in the West).
+#
+# This module tries two strategies:
+# 1. First, rely on CMake’s built-in package support (works only if FFTW3
+# was itself built and installed with CMake, which is often *not* the case).
+# 2. If that fails, fall back to manual search: locate headers and libraries
+# by hand and create imported targets.
+#
+# Provides the following IMPORTED targets on success:
+#
+# FFTW3::fftw3 - double precision base library
+# FFTW3::fftw3f - single precision base library (optional)
+# FFTW3::fftw3l - long double precision base library (optional)
+#
+# FFTW3::fftw3_threads - threads support for double precision
+# FFTW3::fftw3f_threads - threads support for single precision
+# FFTW3::fftw3l_threads - threads support for long double
+#
+# Variables defined:
+# FFTW3_FOUND, FFTW3_INCLUDE_DIR, FFTW3_LIBRARY, etc.
+#
+# Example usage:
+# find_package(FFTW3 REQUIRED)
+# target_link_libraries(myexe PRIVATE FFTW3::fftw3)
+# # optionally: FFTW3::fftw3f, FFTW3::fftw3_threads, etc.
+#
+
+# -------------------------------------------------------------------------
+# STEP 1: Check if CMake’s own FFTW3 package support already worked.
+# If so, we don’t need to do anything else.
+# -------------------------------------------------------------------------
+if (NOT FFTW3_FOUND)
+
+ include(FindPackageHandleStandardArgs)
+
+ # -----------------------------------------------------------------------
+ # STEP 2: Custom fallback — locate FFTW headers and libraries manually.
+ # -----------------------------------------------------------------------
+
+ # Look for header
+ find_path(FFTW3_INCLUDE_DIR
+ NAMES fftw3.h
+ HINTS ENV FFTW3_DIR ENV FFTW_DIR
+ PATH_SUFFIXES include
+ )
+
+ # ---- Double precision (the "default" libfftw3) ----
+ find_library(FFTW3_LIBRARY
+ NAMES fftw3
+ HINTS ENV FFTW3_DIR ENV FFTW_DIR
+ PATH_SUFFIXES lib
+ )
+
+ # ---- Single precision (libfftw3f) ----
+ find_library(FFTW3F_LIBRARY
+ NAMES fftw3f
+ HINTS ENV FFTW3_DIR ENV FFTW_DIR
+ PATH_SUFFIXES lib
+ )
+
+ # ---- Long double precision (libfftw3l) ----
+ find_library(FFTW3L_LIBRARY
+ NAMES fftw3l
+ HINTS ENV FFTW3_DIR ENV FFTW_DIR
+ PATH_SUFFIXES lib
+ )
+
+ # ---- Threaded variants (may or may not exist) ----
+ find_library(FFTW3_THREADS_LIBRARY
+ NAMES fftw3_threads
+ HINTS ENV FFTW3_DIR ENV FFTW_DIR
+ PATH_SUFFIXES lib
+ )
+ find_library(FFTW3F_THREADS_LIBRARY
+ NAMES fftw3f_threads
+ HINTS ENV FFTW3_DIR ENV FFTW_DIR
+ PATH_SUFFIXES lib
+ )
+ find_library(FFTW3L_THREADS_LIBRARY
+ NAMES fftw3l_threads
+ HINTS ENV FFTW3_DIR ENV FFTW_DIR
+ PATH_SUFFIXES lib
+ )
+
+ # Check at least the base double precision lib
+ find_package_handle_standard_args(FFTW3
+ REQUIRED_VARS FFTW3_LIBRARY FFTW3_INCLUDE_DIR
+ )
+
+ # -----------------------------------------------------------------------
+ # STEP 3: Define IMPORTED targets for each library found.
+ # -----------------------------------------------------------------------
+ if (FFTW3_FOUND)
+
+ # --- Double precision ---
+ if (NOT TARGET FFTW3::fftw3)
+ add_library(FFTW3::fftw3 UNKNOWN IMPORTED)
+ set_target_properties(FFTW3::fftw3 PROPERTIES
+ IMPORTED_LOCATION "${FFTW3_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${FFTW3_INCLUDE_DIR}"
+ )
+ endif()
+
+ # --- Single precision ---
+ if (FFTW3F_LIBRARY AND NOT TARGET FFTW3::fftw3f)
+ add_library(FFTW3::fftw3f UNKNOWN IMPORTED)
+ set_target_properties(FFTW3::fftw3f PROPERTIES
+ IMPORTED_LOCATION "${FFTW3F_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${FFTW3_INCLUDE_DIR}"
+ )
+ endif()
+
+ # --- Long double precision ---
+ if (FFTW3L_LIBRARY AND NOT TARGET FFTW3::fftw3l)
+ add_library(FFTW3::fftw3l UNKNOWN IMPORTED)
+ set_target_properties(FFTW3::fftw3l PROPERTIES
+ IMPORTED_LOCATION "${FFTW3L_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${FFTW3_INCLUDE_DIR}"
+ )
+ endif()
+
+ # --- Threads (double) ---
+ if (FFTW3_THREADS_LIBRARY AND NOT TARGET FFTW3::fftw3_threads)
+ add_library(FFTW3::fftw3_threads UNKNOWN IMPORTED)
+ set_target_properties(FFTW3::fftw3_threads PROPERTIES
+ IMPORTED_LOCATION "${FFTW3_THREADS_LIBRARY}"
+ INTERFACE_LINK_LIBRARIES FFTW3::fftw3
+ )
+ endif()
+
+ # --- Threads (single) ---
+ if (FFTW3F_THREADS_LIBRARY AND NOT TARGET FFTW3::fftw3f_threads)
+ add_library(FFTW3::fftw3f_threads UNKNOWN IMPORTED)
+ set_target_properties(FFTW3::fftw3f_threads PROPERTIES
+ IMPORTED_LOCATION "${FFTW3F_THREADS_LIBRARY}"
+ INTERFACE_LINK_LIBRARIES FFTW3::fftw3f
+ )
+ endif()
+
+ # --- Threads (long double) ---
+ if (FFTW3L_THREADS_LIBRARY AND NOT TARGET FFTW3::fftw3l_threads)
+ add_library(FFTW3::fftw3l_threads UNKNOWN IMPORTED)
+ set_target_properties(FFTW3::fftw3l_threads PROPERTIES
+ IMPORTED_LOCATION "${FFTW3L_THREADS_LIBRARY}"
+ INTERFACE_LINK_LIBRARIES FFTW3::fftw3l
+ )
+ endif()
+
+ endif()
+
+endif()
Modified: teem/trunk/CMake/FindFFTW3.cmake
===================================================================
--- teem/trunk/CMake/FindFFTW3.cmake 2025-08-28 23:49:09 UTC (rev 7334)
+++ teem/trunk/CMake/FindFFTW3.cmake 2025-08-29 16:59:41 UTC (rev 7335)
@@ -17,17 +17,28 @@
# along with this library; if not, see <https://www.gnu.org/licenses/>.
#
-# Even though CMake already has a built-in FindFFTW3.cmake, it assumes that
-# fftw3 was installed locally via CMake, but that's not what e.g. Homebrew
-# or apt actually does, so find_package(FFTW3) can succeed but is not able
-# to define imported targets for use with target_link_libraries(FFTW3::fftw3)
-# This is a long-standing issue: https://github.com/FFTW/fftw3/issues/130
-# NOTE: the solution herein was written largely by ChatGPT
+# Even though CMake already has a built-in FindFFTW3.cmake, it assumes that fftw3 was
+# installed locally via CMake, but that's not what e.g. (mac) brew or (linux) apt
+# actually does, so find_package(FFTW3) can succeed but is not able to define imported
+# targets for use with target_link_libraries(FFTW3::fftw3) This is a long-standing issue:
+# https://github.com/FFTW/fftw3/issues/130
+# and there must be various solutions out there, since ChatGPT basically wrote the code
+# below (and is characterically unable to provide a citation for similarly simple but
+# working code online)
-# Try the built-in one first (if available)
+# TODO: handle the various variants for different precisions
+# See FindFFTW3-multiprec.cmake for inspiration
+
+# NOTE: If a working FFTW3Config.cmake is found, it will define
+# FFTW3::fftw3 for us already, so we don’t have to do anything else.
+# This fallback only runs when FFTW3_FOUND is still FALSE.
if (NOT FFTW3_FOUND)
+
+ # Include the helper macro for standard handling of results
include(FindPackageHandleStandardArgs)
+ # Look for the FFTW3 header. Users can help by setting FFTW3_DIR or
+ # by making sure the header is somewhere in the default search paths.
find_path(FFTW3_INCLUDE_DIR
NAMES fftw3.h
HINTS ENV FFTW3_DIR
@@ -34,6 +45,7 @@
PATH_SUFFIXES include
)
+ # Look for the FFTW3 library. Allow FFTW3_DIR to point to its prefix.
find_library(FFTW3_LIBRARY
NAMES fftw3
HINTS ENV FFTW3_DIR
@@ -40,10 +52,14 @@
PATH_SUFFIXES lib
)
+ # Standard handling macro: sets FFTW3_FOUND if the above succeeded
find_package_handle_standard_args(FFTW3
REQUIRED_VARS FFTW3_LIBRARY FFTW3_INCLUDE_DIR
)
+ # If we did find FFTW3, but no imported target exists yet,
+ # create our own IMPORTED target so downstream code can use:
+ # target_link_libraries(myprog PRIVATE FFTW3::fftw3)
if (FFTW3_FOUND AND NOT TARGET FFTW3::fftw3)
add_library(FFTW3::fftw3 UNKNOWN IMPORTED)
set_target_properties(FFTW3::fftw3 PROPERTIES
@@ -52,3 +68,9 @@
)
endif()
endif()
+
+if (FFTW3_FOUND)
+ message(STATUS "Using FFTW3: ${FFTW3_LIBRARY}")
+else()
+ message(STATUS "FFTW3 not found")
+endif()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|