netcdf-c package: fix hdf5 linking on Windows (#42749)

This commit is contained in:
John W. Parent 2024-02-22 16:18:34 -05:00 committed by GitHub
parent b61d964eb8
commit f514e72011
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 53 additions and 9 deletions

View file

@ -1,8 +1,34 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9b057311..37e96a96 100644
index de95010c..25229f9c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1471,6 +1471,7 @@ ENDIF()
@@ -664,6 +664,7 @@ ENDIF(ENABLE_STRICT_NULL_BYTE_HEADER_PADDING)
# *
##
SET(USE_HDF5 ${ENABLE_HDF5})
+SET(IMPORT_HDF5 "")
IF(USE_HDF5)
##
@@ -671,7 +672,6 @@ IF(USE_HDF5)
##
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
@@ -744,6 +744,9 @@ IF(USE_HDF5)
ELSE(MSVC)
FIND_PACKAGE(HDF5 COMPONENTS C HL REQUIRED)
ENDIF(MSVC)
+ # Export HDF5 Dependency so consumers can properly use
+ # exported link interface
+ set(IMPORT_HDF5 "find_dependency(HDF5 COMPONENTS C HL)")
##
# Next, check the HDF5 version. This will inform which
@@ -1481,6 +1484,7 @@ ENDIF()
# Enable Parallel IO with netCDF-4/HDF5 files using HDF5 parallel I/O.
SET(STATUS_PARALLEL "OFF")
@ -10,14 +36,23 @@ index 9b057311..37e96a96 100644
OPTION(ENABLE_PARALLEL4 "Build netCDF-4 with parallel IO" "${HDF5_PARALLEL}")
IF(ENABLE_PARALLEL4 AND ENABLE_HDF5)
IF(NOT HDF5_PARALLEL)
@@ -1492,6 +1493,7 @@ IF(ENABLE_PARALLEL4 AND ENABLE_HDF5)
@@ -1502,6 +1506,7 @@ IF(ENABLE_PARALLEL4 AND ENABLE_HDF5)
FILE(COPY "${netCDF_BINARY_DIR}/tmp/run_par_tests.sh"
DESTINATION ${netCDF_BINARY_DIR}/h5_test
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
+ set(IMPORT_MPI "include(CMakeFindDependencyMacro)\nfind_dependency(mpi COMPONENTS C)")
+ set(IMPORT_MPI "find_dependency(MPI COMPONENTS C)")
ENDIF()
ENDIF()
@@ -2652,6 +2657,8 @@ endif(DEFINED ENV{LIB_FUZZING_ENGINE})
# cmake should be able to find netcdf using find_package and find_library.
# The EXPORT call is paired with one in liblib.
set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/netCDF)
+set(IMPORT_FIND_DEP "include(CMakeFindDependencyMacro)")
+
install(EXPORT netCDFTargets
DESTINATION ${ConfigPackageLocation}
diff --git a/liblib/CMakeLists.txt b/liblib/CMakeLists.txt
index e3eddc0f..0493cb9d 100644
--- a/liblib/CMakeLists.txt
@ -31,14 +66,16 @@ index e3eddc0f..0493cb9d 100644
IF(MOD_NETCDF_NAME)
diff --git a/netCDFConfig.cmake.in b/netCDFConfig.cmake.in
index 9d68eec5..dae2429e 100644
index 9d68eec5..eece09cb 100644
--- a/netCDFConfig.cmake.in
+++ b/netCDFConfig.cmake.in
@@ -14,6 +14,8 @@ set(netCDF_LIBRARIES netCDF::netcdf)
@@ -14,6 +14,10 @@ set(netCDF_LIBRARIES netCDF::netcdf)
# include target information
include("${CMAKE_CURRENT_LIST_DIR}/netCDFTargets.cmake")
+@IMPORT_FIND_DEP@
+@IMPORT_MPI@
+@IMPORT_HDF5@
+
# Compiling Options
#

View file

@ -58,9 +58,12 @@ class NetcdfC(CMakePackage, AutotoolsPackage):
# with the following patch:
patch("4.8.1-win-hdf5-with-zlib.patch", when="@4.8.1: platform=windows")
# TODO: fetch from the upstream repo once https://github.com/Unidata/netcdf-c/pull/2595
# is accepted:
patch("netcdfc-mpi-win-support.patch", when="platform=windows")
# TODO: https://github.com/Unidata/netcdf-c/pull/2595 contains some of the changes
# made in this patch but is not sufficent to replace the patch. There is currently
# no upstream PR (or set of PRs) covering all changes in this path.
# When #2595 lands, this patch should be updated to include only
# the changes not incorporated into that PR
patch("netcdfc_correct_and_export_link_interface.patch", when="platform=windows")
# Some of the patches touch configure.ac and, therefore, require forcing the autoreconf stage:
_force_autoreconf_when = []
@ -342,6 +345,10 @@ def cmake_args(self):
if "platform=windows" in self.pkg.spec:
# Enforce the usage of the vendored version of bzip2 on Windows:
base_cmake_args.append(self.define("Bz2_INCLUDE_DIRS", ""))
if "+shared" in self.pkg.spec["hdf5"]:
base_cmake_args.append(self.define("NC_FIND_SHARED_LIBS", True))
else:
base_cmake_args.append(self.define("NC_FIND_SHARED_LIBS", False))
return base_cmake_args