Skip to content

Commit

Permalink
Merge pull request #2095 from Unidata/condaforge-hdf5-version-check.wif
Browse files Browse the repository at this point in the history
Revamping the HDF5_VERSION logic.
  • Loading branch information
WardF authored Aug 31, 2021
2 parents f4349ef + 9e6b6bc commit 09e0e04
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 26 deletions.
102 changes: 79 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#Minimum required CMake Version
cmake_minimum_required(VERSION 3.6.1)

#Project Name
#Project Name
project(netCDF LANGUAGES C CXX)
set(PACKAGE "netCDF" CACHE STRING "")

Expand Down Expand Up @@ -606,11 +606,20 @@ ENDIF(ENABLE_STRICT_NULL_BYTE_HEADER_PADDING)
##
SET(USE_HDF5 ${ENABLE_HDF5})
IF(USE_HDF5)

##
# Assert HDF5 version meets minimum required version.
##
SET(HDF5_VERSION_REQUIRED 1.8.10)


##
# 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})
Expand All @@ -624,10 +633,27 @@ IF(USE_HDF5)
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}")
set(HDF5_VERSION "${_hdf5_version}" CACHE STRING "")
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()

###
# 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()

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
Expand Down Expand Up @@ -665,25 +691,49 @@ IF(USE_HDF5)
# HDF5 variables we need to munge.
##

##
# Assert HDF5 version meets minimum required version.
##
SET(HDF5_VERSION_REQUIRED 1.8.10)

# 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 "Unable to determine hdf5 version. NetCDF requires at least version ${HDF5_VERSION_REQUIRED}")
ELSE()
IF(${HDF5_VERSION} VERSION_LESS ${HDF5_VERSION_REQUIRED})
MESSAGE(FATAL_ERROR
"netCDF requires at least HDF5 ${HDF5_VERSION_REQUIRED}. Found ${HDF5_VERSION}.")
ELSE()
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()



##
# Include the HDF5 include directory.
##
Expand Down Expand Up @@ -718,6 +768,10 @@ IF(USE_HDF5)
ENDIF(${HDF5_VERSION} VERSION_GREATER "1.8.15")

ELSE(MSVC)
####
# Environmental variables in Windows when using MSVC
# are a hot mess between versions.
####

IF(HDF5_hdf5_LIBRARY AND NOT HDF5_C_LIBRARY)
SET(HDF5_C_LIBRARY ${HDF5_hdf5_LIBRARY})
Expand Down Expand Up @@ -764,6 +818,18 @@ IF(USE_HDF5)
MESSAGE(STATUS "HDF5 has szip.")
ENDIF()

####
# Check to see if HDF5 library is 1.10.6 or greater.
# Used to control path name conversion
####
IF(${HDF5_VERSION} VERSION_GREATER "1.10.5")
SET(HDF5_UTF8_PATHS ON)
ELSE()
SET(HDF5_UTF8_PATHS OFF)
ENDIF()

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}.
Expand Down Expand Up @@ -816,16 +882,6 @@ IF(USE_HDF5)
SET(HAS_PAR_FILTERS no CACHE STRING "")
ENDIF()

# Check to see if HDF5 library is 1.10.6 or greater.
# Used to control path name conversion
IF(${HDF5_VERSION} VERSION_GREATER "1.10.5")
SET(HDF5_UTF8_PATHS ON)
ELSE()
SET(HDF5_UTF8_PATHS OFF)
ENDIF()

MESSAGE("-- Checking for HDF5 version 1.10.6 or later: ${HDF5_UTF8_PATHS}")

FIND_PATH(HAVE_HDF5_H hdf5.h PATHS ${HDF5_INCLUDE_DIR} NO_DEFAULT_PATH)
FIND_PATH(HAVE_HDF5_H hdf5.h)
IF(NOT HAVE_HDF5_H)
Expand Down
14 changes: 11 additions & 3 deletions ncdap_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ IF(ENABLE_TESTS)
IF(BUILD_UTILITIES)
add_sh_test(ncdap tst_ncdap3)
add_sh_test(ncdap testpathcvt)
SET_TESTS_PROPERTIES(ncdap_tst_ncdap3 ncdap_testpathcvt PROPERTIES RUN_SERIAL TRUE)
ENDIF()
IF(HAVE_BASH)
SET_TESTS_PROPERTIES(ncdap_tst_ncdap3 PROPERTIES RUN_SERIAL TRUE)
SET_TESTS_PROPERTIES(ncdap_testpathcvt PROPERTIES RUN_SERIAL TRUE)
ENDIF(HAVE_BASH)


ENDIF()

IF(NOT MSVC)
add_bin_env_test(ncdap t_dap3a)
Expand All @@ -49,6 +54,9 @@ ENDIF()
IF(BUILD_UTILITIES)
add_sh_test(ncdap tst_ber)
add_sh_test(ncdap tst_remote3)
IF(HAVE_BASH)
SET_TESTS_PROPERTIES(ncdap_tst_remote3 PROPERTIES RUN_SERIAL TRUE)
ENDIF(HAVE_BASH)
add_sh_test(ncdap tst_zero_len_var)
add_sh_test(ncdap tst_encode)
# not yet add_sh_test(ncdap tst_hyrax)
Expand All @@ -59,7 +67,7 @@ ENDIF()
SET_TESTS_PROPERTIES(ncdap_tst_longremote3 ncdap_test_manyurls PROPERTIES RUN_SERIAL TRUE)
ENDIF(ENABLE_DAP_LONG_TESTS)

SET_TESTS_PROPERTIES(ncdap_tst_remote3 PROPERTIES RUN_SERIAL TRUE)


ENDIF(BUILD_UTILITIES)

Expand Down

0 comments on commit 09e0e04

Please # to comment.