Skip to content

Commit e33c2f5

Browse files
committed
use pkg-config if HDF5 pkgconfig is available
1 parent 8e58ce6 commit e33c2f5

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

configure.ac

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -812,30 +812,46 @@ if test "x$have_hdf5" = xyes ; then
812812
# "Extra libraries". Test it first before including it to LIBS.
813813
if test "x$extra_libs" != x ; then
814814
saved_LIBS=$LIBS
815-
if test "x$LIBS" = x ; then
816-
LIBS="-lhdf5 $extra_libs"
817-
else
818-
LIBS="-lhdf5 $extra_libs $LIBS"
819-
fi
815+
LIBS="-lhdf5 $extra_libs $LIBS"
820816
AC_MSG_CHECKING([extra libraries shown in libhdf5.settings if valid])
821817
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <hdf5.h>]],
822818
[[H5Fopen("dummy", H5F_ACC_RDWR, H5P_DEFAULT);]])],
823819
[valid_extra_libs=yes], [valid_extra_libs=no])
824820
AC_MSG_RESULT([$valid_extra_libs])
825-
if test "x$valid_extra_libs" = xno ; then
826-
extra_libs=
821+
if test "x$valid_extra_libs" = xno && test -d "$hdf5_lib/pkgconfig" ; then
822+
# extra_libs is not valid, check pkg-config
823+
saved_PKG_CONFIG_PATH=$PKG_CONFIG_PATH
824+
export PKG_CONFIG_PATH="$hdf5_lib/pkgconfig:$PKG_CONFIG_PATH"
825+
extra_ldflags=`pkg-config --libs-only-L hdf5 2> conftest.err`
826+
rm -f conftest.err
827+
extra_libs=`pkg-config --libs-only-l hdf5 2> conftest.err`
828+
rm -f conftest.err
829+
export PKG_CONFIG_PATH=$saved_PKG_CONFIG_PATH
830+
if test "x$extra_ldflags" != x || test "x$extra_libs" != x ; then
831+
saved_LDFLAGS=$LDFLAGS
832+
LDFLAGS="$extra_libs $LDFLAGS"
833+
LIBS="-lhdf5 $extra_libs $saved_LIBS"
834+
AC_MSG_CHECKING([extra libraries shown in libhdf5.settings if valid])
835+
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <hdf5.h>]],
836+
[[H5Fopen("dummy", H5F_ACC_RDWR, H5P_DEFAULT);]])],
837+
[valid_extra_libs=yes], [valid_extra_libs=no])
838+
AC_MSG_RESULT([$valid_extra_libs])
839+
if test "x$valid_extra_libs" = xno ; then
840+
extra_ldflags=
841+
extra_libs=
842+
fi
843+
LDFLAGS=$saved_LDFLAGS
844+
fi
827845
fi
828846
LIBS=$saved_LIBS
829847
fi
830848

831-
if test "x$LIBS" = x ; then
832-
LIBS="-lhdf5 $extra_libs"
833-
else
834-
LIBS="-lhdf5 $extra_libs $LIBS"
849+
LIBS="$extra_libs $LIBS"
850+
if ! echo $LIBS | grep -q "\-lhdf5" ; then
851+
LIBS="-lhdf5 $LIBS"
835852
fi
836-
if test "x$LDFLAGS" = x ; then
837-
LDFLAGS=$extra_ldflags
838-
else
853+
LDFLAGS="$extra_ldflags $LDFLAGS"
854+
if ! echo $LDFLAGS | grep -q "\-L$hdf5_lib" ; then
839855
LDFLAGS="$extra_ldflags $LDFLAGS"
840856
fi
841857
AC_DEFINE([ENABLE_HDF5], [1], [Enable HDF5 I/O method])

0 commit comments

Comments
 (0)