1# -*- Autoconf -*- 2# 3# Copyright (C) 2014-2017 Yann Pouillon 4# 5# This file is part of the LibGridXC software package. For license information, 6# please see the COPYING file in the top-level directory of the LibGridXC source 7# distribution. 8# 9 10 11 12# GXC_LIBXC_DETECT() 13# ------------------ 14# 15# Check whether the specified LibXC library is working. 16# 17AC_DEFUN([GXC_LIBXC_DETECT],[ 18 dnl Init 19 gxc_libxc_default_libs="-lxcf90 -lxc" 20 gxc_libxc_has_hdrs="unknown" 21 gxc_libxc_has_mods="unknown" 22 gxc_libxc_has_incs="unknown" 23 gxc_libxc_has_libs="unknown" 24 gxc_libxc_version="unknown" 25 gxc_libxc_ok="unknown" 26 27 dnl Prepare environment 28 tmp_saved_CPPFLAGS="${CPPFLAGS}" 29 tmp_saved_FCFLAGS="${FCFLAGS}" 30 tmp_saved_LIBS="${LIBS}" 31 CPPFLAGS="${CPPFLAGS} ${gxc_libxc_incs}" 32 FCFLAGS="${FCFLAGS} ${gxc_libxc_incs}" 33 if test "${gxc_libxc_libs}" = ""; then 34 AC_MSG_CHECKING([for LibXC libraries to try]) 35 LIBS="${gxc_libxc_default_libs} ${LIBS}" 36 AC_MSG_RESULT([${gxc_libxc_default_libs}]) 37 else 38 LIBS="${gxc_libxc_libs} ${LIBS}" 39 fi 40 41 dnl Look for C includes 42 AC_LANG_PUSH([C]) 43 AC_CHECK_HEADERS([xc.h xc_funcs.h],[gxc_libxc_has_hdrs="yes"],[gxc_libxc_has_hdrs="no"]) 44 AC_LANG_POP([C]) 45 46 dnl Look for Fortran includes 47 AC_MSG_CHECKING([for LibXC Fortran modules]) 48 AC_LANG_PUSH([Fortran]) 49 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], 50 [[ 51 use xc_f90_lib_m 52 ]])], [gxc_libxc_has_mods="yes"], [gxc_libxc_has_mods="no"]) 53 AC_LANG_POP([Fortran]) 54 AC_MSG_RESULT([${gxc_libxc_has_mods}]) 55 56 dnl Check status of include files 57 if test "${gxc_libxc_has_hdrs}" = "yes" -a \ 58 "${gxc_libxc_has_mods}" = "yes"; then 59 gxc_libxc_has_incs="yes" 60 else 61 gxc_libxc_has_incs="no" 62 fi 63 64 dnl Check whether the Fortran wrappers work 65 if test "${gxc_libxc_has_incs}" = "yes"; then 66 AC_MSG_CHECKING([whether LibXC has Fortran support]) 67 AC_LANG_PUSH([Fortran]) 68 AC_LINK_IFELSE([AC_LANG_PROGRAM([], 69 [[ 70 use xc_f90_lib_m 71 integer :: i 72 type(xc_f90_pointer_t) :: info 73 i = xc_f90_info_number(info) 74 ]])], [gxc_libxc_has_libs="yes"], [gxc_libxc_has_libs="no"]) 75 AC_LANG_POP([Fortran]) 76 AC_MSG_RESULT([${gxc_libxc_has_libs}]) 77 fi 78 79 dnl Final adjustments 80 if test "${gxc_libxc_has_incs}" = "yes" -a \ 81 "${gxc_libxc_has_libs}" = "yes"; then 82 gxc_libxc_ok="yes" 83 if test "${gxc_libxc_libs}" = ""; then 84 gxc_libxc_libs="${gxc_libxc_default_libs}" 85 fi 86 else 87 gxc_libxc_ok="no" 88 fi 89 90 dnl Restore environment 91 CPPFLAGS="${tmp_saved_CPPFLAGS}" 92 FCFLAGS="${tmp_saved_FCFLAGS}" 93 LIBS="${tmp_saved_LIBS}" 94]) # GXC_LIBXC_DETECT 95