1dnl--------------------------------------------------------------------------------
2dnl
3dnl This file is part of Code_Saturne, a general-purpose CFD tool.
4dnl
5dnl Copyright (C) 1998-2021 EDF S.A.
6dnl
7dnl This program is free software; you can redistribute it and/or modify it under
8dnl the terms of the GNU General Public License as published by the Free Software
9dnl Foundation; either version 2 of the License, or (at your option) any later
10dnl version.
11dnl
12dnl This program is distributed in the hope that it will be useful, but WITHOUT
13dnl ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14dnl FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15dnl details.
16dnl
17dnl You should have received a copy of the GNU General Public License along with
18dnl this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
19dnl Street, Fifth Floor, Boston, MA 02110-1301, USA.
20dnl
21dnl--------------------------------------------------------------------------------
22
23# CS_AC_TEST_PETSC
24#----------------
25# modifies or sets cs_have_petsc, PETSC_CPPFLAGS, PETSC_LDFLAGS, and PETSC_LIBS
26# depending on libraries found
27
28AC_DEFUN([CS_AC_TEST_PETSC], [
29
30cs_have_petsc=no
31cs_have_petsc_header=no
32petsc_prefix=""
33cs_abs_srcdir=`cd $srcdir && pwd`
34
35AC_ARG_WITH(petsc,
36            [AS_HELP_STRING([--with-petsc=PATH],
37                            [specify prefix directory for PETSc])],
38            [if test "x$withval" = "x"; then
39               with_petsc=no
40             fi],
41            [with_petsc=no])
42
43AC_ARG_WITH(petsc-lib,
44            [AS_HELP_STRING([--with-petsc-lib=PATH],
45                            [specify directory for PETSc library])],
46            [if test "x$with_petsc" != "xno"; then
47               with_petsc=yes  saved_LIBS="$LIBS"
48             fi
49             PETSC_DIR="$with_petsc_lib/petsc"],
50            [if test "x$with_petsc" != "xno" -a "x$with_petsc" != "xyes" \
51	          -a "x$with_petsc" != "xcheck"; then
52               PETSC_DIR="$with_petsc/lib/petsc"
53             fi])
54
55if test "x$with_petsc" != "xno" ; then
56  if test -f ${PETSC_DIR}/conf/variables ; then
57    PETSC_CPPFLAGS=$(make -s -f "$cs_abs_srcdir/build-aux/petsc-variables.makefile" PETSC_DIR="${PETSC_DIR}" getincludedirs)
58    PETSC_LDFLAGS=""
59    PETSC_LIBS=$(make -s -f "$cs_abs_srcdir/build-aux/petsc-variables.makefile"  PETSC_DIR="${PETSC_DIR}" getlinklibs)
60  elif test -f ${PETSC_DIR}/conf/petscvariables ; then
61    PETSC_CPPFLAGS=$(make -s -f "$cs_abs_srcdir/build-aux/petsc-petscvariables.makefile" PETSC_DIR="${PETSC_DIR}" getincludedirs)
62    PETSC_LDFLAGS=""
63    PETSC_LIBS=$(make -s -f "$cs_abs_srcdir/build-aux/petsc-petscvariables.makefile" PETSC_DIR="${PETSC_DIR}" getlinklibs)
64  else
65      AC_MSG_FAILURE([${PETSC_DIR}/conf/variables or ${PETSC_DIR}/conf/petscvariables not found.
66Check --with-petsc or --with-petsc-lib option or PETSc directory structure
67({--with-petsc}/lib/conf/variables or {--with-petsc_lib}/conf/variables or
68 {--with-petsc}/lib/conf/petscvariables or {--with-petsc_lib}/conf/petscvariables
69should be present).])
70  fi
71
72  saved_CPPFLAGS="$CPPFLAGS"
73  saved_LDFLAGS="$LDFLAGS"
74  saved_LIBS="$LIBS"
75
76  CPPFLAGS="${CPPFLAGS} ${PETSC_CPPFLAGS} ${MPI_CPPFLAGS}"
77  LDFLAGS="${LDFLAGS} ${MPI_LDFLAGS}"
78  LIBS="${LIBS} ${PETSC_LIBS} ${MPI_LIBS}"
79
80  AC_MSG_CHECKING([for PETSc library])
81
82  AC_LINK_IFELSE([AC_LANG_PROGRAM(
83[[#include <petscsys.h>]],
84[[PetscInitializeNoArguments();]])
85                   ],
86                   [ AC_DEFINE([HAVE_PETSC], 1, [PETSc support])
87                     cs_have_petsc=yes
88                   ],
89                   [ AC_MSG_WARN([no PETSc support])
90                     cs_have_petsc=no
91                   ],
92                  )
93
94  AC_MSG_RESULT($cs_have_petsc)
95
96  if test "x$cs_have_petsc" = "xno"; then
97    PETSC_CPPFLAGS=""
98    PETSC_LDFLAGS=""
99    PETSC_LIBS=""
100  fi
101
102  CPPFLAGS="$saved_CPPFLAGS"
103  LDFLAGS="$saved_LDFLAGS"
104  LIBS="$saved_LIBS"
105
106  unset saved_CPPFLAGS
107  unset saved_LDFLAGS
108  unset saved_LIBS
109
110fi
111
112AM_CONDITIONAL(HAVE_PETSC, test x$cs_have_petsc = xyes)
113
114AC_SUBST(cs_have_petsc)
115AC_SUBST(PETSC_CPPFLAGS)
116AC_SUBST(PETSC_LDFLAGS)
117AC_SUBST(PETSC_LIBS)
118])dnl
119
120