ax_lib_hdf5.m4 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. # ===========================================================================
  2. # http://www.gnu.org/software/autoconf-archive/ax_lib_hdf5.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_LIB_HDF5([serial/parallel])
  8. #
  9. # DESCRIPTION
  10. #
  11. # This macro provides tests of the availability of HDF5 library.
  12. #
  13. # The optional macro argument should be either 'serial' or 'parallel'. The
  14. # former only looks for serial HDF5 installations via h5cc. The latter
  15. # only looks for parallel HDF5 installations via h5pcc. If the optional
  16. # argument is omitted, serial installations will be preferred over
  17. # parallel ones.
  18. #
  19. # The macro adds a --with-hdf5 option accepting one of three values:
  20. #
  21. # no - do not check for the HDF5 library.
  22. # yes - do check for HDF5 library in standard locations.
  23. # path - complete path to the HDF5 helper script h5cc or h5pcc.
  24. #
  25. # If HDF5 is successfully found, this macro calls
  26. #
  27. # AC_SUBST(HDF5_VERSION)
  28. # AC_SUBST(HDF5_CC)
  29. # AC_SUBST(HDF5_CFLAGS)
  30. # AC_SUBST(HDF5_CPPFLAGS)
  31. # AC_SUBST(HDF5_LDFLAGS)
  32. # AC_SUBST(HDF5_LIBS)
  33. # AC_SUBST(HDF5_FC)
  34. # AC_SUBST(HDF5_FFLAGS)
  35. # AC_SUBST(HDF5_FLIBS)
  36. # AC_DEFINE(HAVE_HDF5)
  37. #
  38. # and sets with_hdf5="yes". Additionally, the macro sets
  39. # with_hdf5_fortran="yes" if a matching Fortran wrapper script is found.
  40. # Note that Autconf's Fortran support is not used to perform this check.
  41. # H5CC and H5FC will contain the appropriate serial or parallel HDF5
  42. # wrapper script locations.
  43. #
  44. # If HDF5 is disabled or not found, this macros sets with_hdf5="no" and
  45. # with_hdf5_fortran="no".
  46. #
  47. # Your configuration script can test $with_hdf to take any further
  48. # actions. HDF5_{C,CPP,LD}FLAGS may be used when building with C or C++.
  49. # HDF5_F{FLAGS,LIBS} should be used when building Fortran applications.
  50. #
  51. # To use the macro, one would code one of the following in "configure.ac"
  52. # before AC_OUTPUT:
  53. #
  54. # 1) dnl Check for HDF5 support
  55. # AX_LIB_HDF5()
  56. #
  57. # 2) dnl Check for serial HDF5 support
  58. # AX_LIB_HDF5([serial])
  59. #
  60. # 3) dnl Check for parallel HDF5 support
  61. # AX_LIB_HDF5([parallel])
  62. #
  63. # One could test $with_hdf5 for the outcome or display it as follows
  64. #
  65. # echo "HDF5 support: $with_hdf5"
  66. #
  67. # You could also for example, override the default CC in "configure.ac" to
  68. # enforce compilation with the compiler that HDF5 uses:
  69. #
  70. # AX_LIB_HDF5([parallel])
  71. # if test "$with_hdf5" = "yes"; then
  72. # CC="$HDF5_CC"
  73. # else
  74. # AC_MSG_ERROR([Unable to find HDF5, we need parallel HDF5.])
  75. # fi
  76. #
  77. # LICENSE
  78. #
  79. # Copyright (c) 2009 Timothy Brown <tbrown@freeshell.org>
  80. # Copyright (c) 2010 Rhys Ulerich <rhys.ulerich@gmail.com>
  81. #
  82. # Copying and distribution of this file, with or without modification, are
  83. # permitted in any medium without royalty provided the copyright notice
  84. # and this notice are preserved. This file is offered as-is, without any
  85. # warranty.
  86. #serial 8
  87. AC_DEFUN([AX_LIB_HDF5], [
  88. AC_REQUIRE([AC_PROG_SED])
  89. AC_REQUIRE([AC_PROG_AWK])
  90. AC_REQUIRE([AC_PROG_GREP])
  91. dnl Check first argument is one of the recognized values.
  92. dnl Fail eagerly if is incorrect as this simplifies case statements below.
  93. if test "m4_normalize(m4_default([$1],[]))" = "" ; then
  94. : # Recognized value
  95. elif test "m4_normalize(m4_default([$1],[]))" = "serial" ; then
  96. : # Recognized value
  97. elif test "m4_normalize(m4_default([$1],[]))" = "parallel"; then
  98. : # Recognized value
  99. else
  100. AC_MSG_ERROR([
  101. Unrecognized value for AX[]_LIB_HDF5 within configure.ac.
  102. If supplied, argument 1 must be either 'serial' or 'parallel'.
  103. ])
  104. fi
  105. dnl Add a default --with-hdf5 configuration option.
  106. AC_ARG_WITH([hdf5],
  107. AS_HELP_STRING(
  108. [--with-hdf5=[yes/no/PATH]],
  109. m4_case(m4_normalize([$1]),
  110. [serial], [location of h5cc for serial HDF5 configuration],
  111. [parallel], [location of h5pcc for parallel HDF5 configuration],
  112. [location of h5cc or h5pcc for HDF5 configuration])
  113. ),
  114. [if test "$withval" = "no"; then
  115. with_hdf5="no"
  116. elif test "$withval" = "yes"; then
  117. with_hdf5="yes"
  118. else
  119. with_hdf5="yes"
  120. H5CC="$withval"
  121. fi],
  122. [with_hdf5="yes"]
  123. )
  124. dnl Set defaults to blank
  125. HDF5_CC=""
  126. HDF5_VERSION=""
  127. HDF5_CFLAGS=""
  128. HDF5_CPPFLAGS=""
  129. HDF5_LDFLAGS=""
  130. HDF5_LIBS=""
  131. HDF5_FC=""
  132. HDF5_FFLAGS=""
  133. HDF5_FLIBS=""
  134. dnl Try and find hdf5 compiler tools and options.
  135. if test "$with_hdf5" = "yes"; then
  136. if test -z "$H5CC"; then
  137. dnl Check to see if H5CC is in the path.
  138. AC_PATH_PROGS(
  139. [H5CC],
  140. m4_case(m4_normalize([$1]),
  141. [serial], [h5cc],
  142. [parallel], [h5pcc],
  143. [h5cc h5pcc]),
  144. [])
  145. else
  146. AC_MSG_CHECKING([Using provided HDF5 C wrapper])
  147. AC_MSG_RESULT([$H5CC])
  148. fi
  149. AC_MSG_CHECKING([for HDF5 libraries])
  150. if test ! -f "$H5CC" || test ! -x "$H5CC"; then
  151. AC_MSG_RESULT([no])
  152. AC_MSG_WARN(m4_case(m4_normalize([$1]),
  153. [serial], [
  154. Unable to locate serial HDF5 compilation helper script 'h5cc'.
  155. Please specify --with-hdf5=<LOCATION> as the full path to h5cc.
  156. HDF5 support is being disabled (equivalent to --with-hdf5=no).
  157. ], [parallel],[
  158. Unable to locate parallel HDF5 compilation helper script 'h5pcc'.
  159. Please specify --with-hdf5=<LOCATION> as the full path to h5pcc.
  160. HDF5 support is being disabled (equivalent to --with-hdf5=no).
  161. ], [
  162. Unable to locate HDF5 compilation helper scripts 'h5cc' or 'h5pcc'.
  163. Please specify --with-hdf5=<LOCATION> as the full path to h5cc or h5pcc.
  164. HDF5 support is being disabled (equivalent to --with-hdf5=no).
  165. ]))
  166. with_hdf5="no"
  167. with_hdf5_fortran="no"
  168. else
  169. dnl Get the h5cc output
  170. HDF5_SHOW=$(eval $H5CC -show)
  171. dnl Get the actual compiler used
  172. HDF5_CC=$(eval $H5CC -show | $AWK '{print $[]1}')
  173. dnl h5cc provides both AM_ and non-AM_ options
  174. dnl depending on how it was compiled either one of
  175. dnl these are empty. Lets roll them both into one.
  176. dnl Look for "HDF5 Version: X.Y.Z"
  177. HDF5_VERSION=$(eval $H5CC -showconfig | $GREP 'HDF5 Version:' \
  178. | $AWK '{print $[]3}')
  179. dnl A ideal situation would be where everything we needed was
  180. dnl in the AM_* variables. However most systems are not like this
  181. dnl and seem to have the values in the non-AM variables.
  182. dnl
  183. dnl We try the following to find the flags:
  184. dnl (1) Look for "NAME:" tags
  185. dnl (2) Look for "H5_NAME:" tags
  186. dnl (3) Look for "AM_NAME:" tags
  187. dnl
  188. HDF5_tmp_flags=$(eval $H5CC -showconfig \
  189. | $GREP 'FLAGS\|Extra libraries:' \
  190. | $AWK -F: '{printf("%s "), $[]2}' )
  191. dnl Find the installation directory and append include/
  192. HDF5_tmp_inst=$(eval $H5CC -showconfig \
  193. | $GREP 'Installation point:' \
  194. | $AWK -F: '{print $[]2}' )
  195. dnl Add this to the CPPFLAGS
  196. HDF5_CPPFLAGS="-I${HDF5_tmp_inst}/include"
  197. dnl Now sort the flags out based upon their prefixes
  198. for arg in $HDF5_SHOW $HDF5_tmp_flags ; do
  199. case "$arg" in
  200. -I*) echo $HDF5_CPPFLAGS | $GREP -e "$arg" 2>&1 >/dev/null \
  201. || HDF5_CPPFLAGS="$arg $HDF5_CPPFLAGS"
  202. ;;
  203. -L*) echo $HDF5_LDFLAGS | $GREP -e "$arg" 2>&1 >/dev/null \
  204. || HDF5_LDFLAGS="$arg $HDF5_LDFLAGS"
  205. ;;
  206. -l*) echo $HDF5_LIBS | $GREP -e "$arg" 2>&1 >/dev/null \
  207. || HDF5_LIBS="$arg $HDF5_LIBS"
  208. ;;
  209. esac
  210. done
  211. HDF5_LIBS="$HDF5_LIBS -lhdf5"
  212. AC_MSG_RESULT([yes (version $[HDF5_VERSION])])
  213. dnl See if we can compile
  214. ax_lib_hdf5_save_CC=$CC
  215. ax_lib_hdf5_save_CPPFLAGS=$CPPFLAGS
  216. ax_lib_hdf5_save_LIBS=$LIBS
  217. ax_lib_hdf5_save_LDFLAGS=$LDFLAGS
  218. CC=$HDF5_CC
  219. CPPFLAGS=$HDF5_CPPFLAGS
  220. LIBS=$HDF5_LIBS
  221. LDFLAGS=$HDF5_LDFLAGS
  222. AC_CHECK_HEADER([hdf5.h], [ac_cv_hadf5_h=yes], [ac_cv_hadf5_h=no])
  223. AC_CHECK_LIB([hdf5], [H5Fcreate], [ac_cv_libhdf5=yes],
  224. [ac_cv_libhdf5=no])
  225. if test "$ac_cv_hadf5_h" = "no" && test "$ac_cv_libhdf5" = "no" ; then
  226. AC_MSG_WARN([Unable to compile HDF5 test program])
  227. fi
  228. dnl Look for HDF5's high level library
  229. AC_HAVE_LIBRARY([hdf5_hl], [HDF5_LIBS="$HDF5_LIBS -lhdf5_hl"], [], [])
  230. CC=$ax_lib_hdf5_save_CC
  231. LIBS=$ax_lib_hdf5_save_LIBS
  232. LDFLAGS=$ax_lib_hdf5_save_LDFLAGS
  233. AC_MSG_CHECKING([for matching HDF5 Fortran wrapper])
  234. dnl Presume HDF5 Fortran wrapper is just a name variant from H5CC
  235. H5FC=$(eval echo -n $H5CC | $SED -n 's/cc$/fc/p')
  236. if test -x "$H5FC"; then
  237. AC_MSG_RESULT([$H5FC])
  238. with_hdf5_fortran="yes"
  239. AC_SUBST([H5FC])
  240. dnl Again, pry any remaining -Idir/-Ldir from compiler wrapper
  241. for arg in `$H5FC -show`
  242. do
  243. case "$arg" in #(
  244. -I*) echo $HDF5_FFLAGS | $GREP -e "$arg" >/dev/null \
  245. || HDF5_FFLAGS="$arg $HDF5_FFLAGS"
  246. ;;#(
  247. -L*) echo $HDF5_FFLAGS | $GREP -e "$arg" >/dev/null \
  248. || HDF5_FFLAGS="$arg $HDF5_FFLAGS"
  249. dnl HDF5 installs .mod files in with libraries,
  250. dnl but some compilers need to find them with -I
  251. echo $HDF5_FFLAGS | $GREP -e "-I${arg#-L}" >/dev/null \
  252. || HDF5_FFLAGS="-I${arg#-L} $HDF5_FFLAGS"
  253. ;;
  254. esac
  255. done
  256. dnl Make Fortran link line by inserting Fortran libraries
  257. for arg in $HDF5_LIBS
  258. do
  259. case "$arg" in #(
  260. -lhdf5_hl) HDF5_FLIBS="$HDF5_FLIBS -lhdf5hl_fortran $arg"
  261. ;; #(
  262. -lhdf5) HDF5_FLIBS="$HDF5_FLIBS -lhdf5_fortran $arg"
  263. ;; #(
  264. *) HDF5_FLIBS="$HDF5_FLIBS $arg"
  265. ;;
  266. esac
  267. done
  268. else
  269. AC_MSG_RESULT([no])
  270. with_hdf5_fortran="no"
  271. fi
  272. AC_SUBST([HDF5_VERSION])
  273. AC_SUBST([HDF5_CC])
  274. AC_SUBST([HDF5_CFLAGS])
  275. AC_SUBST([HDF5_CPPFLAGS])
  276. AC_SUBST([HDF5_LDFLAGS])
  277. AC_SUBST([HDF5_LIBS])
  278. AC_SUBST([HDF5_FC])
  279. AC_SUBST([HDF5_FFLAGS])
  280. AC_SUBST([HDF5_FLIBS])
  281. AC_DEFINE([HAVE_HDF5], [1], [Defined if you have HDF5 support])
  282. fi
  283. fi
  284. ])