changeset 33158:baf7621aa073 stable

build: Improve checks for SUNDIALS 7 compatibility (bug #65392). * m4/acinclude.m4 (OCTAVE_CHECK_SUNDIALS_SUNCONTEXT_CREATE): New function to check whether the function "SUNContext_Create" is needed and whether it is exported from sundials_core library. (OCTAVE_CHECK_SUNDIALS_SUNLINSOL_KLU): Use new function. * configure.ac: Remove unconditional check for sundials_core library.
author Markus Mützel <markus.muetzel@gmx.de>
date Tue, 05 Mar 2024 09:00:30 +0100
parents 05f32a32ec3f
children 2ac3523783ee b4f8f14dc1fb
files configure.ac m4/acinclude.m4
diffstat 2 files changed, 63 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Wed Mar 06 11:32:20 2024 -0500
+++ b/configure.ac	Tue Mar 05 09:00:30 2024 +0100
@@ -2356,32 +2356,20 @@
   LIBS="$save_LIBS"
 fi
 
-### Check for SUNDIALS core library and header.
-
-if test -n "$SUNDIALS_IDA_LIBS" && test -n "$SUNDIALS_NVECSERIAL_LIBS"; then
-
-  save_CPPFLAGS="$CPPFLAGS"
-  save_LDFLAGS="$LDFLAGS"
-  save_LIBS="$LIBS"
-  LIBS="$SUNDIALS_CORE_LIBS $LIBS"
-  LDFLAGS="$SUNDIALS_CORE_LDFLAGS $LDFLAGS"
-  CPPFLAGS="$SUNDIALS_CORE_CPPFLAGS $CPPFLAGS"
-  OCTAVE_CHECK_LIB(sundials_core, [SUNDIALS core],
-    [SUNDIALS core library not found.],
-    [sundials_core.h sundials/sundials_core.h], [SUNContext_Create],
-    [], [])
-  CPPFLAGS="$save_CPPFLAGS"
-  LDFLAGS="$save_LDFLAGS"
-  LIBS="$save_LIBS"
+if test -n "$SUNDIALS_IDA_LIBS" \
+    && test -n "$SUNDIALS_NVECSERIAL_LIBS"; then
+  octave_have_sundials_libs=yes
+else
+  octave_have_sundials_libs=no
 fi
 
 ### Check for SUNDIALS library features, some required, some optional.
 
-if test -n "$SUNDIALS_IDA_LIBS" && test -n "$SUNDIALS_NVECSERIAL_LIBS"; then
-
-  CPPFLAGS="$SUNDIALS_IDA_CPPFLAGS $SUNDIALS_NVECSERIAL_CPPFLAGS $SUNDIALS_CORE_CPPFLAGS $KLU_CPPFLAGS $BLAS_CPPFLAGS $CPPFLAGS"
-  LDFLAGS="$SUNDIALS_IDA_LDFLAGS $SUNDIALS_NVECSERIAL_LDFLAGS $SUNDIALS_CORE_LDFLAGS $KLU_LDFLAGS $BLAS_LDFLAGS $LDFLAGS"
-  LIBS="$SUNDIALS_IDA_LIBS $SUNDIALS_NVECSERIAL_LIBS $SUNDIALS_CORE_LIBS $KLU_LIBS $BLAS_LIBS $FLIBS $LIBS"
+if test "x$octave_have_sundials_libs" == xyes; then
+
+  CPPFLAGS="$SUNDIALS_IDA_CPPFLAGS $SUNDIALS_NVECSERIAL_CPPFLAGS $KLU_CPPFLAGS $BLAS_CPPFLAGS $CPPFLAGS"
+  LDFLAGS="$SUNDIALS_IDA_LDFLAGS $SUNDIALS_NVECSERIAL_LDFLAGS $KLU_LDFLAGS $BLAS_LDFLAGS $LDFLAGS"
+  LIBS="$SUNDIALS_IDA_LIBS $SUNDIALS_NVECSERIAL_LIBS $KLU_LIBS $BLAS_LIBS $FLIBS $LIBS"
   if test -z "$warn_sundials_nvecserial" && test -z "$warn_sundials_ida"; then
     dnl Any of the following tests could determine that SUNDIALS is
     dnl incompatible and should be disabled.  In that event, they all populate
@@ -2417,7 +2405,7 @@
 dnl How can we do a better job here?  Do we need to disable sundials
 dnl any tests fail, or can we fix __ode15__.cc so that it still partially
 dnl works when some things are missing (for example, KLU)?
-if test -n "$SUNDIALS_IDA_LIBS" && test -n "$SUNDIALS_NVECSERIAL_LIBS"; then
+if test "x$octave_have_sundials_libs" == xyes; then
   if test "x$octave_cv_sundials_sunlinsol_dense" = xyes \
       && test "x$octave_cv_sundials_realtype_is_double" = xyes \
       && test "x$octave_have_sundials_compatible_api" = xyes; then
--- a/m4/acinclude.m4	Wed Mar 06 11:32:20 2024 -0500
+++ b/m4/acinclude.m4	Tue Mar 05 09:00:30 2024 +0100
@@ -2293,6 +2293,40 @@
   ])
 ])
 dnl
+dnl Check for library that exports SUNContext_Create.
+dnl
+AC_DEFUN([OCTAVE_CHECK_SUNDIALS_SUNCONTEXT_CREATE], [
+  save_LIBS=$LIBS
+  LIBS="$SUNDIALS_IDA_LIBS $SUNDIALS_NVECSERIAL_LIBS $LIBS"
+  dnl Check for SUNContext_Create without linking to libsundials_core.
+  dnl That should succeed for SUNDIALS version 6.
+  AC_CHECK_FUNC([SUNContext_Create])
+  LIBS="$save_LIBS"
+  if test "x$ac_cv_func_SUNContext_Create" != xyes; then
+    ## SUNDIALS version 7 exports SUNContext_Create from libsundials_core
+    save_CPPFLAGS="$CPPFLAGS"
+    save_LDFLAGS="$LDFLAGS"
+    save_LIBS="$LIBS"
+    LIBS="$SUNDIALS_CORE_LIBS $LIBS"
+    LDFLAGS="$SUNDIALS_CORE_LDFLAGS $LDFLAGS"
+    CPPFLAGS="$SUNDIALS_CORE_CPPFLAGS $CPPFLAGS"
+    ## Unset cache variable from previous check
+    unset ac_cv_func_SUNContext_Create
+    OCTAVE_CHECK_LIB(sundials_core, [SUNDIALS core], [],
+      [sundials_core.h sundials/sundials_core.h], [SUNContext_Create],
+      [], [])
+    CPPFLAGS="$save_CPPFLAGS"
+    LDFLAGS="$save_LDFLAGS"
+    LIBS="$save_LIBS"
+  fi
+  if test "x$ac_cv_func_SUNContext_Create" = xyes \
+    || test "x$octave_cv_lib_sundials_core" = xyes; then
+    ## SUNDIALS prior to version 6 does not need SUNContext_Create
+    AC_DEFINE(HAVE_SUNDIALS_SUNCONTEXT, 1,
+      [Define to 1 if SUNDIALS API uses a SUNContext object.])
+  fi
+])
+dnl
 dnl Check whether SUNDIALS libraries provide a compatible interface.
 dnl The current recommended interface was introduced in SUNDIALS version 4.
 dnl The deprecated interface that Octave currently works to be compatible with
@@ -2302,7 +2336,7 @@
   ac_octave_save_LIBS=$LIBS
   LIBS="$SUNDIALS_IDA_LIBS $SUNDIALS_NVECSERIAL_LIBS $LIBS"
   dnl Current API functions present in SUNDIALS version 4
-  AC_CHECK_FUNCS([IDASetJacFn IDASetLinearSolver SUNLinSol_Dense SUNSparseMatrix_Reallocate SUNContext_Create])
+  AC_CHECK_FUNCS([IDASetJacFn IDASetLinearSolver SUNLinSol_Dense SUNSparseMatrix_Reallocate])
   dnl FIXME: The purpose of the following tests is to detect the deprecated
   dnl API from SUNDIALS version 3, which should only be used if the current
   dnl API tests above failed. For now, always test for ida_direct.h.
@@ -2323,10 +2357,6 @@
     octave_have_sundials_compatible_api=no
   fi
   AC_MSG_RESULT([$octave_have_sundials_compatible_api])
-  if test "x$ac_cv_func_SUNContext_Create" = xyes; then
-    AC_DEFINE(HAVE_SUNDIALS_SUNCONTEXT, 1,
-      [Define to 1 if SUNDIALS' API is using a SUNContext object.])
-  fi
   if test $octave_have_sundials_compatible_api = no; then
     warn_sundials_disabled="SUNDIALS libraries do not provide an API that is compatible with Octave.  The solvers ode15i and ode15s will be disabled."
     OCTAVE_CONFIGURE_WARNING([warn_sundials_disabled])
@@ -2418,7 +2448,15 @@
      #  include <ufsparse/klu.h>
      #endif
     ])
+  ## Check for library that exports SUNContext_Create
+  OCTAVE_CHECK_SUNDIALS_SUNCONTEXT_CREATE
   ## Check for current KLU function name first.
+  save_CPPFLAGS="$CPPFLAGS"
+  save_LDFLAGS="$LDFLAGS"
+  save_LIBS="$LIBS"
+  CPPFLAGS="$SUNDIALS_CORE_CPPFLAGS $CPPFLAGS"
+  LDFLAGS="$SUNDIALS_CORE_LDFLAGS $LDFLAGS"
+  LIBS="$SUNDIALS_CORE_LIBS $LIBS"
   OCTAVE_CHECK_LIB(sundials_sunlinsolklu, SUNLINSOL_KLU, [],
     [], [SUNLinSol_KLU], [],
     [don't use SUNDIALS SUNLINSOL_KLU library, disable ode15i and ode15s sparse Jacobian],
@@ -2445,9 +2483,12 @@
          #include <sunlinsol/sunlinsol_klu.h>
          #endif
          ]], [[
-         #if defined (HAVE_SUNCONTEXT_CREATE)
+         #if defined (HAVE_SUNDIALS_SUNCONTEXT)
+         #  if ! defined (SUN_COMM_NULL)
+         #    define SUN_COMM_NULL NULL
+         #  endif
            SUNContext *sunContext;
-           if (SUNContext_Create (NULL, sunContext) < 0)
+           if (SUNContext_Create (SUN_COMM_NULL, sunContext) < 0)
              1/0;  // provoke an error
            SUNLinSol_KLU (0, 0, *sunContext);
            SUNContext_Free (sunContext);
@@ -2464,7 +2505,7 @@
       [], [SUNKLU], [],
       [don't use SUNDIALS SUNLINSOL_KLU library, disable ode15i and ode15s sparse Jacobian],
       [AC_CHECK_FUNCS([SUNKLU])
-       AC_CACHE_CHECK([whether compiling a program that calls SUNLinSol_KLU works],
+       AC_CACHE_CHECK([whether compiling a program that calls SUNKLU works],
         [octave_cv_sundials_sunlinsol_klu],
         [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
            #if defined (HAVE_IDA_IDA_H)
@@ -2500,6 +2541,9 @@
     warn_sundials_sunlinsol_klu="SUNDIALS IDA library not configured with SUNLINSOL_KLU or sunlinsol_klu.h is not usable.  The solvers ode15i and ode15s will not support the sparse Jacobian feature."
     OCTAVE_CONFIGURE_WARNING([warn_sundials_sunlinsol_klu])
   fi
+  CPPFLAGS="$save_CPPFLAGS"
+  LDFLAGS="$save_LDFLAGS"
+  LIBS="$save_LIBS"
 ])
 dnl
 dnl Like AC_CONFIG_FILES, but don't touch the output file if it already