Skip to content

Commit a5ae1d2

Browse files
committed
Improve HDF5 in configure
1 parent 6d1e9df commit a5ae1d2

File tree

4 files changed

+410
-120
lines changed

4 files changed

+410
-120
lines changed

configure.ac

+66-111
Original file line numberDiff line numberDiff line change
@@ -20,145 +20,88 @@ AC_SUBST([VERSION_MAJOR])
2020
AC_SUBST([VERSION_MINOR])
2121
AC_SUBST([VERSION_PATCH])
2222

23-
# Checks for programs.
23+
24+
25+
## -------------------
26+
## Checks for programs
27+
## -------------------
28+
2429
AC_LANG(C)
2530
AC_PROG_CC
26-
# Make sure the c compiler supports C99
31+
32+
# C99 support
2733
m4_version_prereq([2.70],[], [AC_PROG_CC_C99])
28-
AS_IF([test "$ac_cv_prog_cc_c99" = "no"], [AC_MSG_ERROR([The compiler does not support C99])])
34+
AS_IF([test "$ac_cv_prog_cc_c99" = "no"],
35+
[AC_MSG_ERROR([The compiler does not support C99])])
2936
AC_PROG_CC_C_O
3037

38+
# Fortran
3139
AC_PROG_FC
3240
AC_FC_FREEFORM
3341
AC_FC_SRCEXT([f90])
34-
3542
AC_PROG_FC_C_O
43+
AC_FC_LIBRARY_LDFLAGS
44+
45+
# pkg-config
46+
PKG_PROG_PKG_CONFIG()
47+
PKG_CFLAGS=""
48+
3649
AC_PROG_INSTALL
3750
AC_PROG_LIBTOOL
3851
AC_PROG_LN_S
39-
PKG_PROG_PKG_CONFIG()
40-
PKG_LIBS=""
41-
PKG_CFLAGS=""
4252

43-
AC_FC_LIBRARY_LDFLAGS
4453

54+
## ---------
55+
## Libraries
56+
## ---------
57+
58+
# Checks for basic header files.
59+
AC_CHECK_HEADERS([fcntl.h inttypes.h stdint.h stdlib.h string.h unistd.h])
4560

4661

62+
### HDF5
63+
### ----
64+
4765
# Configure with HDF5 (default: --with-hdf5 using pkg-config) [optional]:
4866
# ./configure [--with-hdf5 or --with-hdf5=yes]
67+
4968
# Configure with user-provided path to HDF5:
5069
# ./configure --with-hdf5=/usr/lib/x86_64-linux-gnu/hdf5/serial
70+
5171
# Configure without HDF5:
5272
# ./configure --without-hdf5 [or --with-hdf5=no]
5373

54-
# when configure complains about missing install-sh or install.sh, execute:
55-
# automake --add-missing --copy
56-
57-
# Checks for basic libraries.
58-
AC_CHECK_LIB([m], [sqrt])
59-
# Checks for basic header files.
60-
AC_CHECK_HEADERS([fcntl.h inttypes.h stdint.h stdlib.h string.h unistd.h])
61-
62-
# Search for pthread
63-
have_pthreads=no
64-
AC_SEARCH_LIBS([pthread_create], [pthread], [have_pthreads=yes])
65-
66-
if test "x${have_pthreads}" = xyes; then
67-
AC_CHECK_HEADERS([pthread.h], [], [have_pthreads=no])
68-
PKG_LIBS="${PKG_LIBS} -lpthread"
69-
fi
70-
71-
if test "x${have_pthreads}" = xno; then
72-
AC_MSG_ERROR([
73-
------------------------------------------
74-
The pthread library and header file
75-
required to build TREXIO. Stopping...
76-
Check 'config.log' for more information.
77-
------------------------------------------])
78-
fi
79-
80-
AC_ARG_WITH([hdf5],
81-
AS_HELP_STRING([--with-hdf5],
82-
[Include HDF5 functionality @<:@default: yes@:>@])],
83-
[hdf5=${withval}],
84-
[hdf5=yes])
8574

8675
PKG_HDF5=""
87-
if test "x${hdf5}" = xno; then
76+
AX_LIB_HDF5([serial])
77+
78+
if test "x${with_hdf5}" = xno; then
8879
AC_MSG_WARN([
8980
------------------------------------------
9081
Configuring with the HDF5 library is
9182
recommended to build efficient TREXIO.
9283
------------------------------------------])
84+
fi
9385

94-
elif test "x${hdf5}" = xyes; then
86+
CFLAGS="${HDF5_CFLAGS} ${CFLAGS}"
87+
CPPFLAGS="${HDF5_CPPFLAGS} ${CPPFLAGS}"
88+
LDFLAGS="${HDF5_LDFLAGS} ${LDFLAGS}"
89+
LIBS="${HDF5_LIBS} ${LIBS}"
9590

96-
# Check if HDF5 is already configured (e.g. after calling `module load hdf5-<version>`)
97-
AC_CHECK_HEADERS([hdf5_hl.h])
98-
AC_CHECK_LIB([hdf5_hl], [H5LTfind_dataset], [], [have_hdf5_hl=no])
9991

100-
AC_CHECK_HEADERS([hdf5.h])
101-
AC_CHECK_LIB([hdf5], [H5open], [], [have_hdf5=no])
92+
# Check if hdf5 if available with pkg-config
10293

103-
if test "x${have_hdf5}" = xno; then
104-
# If HDF5 is not configured, try using pkg-config
105-
PKG_CHECK_MODULES([HDF5], [hdf5 >= 1.8])
106-
CFLAGS="$(pkg-config --cflags hdf5) ${CFLAGS}"
107-
LDFLAGS="$(pkg-config --libs hdf5) -lhdf5_hl ${LDFLAGS}"
94+
PKG_CHECK_MODULES([HDF5], [hdf5 >= 1.8], [
10895
PKG_HDF5="hdf5"
109-
PKG_LIBS="${PKG_LIBS} -lhdf5_hl"
110-
else
96+
],[
11197
PKG_HDF5=""
112-
PKG_LIBS="${PKG_LIBS} ${HDF5_LIBS} -lhdf5_hl"
113-
PKG_CFLAGS="${PKG_CFLAGS} ${HDF5_CFLAGS}"
114-
CFLAGS="${HDF5_LIBS} ${CFLAGS}"
115-
LDFLAGS="${HDF5_CFLAGS} -lhdf5_hl ${LDFLAGS}"
116-
fi
117-
118-
else
119-
120-
if test "x${hdf5}" = x; then
121-
AC_MSG_ERROR([
122-
------------------------------------------
123-
The path to HDF5 library is required.
124-
Maybe you forgot to pass --with-hdf5="/your/path/" to configure script.
125-
Stopping...
126-
------------------------------------------])
127-
fi
128-
129-
CPPFLAGS="-I${hdf5}/include ${CPPFLAGS}"
130-
LDFLAGS="-L${hdf5} ${LDFLAGS}"
98+
])
99+
PKG_CFLAGS="${PKG_CFLAGS}"
131100

132-
AC_CHECK_HEADERS([hdf5_hl.h])
133-
AC_CHECK_LIB([hdf5_hl], [H5LTfind_dataset], [], [have_hdf5_hl=no])
134-
135-
AC_CHECK_HEADERS([hdf5.h])
136-
AC_CHECK_LIB([hdf5], [H5open], [], [have_hdf5=no])
137-
138-
PKG_HDF5=""
139-
PKG_LIBS="${PKG_LIBS} -L${hdf5} -lhdf5_hl"
140-
PKG_CFLAGS="${PKG_CFLAGS} -I${hdf5}/include"
141-
fi
142101
AC_SUBST([PKG_HDF5])
143-
AC_SUBST([PKG_LIBS])
144102
AC_SUBST([PKG_CFLAGS])
145103

146104

147-
# add -fPIC if not present in CFLAGS, necessary to compile TREXIO
148-
# TODO: replace with AM_CFLAGS for appropriate targer once Automake is introduced
149-
case "${CFLAGS}" in
150-
*-fPIC*)
151-
;;
152-
*)
153-
AC_MSG_WARN([
154-
------------------------------------------
155-
Adding -fPIC option to CFLAGS.
156-
This is necessary to build TREXIO.
157-
------------------------------------------])
158-
CFLAGS="${CFLAGS} -fPIC"
159-
;;
160-
esac
161-
162105
# Checks for typedefs, structures, and compiler characteristics.
163106
AC_TYPE_INT32_T
164107
AC_TYPE_INT64_T
@@ -194,6 +137,19 @@ if test "x${TREXIO_DEVEL}" != "x"; then
194137

195138
fi
196139

140+
## Libm
141+
## ----
142+
143+
AC_SEARCH_LIBS([sqrt], [m], [], AC_MSG_ERROR([The libm library is required]))
144+
AC_CHECK_HEADERS([math.h])
145+
146+
### pthread
147+
### -------
148+
149+
AC_SEARCH_LIBS([pthread_create], [pthread], [], AC_MSG_ERROR([The pthread library is required]))
150+
AC_CHECK_HEADERS([pthread.h])
151+
152+
197153
AC_CONFIG_FILES([Makefile
198154
pkgconfig/trexio.pc])
199155
AC_OUTPUT
@@ -203,23 +159,22 @@ echo \
203159

204160
${PACKAGE_NAME} Version ${PACKAGE_VERSION} ${TREXIO_DEVEL}
205161

206-
Prefix: '${prefix}'.
207-
208-
CC: ${CC}
209-
CPPFLAGS: ${CPPFLAGS}
210-
CFLAGS: ${CFLAGS}
211-
FC: ${FC}
212-
FCLAGS: ${FCFLAGS}
213-
LDFLAGS: ${LDFLAGS}
214-
LIBS: ${LIBS}
162+
Prefix ........: ${prefix}
163+
CC ............: ${CC}
164+
CPPFLAGS ......: ${CPPFLAGS}
165+
CFLAGS ........: ${CFLAGS}
166+
FC ............: ${FC}
167+
FCLAGS ........: ${FCFLAGS}
168+
LDFLAGS .......: ${LDFLAGS}
169+
LIBS ..........: ${LIBS}
215170

216171
Package features:
217-
Compilation with HDF5: ${hdf5}
172+
Compilation with HDF5: ${with_hdf5}
218173

219174
Now type 'make @<:@<target>@:>@'
220175
where the optional <target> is:
221-
all - build C and Fortran APIs
222-
check - check C and Fortran APIs
223-
clean - clean the produced files
176+
all - build C library and Fortran binding
177+
check - run unit tests
178+
install - install the library
224179
--------------------------------------------------"
225180

0 commit comments

Comments
 (0)