From 257b27afd172c44738bd183ee997a74de8da3505 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Thu, 18 Jan 2024 14:12:55 +0000 Subject: [PATCH 01/11] CMake: Remove unused `add_definitions` --- cmake/dependencies.cmake | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index fb7adb6f5..98eadef47 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -166,11 +166,9 @@ if(USE_HDF5) if(NC_FIND_SHARED_LIBS) set(NC_HDF5_LINK_TYPE "shared") set(NC_HDF5_LINK_TYPE_UPPER "SHARED") - ADD_DEFINITIONS(-DH5_BUILT_AS_DYNAMIC_LIB) else(NC_FIND_SHARED_LIBS) set(NC_HDF5_LINK_TYPE "static") set(NC_HDF5_LINK_TYPE_UPPER "STATIC") - ADD_DEFINITIONS(-DH5_BUILT_AS_STATIC_LIB ) endif(NC_FIND_SHARED_LIBS) ##### From ef001e3cfd928a3946932f201f7efcf10a04b5a6 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Thu, 18 Jan 2024 14:34:30 +0000 Subject: [PATCH 02/11] CMake: Use built-in `FindHDF5` module to find HDF5 Set the required version so that the module deals with working out the version for us --- cmake/dependencies.cmake | 65 ++-------------------------------------- 1 file changed, 3 insertions(+), 62 deletions(-) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 98eadef47..5fbd1cf91 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -164,74 +164,15 @@ if(USE_HDF5) # by explicitly modifying NC_FIND_SHARED_LIBS. ## if(NC_FIND_SHARED_LIBS) - set(NC_HDF5_LINK_TYPE "shared") - set(NC_HDF5_LINK_TYPE_UPPER "SHARED") + set(HDF5_USE_STATIC_LIBRARIES OFF) else(NC_FIND_SHARED_LIBS) - set(NC_HDF5_LINK_TYPE "static") - set(NC_HDF5_LINK_TYPE_UPPER "STATIC") + set(HDF5_USE_STATIC_LIBRARIES ON) endif(NC_FIND_SHARED_LIBS) ##### # First, find the C and HL libraries. - # - # This has been updated to reflect what is in the hdf5 - # examples, even though the previous version of what we - # had worked. ##### - if(MSVC) - set(SEARCH_PACKAGE_NAME ${HDF5_PACKAGE_NAME}) - find_package(HDF5 NAMES ${SEARCH_PACKAGE_NAME} COMPONENTS C HL CONFIG REQUIRED ${NC_HDF5_LINK_TYPE}) - else(MSVC) - find_package(HDF5 COMPONENTS C HL REQUIRED) - endif(MSVC) - - ## - # Next, check the HDF5 version. This will inform which - # HDF5 variables we need to munge. - ## - - # Some versions of HDF5 set HDF5_VERSION_STRING instead of HDF5_VERSION - if(HDF5_VERSION_STRING AND NOT HDF5_VERSION) - set(HDF5_VERSION ${HDF5_VERSION_STRING}) - endif() - - - ### - # If HDF5_VERSION is undefined, attempt to determine it programatically. - ### - if("${HDF5_VERSION}" STREQUAL "") - message(STATUS "HDF5_VERSION not detected. Attempting to determine programatically.") - IF (EXISTS "${HDF5_INCLUDE_DIR}/H5pubconf.h") - file(READ "${HDF5_INCLUDE_DIR}/H5pubconf.h" _hdf5_version_lines - REGEX "#define[ \t]+H5_VERSION") - string(REGEX REPLACE ".*H5_VERSION .*\"\(.*\)\".*" "\\1" _hdf5_version "${_hdf5_version_lines}") - set(HDF5_VERSION "${_hdf5_version}" CACHE STRING "") - unset(_hdf5_version) - unset(_hdf5_version_lines) - message(STATUS "Found HDF5 libraries version ${HDF5_VERSION}") - endif() - else() - set(HDF5_VERSION ${HDF5_VERSION} CACHE STRING "") - endif() - - ### - # If HDF5_VERSION is still empty, we have a problem. - # Error out. - ### - if("${HDF5_VERSION}" STREQUAL "") - message(FATAL_ERR "Unable to determine HDF5 version. NetCDF requires at least version ${HDF5_VERSION_REQUIRED}. Please ensure that libhdf5 is installed and accessible.") - endif() - - ### - # Now that we know HDF5_VERSION isn't empty, we can check for minimum required version, - # and toggle various options. - ### - - if(${HDF5_VERSION} VERSION_LESS ${HDF5_VERSION_REQUIRED}) - message(FATAL_ERROR "netCDF requires at least HDF5 ${HDF5_VERSION_REQUIRED}. Found ${HDF5_VERSION}.") - endif() - - + find_package(HDF5 ${HDF5_VERSION_REQUIRED} COMPONENTS C HL REQUIRED) ## # Include the HDF5 include directory. From 9e993a06cdd13aa0748056a115ca21879d9726d7 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Thu, 18 Jan 2024 14:35:19 +0000 Subject: [PATCH 03/11] CMake: Remove duplicated checks for HDF5 header This *must* have been found by call to `find_package` earlier --- cmake/dependencies.cmake | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 5fbd1cf91..5e9566e17 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -248,16 +248,6 @@ if(USE_HDF5) set(HDF5_C_LIBRARY_hdf5 "${HDF5_C_LIBRARY}" ) endif() - find_path(HAVE_HDF5_H hdf5.h PATHS ${HDF5_INCLUDE_DIR} NO_DEFAULT_PATH) - if(NOT HAVE_HDF5_H) - message(FATAL_ERROR "Compiling a test with hdf5 failed. Either hdf5.h cannot be found, or the log messages should be checked for another reason.") - else(NOT HAVE_HDF5_H) - target_include_directories(netcdf - PRIVATE - ${HAVE_HDF5_H} - ) - endif(NOT HAVE_HDF5_H) - include(cmake/check_hdf5.cmake) # Check to ensure that HDF5 was built with zlib. @@ -349,15 +339,11 @@ if(USE_HDF5) set(HAS_PAR_FILTERS no CACHE STRING "" ) endif() - find_path(HAVE_HDF5_H hdf5.h PATHS ${HDF5_INCLUDE_DIR} NO_DEFAULT_PATH) - if(NOT HAVE_HDF5_H) - message(FATAL_ERROR "Compiling a test with hdf5 failed. Either hdf5.h cannot be found, or the log messages should be checked for another reason.") - else(NOT HAVE_HDF5_H) - target_include_directories(netcdf - PRIVATE - ${HAVE_HDF5_H} - ) - endif(NOT HAVE_HDF5_H) + set(HAVE_HDF5_H ${HDF5_C_INCLUDE_DIR}) + target_include_directories(netcdf + PRIVATE + ${HAVE_HDF5_H} + ) #option to include HDF5 High Level header file (hdf5_hl.h) in case we are not doing a make install target_include_directories(netcdf From 37b5c619f92412f782d5ff3b0f077df4188c5171 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Thu, 18 Jan 2024 14:36:07 +0000 Subject: [PATCH 04/11] CMake: Don't repeat check for HDF5 parallel feature from `FindHDF5` --- cmake/dependencies.cmake | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 5e9566e17..759353509 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -290,20 +290,7 @@ if(USE_HDF5) message("-- HDF5_UTF8_PATHS (HDF5 version 1.10.6+): ${HDF5_UTF8_PATHS}") # Find out if HDF5 was built with parallel support. - # Do that by checking for the targets H5Pget_fapl_mpiposx and - # H5Pget_fapl_mpio in ${HDF5_LIB}. - - # H5Pset_fapl_mpiposix and H5Pget_fapl_mpiposix have been removed since HDF5 1.8.12. - # Use H5Pset_fapl_mpio and H5Pget_fapl_mpio, instead. - # CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5Pget_fapl_mpiposix "" HDF5_IS_PARALLEL_MPIPOSIX) - - CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5Pget_fapl_mpio "" HDF5_IS_PARALLEL_MPIO) - if(HDF5_IS_PARALLEL_MPIO) - set(HDF5_PARALLEL ON) - else() - set(HDF5_PARALLEL OFF) - endif() - set(HDF5_PARALLEL ${HDF5_PARALLEL} ) + set(HDF5_PARALLEL ${HDF5_IS_PARALLEL}) #Check to see if HDF5 library has collective metadata APIs, (HDF5 >= 1.10.0) CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5Pset_all_coll_metadata_ops "" HDF5_HAS_COLL_METADATA_OPS) From eee6380dd38571b8b643b2b94b183e1820479e3c Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Thu, 18 Jan 2024 14:36:35 +0000 Subject: [PATCH 05/11] CMake: Remove unused variable --- cmake/dependencies.cmake | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 759353509..44193c24c 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -295,12 +295,6 @@ if(USE_HDF5) #Check to see if HDF5 library has collective metadata APIs, (HDF5 >= 1.10.0) CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5Pset_all_coll_metadata_ops "" HDF5_HAS_COLL_METADATA_OPS) - if(HDF5_PARALLEL) - set(HDF5_CC h5pcc ) - else() - set(HDF5_CC h5cc ) - endif() - # Check to see if H5Dread_chunk is available CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5Dread_chunk "" HAS_READCHUNKS) From 638cdb3a662dd930c3ee677414c4095ec1d061d4 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Fri, 16 Feb 2024 09:25:13 +0000 Subject: [PATCH 06/11] CMake: Lowercase some functions --- cmake/dependencies.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 44193c24c..bf523cf68 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -293,13 +293,13 @@ if(USE_HDF5) set(HDF5_PARALLEL ${HDF5_IS_PARALLEL}) #Check to see if HDF5 library has collective metadata APIs, (HDF5 >= 1.10.0) - CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5Pset_all_coll_metadata_ops "" HDF5_HAS_COLL_METADATA_OPS) + check_library_exists(${HDF5_C_LIBRARY_hdf5} H5Pset_all_coll_metadata_ops "" HDF5_HAS_COLL_METADATA_OPS) # Check to see if H5Dread_chunk is available - CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5Dread_chunk "" HAS_READCHUNKS) + check_library_exists(${HDF5_C_LIBRARY_hdf5} H5Dread_chunk "" HAS_READCHUNKS) # Check to see if H5Pset_fapl_ros3 is available - CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5Pset_fapl_ros3 "" HAS_HDF5_ROS3) + check_library_exists(${HDF5_C_LIBRARY_hdf5} H5Pset_fapl_ros3 "" HAS_HDF5_ROS3) # Check to see if this is hdf5-1.10.3 or later. if(HAS_READCHUNKS) From 9bbdd4cd7bf8691606aeb85f2b98db85f2bef4a8 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Fri, 16 Feb 2024 09:57:45 +0000 Subject: [PATCH 07/11] Replace use of `HAVE_HDF5_H` feature macro with `USE_HDF5` --- cmake/dependencies.cmake | 9 +-------- config.h.cmake.in | 6 ------ nc_test4/test_filter_vlen.c | 2 +- nc_test4/tst_filter_vlen.c | 2 +- nczarr_test/ncdumpchunks.c | 2 +- nczarr_test/test_chunkcases.c | 5 ----- nczarr_test/test_unlim_io.c | 5 ----- nczarr_test/test_utils.c | 2 +- nczarr_test/testfilter.c | 5 ----- nczarr_test/testfilter_misc.c | 2 +- nczarr_test/testfilter_multi.c | 2 +- 11 files changed, 7 insertions(+), 35 deletions(-) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index bf523cf68..6f879dfb1 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -320,16 +320,9 @@ if(USE_HDF5) set(HAS_PAR_FILTERS no CACHE STRING "" ) endif() - set(HAVE_HDF5_H ${HDF5_C_INCLUDE_DIR}) target_include_directories(netcdf PRIVATE - ${HAVE_HDF5_H} - ) - - #option to include HDF5 High Level header file (hdf5_hl.h) in case we are not doing a make install - target_include_directories(netcdf - PRIVATE - ${HDF5_HL_INCLUDE_DIR} + ${HDF5_INCLUDE_DIRS} ) endif(USE_HDF5) diff --git a/config.h.cmake.in b/config.h.cmake.in index f10a3a91a..d218a1533 100644 --- a/config.h.cmake.in +++ b/config.h.cmake.in @@ -283,12 +283,6 @@ are set when opening a binary file on Windows. */ /* Define to 1 if you have libsz */ #cmakedefine HAVE_SZ 1 -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_HDF5_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_HDF5_HL_H 1 - /* Define to 1 if the system has the type `int64'. */ #cmakedefine HAVE_INT64 1 diff --git a/nc_test4/test_filter_vlen.c b/nc_test4/test_filter_vlen.c index 827087bb5..b5639bc37 100644 --- a/nc_test4/test_filter_vlen.c +++ b/nc_test4/test_filter_vlen.c @@ -8,7 +8,7 @@ #include #include -#ifdef HAVE_HDF5_H +#ifdef USE_HDF5 #include #endif #include "netcdf.h" diff --git a/nc_test4/tst_filter_vlen.c b/nc_test4/tst_filter_vlen.c index 677541b1c..3756b3a2e 100644 --- a/nc_test4/tst_filter_vlen.c +++ b/nc_test4/tst_filter_vlen.c @@ -8,7 +8,7 @@ #include #include -#ifdef HAVE_HDF5_H +#ifdef USE_HDF5 #include #endif #include "netcdf.h" diff --git a/nczarr_test/ncdumpchunks.c b/nczarr_test/ncdumpchunks.c index 17bcc76c2..e4da59f1d 100644 --- a/nczarr_test/ncdumpchunks.c +++ b/nczarr_test/ncdumpchunks.c @@ -23,7 +23,7 @@ #include "ncpathmgr.h" #include "nclog.h" -#ifdef HAVE_HDF5_H +#ifdef USE_HDF5 #include #include #endif diff --git a/nczarr_test/test_chunkcases.c b/nczarr_test/test_chunkcases.c index 91774c939..7241a8cf3 100644 --- a/nczarr_test/test_chunkcases.c +++ b/nczarr_test/test_chunkcases.c @@ -8,11 +8,6 @@ #include "ncpathmgr.h" #include "nclist.h" -#ifdef HAVE_HDF5_H -#include -#include -#endif - #ifdef ENABLE_NCZARR #include "zincludes.h" #endif diff --git a/nczarr_test/test_unlim_io.c b/nczarr_test/test_unlim_io.c index 15f10723a..ed78c6a48 100644 --- a/nczarr_test/test_unlim_io.c +++ b/nczarr_test/test_unlim_io.c @@ -9,11 +9,6 @@ #include "ncpathmgr.h" #include "nclist.h" -#ifdef HAVE_HDF5_H -#include -#include -#endif - #ifdef ENABLE_NCZARR #include "zincludes.h" #endif diff --git a/nczarr_test/test_utils.c b/nczarr_test/test_utils.c index d13b88018..224d0e788 100644 --- a/nczarr_test/test_utils.c +++ b/nczarr_test/test_utils.c @@ -18,7 +18,7 @@ #include "XGetopt.h" #endif -#ifdef HAVE_HDF5_H +#ifdef USE_HDF5 #include #include #endif diff --git a/nczarr_test/testfilter.c b/nczarr_test/testfilter.c index ee599a054..cc5fb07ab 100644 --- a/nczarr_test/testfilter.c +++ b/nczarr_test/testfilter.c @@ -38,15 +38,10 @@ data: \endcode */ -#include "config.h" #include #include #include -#ifdef HAVE_HDF5_H -#include -#endif - #include "netcdf.h" /* The HDF assigned id for bzip compression */ diff --git a/nczarr_test/testfilter_misc.c b/nczarr_test/testfilter_misc.c index b54c9864f..6de3682a6 100644 --- a/nczarr_test/testfilter_misc.c +++ b/nczarr_test/testfilter_misc.c @@ -8,7 +8,7 @@ #include #include -#ifdef HAVE_HDF5_H +#ifdef USE_HDF5 #include #endif diff --git a/nczarr_test/testfilter_multi.c b/nczarr_test/testfilter_multi.c index 3f1e8d726..bf756c553 100644 --- a/nczarr_test/testfilter_multi.c +++ b/nczarr_test/testfilter_multi.c @@ -12,7 +12,7 @@ Test support for multiple filters per variable #include #include -#ifdef HAVE_HDF5_H +#ifdef USE_HDF5 #include #endif From 18bd56d94bd90294e9e0f678c1413807bde5303f Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Fri, 16 Feb 2024 10:27:30 +0000 Subject: [PATCH 08/11] CMake: Rely on CMake-bundled `FindHDF5` --- cmake/dependencies.cmake | 168 +++++++-------------------------------- 1 file changed, 29 insertions(+), 139 deletions(-) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 6f879dfb1..9a860bb78 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -109,152 +109,39 @@ if(USE_HDF5) ## set(HDF5_VERSION_REQUIRED 1.8.10) - + ### + # For now we assume that if we are building netcdf + # as a shared library, we will use hdf5 as a shared + # library. If we are building netcdf statically, + # we will use a static library. This can be toggled + # by explicitly modifying NC_FIND_SHARED_LIBS. ## - # Accommodate developers who have hdf5 libraries and - # headers on their system, but do not have a the hdf - # .cmake files. If this is the case, they should - # specify HDF5_HL_LIBRARY, HDF5_LIBRARY, HDF5_INCLUDE_DIR manually. - # - # This script will attempt to determine the version of the HDF5 library programatically. - ## - if(HDF5_C_LIBRARY AND HDF5_HL_LIBRARY AND HDF5_INCLUDE_DIR) - set(HDF5_LIBRARIES ${HDF5_C_LIBRARY} ${HDF5_HL_LIBRARY} ) - set(HDF5_C_LIBRARIES ${HDF5_C_LIBRARY} ) - set(HDF5_C_LIBRARY_hdf5 ${HDF5_C_LIBRARY} ) - set(HDF5_HL_LIBRARIES ${HDF5_HL_LIBRARY} ) - target_include_directories(netcdf - PRIVATE - ${HDF5_INCLUDE_DIR} - ) - message(STATUS "Using HDF5 C Library: ${HDF5_C_LIBRARY}") - message(STATUS "Using HDF5 HL LIbrary: ${HDF5_HL_LIBRARY}") - if (EXISTS "${HDF5_INCLUDE_DIR}/H5pubconf.h") - file(READ "${HDF5_INCLUDE_DIR}/H5pubconf.h" _hdf5_version_lines - REGEX "#define[ \t]+H5_VERSION") - string(REGEX REPLACE ".*H5_VERSION .*\"\(.*\)\".*" "\\1" _hdf5_version "${_hdf5_version_lines}") - set(HDF5_VERSION "${_hdf5_version}" CACHE STRING "") - set(HDF5_VERSION ${HDF5_VERSION} PARENT_SCOPE) - unset(_hdf5_version) - unset(_hdf5_version_lines) - endif () - message(STATUS "Found HDF5 libraries version ${HDF5_VERSION}") - ### - # If HDF5_VERSION is still empty, we have a problem. - # Error out. - ### - if("${HDF5_VERSION}" STREQUAL "") - message(FATAL_ERR "Unable to determine HDF5 version. NetCDF requires at least version ${HDF5_VERSION_REQUIRED}. Please ensure that libhdf5 is installed and accessible.") - endif() + if(NC_FIND_SHARED_LIBS) + set(HDF5_USE_STATIC_LIBRARIES OFF) + else(NC_FIND_SHARED_LIBS) + set(HDF5_USE_STATIC_LIBRARIES ON) + endif(NC_FIND_SHARED_LIBS) - ### - # Now that we know HDF5_VERSION isn't empty, we can check for minimum required version, - # and toggle various options. - ### - if(${HDF5_VERSION} VERSION_LESS ${HDF5_VERSION_REQUIRED}) - message(FATAL_ERROR "netCDF requires at least HDF5 ${HDF5_VERSION_REQUIRED}. Found ${HDF5_VERSION}.") - endif() + ##### + # First, find the C and HL libraries. + ##### + find_package(HDF5 ${HDF5_VERSION_REQUIRED} COMPONENTS C HL REQUIRED) - else(HDF5_C_LIBRARY AND HDF5_HL_LIBRARY AND HDF5_INCLUDE_DIR) # We are seeking out HDF5 with Find Package. - ### - # For now we assume that if we are building netcdf - # as a shared library, we will use hdf5 as a shared - # library. If we are building netcdf statically, - # we will use a static library. This can be toggled - # by explicitly modifying NC_FIND_SHARED_LIBS. - ## - if(NC_FIND_SHARED_LIBS) - set(HDF5_USE_STATIC_LIBRARIES OFF) - else(NC_FIND_SHARED_LIBS) - set(HDF5_USE_STATIC_LIBRARIES ON) - endif(NC_FIND_SHARED_LIBS) - - ##### - # First, find the C and HL libraries. - ##### - find_package(HDF5 ${HDF5_VERSION_REQUIRED} COMPONENTS C HL REQUIRED) - - ## - # Include the HDF5 include directory. - ## - if(HDF5_INCLUDE_DIRS AND NOT HDF5_INCLUDE_DIR) - set(HDF5_INCLUDE_DIR ${HDF5_INCLUDE_DIRS} ) - endif() - message(STATUS "Using HDF5 include dir: ${HDF5_INCLUDE_DIR}") - target_include_directories(netcdf - PRIVATE - ${HDF5_INCLUDE_DIR} - ) - - ### - # This is the block where we figure out what the appropriate - # variables are, and we ensure that we end up with - # HDF5_C_LIBRARY, HDF5_HL_LIBRARY and HDF5_LIBRARIES. - ### - if(MSVC) - #### - # Environmental variables in Windows when using MSVC - # are a hot mess between versions. - #### - - ## - # HDF5 1.8.15 defined HDF5_LIBRARIES. - ## - if(${HDF5_VERSION} VERSION_LESS "1.8.16") - set(HDF5_C_LIBRARY hdf5 ) - set(HDF5_C_LIBRARY_hdf5 hdf5 ) - endif(${HDF5_VERSION} VERSION_LESS "1.8.16") - - if(${HDF5_VERSION} VERSION_GREATER "1.8.15") - if(NOT HDF5_LIBRARIES AND HDF5_C_${NC_HDF5_LINK_TYPE_UPPER}_LIBRARY AND HDF5_HL_${NC_HDF5_LINK_TYPE_UPPER}_LIBRARY) - set(HDF5_C_LIBRARY ${HDF5_C_${NC_HDF5_LINK_TYPE_UPPER}_LIBRARY} ) - set(HDF5_C_LIBRARY_hdf5 ${HDF5_C_${NC_HDF5_LINK_TYPE_UPPER}_LIBRARY} ) - set(HDF5_HL_LIBRARY ${HDF5_HL_${NC_HDF5_LINK_TYPE_UPPER}_LIBRARY} ) - - set(HDF5_LIBRARIES ${HDF5_C_${NC_HDF5_LINK_TYPE_UPPER}_LIBRARY} ${HDF5_HL_${NC_HDF5_LINK_TYPE_UPPER}_LIBRARY} ) - endif() - endif(${HDF5_VERSION} VERSION_GREATER "1.8.15") - - else(MSVC) - - # Depending on the install, either HDF5_hdf_library or - # HDF5_C_LIBRARIES may be defined. We must check for either. - if(HDF5_C_LIBRARIES AND NOT HDF5_hdf5_LIBRARY) - set(HDF5_hdf5_LIBRARY ${HDF5_C_LIBRARIES} ) - endif() - - # Some versions of find_package set HDF5_C_LIBRARIES, but not HDF5_C_LIBRARY - # We use HDF5_C_LIBRARY below, so need to make sure it is set. - if(HDF5_C_LIBRARIES AND NOT HDF5_C_LIBRARY) - set(HDF5_C_LIBRARY ${HDF5_C_LIBRARIES} ) - endif() - - # Same issue as above... - if(HDF5_HL_LIBRARIES AND NOT HDF5_HL_LIBRARY) - set(HDF5_HL_LIBRARY ${HDF5_HL_LIBRARIES} ) - endif() - - endif(MSVC) - if(NOT HDF5_C_LIBRARY) - set(HDF5_C_LIBRARY hdf5 ) - endif() - - endif(HDF5_C_LIBRARY AND HDF5_HL_LIBRARY AND HDF5_INCLUDE_DIR) + message(STATUS "Using HDF5 include dir: ${HDF5_INCLUDE_DIRS}") + target_include_directories(netcdf + PRIVATE + ${HDF5_INCLUDE_DIRS} + ) find_package(Threads) - # There is a missing case in the above code so default it - if(NOT HDF5_C_LIBRARY_hdf5 OR "${HDF5_C_LIBRARY_hdf5}" STREQUAL "" ) - set(HDF5_C_LIBRARY_hdf5 "${HDF5_C_LIBRARY}" ) - endif() - - include(cmake/check_hdf5.cmake) + set (CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIRS}) # Check to ensure that HDF5 was built with zlib. # This needs to be near the beginning since we # need to know whether to add "-lz" to the symbol # tests below. - + include(check_hdf5) check_hdf5_feature(HAVE_HDF5_ZLIB H5_HAVE_ZLIB_H) if(NOT HAVE_HDF5_ZLIB) message(FATAL_ERROR "HDF5 was built without zlib. Rebuild HDF5 with zlib.") @@ -287,19 +174,22 @@ if(USE_HDF5) set(HDF5_UTF8_PATHS OFF ) endif() - message("-- HDF5_UTF8_PATHS (HDF5 version 1.10.6+): ${HDF5_UTF8_PATHS}") + message(STATUS "-- HDF5_UTF8_PATHS (HDF5 version 1.10.6+): ${HDF5_UTF8_PATHS}") # Find out if HDF5 was built with parallel support. set(HDF5_PARALLEL ${HDF5_IS_PARALLEL}) + set(CMAKE_REQUIRED_LIBRARIES HDF5::HDF5) + include(CheckSymbolExists) + #Check to see if HDF5 library has collective metadata APIs, (HDF5 >= 1.10.0) - check_library_exists(${HDF5_C_LIBRARY_hdf5} H5Pset_all_coll_metadata_ops "" HDF5_HAS_COLL_METADATA_OPS) + check_symbol_exists(H5Pset_all_coll_metadata_ops "hdf5.h" HDF5_HAS_COLL_METADATA_OPS) # Check to see if H5Dread_chunk is available - check_library_exists(${HDF5_C_LIBRARY_hdf5} H5Dread_chunk "" HAS_READCHUNKS) + check_symbol_exists(H5Dread_chunk "hdf5.h" HAS_READCHUNKS) # Check to see if H5Pset_fapl_ros3 is available - check_library_exists(${HDF5_C_LIBRARY_hdf5} H5Pset_fapl_ros3 "" HAS_HDF5_ROS3) + check_symbol_exists(H5Pset_fapl_ros3 "hdf5.h" HAS_HDF5_ROS3) # Check to see if this is hdf5-1.10.3 or later. if(HAS_READCHUNKS) From 2dd7b50d2eb96104969809997c320af90864aaae Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Fri, 16 Feb 2024 10:48:34 +0000 Subject: [PATCH 09/11] Docs: Update examples of specifying custom library paths to CMake --- docs/FAQ.md | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 2dcd67af1..913591a11 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -1944,23 +1944,12 @@ Not at this time; it is required to instead build first one version, and then th How can I specify linking against a particular library? {#partlib} ------------------------------------------------------- -It depends on the library. To specify a custom `ZLib`, for example, you would do the following: - - $ cmake [Source Directory] -DZLIB_LIBRARY=/path/to/my/zlib.lib - - -`HDF5` is more complex, since it requires both the `hdf5` and `hdf5_hl` libraries. You would specify custom `HDF5` libraries as follows: - - $ cmake [Source Directory] -DHDF5_C_LIBRARY=/path/to/hdf5.lib \ - -DHDF5_HL_LIBRARY=/path/to/hdf5_hl.lib \ - -DHDF5_INCLUDE_DIR=/path/to/hdf5/include - - -Alternatively, you may specify: +For most libraries, you can specify `_ROOT`. To specify +custom `ZLib` and `HDF5`, for example, you would do the following: $ cmake [Source Directory] \ - -DHDF5_LIBRARIES="/path/to/hdf5.lib;/path/to/hdf5_hl.lib" \ - -DHDF5_INCLUDE_DIRS=/path/to/hdf5/include/ + -DZLIB_ROOT=/path/to/zlib/install \ + -DHDF5_ROOT=/path/to/hdf5/install What if I want to link against multiple libraries in a non-standard location {#nonstdloc} @@ -1982,11 +1971,8 @@ How can I specify a Parallel Build using HDF5 {#parallelhdf} If cmake is having problems finding the parallel `HDF5` install, you can specify the location manually: - $ cmake [Source Directory] -DENABLE_PARALLEL=ON \ - -DHDF5_C_LIBRARY=/usr/lib64/openmpi/lib/libhdf5.so \ - -DHDF5_HL_LIBRARY=/usr/lib64/openmpi/lib/libhdf5.hl.so \ - -DHDF5_INCLUDE_DIR=/usr/include/openmpi-x86_64 \ + -DHDF5_ROOT=/usr/lib64/openmpi/lib/ You will, of course, need to use the location of the libraries specific to your development environment. From 907e5cc43f4640e6f1077e05b80cf3a7818bc4e9 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Fri, 16 Feb 2024 10:51:20 +0000 Subject: [PATCH 10/11] CMake: Use `target_link_libraries` with `HDF5::HDF5` target --- cmake/dependencies.cmake | 10 ++-------- h5_test/CMakeLists.txt | 3 +-- libdispatch/CMakeLists.txt | 2 +- libhdf5/CMakeLists.txt | 2 +- liblib/CMakeLists.txt | 20 ++------------------ libnczarr/CMakeLists.txt | 2 +- libsrc4/CMakeLists.txt | 2 +- ncdump/CMakeLists.txt | 14 ++++++-------- plugins/CMakeLists.txt | 2 +- 9 files changed, 16 insertions(+), 41 deletions(-) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 9a860bb78..9c818f987 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -128,9 +128,9 @@ if(USE_HDF5) find_package(HDF5 ${HDF5_VERSION_REQUIRED} COMPONENTS C HL REQUIRED) message(STATUS "Using HDF5 include dir: ${HDF5_INCLUDE_DIRS}") - target_include_directories(netcdf + target_link_libraries(netcdf PRIVATE - ${HDF5_INCLUDE_DIRS} + HDF5::HDF5 ) find_package(Threads) @@ -209,12 +209,6 @@ if(USE_HDF5) set(HDF5_HAS_PAR_FILTERS FALSE CACHE BOOL "" ) set(HAS_PAR_FILTERS no CACHE STRING "" ) endif() - - target_include_directories(netcdf - PRIVATE - ${HDF5_INCLUDE_DIRS} - ) - endif(USE_HDF5) ################################ diff --git a/h5_test/CMakeLists.txt b/h5_test/CMakeLists.txt index 3f040c9cb..96d551cdf 100644 --- a/h5_test/CMakeLists.txt +++ b/h5_test/CMakeLists.txt @@ -14,8 +14,7 @@ FOREACH(CTEST ${H5TESTS}) ADD_EXECUTABLE(${CTEST} ${CTEST}.c) TARGET_LINK_LIBRARIES(${CTEST} netcdf - ${HDF5_HL_LIBRARIES} - ${HDF5_C_LIBRARIES} + HDF5::HDF5 hdf5::hdf5_hl ) ADD_TEST(${CTEST} ${EXECUTABLE_OUTPUT_PATH}/${CTEST}) ENDFOREACH() diff --git a/libdispatch/CMakeLists.txt b/libdispatch/CMakeLists.txt index c1af58d11..2ad44f5d5 100644 --- a/libdispatch/CMakeLists.txt +++ b/libdispatch/CMakeLists.txt @@ -69,7 +69,7 @@ endif(REGEDIT) if (USE_HDF5) - target_include_directories(dispatch PRIVATE ${HDF5_INCLUDE_DIR}) + target_link_libraries(dispatch PRIVATE HDF5::HDF5) endif(USE_HDF5) if(STATUS_PARALLEL) diff --git a/libhdf5/CMakeLists.txt b/libhdf5/CMakeLists.txt index d018f4abf..a5d14a139 100644 --- a/libhdf5/CMakeLists.txt +++ b/libhdf5/CMakeLists.txt @@ -28,7 +28,7 @@ if(STATUS_PARALLEL) target_link_libraries(netcdfhdf5 PUBLIC MPI::MPI_C) endif(STATUS_PARALLEL) -target_include_directories(netcdfhdf5 PUBLIC ${HDF5_INCLUDE_DIR}) +target_link_libraries(netcdfhdf5 PUBLIC HDF5::HDF5) # Remember to package this file for CMake builds. add_extra_dist(${libnchdf5_SOURCES} CMakeLists.txt) diff --git a/liblib/CMakeLists.txt b/liblib/CMakeLists.txt index 2adbb4f9b..2f8759730 100644 --- a/liblib/CMakeLists.txt +++ b/liblib/CMakeLists.txt @@ -140,23 +140,7 @@ if(ENABLE_NCZARR_ZIP) endif() if(USE_HDF5) - if(NOT MSVC) - # Some version of cmake define HDF5_hdf5_LIBRARY instead of - # HDF5_LIBRARY. Same with HDF5_HL_LIBRARIES - if(HDF5_hdf5_LIBRARY AND NOT HDF5_C_LIBRARIES) - set(HDF5_C_LIBRARIES ${HDF5_hdf5_LIBRARY}) - endif() - if(HDF5_hdf5_hl_LIBRARY AND NOT HDF5_HL_LIBRARIES) - set(HDF5_HL_LIBRARIES ${HDF5_hdf5_hl_LIBRARY}) - endif() - # The order of the libraries is important here for static - # builds: - # Make sure that HDF5_C_LIBRARY appears *after* - # HDF5_HL_LIBRARY. - set(TLL_LIBS ${HDF5_HL_LIBRARIES} ${HDF5_C_LIBRARIES} ${HDF5_LIBRARIES} ${TLL_LIBS} ${Szip_LIBRARY}) - else() # Windows CMake defines HDF5_LIBRARIES. - set(TLL_LIBS ${HDF5_LIBRARIES} ${TLL_LIBS} ${Szip_LIBRARY}) - endif() + set(TLL_LIBS HDF5::HDF5 hdf5::hdf5_hl ${TLL_LIBS} ${Szip_LIBRARY}) endif() if(FOUND_CURL) @@ -234,4 +218,4 @@ set(NC_LIBS ${NC_LIBS} PARENT_SCOPE) file(GLOB CUR_EXTRA_DIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/*.c) set(CUR_EXTRA_DIST ${CUR_EXTRA_DIST} CMakeLists.txt Makefile.am) -ADD_EXTRA_DIST("${CUR_EXTRA_DIST}") \ No newline at end of file +ADD_EXTRA_DIST("${CUR_EXTRA_DIST}") diff --git a/libnczarr/CMakeLists.txt b/libnczarr/CMakeLists.txt index 7e42de778..87b98acad 100644 --- a/libnczarr/CMakeLists.txt +++ b/libnczarr/CMakeLists.txt @@ -62,7 +62,7 @@ add_library(nczarr OBJECT ${libnczarr_SOURCES}) target_include_directories(nczarr PUBLIC ../libncpoco) if (USE_HDF5) - target_include_directories(nczarr PRIVATE ${HDF5_INCLUDE_DIR}) + target_link_libraries(nczarr PRIVATE HDF5::HDF5) endif(USE_HDF5) if(STATUS_PARALLEL) diff --git a/libsrc4/CMakeLists.txt b/libsrc4/CMakeLists.txt index b9e0f857a..9ba0d4398 100644 --- a/libsrc4/CMakeLists.txt +++ b/libsrc4/CMakeLists.txt @@ -36,7 +36,7 @@ set(ARGS_MANPAGE -DAPI=C) if (USE_HDF5) set(ARGS_MANPAGE ${ARGS_MANPAGE} -DNETCDF4=TRUE) - target_include_directories(netcdf4 PRIVATE ${HDF5_INCLUDE_DIR}) + target_link_libraries(netcdf4 PRIVATE HDF5::HDF5) endif(USE_HDF5) if (BUILD_DAP) diff --git a/ncdump/CMakeLists.txt b/ncdump/CMakeLists.txt index 86e637f37..a4e3a9440 100644 --- a/ncdump/CMakeLists.txt +++ b/ncdump/CMakeLists.txt @@ -45,8 +45,13 @@ add_executable(ncfilteravail ${ncfilteravail_FILES}) if(USE_HDF5) add_executable(nc4print nc4print.c nc4printer.c) + target_link_libraries(nc4print netcdf ${ALL_TLL_LIBS}) + add_executable(printfqn ${printfqn_FILES}) + target_link_libraries(printfqn netcdf ${ALL_TLL_LIBS}) + add_executable(nchdf5version ${nchdf5version_FILES}) + target_link_libraries(nchdf5version netcdf ${ALL_TLL_LIBS}) endif(USE_HDF5) if(ENABLE_DAP) @@ -60,13 +65,6 @@ target_link_libraries(ncvalidator netcdf ${ALL_TLL_LIBS}) target_link_libraries(ncpathcvt netcdf ${ALL_TLL_LIBS}) target_link_libraries(ncfilteravail netcdf ${ALL_TLL_LIBS}) -if(USE_HDF5) - target_link_libraries(nc4print netcdf ${ALL_TLL_LIBS}) - target_link_libraries(printfqn netcdf ${ALL_TLL_LIBS}) - target_link_libraries(nchdf5version netcdf ${ALL_TLL_LIBS}) - target_include_directories(ncdump PRIVATE ${HDF5_INCLUDE_DIR}) -endif(USE_HDF5) - if(ENABLE_DAP) target_link_libraries(ocprint netcdf ${ALL_TLL_LIBS}) endif(ENABLE_DAP) @@ -127,7 +125,7 @@ endif() IF(USE_HDF5) add_executable(tst_fileinfo tst_fileinfo.c) - target_link_libraries(tst_fileinfo netcdf) + target_link_libraries(tst_fileinfo netcdf ${ALL_TLL_LIBS}) ENDIF() IF(MSVC) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 8f5ac6a22..332024552 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -72,7 +72,7 @@ macro(buildplugin TARGET TARGETLIB) endif(STATUS_PARALLEL) if (USE_HDF5) - target_include_directories(${TARGET} PRIVATE ${HDF5_INCLUDE_DIR}) + target_link_libraries(${TARGET} PRIVATE HDF5::HDF5) endif(USE_HDF5) endmacro() From 11d484cbe2fa783462a7e826c0198ce5b53b1653 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Fri, 16 Feb 2024 11:18:19 +0000 Subject: [PATCH 11/11] CI: Bump version of HDF5 1.14 --- .github/workflows/run_tests_cdash.yml | 6 +++--- .github/workflows/run_tests_osx.yml | 10 +++++----- .github/workflows/run_tests_s3.yml | 4 ++-- .github/workflows/run_tests_ubuntu.yml | 16 ++++++++-------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/run_tests_cdash.yml b/.github/workflows/run_tests_cdash.yml index b8d10ef11..5dd5c85cb 100644 --- a/.github/workflows/run_tests_cdash.yml +++ b/.github/workflows/run_tests_cdash.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: - hdf5: [ 1.10.8, 1.12.2, 1.14.0 ] + hdf5: [ 1.10.8, 1.12.2, 1.14.3 ] steps: - uses: actions/checkout@v3 @@ -66,7 +66,7 @@ jobs: strategy: matrix: - hdf5: [ 1.14.0 ] + hdf5: [ 1.14.3 ] steps: @@ -126,7 +126,7 @@ jobs: strategy: matrix: - hdf5: [ 1.10.8, 1.12.2, 1.14.0 ] + hdf5: [ 1.10.8, 1.12.2, 1.14.3 ] steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/run_tests_osx.yml b/.github/workflows/run_tests_osx.yml index dd0917e36..21198ae84 100644 --- a/.github/workflows/run_tests_osx.yml +++ b/.github/workflows/run_tests_osx.yml @@ -20,7 +20,7 @@ jobs: strategy: matrix: - hdf5: [ 1.12.2, 1.14.0 ] + hdf5: [ 1.12.2, 1.14.3 ] steps: @@ -57,7 +57,7 @@ jobs: strategy: matrix: - hdf5: [ 1.12.2, 1.14.0 ] + hdf5: [ 1.12.2, 1.14.3 ] use_nc4: [ nc3, nc4 ] use_dap: [ dap_off, dap_on ] use_nczarr: [ nczarr_off, nczarr_on ] @@ -163,7 +163,7 @@ jobs: strategy: matrix: - hdf5: [ 1.12.2, 1.14.0 ] + hdf5: [ 1.12.2, 1.14.3 ] use_nc4: [ nc3, nc4 ] use_dap: [ dap_off, dap_on ] use_nczarr: [ nczarr_off, nczarr_on ] @@ -259,7 +259,7 @@ jobs: strategy: matrix: - hdf5: [ 1.12.2, 1.14.0 ] + hdf5: [ 1.12.2, 1.14.3 ] steps: - uses: actions/checkout@v3 @@ -340,7 +340,7 @@ jobs: strategy: matrix: - hdf5: [ 1.12.2, 1.14.0 ] + hdf5: [ 1.12.2, 1.14.3 ] steps: diff --git a/.github/workflows/run_tests_s3.yml b/.github/workflows/run_tests_s3.yml index ddbb353c8..61af997dc 100644 --- a/.github/workflows/run_tests_s3.yml +++ b/.github/workflows/run_tests_s3.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: - hdf5: [ 1.10.8, 1.12.2, 1.14.0 ] + hdf5: [ 1.10.8, 1.12.2, 1.14.3 ] steps: - uses: actions/checkout@v3 @@ -70,7 +70,7 @@ jobs: strategy: matrix: - hdf5: [ 1.14.0 ] + hdf5: [ 1.14.3 ] steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/run_tests_ubuntu.yml b/.github/workflows/run_tests_ubuntu.yml index 854c8bf74..d7a522b05 100644 --- a/.github/workflows/run_tests_ubuntu.yml +++ b/.github/workflows/run_tests_ubuntu.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: - hdf5: [ 1.10.8, 1.12.2, 1.14.0 ] + hdf5: [ 1.10.8, 1.12.2, 1.14.3 ] steps: - uses: actions/checkout@v3 @@ -66,7 +66,7 @@ jobs: strategy: matrix: - hdf5: [ 1.14.0 ] + hdf5: [ 1.14.3 ] steps: @@ -128,7 +128,7 @@ jobs: strategy: matrix: - hdf5: [ 1.14.0 ] + hdf5: [ 1.14.3 ] steps: - uses: actions/checkout@v3 @@ -223,7 +223,7 @@ jobs: strategy: matrix: - hdf5: [ 1.14.0 ] + hdf5: [ 1.14.3 ] steps: - uses: actions/checkout@v3 @@ -303,7 +303,7 @@ jobs: strategy: matrix: - hdf5: [ 1.14.0 ] + hdf5: [ 1.14.3 ] steps: @@ -383,7 +383,7 @@ jobs: strategy: matrix: - hdf5: [ 1.14.0 ] + hdf5: [ 1.14.3 ] steps: @@ -460,7 +460,7 @@ jobs: strategy: matrix: - hdf5: [1.10.8, 1.12.2, 1.14.0 ] + hdf5: [1.10.8, 1.12.2, 1.14.3 ] use_nc4: [ nc3, nc4 ] use_dap: [ dap_off, dap_on ] use_nczarr: [ nczarr_off, nczarr_on ] @@ -624,7 +624,7 @@ jobs: strategy: matrix: - hdf5: [ 1.10.8, 1.12.2, 1.14.0 ] + hdf5: [ 1.10.8, 1.12.2, 1.14.3 ] use_nc4: [ nc3, nc4 ] use_dap: [ dap_off, dap_on ] use_nczarr: [ nczarr_off, nczarr_on ]