Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

278 lines
9.2KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_lib_netcdf4.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_LIB_NETCDF4([serial/parallel])
  8. #
  9. # DESCRIPTION
  10. #
  11. # This macro provides tests of the availability of the NetCDF v4 library.
  12. #
  13. # The optional macro argument should be either 'serial' or 'parallel'. The
  14. # macro will call nc-config to check the output of the '--has-pnetcdf'
  15. # option and error out if the requested parallel isn't supported.
  16. #
  17. # If the optional argument is omitted, no check is made to see if NetCDF
  18. # has parallel support.
  19. #
  20. # The macro adds a --with-netcdf4 option accepting one of three values:
  21. #
  22. # no - do not check for the NetCDF4 library.
  23. # yes - do check for NetCDF4 library in standard locations.
  24. # path - installation prefix for NetCDF version 4.
  25. #
  26. # If NetCDF4 is successfully found, this macro calls
  27. #
  28. # AC_SUBST(NETCDF4_VERSION)
  29. # AC_SUBST(NETCDF4_CC)
  30. # AC_SUBST(NETCDF4_CFLAGS)
  31. # AC_SUBST(NETCDF4_CPPFLAGS)
  32. # AC_SUBST(NETCDF4_LDFLAGS)
  33. # AC_SUBST(NETCDF4_LIBS)
  34. # AC_SUBST(NETCDF4_FC)
  35. # AC_SUBST(NETCDF4_FFLAGS)
  36. # AC_SUBST(NETCDF4_FLIBS)
  37. # AC_DEFINE(HAVE_NETCDF4)
  38. #
  39. # It also sets
  40. #
  41. # with_netcdf4="yes"
  42. # with_netcdf4_fortran="yes" (if NetCDF has Fortran support)
  43. # with_netcdf4_parallel="yes" (if NetCDF has MPI support)
  44. #
  45. # If NetCDF4 is disabled or not found, this macros sets
  46. #
  47. # with_netcdf4="no"
  48. # with_netcdf4_fortran="no"
  49. #
  50. # Note it does not set with_netcdf4_parallel in this case.
  51. #
  52. # Your configuration script can test $with_netcdf4 to take any further
  53. # actions. NETCDF4_{C,CPP,LD}FLAGS may be used when building with C or
  54. # C++. NETCDF4_F{FLAGS,LIBS} and NETCDF4_LDFLAGS should be used when
  55. # building Fortran applications.
  56. #
  57. # To use the macro, one would code one of the following in "configure.ac"
  58. # before AC_OUTPUT:
  59. #
  60. # 1) dnl Check for NetCDF4 support
  61. # AX_LIB_NETCDF4()
  62. #
  63. # 2) dnl Check for serial NetCDF4 support
  64. # AX_LIB_NETCDF4([serial])
  65. #
  66. # 3) dnl Check for parallel NetCDF4 support
  67. # AX_LIB_NETCDF4([parallel])
  68. #
  69. # One could test $with_netcdf4 for the outcome or display it as follows
  70. #
  71. # echo "NetCDF v4 support: $with_netcdf4"
  72. #
  73. # One could also for example, override the default CC in "configure.ac" to
  74. # enforce compilation with the compiler that NetCDF v4 was built with:
  75. #
  76. # AX_LIB_NETCDF4([parallel])
  77. # if test "$with_netcdf4" = "yes"; then
  78. # CC="$NETCDF4_CC"
  79. # else
  80. # AC_MSG_ERROR([Unable to find NetCDF4, we need parallel NetCDF4.])
  81. # fi
  82. #
  83. # LICENSE
  84. #
  85. # Copyright (c) 2016 Timothy Brown <tbrown@freeshell.org>
  86. #
  87. # Copying and distribution of this file, with or without modification, are
  88. # permitted in any medium without royalty provided the copyright notice
  89. # and this notice are preserved. This file is offered as-is, without any
  90. # warranty.
  91. #serial 2
  92. AC_DEFUN([AX_LIB_NETCDF4], [
  93. AC_REQUIRE([AC_PROG_SED])
  94. AC_REQUIRE([AC_PROG_AWK])
  95. AC_REQUIRE([AC_PROG_GREP])
  96. dnl Check first argument is one of the recognized values.
  97. dnl Fail eagerly if is incorrect as this simplifies case statements below.
  98. if test "m4_normalize(m4_default([$1],[]))" = "" ; then
  99. netcdf4_requested_mode="serial"
  100. elif test "m4_normalize(m4_default([$1],[]))" = "serial" ; then
  101. netcdf4_requested_mode="serial"
  102. elif test "m4_normalize(m4_default([$1],[]))" = "parallel"; then
  103. netcdf4_requested_mode="parallel"
  104. else
  105. AC_MSG_ERROR([
  106. Unrecognized value for AX[]_LIB_NETCDF4 within configure.ac.
  107. If supplied, argument 1 must be either 'serial' or 'parallel'.
  108. ])
  109. fi
  110. dnl Add a default --with-netcdf4 configuration option.
  111. AC_ARG_WITH([netcdf4],
  112. AS_HELP_STRING(
  113. [--with-netcdf4=[yes/no/PATH]],
  114. m4_case(m4_normalize([$1]),
  115. [serial], [base directory of serial NetCDF4 installation],
  116. [parallel], [base directory of parallel NetCDF4 installation],
  117. [base directory of NetCDF4 installation])
  118. ),
  119. [if test "$withval" = "no"; then
  120. with_netcdf4="no"
  121. elif test "$withval" = "yes"; then
  122. with_netcdf4="yes"
  123. else
  124. with_netcdf4="yes"
  125. NETCDF4_PREFIX="${withval}"
  126. NC_CONFIG="${withval}/bin/nc-config"
  127. fi],
  128. [with_netcdf4="yes"]
  129. )
  130. dnl Set defaults to blank
  131. NETCDF4_CC=""
  132. NETCDF4_VERSION=""
  133. NETCDF4_CFLAGS=""
  134. NETCDF4_CPPFLAGS=""
  135. NETCDF4_LDFLAGS=""
  136. NETCDF4_LIBS=""
  137. NETCDF4_FC=""
  138. NETCDF4_FFLAGS=""
  139. NETCDF4_FLIBS=""
  140. dnl Try and find NetCDF4 tools and options.
  141. if test "$with_netcdf4" = "yes"; then
  142. if test -z "$NC_CONFIG"; then
  143. dnl Check to see if NC_CONFIG is in the path.
  144. AC_PATH_PROGS([NC_CONFIG], [nc-config], [])
  145. NETCDF4_PREFIX=$(AS_DIRNAME([$(AS_DIRNAME(["$NC_CONFIG"]))]))
  146. else
  147. AC_MSG_CHECKING([Using provided NetCDF4 prefix])
  148. AC_MSG_RESULT([$NC_CONFIG])
  149. fi
  150. AC_MSG_CHECKING([for NetCDF4 libraries])
  151. if test ! -f "$NC_CONFIG" || test ! -x "$NC_CONFIG"; then
  152. AC_MSG_RESULT([no])
  153. AC_MSG_WARN([
  154. Unable to locate NetCDF4 compilation helper script 'nc-config'.
  155. Please specify --with-netcdf4=<LOCATION> as the full path prefix
  156. where NetCDF4 has been installed.
  157. NetCDF4 support is being disabled (equivalent to --with-netcdf4=no).
  158. ])
  159. with_netcdf4="no"
  160. with_netcdf4_fortran="no"
  161. else
  162. dnl Get the actual compiler used
  163. NETCDF4_CC=$(eval $NC_CONFIG --cc | $AWK '{print $[]1}')
  164. if test "$NETCDF4_CC" = "ccache"; then
  165. NETCDF4_CC=$(eval $NC_CONFIG --cc | $AWK '{print $[]2}')
  166. fi
  167. dnl Look for version
  168. NETCDF4_VERSION=$(eval $NC_CONFIG --version | $AWK '{print $[]2}')
  169. dnl Look for the CFLAGS
  170. NETCDF4_CFLAGS=$(eval $NC_CONFIG --cflags)
  171. dnl Look for the LIBS and LDFLAGS
  172. NETCDF4_tmp_clibs=$(eval $NC_CONFIG --libs)
  173. dnl Sort out the tmp libs based on their prefixes
  174. for arg in $NETCDF4_tmp_clibs ; do
  175. case "$arg" in
  176. -L*) echo $NETCDF4_LDFLAGS | $GREP -e "$arg" 2>&1 >/dev/null \
  177. || NETCDF4_LDFLAGS="$arg $NETCDF4_LDFLAGS"
  178. ;;
  179. -l*) echo $NETCDF4_LIBS | $GREP -e "$arg" 2>&1 >/dev/null \
  180. || NETCDF4_LIBS="$arg $NETCDF4_LIBS"
  181. ;;
  182. esac
  183. done
  184. AC_MSG_RESULT([yes (version $[NETCDF4_VERSION])])
  185. dnl See if we need (and have) parallel support
  186. if test "$netcdf4_requested_mode" = "parallel" ; then
  187. with_netcdf4_parallel=$(eval $NC_CONFIG --has-pnetcdf)
  188. if test "$with_netcdf4_parallel" = "no" ; then
  189. AC_MSG_ERROR([
  190. parallel NetCDF4 is not supported (while it was requested)
  191. ])
  192. fi
  193. fi
  194. dnl See if we can compile
  195. ax_lib_netcdf4_save_CC=$CC
  196. ax_lib_netcdf4_save_CPPFLAGS=$CPPFLAGS
  197. ax_lib_netcdf4_save_LIBS=$LIBS
  198. ax_lib_netcdf4_save_LDFLAGS=$LDFLAGS
  199. CC=$NETCDF4_CC
  200. CFLAGS=$NETCDF4_CFLAGS
  201. LIBS=$NETCDF4_LIBS
  202. LDFLAGS=$NETCDF4_LDFLAGS
  203. AC_CHECK_HEADER([netcdf.h], [ac_cv_netcdf4_h=yes], [ac_cv_netcdf4_h=no])
  204. AC_CHECK_LIB([netcdf], [nc_create], [ac_cv_libnetcdf4=yes],
  205. [ac_cv_libnetcdf4=no])
  206. if test "$ac_cv_netcdf4_h" = "no" && \
  207. test "$ac_cv_libnetcdf4" = "no" ; then
  208. AC_MSG_WARN([Unable to compile NetCDF4 test program])
  209. fi
  210. CC=$ax_lib_netcdf4_save_CC
  211. CFLAGS=$ax_lib_netcdf4_save_CFLAGS
  212. LIBS=$ax_lib_netcdf4_save_LIBS
  213. LDFLAGS=$ax_lib_hdf5_save_LDFLAGS
  214. AC_MSG_CHECKING([for matching NetCDF4 Fortran libraries])
  215. NF_CONFIG="${NETCDF4_PREFIX}/bin/nf-config"
  216. if test ! -f "$NF_CONFIG" || test ! -x "$NF_CONFIG"; then
  217. AC_MSG_RESULT([no])
  218. with_netcdf4_fortran="no"
  219. else
  220. NETCDF_FVERSION=$(eval $NF_CONFIG --version | $AWK '{print $[]2}')
  221. AC_MSG_RESULT([yes (version $[NETCDF_FVERSION])])
  222. NETCDF4_FC=$(eval $NF_CONFIG --fc | $AWK '{print $[]1}')
  223. if test "$NETCDF4_FC" = "ccache"; then
  224. NETCDF4_FC=$(eval $NF_CONFIG --fc | $AWK '{print $[]2}')
  225. fi
  226. dnl Look for the FFLAGS
  227. NETCDF4_FFLAGS=$(eval $NC_CONFIG --fflags)
  228. dnl Look for the FLIBS and LDFLAGS
  229. NETCDF4_tmp_flibs=$(eval $NC_CONFIG --flibs)
  230. dnl Sort out the tmp libs based on their prefixes
  231. for arg in $NETCDF4_tmp_flibs ; do
  232. case "$arg" in
  233. -L*) echo $NETCDF4_LDFLAGS | $GREP -e "$arg" 2>&1 >/dev/null \
  234. || NETCDF4_LDFLAGS="$arg $NETCDF4_LDFLAGS"
  235. ;;
  236. -l*) echo $NETCDF4_FLIBS | $GREP -e "$arg" 2>&1 >/dev/null \
  237. || NETCDF4_FLIBS="$arg $NETCDF4_FLIBS"
  238. ;;
  239. esac
  240. done
  241. with_netcdf4_fortran="yes"
  242. fi
  243. AC_SUBST([NETCDF4_VERSION])
  244. AC_SUBST([NETCDF4_CC])
  245. AC_SUBST([NETCDF4_CFLAGS])
  246. AC_SUBST([NETCDF4_LDFLAGS])
  247. AC_SUBST([NETCDF4_LIBS])
  248. AC_SUBST([NETCDF4_FC])
  249. AC_SUBST([NETCDF4_FFLAGS])
  250. AC_SUBST([NETCDF4_FLIBS])
  251. AC_DEFINE([HAVE_NETCDF4], [1], [Defined if you have NETCDF4 support])
  252. fi
  253. fi
  254. ])