Skip to content

Commit

Permalink
HDF5 1.14.4, Zlib 2.2.1: improve robustness of HDF5 find
Browse files Browse the repository at this point in the history
this uses CMake >= 3.19 as older CMake generally isn't used anymore
and doesn't function well on modern systems anyway
  • Loading branch information
scivision committed Jul 18, 2024
1 parent a9769e9 commit cb4ae83
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.15...3.30)
cmake_minimum_required(VERSION 3.19...3.30)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "please use out-of-source build
Expand Down Expand Up @@ -68,6 +68,14 @@ endif()

# --- configure

# Conda's HDF5 never works with the system compiler
if(DEFINED ENV{CONDA_PREFIX})
list(APPEND CMAKE_IGNORE_PREFIX_PATH $ENV{CONDA_PREFIX})
list(APPEND CMAKE_IGNORE_PATH $ENV{CONDA_PREFIX}/bin)
# need CMAKE_IGNORE_PATH for CMake < 3.23
# and to ensure system env var PATH doesn't interfere despite CMAKE_IGNORE_PREFIX_PATH
endif()

if(FCLAW_ENABLE_HDF5 AND NOT TARGET HDF5::HDF5)
if(FCLAW_ENABLE_SUBMODULES)

Expand Down
41 changes: 23 additions & 18 deletions cmake/Modules/FindHDF5.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,8 @@ Targets
#]=======================================================================]

include(CheckSymbolExists)
include(CheckCSourceCompiles)
include(CheckFortranSourceCompiles)
include(CheckSourceCompiles)

# this is to help avoid unwanted Anaconda HDF5 or stray h5cc compiler script
set(_use_sys_env_path ${CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH})
set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH false)

function(get_flags exec outvar)

Expand Down Expand Up @@ -656,7 +652,7 @@ endfunction(hdf5_c_wrap)

function(check_c_links)

list(INSERT CMAKE_REQUIRED_LIBRARIES 0 ${HDF5_C_LIBRARIES})
list(PREPEND CMAKE_REQUIRED_LIBRARIES ${HDF5_C_LIBRARIES})
set(CMAKE_REQUIRED_INCLUDES ${HDF5_C_INCLUDE_DIR})

if(HDF5_parallel_FOUND)
Expand Down Expand Up @@ -699,14 +695,14 @@ else()
]=])
endif(HDF5_parallel_FOUND)

check_c_source_compiles("${src}" HDF5_C_links)
check_source_compiles(C "${src}" HDF5_C_links)

endfunction(check_c_links)


function(check_fortran_links)

list(INSERT CMAKE_REQUIRED_LIBRARIES 0 ${HDF5_Fortran_LIBRARIES} ${HDF5_C_LIBRARIES})
list(PREPEND CMAKE_REQUIRED_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${HDF5_C_LIBRARIES})
set(CMAKE_REQUIRED_INCLUDES ${HDF5_Fortran_INCLUDE_DIR} ${HDF5_C_INCLUDE_DIR})

if(HDF5_parallel_FOUND)
Expand Down Expand Up @@ -740,13 +736,22 @@ else()
end program")
endif()

check_fortran_source_compiles(${src} HDF5_Fortran_links SRC_EXT f90)
check_source_compiles(Fortran ${src} HDF5_Fortran_links)

endfunction(check_fortran_links)


function(check_hdf5_link)

# HDF5 bug #3663 for HDF5 1.14.2, 1.14.3, ...?
# https://github.com/HDFGroup/hdf5/issues/3663
if(WIN32 AND CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
if(HDF5_VERSION MATCHES "1.14.[2-3]")
message(VERBOSE "FindHDF5: applying workaround for HDF5 bug #3663 with Intel oneAPI on Windows")
list(APPEND CMAKE_REQUIRED_LIBRARIES shlwapi)
endif()
endif()

if(NOT HDF5_C_FOUND)
return()
endif()
Expand Down Expand Up @@ -789,14 +794,15 @@ if(NOT HDF5_ROOT)
endif()
endif()


# --- library suffixes

set(hdf5_lsuf lib hdf5/lib) # need explicit "lib" for self-built HDF5
if(NOT HDF5_ROOT)
list(INSERT hdf5_lsuf 0 hdf5/openmpi hdf5/mpich) # Ubuntu
list(INSERT hdf5_lsuf 0 openmpi/lib mpich/lib) # CentOS
list(PREPEND hdf5_lsuf hdf5/openmpi hdf5/mpich) # Ubuntu
list(PREPEND hdf5_lsuf openmpi/lib mpich/lib) # CentOS
if(NOT parallel IN_LIST HDF5_FIND_COMPONENTS)
list(INSERT hdf5_lsuf 0 hdf5/serial) # Ubuntu
list(PREPEND hdf5_lsuf hdf5/serial) # Ubuntu
endif()
endif()

Expand All @@ -811,13 +817,13 @@ else()
endif()

# Ubuntu
list(INSERT hdf5_isuf 0 hdf5/openmpi hdf5/mpich)
list(INSERT hdf5_msuf 0 hdf5/openmpi hdf5/mpich)
list(PREPEND hdf5_isuf hdf5/openmpi hdf5/mpich)
list(PREPEND hdf5_msuf hdf5/openmpi hdf5/mpich)

if(NOT parallel IN_LIST HDF5_FIND_COMPONENTS)
# Ubuntu
list(INSERT hdf5_isuf 0 hdf5/serial)
list(INSERT hdf5_msuf 0 hdf5/serial)
list(PREPEND hdf5_isuf hdf5/serial)
list(PREPEND hdf5_msuf hdf5/serial)
endif()

if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64|AMD64)")
Expand All @@ -829,7 +835,7 @@ endif()
if(NOT HDF5_ROOT AND CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
# CentOS paths
if(parallel IN_LIST HDF5_FIND_COMPONENTS)
list(INSERT hdf5_msuf 0 gfortran/modules/openmpi gfortran/modules/mpich)
list(PREPEND hdf5_msuf gfortran/modules/openmpi gfortran/modules/mpich)
else()
list(APPEND hdf5_msuf gfortran/modules)
endif()
Expand Down Expand Up @@ -874,7 +880,6 @@ check_hdf5_link()

set(CMAKE_REQUIRED_LIBRARIES)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH ${_use_sys_env_path})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(HDF5
Expand Down
4 changes: 2 additions & 2 deletions cmake/libraries.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"zlib": {
"url" : "https://github.com/zlib-ng/zlib-ng.git",
"tag": "2.1.5"
"tag": "2.2.1"
},
"hdf5": {
"url": "https://github.com/HDFGroup/hdf5/archive/refs/tags/hdf5-1_14_3.tar.gz"
"url": "https://github.com/HDFGroup/hdf5/archive/refs/tags/hdf5_1.14.4.3.tar.gz"
}
}

0 comments on commit cb4ae83

Please sign in to comment.