From d42dc7f449fe21fe786671d759c0e72df0176216 Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 1 Nov 2021 11:55:34 +0100 Subject: [PATCH] optional HDF5 compilation via configure script and pre-processor macros --- Makefile.am | 57 +++++++++++++++---------- configure.ac | 14 +++--- src/templates_front/build.sh | 20 ++++----- src/templates_front/templator_front.org | 57 +++++++++++++++++++++++-- 4 files changed, 105 insertions(+), 43 deletions(-) diff --git a/Makefile.am b/Makefile.am index 8ae0413..d71d896 100644 --- a/Makefile.am +++ b/Makefile.am @@ -36,10 +36,6 @@ ACLOCAL_AMFLAGS = -I m4 CLEANFILES = trexio.mod BUILT_SOURCES = trexio.mod -VERSION_MAJOR = @VERSION_MAJOR@ -VERSION_MINOR = @VERSION_MINOR@ -VERSION_PATCH = @VERSION_PATCH@ - SUBDIRS = pkgconfigdir = $(libdir)/pkgconfig @@ -62,11 +58,16 @@ SOURCES = \ src/trexio.c \ src/trexio_private.h \ src/trexio_s.h \ - src/trexio_hdf5.c \ - src/trexio_hdf5.h \ src/trexio_text.c \ src/trexio_text.h +if DO_HDF5 + +SOURCES += src/trexio_hdf5.c \ + src/trexio_hdf5.h + +endif + ORG_FILES = \ src/templates_front/templator_front.org \ src/templates_text/templator_text.org \ @@ -79,24 +80,30 @@ src_libtrexio_la_SOURCES = $(SOURCES) # =============== TESTS =============== # TESTS_C = \ - tests/open_hdf5 \ tests/open_text \ - tests/io_num_hdf5 \ tests/io_num_text \ - tests/io_dset_float_hdf5 \ tests/io_dset_float_text \ - tests/io_dset_int_hdf5 \ tests/io_dset_int_text \ - tests/io_safe_dset_float_hdf5 \ tests/io_safe_dset_float_text \ - tests/io_str_hdf5 \ tests/io_str_text \ - tests/io_dset_str_hdf5 \ tests/io_dset_str_text \ - tests/overwrite_all_hdf5 \ tests/overwrite_all_text \ tests/io_all +if DO_HDF5 + +TESTS_C += \ + tests/open_hdf5 \ + tests/io_num_hdf5 \ + tests/io_dset_float_hdf5 \ + tests/io_dset_int_hdf5 \ + tests/io_safe_dset_float_hdf5 \ + tests/io_str_hdf5 \ + tests/io_dset_str_hdf5 \ + tests/overwrite_all_hdf5 + +endif + TESTS_F = \ tests/test_f @@ -108,24 +115,30 @@ LDADD = src/libtrexio.la # in principal, specifying -no-install (see below) is not mandatory # for the tests to compile and pass, but the produced test binaries differ -tests_open_hdf5_LDFLAGS = -no-install tests_open_text_LDFLAGS = -no-install -tests_io_num_hdf5_LDFLAGS = -no-install tests_io_num_text_LDFLAGS = -no-install -tests_io_dset_float_hdf5_LDFLAGS = -no-install tests_io_dset_float_text_LDFLAGS = -no-install -tests_io_dset_int_hdf5_LDFLAGS = -no-install tests_io_dset_int_text_LDFLAGS = -no-install -tests_io_safe_dset_float_hdf5_LDFLAGS = -no-install tests_io_safe_dset_float_text_LDFLAGS = -no-install -tests_io_str_hdf5_LDFLAGS = -no-install tests_io_str_text_LDFLAGS = -no-install -tests_io_dset_str_hdf5_LDFLAGS = -no-install tests_io_dset_str_text_LDFLAGS = -no-install -tests_overwrite_all_hdf5_LDFLAGS = -no-install tests_overwrite_all_text_LDFLAGS = -no-install tests_io_all_LDFLAGS = -no-install +if DO_HDF5 + +tests_open_hdf5_LDFLAGS = -no-install +tests_io_num_hdf5_LDFLAGS = -no-install +tests_io_dset_float_hdf5_LDFLAGS = -no-install +tests_io_dset_int_hdf5_LDFLAGS = -no-install +tests_io_safe_dset_float_hdf5_LDFLAGS = -no-install +tests_io_str_hdf5_LDFLAGS = -no-install +tests_io_dset_str_hdf5_LDFLAGS = -no-install +tests_overwrite_all_hdf5_LDFLAGS = -no-install + +endif + + test_trexio_f = $(srcdir)/tests/trexio_f.f90 $(test_trexio_f): $(trexio_f) diff --git a/configure.ac b/configure.ac index 55b705d..5f60c87 100644 --- a/configure.ac +++ b/configure.ac @@ -14,13 +14,9 @@ AC_CONFIG_MACRO_DIR([m4]) VERSION_MAJOR=`echo ${PACKAGE_VERSION} | cut -d. -f1` VERSION_MINOR=`echo ${PACKAGE_VERSION} | cut -d. -f2` VERSION_PATCH=`echo ${PACKAGE_VERSION} | cut -d. -f3 | cut -d- -f1` -AC_DEFINE_UNQUOTED(TREXIO_PACKAGE_VERSION, ["${PACKAGE_VERSION}"], [full version]) -AC_DEFINE_UNQUOTED(TREXIO_VERSION_MAJOR, [$VERSION_MAJOR], [major version]) -AC_DEFINE_UNQUOTED(TREXIO_VERSION_MINOR, [$VERSION_MINOR], [minor version]) -AC_DEFINE_UNQUOTED(TREXIO_VERSION_PATCH, [$VERSION_PATCH], [patch version]) -AC_SUBST([VERSION_MAJOR]) -AC_SUBST([VERSION_MINOR]) -AC_SUBST([VERSION_PATCH]) +AC_DEFINE_UNQUOTED(VERSION_MAJOR, [$VERSION_MAJOR], [major version]) +AC_DEFINE_UNQUOTED(VERSION_MINOR, [$VERSION_MINOR], [minor version]) +AC_DEFINE_UNQUOTED(VERSION_PATCH, [$VERSION_PATCH], [patch version]) ## Save system information, e.g. user name @@ -110,6 +106,8 @@ AC_SUBST([PKG_HDF5]) AC_SUBST([PKG_CFLAGS]) AC_SUBST([PKG_LIBS]) +AM_CONDITIONAL([DO_HDF5],[test "$with_hdf5" = "yes"]) + # The block below should only execute if the ax_lib_hdf5.m4 macro failed to find HDF5. # It is only needed to manually build Python API because setup.py depends on HDF5. @@ -203,7 +201,7 @@ CC ............: ${CC} CPPFLAGS ......: ${CPPFLAGS} CFLAGS ........: ${CFLAGS} FC ............: ${FC} -FCLAGS ........: ${FCFLAGS} +FCFLAGS .......: ${FCFLAGS} LDFLAGS .......: ${LDFLAGS} LIBS ..........: ${LIBS} diff --git a/src/templates_front/build.sh b/src/templates_front/build.sh index 97e53a3..4d75e07 100644 --- a/src/templates_front/build.sh +++ b/src/templates_front/build.sh @@ -4,20 +4,20 @@ cat prefix_front.c > trexio.c cat prefix_front.h > trexio.h +# parse the config-defined version attributes to pass them to Fortran module file +VERSION_VAL=`grep "PACKAGE_VERSION" ../../include/config.h | cut -d " " -f 3` +VERSION_MAJOR_VAL=`grep "VERSION_MAJOR" ../../include/config.h | cut -d " " -f 3` +VERSION_MINOR_VAL=`grep "VERSION_MINOR" ../../include/config.h | cut -d " " -f 3` +VERSION_PATCH_VAL=`grep "VERSION_PATCH" ../../include/config.h | cut -d " " -f 3` + # grep some usefull constants from the config.h echo "" >> trexio.h -grep "TREXIO_PACKAGE_VERSION" ../../include/config.h >> trexio.h -grep "TREXIO_VERSION_MAJOR" ../../include/config.h >> trexio.h -grep "TREXIO_VERSION_MINOR" ../../include/config.h >> trexio.h -grep "TREXIO_VERSION_PATCH" ../../include/config.h >> trexio.h +echo "#define TREXIO_PACKAGE_VERSION ${VERSION_VAL}" >> trexio.h +echo "#define TREXIO_VERSION_MAJOR ${VERSION_MAJOR_VAL}" >> trexio.h +echo "#define TREXIO_VERSION_MINOR ${VERSION_MINOR_VAL}" >> trexio.h +echo "#define TREXIO_VERSION_PATCH ${VERSION_PATCH_VAL}" >> trexio.h echo "" >> trexio.h -# parse the config-defined version attributes to pass them to Fortran module file -VERSION_VAL=`grep "TREXIO_PACKAGE_VERSION" ../../include/config.h | cut -d " " -f 3` -VERSION_MAJOR_VAL=`grep "TREXIO_VERSION_MAJOR" ../../include/config.h | cut -d " " -f 3` -VERSION_MINOR_VAL=`grep "TREXIO_VERSION_MINOR" ../../include/config.h | cut -d " " -f 3` -VERSION_PATCH_VAL=`grep "TREXIO_VERSION_PATCH" ../../include/config.h | cut -d " " -f 3` - cat prefix_s_front.h > trexio_s.h cat prefix_fortran.f90 > trexio_f.f90 cat prefix_python.py > trexio.py diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index 106b3d9..74191f9 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -32,6 +32,11 @@ typedef int32_t trexio_exit_code; #+begin_src c :tangle prefix_front.c :noweb yes <
> + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + #include #include #include @@ -42,7 +47,9 @@ typedef int32_t trexio_exit_code; #include "trexio_private.h" #include "trexio_s.h" #include "trexio_text.h" -#include "trexio_hdf5.h" +#ifdef HAVE_HDF5 + #include "trexio_hdf5.h" +#endif /* #include "trexio_json.h" ,*/ @@ -739,9 +746,11 @@ trexio_open(const char* file_name, const char mode, result_tmp = malloc(sizeof(trexio_text_t)); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: result_tmp = malloc(sizeof(trexio_hdf5_t)); break; +#endif /* case TREXIO_JSON: result = (trexio_t*) malloc (sizeof(trexio_json_t)); @@ -790,9 +799,11 @@ trexio_open(const char* file_name, const char mode, rc = trexio_text_init(result); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: rc = trexio_hdf5_init(result); break; +#endif /* case TREXIO_JSON: rc = trexio_json_init(result); @@ -820,9 +831,11 @@ trexio_open(const char* file_name, const char mode, rc = trexio_text_write_metadata_package_version(result, TREXIO_PACKAGE_VERSION); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: rc = trexio_hdf5_write_metadata_package_version(result, TREXIO_PACKAGE_VERSION); break; +#endif /* case TREXIO_JSON: rc = trexio_json_write_metadata_package_version(result, TREXIO_PACKAGE_VERSION); @@ -848,9 +861,11 @@ trexio_open(const char* file_name, const char mode, rc = trexio_text_lock(result); break; /* HDF5 v.>=1.10 has file locking activated by default */ +#ifdef HAVE_HDF5 case TREXIO_HDF5: rc = TREXIO_SUCCESS; break; +#endif /* case TREXIO_JSON: rc = trexio_json_lock(result); @@ -992,9 +1007,11 @@ trexio_close (trexio_t* file) rc = trexio_text_deinit(file); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: rc = trexio_hdf5_deinit(file); break; +#endif /* case TREXIO_JSON: rc = trexio_json_deinit(file); @@ -1017,9 +1034,11 @@ trexio_close (trexio_t* file) rc = trexio_text_unlock(file); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: rc = TREXIO_SUCCESS; break; +#endif /* case TREXIO_JSON: rc = trexio_json_unlock(file); @@ -1201,9 +1220,11 @@ trexio_read_$group_num$_64 (trexio_t* const file, $group_num_dtype_double$* cons return trexio_text_read_$group_num$(file, num); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: return trexio_hdf5_read_$group_num$(file, num); break; +#endif /* case TREXIO_JSON: return trexio_json_read_$group_num$(file, num); @@ -1229,9 +1250,11 @@ trexio_write_$group_num$_64 (trexio_t* const file, const $group_num_dtype_double return trexio_text_write_$group_num$(file, num); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: return trexio_hdf5_write_$group_num$(file, num); - break; + break; +#endif /* case TREXIO_JSON: return trexio_json_write_$group_num$(file, num); @@ -1261,9 +1284,11 @@ trexio_read_$group_num$_32 (trexio_t* const file, $group_num_dtype_single$* cons rc = trexio_text_read_$group_num$(file, &num_64); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: rc = trexio_hdf5_read_$group_num$(file, &num_64); break; +#endif /* case TREXIO_JSON: rc =trexio_json_read_$group_num$(file, &num_64); @@ -1293,9 +1318,11 @@ trexio_write_$group_num$_32 (trexio_t* const file, const $group_num_dtype_single return trexio_text_write_$group_num$(file, ($group_num_dtype_double$) num); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: return trexio_hdf5_write_$group_num$(file, ($group_num_dtype_double$) num); - break; + break; +#endif /* case TREXIO_JSON: return trexio_json_write_$group_num$(file, ($group_num_dtype_double$) num); @@ -1340,9 +1367,11 @@ trexio_has_$group_num$ (trexio_t* const file) return trexio_text_has_$group_num$(file); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: return trexio_hdf5_has_$group_num$(file); break; +#endif /* case TREXIO_JSON: return trexio_json_has_$group_num$(file); @@ -1583,9 +1612,11 @@ trexio_read_$group_dset$_64 (trexio_t* const file, $group_dset_dtype_double$* co rc = trexio_text_read_$group_dset$(file, $group_dset$, rank, dims); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: rc = trexio_hdf5_read_$group_dset$(file, $group_dset$, rank, dims); break; +#endif /* case TREXIO_JSON: rc = trexio_json_read_$group_dset$(file, $group_dset$, rank, dims); @@ -1657,9 +1688,11 @@ trexio_write_$group_dset$_64 (trexio_t* const file, const $group_dset_dtype_doub rc = trexio_text_write_$group_dset$(file, $group_dset$_p, rank, dims); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: rc = trexio_hdf5_write_$group_dset$(file, $group_dset$_p, rank, dims); break; +#endif /* case TREXIO_JSON: rc = trexio_json_write_$group_dset$(file, $group_dset$_p, rank, dims); @@ -1717,9 +1750,11 @@ trexio_read_$group_dset$_32 (trexio_t* const file, $group_dset_dtype_single$* co rc = trexio_text_read_$group_dset$(file, $group_dset$_64, rank, dims); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: rc = trexio_hdf5_read_$group_dset$(file, $group_dset$_64, rank, dims); break; +#endif /* case TREXIO_JSON: rc = trexio_json_read_$group_dset$(file, $group_dset$_64, rank, dims); @@ -1796,9 +1831,11 @@ trexio_write_$group_dset$_32 (trexio_t* const file, const $group_dset_dtype_sing rc = trexio_text_write_$group_dset$(file, $group_dset$_64, rank, dims); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: rc = trexio_hdf5_write_$group_dset$(file, $group_dset$_64, rank, dims); break; +#endif /* case TREXIO_JSON: rc = trexio_json_write_$group_dset$(file, $group_dset$_64, rank, dims); @@ -1960,9 +1997,11 @@ trexio_has_$group_dset$ (trexio_t* const file) return trexio_text_has_$group_dset$(file); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: return trexio_hdf5_has_$group_dset$(file); break; +#endif /* case TREXIO_JSON: return trexio_json_has_$group_dset$(file); @@ -2405,9 +2444,11 @@ trexio_read_$group_dset$_low (trexio_t* const file, char* dset_out, const int32_ return trexio_text_read_$group_dset$(file, dset_out, rank, dims, (uint32_t) max_str_len); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: return trexio_hdf5_read_$group_dset$(file, dset_out, rank, dims, (uint32_t) max_str_len); break; +#endif /* case TREXIO_JSON: rc = trexio_json_read_$group_dset$(file, dset_out, rank, dims); @@ -2529,9 +2570,11 @@ trexio_write_$group_dset$_low (trexio_t* const file, const char* dset_in, const rc = trexio_text_write_$group_dset$(file, (const char**) dset_str, rank, dims); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: rc = trexio_hdf5_write_$group_dset$(file, (const char**) dset_str, rank, dims); break; +#endif /* case TREXIO_JSON: rc = trexio_json_write_$group_dset$(file, dset, rank, dims); @@ -2597,9 +2640,11 @@ trexio_has_$group_dset$ (trexio_t* const file) return trexio_text_has_$group_dset$(file); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: return trexio_hdf5_has_$group_dset$(file); break; +#endif /* case TREXIO_JSON: return trexio_json_has_$group_dset$(file); @@ -2846,9 +2891,11 @@ trexio_read_$group_str$ (trexio_t* const file, char* const str_out, const int32_ return trexio_text_read_$group_str$(file, str_out, (uint32_t) max_str_len); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: return trexio_hdf5_read_$group_str$(file, str_out, (uint32_t) max_str_len); break; +#endif /* case TREXIO_JSON: return trexio_json_read_$group_str$(file, str); @@ -2879,9 +2926,11 @@ trexio_write_$group_str$ (trexio_t* const file, const char* str, const int32_t m return trexio_text_write_$group_str$(file, str); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: return trexio_hdf5_write_$group_str$(file, str); break; +#endif /* case TREXIO_JSON: return trexio_json_write_$group_str$(file, str); @@ -2908,9 +2957,11 @@ trexio_has_$group_str$ (trexio_t* const file) return trexio_text_has_$group_str$(file); break; +#ifdef HAVE_HDF5 case TREXIO_HDF5: return trexio_hdf5_has_$group_str$(file); break; +#endif /* case TREXIO_JSON: return trexio_json_has_$group_str$(file);