changeset 23021:6094018f5e72

refactor configure checks for Sundials (bug #50003) * configure.ac: Check for Sundials nvecserial and ida libraries separately from the IDAKLU feature. * acinclude.m4 (OCTAVE_CHECK_SUNDIALS_IDAKLU): New macro. * oct-conf-post.in.h: Define HAVE_SUNDIALS here, depending on the values of other HAVE_SUNDIALS_XYZ macros.
author John W. Eaton <jwe@octave.org>
date Sat, 07 Jan 2017 18:42:35 -0500
parents 1dfbdd593c5b
children 305cdc1d444b
files configure.ac m4/acinclude.m4 oct-conf-post.in.h
diffstat 3 files changed, 77 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Sat Jan 07 18:39:50 2017 -0500
+++ b/configure.ac	Sat Jan 07 18:42:35 2017 -0500
@@ -1557,34 +1557,6 @@
 FFT_DIR="fftpack"
 AC_SUBST(FFT_DIR)
 
-### Check for KLU library and header.
-OCTAVE_CHECK_LIB(klu, KLU,
-  [KLU library not found.  This will result in some lack of functionality for sparse matrices],
-  [suitesparse/klu.h ufsparse/klu.h klu/klu.h klu.h], [klu_solve],
-  [], [don't use KLU library, disable some sparse matrix functionality])
-
-### Check for SUNDIALS_IDA library and header.
-save_CPPFLAGS="$CPPFLAGS"
-save_LIBS="$LIBS"
-CPPFLAGS="$KLU_CPPFLAGS $CPPFLAGS"
-LIBS="$KLU_LDFLAGS $KLU_LIBS $LIBS"
-OCTAVE_CHECK_LIB(sundials_ida, SUNDIALS_IDA,
-  [SUNDIALS_IDA library with IDAKLU solver support not found.  Solvers ode15i and ode15s will be disabled.],
-  [ida/ida.h ida.h], [IDAKLU], [], [],
-  [warn_sundials_ida=
-   OCTAVE_CHECK_SIZEOF_SUNDIALS_IDA_REALTYPE])
-LIBS="$save_LIBS"
-CPPFLAGS="$save_CPPFLAGS"
-
-## Additional check for sundials_nvecserial library
-OCTAVE_CHECK_LIB(sundials_nvecserial, SUNDIALS_NVECSERIAL,
-  [SUNDIALS_NVECSERIAL library not found.  Solvers ode15i and ode15s will be disabled.],
-  [nvector/nvector_serial.h nvector_serial.h ], [N_VNew_Serial],[],[],[])
-
-if test -n "$SUNDIALS_IDA_LIBS" && test -n "$SUNDIALS_NVECSERIAL_LIBS" && test $octave_cv_sizeof_ida_double = yes; then
-  AC_DEFINE(HAVE_SUNDIALS, 1, [Define to 1 if both SUNDIALS_IDA and SUNDIALS_NVECSERIAL are available.])
-fi
-
 ### Check for GLPK library and header.
 
 save_CPPFLAGS="$CPPFLAGS"
@@ -2124,6 +2096,13 @@
   LIBS="$save_LIBS"
 fi
 
+### Check for KLU library and header.
+
+OCTAVE_CHECK_LIB(klu, KLU,
+  [KLU library not found.  This will result in some lack of functionality for sparse matrices],
+  [suitesparse/klu.h ufsparse/klu.h klu/klu.h klu.h], [klu_solve],
+  [], [don't use KLU library, disable some sparse matrix functionality])
+
 ## If using SuiteSparse libraries, check for suitesparseconfig library.
 
 SUITESPARSE_CONFIG_LIBS=
@@ -2133,6 +2112,7 @@
    || test x$octave_cv_lib_ccolamd = xyes \
    || test x$octave_cv_lib_cholmod = xyes \
    || test x$octave_cv_lib_cxsparse = xyes \
+   || test x$octave_cv_lib_klu = xyes \
    || test x$octave_cv_lib_umfpack = xyes; then
   ## SuiteSparse >= 4.0 needs additional link library for SuiteSparse_time
   save_CPPFLAGS="$CPPFLAGS"
@@ -2161,6 +2141,35 @@
   CPPFLAGS="$save_CPPFLAGS"
 fi
 
+### Check for Sundials nvecserial library and header.
+
+OCTAVE_CHECK_LIB(sundials_nvecserial, [Sundials nvecserial],
+  [Sundials nvecserial library not found.  Solvers ode15i and ode15s will be disabled.],
+  [nvector/nvector_serial.h nvector_serial.h ], [N_VNew_Serial],
+  [], [don't use Sundials nvecserial library, solvers ode15i and ode15s will be disabled])
+
+if test -n "$SUNDIALS_NVECSERIAL_LIBS"; then
+  AC_DEFINE(HAVE_SUNDIALS_NVECSERIAL, 1,
+    [Define to 1 if Sundials nvecserial is available.])
+fi
+
+### Check for Sundials IDA library and header.
+
+save_LIBS="$LIBS"
+LIBS="$SUNDIALS_NVECSERIAL_LIBS $BLAS_LIBS $FLIBS $LIBS"
+OCTAVE_CHECK_LIB(sundials_ida, [Sundials IDA],
+  [Sundials IDA library not found.  Solvers ode15i and ode15s will be disabled.],
+  [ida/ida.h ida.h], [IDAInit],
+  [], [don't use Sundials IDA library, solvers ode15i and ode15s will be disabled],
+  [warn_sundials_ida=
+   OCTAVE_CHECK_SIZEOF_SUNDIALS_IDA_REALTYPE
+   OCTAVE_CHECK_SUNDIALS_IDAKLU])
+LIBS="$save_LIBS"
+
+if test -n "$SUNDIALS_IDA_LIBS"; then
+  AC_DEFINE(HAVE_SUNDIALS_IDA, 1, [Define to 1 if Sundials IDA is available.])
+fi
+
 ### Check for ARPACK library.
 
 save_LIBS="$LIBS"
--- a/m4/acinclude.m4	Sat Jan 07 18:39:50 2017 -0500
+++ b/m4/acinclude.m4	Sat Jan 07 18:42:35 2017 -0500
@@ -1680,10 +1680,11 @@
   FFLAGS="$ac_octave_save_FFLAGS"
 ])
 dnl
-dnl Check whether sundials_ida library is configured with double precision realtype
+dnl Check whether Sundials IDA library is configured with double
+dnl precision realtype.
 dnl
 AC_DEFUN([OCTAVE_CHECK_SIZEOF_SUNDIALS_IDA_REALTYPE], [
-  AC_CACHE_CHECK([whether sundials_ida is configured with double precision realtype],
+  AC_CACHE_CHECK([whether Sundials IDA is configured with double precision realtype],
     [octave_cv_sizeof_ida_double],
     [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
         #if defined (HAVE_IDA_IDA_H)
@@ -1700,9 +1701,38 @@
   ])
   if test $octave_cv_sizeof_ida_double = yes; then
     AC_DEFINE(HAVE_SUNDIALS_IDA_DOUBLE, 1,
-      [Define to 1 if sundials_ida is configured with realtype as double.])
+      [Define to 1 if Sundials IDA is configured with realtype as double.])
   else
-    warn_sundials_ida="sundials_ida library found, but it's not configured with double precision realtype; function ode15i and ode15s will be disabled"
+    warn_sundials_ida_double="Sundials IDA library not configured with double precision realtype, ode15i and ode15s will be disabled"
+    OCTAVE_CONFIGURE_WARNING([warn_sundials_ida_double])
+  fi
+])
+dnl
+dnl Check whether Sundials IDA library is configured with IDAKLU
+dnl enabled.
+dnl
+AC_DEFUN([OCTAVE_CHECK_SUNDIALS_IDAKLU], [
+  AC_CHECK_HEADERS([ida/ida_klu.h ida_klu.h])
+  AC_CACHE_CHECK([whether Sundials IDA is configured with IDAKLU enabled],
+    [octave_cv_sundials_idaklu],
+    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+         #if defined (HAVE_IDA_IDA_KLU_H)
+         #include <ida/ida_klu.h>
+         #else
+         #include <ida_klu.h>
+         #endif
+         ]], [[
+         IDAKLU (0, 0, 0, 0);
+      ]])],
+      octave_cv_sundials_idaklu=yes,
+      octave_cv_sundials_idaklu=no)
+    ])
+  if test $octave_cv_sundials_idaklu = yes; then
+    AC_DEFINE(HAVE_SUNDIALS_IDAKLU, 1,
+      [Define to 1 if Sundials IDA is configured with IDAKLU enabled.])
+  else
+    warn_sundials_idaklu="Sundials IDA library not configured with IDAKLU, ode15i and ode15s will not support the sparse Jacobian feature"
+    OCTAVE_CONFIGURE_WARNING([warn_sundials_idaklu])
   fi
 ])
 dnl
--- a/oct-conf-post.in.h	Sat Jan 07 18:39:50 2017 -0500
+++ b/oct-conf-post.in.h	Sat Jan 07 18:42:35 2017 -0500
@@ -193,3 +193,9 @@
    the notes at the top of the generated octave-config.h file.  */
 
 #define OCTAVE_AUTOCONFIG_H_INCLUDED 1
+
+#if defined (HAVE_SUNDIALS_NVECSERIAL) \
+  && defined (HAVE_SUNDIALS_IDA) \
+  && defined (HAVE_SUNDIALS_IDA_DOUBLE)
+#  define HAVE_SUNDIALS 1
+#endif