ax_petsc_lib.m4 5.28 KB
Newer Older
Pietro Incardona's avatar
Pietro Incardona committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
# ===========================================================================
#        http://www.gnu.org/software/autoconf-archive/ax_lib_petsc.html
# ===========================================================================
#
# SYNOPSIS
#
#   AX_LIB_PETSC()
#
# DESCRIPTION
#
#   This macro provides tests of the availability of PETSC library.
#
#
#   The macro adds a --with-petsc option accepting one of three values:
#
#     no   - do not check for the PETSC library.
#     yes  - do check for PETSC library in standard locations.
#     path - complete path to the PETSC library.
#
#   If PETSC is successfully found, this macro calls
#
#     AC_SUBST(PETSC_INCLUDE)
#     AC_SUBST(PETSC_LIB)
#     AC_DEFINE(HAVE_PETSC)
#
#   and sets with_petsc="yes"
#
#   If PETSC is disabled or not found, this macros sets with_petsc="no"
#
#   Your configuration script can test $with_petsc to take any further
#   actions. PETSC_{INCLUDE,LIB} may be used when building with C or C++.
#
#   To use the macro, one would code one of the following in "configure.ac"
#   before AC_OUTPUT:
#
#     1) dnl Check for PETSC support
#        AX_LIB_PETSC()
#
#   One could test $with_petsc for the outcome or display it as follows
#
#     echo "PETSC support:  $with_petsc"
#
#   You could also for example, override the default CC in "configure.ac"
#
# LICENSE
#
#   Copyright (c) 2009 Timothy Brown <tbrown@freeshell.org>
#   Copyright (c) 2010 Rhys Ulerich <rhys.ulerich@gmail.com>
#
#   Copying and distribution of this file, with or without modification, are
#   permitted in any medium without royalty provided the copyright notice
#   and this notice are preserved. This file is offered as-is, without any
#   warranty.

#serial 12

AC_DEFUN([AX_LIB_PETSC], [
        AC_MSG_CHECKING(for PETSC library)
        AC_REQUIRE([AC_PROG_CC])
        #
        # User hints...
        #
        AC_ARG_VAR([PETSC], [PETSC library location])
        AC_ARG_WITH([petsc],
                [AC_HELP_STRING([--with-petsc],
                [user defined path to PETSC library])],
                [
                        if test -n "$PETSC" ; then
                                AC_MSG_RESULT(yes)
                                with_petsc=$PETSC
                        elif test "$withval" != no ; then
                                AC_MSG_RESULT(yes)
                                with_petsc=$withval
                        else
                                AC_MSG_RESULT(no)
                        fi
                ],
                [
                        if test -n "$PETSC" ; then
                                with_petsc=$PETSC
                                AC_MSG_RESULT(yes)
                        else
                                with_petsc=/usr
                                if test ! -f "$with_petsc/include/petsc.h" ; then
                                        with_petsc=/usr/local
                                        if test ! -f "$with_petsc/include/petsc.h" ; then
                                                with_petsc=""
                                                AC_MSG_RESULT(failed)
                                        else
                                                AC_MSG_RESULT(yes)
                                        fi
                                else
                                        AC_MSG_RESULT(yes)
                                fi
                        fi
                ])
        #
        # locate PETSC library
        #
incardon's avatar
incardon committed
100

Pietro Incardona's avatar
Pietro Incardona committed
101 102 103 104
                if test -n "$with_petsc" ; then
                        old_CC=$CC
                        old_CFLAGS=$CFLAGS
                        old_LDFLAGS=$LDFLAGS
incardon's avatar
incardon committed
105 106 107
			AX_OPENMP([CFLAGS="$OPENMP_CFLAGS"
				   LDFLAGS="$OPENMP_LDFLAGS"],[])
                        CFLAGS="$CFLAGS -I$with_petsc/include $HDF5_INCLUDE $METIS_INCLUDE "
108
                        LDFLAGS="$LDFLAGS -L$with_petsc/lib $HDF5_LDFLAGS  $HDF5_LIBS $METIS_LIB -lmetis $SUITESPARSE_LIBS"
Pietro Incardona's avatar
Pietro Incardona committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
			CC=$CXX

                        AC_LANG_SAVE
                        AC_LANG_C

                        AC_CHECK_HEADER([petsc.h],petsc_h=yes,## Copy LIB and include in the target directory
AC_MSG_WARN([could not find header file petsc.h]))
                        AC_CHECK_LIB([petsc],[PetscTrMalloc],petsc_lib=yes,AC_MSG_WARN([could not find libpetsc]))
                                
                        AC_LANG_RESTORE

                        CFLAGS=$old_CFLAGS
                        LDFLAGS=$old_LDFLAGS
                        CC=$old_CC

                        AC_MSG_CHECKING(PETSC in $with_petsc)
Pietro Incardona's avatar
Pietro Incardona committed
125
                        if test x"$petsc_lib" = x"yes" -a x"$petsc_h" = x"yes" ; then
Pietro Incardona's avatar
Pietro Incardona committed
126
                                AC_SUBST(PETSC_INCLUDE, [-I$with_petsc/include])
Pietro Incardona's avatar
Pietro Incardona committed
127
                                AC_SUBST(PETSC_LIB, ["-L$with_petsc/lib -lpetsc"])
Pietro Incardona's avatar
Pietro Incardona committed
128 129 130 131 132 133 134 135 136 137
                                AC_MSG_RESULT(ok)
 				AC_DEFINE(HAVE_PETSC,1,[Define if you have PETSC library])
                        else
                                AC_MSG_RESULT(failed)
                        fi
                fi
                #
                #
                #
                if test x = x"$PETSC_LIB" ; then
incardon's avatar
incardon committed
138
                        ifelse([$2],,[],[$2])
Pietro Incardona's avatar
Pietro Incardona committed
139 140 141 142 143 144
                        :
                else
                        ifelse([$1],,[],[$1])
                        :
                fi
        ])dnl AX_LIB_PETSC