changeset 15969:139f4b19a3ac

build: Improve detection of FFTW multi-threading * build-aux/common.mk: Remove FFTW3_THREADS_LIBS and FFTW3F_THREADS_LIB. * m4/acinclude.m4 (OCTAVE_CHECK_FFTW_THREADS): New macro to encapsulate checking for multi-threading support in the FFTW library. * configure.ac: Call it.
author Mike Miller <mtmiller@ieee.org>
date Mon, 21 Jan 2013 01:58:07 -0500
parents d56dd6794a20
children ca6202597201
files build-aux/common.mk configure.ac m4/acinclude.m4
diffstat 3 files changed, 54 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/build-aux/common.mk	Fri Jan 18 16:48:12 2013 -0500
+++ b/build-aux/common.mk	Mon Jan 21 01:58:07 2013 -0500
@@ -220,7 +220,7 @@
 
 FFTW_XCPPFLAGS = $(FFTW3_CPPFLAGS) $(FFTW3F_CPPFLAGS)
 FFTW_XLDFLAGS = $(FFTW3_LDFLAGS) $(FFTW3F_LDFLAGS)
-FFTW_XLIBS = $(FFTW3_THREADS_LIBS) $(FFTW3F_THREADS_LIBS) $(FFTW3_LIBS) $(FFTW3F_LIBS)
+FFTW_XLIBS = $(FFTW3_LIBS) $(FFTW3F_LIBS)
 
 FT2_CFLAGS = @FT2_CFLAGS@
 FT2_LIBS = @FT2_LIBS@
--- a/configure.ac	Fri Jan 18 16:48:12 2013 -0500
+++ b/configure.ac	Mon Jan 21 01:58:07 2013 -0500
@@ -824,12 +824,8 @@
   [])
 
 if test $build_fftw_threads = true; then
-  OCTAVE_CHECK_LIB(fftw3_threads, FFTW3_THREADS,
-    [FFTW3_THREADS library not found.  The single-threaded library is used instead.],
-    [fftw3.h], [fftw_plan_with_nthreads])
-  OCTAVE_CHECK_LIB(fftw3f_threads, FFTW3F_THREADS,
-    [FFTW3F_THREADS library not found.  The single-threaded library is used instead.],
-    [fftw3.h], [fftwf_plan_with_nthreads])
+  OCTAVE_CHECK_FFTW_THREADS(fftw3, fftw_plan_with_nthreads)
+  OCTAVE_CHECK_FFTW_THREADS(fftw3f, fftwf_plan_with_nthreads)
 fi
 
 AM_CONDITIONAL([AMCOND_HAVE_FFTW],
@@ -2907,11 +2903,9 @@
   FFTW3 CPPFLAGS:              $FFTW3_CPPFLAGS
   FFTW3 LDFLAGS:               $FFTW3_LDFLAGS
   FFTW3 libraries:             $FFTW3_LIBS
-  FFTW3_THREADS libraries:     $FFTW3_THREADS_LIBS
   FFTW3F CPPFLAGS:             $FFTW3F_CPPFLAGS
   FFTW3F LDFLAGS:              $FFTW3F_LDFLAGS
   FFTW3F libraries:            $FFTW3F_LIBS
-  FFTW3F_THREADS libraries:    $FFTW3F_THREADS_LIBS
   fontconfig CFLAGS:           $FONTCONFIG_CFLAGS
   fontconfig libraries:        $FONTCONFIG_LIBS
   FreeType2 CFLAGS:            $FT2_CFLAGS
--- a/m4/acinclude.m4	Fri Jan 18 16:48:12 2013 -0500
+++ b/m4/acinclude.m4	Mon Jan 21 01:58:07 2013 -0500
@@ -93,6 +93,57 @@
   fi
 ])
 dnl
+dnl Check whether the FFTW library supports multi-threading. This macro
+dnl should be called once per FFTW precision passing in the library
+dnl variant (e.g. "fftw3") and a function in the thread support API
+dnl (e.g. "fftw_plan_with_nthreads"). Depending on how FFTW was built,
+dnl the thread functions could be compiled into the main FFTW library or
+dnl could be a separate add-on library that is passed to the linker
+dnl ahead of the main FFTW library.
+dnl
+AC_DEFUN([OCTAVE_CHECK_FFTW_THREADS], [
+  ac_octave_save_CPPFLAGS="$CPPFLAGS"
+  ac_octave_save_LDFLAGS="$LDFLAGS"
+  ac_octave_save_LIBS="$LIBS"
+  CPPFLAGS="$m4_toupper([$1])_CPPFLAGS $CPPFLAGS"
+  LDFLAGS="$m4_toupper([$1])_LDFLAGS $LDFLAGS"
+  LIBS="$m4_toupper([$1])_LIBS $LIBS"
+  AC_CACHE_CHECK([for $1 multi-threading support],
+    [octave_cv_[$1]_threads_lib],
+    [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+      #include <fftw3.h>
+      ]], [[
+      $2 (2);
+      ]])],
+      [octave_cv_[$1]_threads_lib=yes],
+      [LIBS="-l[$1]_threads $LIBS"
+      AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+        #include <fftw3.h>
+        ]], [[
+        $2 (2);
+        ]])],
+        [octave_cv_[$1]_threads_lib="-l[$1]_threads"],
+        [octave_cv_[$1]_threads_lib=no])
+    ])
+  ])
+  case $octave_cv_[$1]_threads_lib in
+    -l*)
+      m4_toupper([$1])_LIBS="$octave_cv_[$1]_threads_lib $m4_toupper([$1])_LIBS"
+      ;;
+    no)
+      AC_MSG_WARN([No $1 multi-threading support found.])
+      AC_MSG_WARN([The single-threaded library will be used instead.])
+      ;;
+  esac
+  if test $octave_cv_[$1]_threads_lib != no; then
+    AC_DEFINE([HAVE_]m4_toupper([$1])[_THREADS], 1,
+      [Define to 1 if ]m4_toupper([$1])[ has multi-threading support.])
+  fi
+  CPPFLAGS="$ac_octave_save_CPPFLAGS"
+  LDFLAGS="$ac_octave_save_LDFLAGS"
+  LIBS="$ac_octave_save_LIBS"
+])
+dnl
 dnl Check whether a math mapper function is available in <cmath>.
 dnl Will define HAVE_CMATH_FUNC if there is a double variant and
 dnl HAVE_CMATH_FUNCF if there is a float variant.