Skip to content

Commit

Permalink
netcdf: apply patches to build system
Browse files Browse the repository at this point in the history
The netCDF CMake build system does not use find_package in a way which
is compatible to conan, so a couple of patches have been required to get
the build running.
  • Loading branch information
d70-t committed Jul 1, 2020
1 parent 0ad1a39 commit 4ee187a
Show file tree
Hide file tree
Showing 5 changed files with 315 additions and 2 deletions.
8 changes: 8 additions & 0 deletions recipes/netcdf/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@ sources:
"4.7.4":
url: "https://github.com/Unidata/netcdf-c/archive/v4.7.4.tar.gz"
sha256: "99930ad7b3c4c1a8e8831fb061cb02b2170fc8e5ccaeda733bd99c3b9d31666b"
patches:
"4.7.4":
- patch_file: "patches/use-CURL_LIBRARIES-in-stead-of-CURL_LIBRARY.patch"
base_path: "source_subfolder"
- patch_file: "patches/disable-makedist.patch"
base_path: "source_subfolder"
- patch_file: "patches/use-find_package-for-hdf5.patch"
base_path: "source_subfolder"
12 changes: 10 additions & 2 deletions recipes/netcdf/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class NetcdfConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
topics = ("array", "dataset", "scientific")

generators = "cmake"
exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake_find_package"
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
Expand Down Expand Up @@ -65,10 +66,12 @@ def _configure_cmake(self):
if not self._cmake:
cmake = CMake(self)
cmake.definitions["CMAKE_INSTALL_PREFIX"] = self.package_folder
cmake.definitions["ENABLE_NETCDF4"] = self.options.with_netcdf4
cmake.definitions["ENABLE_NETCDF_4"] = self.options.with_netcdf4
cmake.definitions["ENABLE_DAP"] = self.options.with_dap
cmake.definitions["BUILD_UTILITIES"] = self.options.with_utilities
cmake.definitions["BUILD_SHARED_LIBS"] = self.options.shared
cmake.definitions["ENABLE_TESTS"] = False
cmake.definitions["NC_FIND_SHARED_LIBS"] = self.options["hdf5"].shared

cmake.configure(
source_folder=self._source_subfolder,
Expand All @@ -78,7 +81,12 @@ def _configure_cmake(self):

return self._cmake

def _patch_sources(self):
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake.build()

Expand Down
25 changes: 25 additions & 0 deletions recipes/netcdf/all/patches/disable-makedist.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -117,11 +117,6 @@ MACRO(CHECK_C_LINKER_FLAG M_FLAG M_RESULT)
SET(CMAKE_REQUIRED_FLAGS "${T_REQ_FLAG}")
ENDMACRO()

-# Enable 'dist and distcheck'.
-# File adapted from http://ensc.de/cmake/FindMakeDist.cmake
-FIND_PACKAGE(MakeDist)
-# End 'enable dist and distcheck'
-
# Set the build type.
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE DEBUG CACHE STRING "Choose the type of build, options are: None, Debug, Release."
@@ -1932,10 +1927,6 @@ INSTALL(PROGRAMS ${netCDF_BINARY_DIR}/nc-config
##
print_conf_summary()

-# Enable Makedist files.
-ADD_MAKEDIST()
-ENABLE_MAKEDIST(README.md COPYRIGHT RELEASE_NOTES.md INSTALL INSTALL.cmake test_prog.c lib_flags.am cmake CMakeLists.txt COMPILE.cmake.txt config.h.cmake.in cmake_uninstall.cmake.in netcdf-config-version.cmake.in netcdf-config.cmake.in FixBundle.cmake.in nc-config.cmake.in configure configure.ac install-sh config.h.in config.sub CTestConfig.cmake.in)
-
#####
# Configure and print the libnetcdf.settings file.
#####
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -854,7 +854,7 @@ ENDIF()
# Option to support byte-range reading of remote datasets
OPTION(ENABLE_BYTERANGE "Enable byte-range access to remote datasets.." OFF)

-IF(NOT CURL_LIBRARY)
+IF(NOT CURL_LIBRARIES)
IF(ENABLE_BYTERANGE)
MESSAGE(FATAL_ERROR "Byte-range support specified, CURL libraries are not found.")
ENDIF()
--- a/liblib/CMakeLists.txt
+++ b/liblib/CMakeLists.txt
@@ -88,7 +88,7 @@ IF(USE_HDF5 OR USE_NETCDF4)
ENDIF()

IF(USE_DAP)
- SET(TLL_LIBS ${TLL_LIBS} ${CURL_LIBRARY})
+ SET(TLL_LIBS ${TLL_LIBS} ${CURL_LIBRARIES})
ENDIF()

IF(USE_HDF4)
250 changes: 250 additions & 0 deletions recipes/netcdf/all/patches/use-find_package-for-hdf5.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -571,175 +571,12 @@ OPTION(USE_HDF5 "Use HDF5." ${ENABLE_NETCDF_4})
IF(USE_HDF5 OR ENABLE_NETCDF_4)
SET(USE_HDF5 ON)
SET(USE_NETCDF4 ON)
- ##
- # 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.
- ##
- 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})
- INCLUDE_DIRECTORIES(${HDF5_INCLUDE_DIR})
- MESSAGE(STATUS "Using HDF5 C Library: ${HDF5_C_LIBRARY}")
- MESSAGE(STATUS "Using HDF5 HL LIbrary: ${HDF5_HL_LIBRARY}")
- 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(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)
-
- #####
- # 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.
- ##
-
- ##
- # Assert HDF5 version meets minimum required version.
- ##
- SET(HDF5_VERSION_REQUIRED 1.8.10)
- SET(HDF5_PAR_FILTER_VERSION 1.10.3)
-
- IF(HDF5_VERSION_STRING AND NOT HDF5_VERSION)
- SET(HDF5_VERSION ${HDF5_VERSION_STRING})
- ENDIF()

- 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 "Found HDF5 libraries version ${HDF5_VERSION}")
- ENDIF()
- ENDIF()
+ FIND_PACKAGE(HDF5 REQUIRED)
+ INCLUDE_DIRECTORIES(${HDF5_INCLUDE_DIRS})
+ MESSAGE(STATUS "Using HDF5 Libraries: ${HDF5_LIBRARIES}")

- # Determine whether parallel filter operation is supported.
- IF(${HDF5_VERSION} VERSION_LESS ${HDF5_PAR_FILTER_VERSION})
- SET(HDF5_HAS_PAR_FILTERS, "no")
- ELSE()
- SET(HDF5_HAS_PAR_FILTERS, "yes")
- ENDIF()
-
- ##
- # 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}")
- INCLUDE_DIRECTORIES(${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)
- ##
- # 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()
-
- 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)
-
- 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()
-
- # 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()
-
- #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 to see if H5Z_SZIP exists in HDF5_Libraries. If so, we must use szip.
- CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5Z_SZIP "" USE_SZIP)
- IF(USE_SZIP)
- FIND_LIBRARY(SZIP NAMES szip sz)
- IF(SZIP)
- SET(HAVE_H5Z_SZIP 1)
- SET(SZIP_LIBRARY ${SZIP})
- SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${SZIP})
- MESSAGE(STATUS "HDF5 has szip.")
- ELSE()
- MESSAGE(FATAL_ERROR "HDF5 Requires SZIP, but cannot find libszip or libsz.")
- ENDIF()
- ENDIF()
-
- CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5Pset_libver_bounds "" HAVE_H5PSET_LIBVER_BOUNDS)
- CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5free_memory "" HAVE_H5FREE_MEMORY)
- CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5allocate_memory "" HAVE_H5ALLOCATE_MEMORY)
- CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5resize_memory "" HAVE_H5RESIZE_MEMORY)
+ SET(HDF5_PARALLEL OFF)

IF(HDF5_PARALLEL)
SET(HDF5_CC h5pcc)
@@ -747,39 +584,13 @@ IF(USE_HDF5 OR ENABLE_NETCDF_4)
SET(HDF5_CC h5cc)
ENDIF()

- # Check to see if this is hdf5-1.10.3 or later.
- CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5Dread_chunk "" HDF5_SUPPORTS_PAR_FILTERS)
-
- SET(H5_USE_16_API 1)
- OPTION(NC_ENABLE_HDF_16_API "Enable HDF5 1.6.x Compatibility(Required)" ON)
- IF(NOT NC_ENABLE_HDF_16_API)
- SET(H5_USE_16_API 0)
- ENDIF()
+ SET(H5_USE_16_API 1)

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)
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)
- INCLUDE_DIRECTORIES(${HAVE_HDF5_H})
ENDIF(NOT HAVE_HDF5_H)

- # Check to ensure that HDF5 was built with zlib.
- set (CMAKE_REQUIRED_INCLUDES ${HAVE_HDF5_H})
- CHECK_C_SOURCE_COMPILES("#include <H5pubconf.h>
- #if !H5_HAVE_ZLIB_H
- #error
- #endif
- int main() {
- int x = 1;}" HAVE_HDF5_ZLIB)
- IF(NOT HAVE_HDF5_ZLIB)
- MESSAGE(FATAL_ERROR "HDF5 was built without zlib. Rebuild HDF5 with zlib.")
- ENDIF()
-
- #option to include HDF5 High Level header file (hdf5_hl.h) in case we are not doing a make install
- INCLUDE_DIRECTORIES(${HDF5_HL_INCLUDE_DIR})
-
-
ENDIF(USE_HDF5 OR ENABLE_NETCDF_4)

# See if we have libcurl
--- a/liblib/CMakeLists.txt
+++ b/liblib/CMakeLists.txt
@@ -68,23 +68,7 @@ IF(HAVE_LIBDL)
ENDIF()

IF(USE_HDF5 OR USE_NETCDF4)
- 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} ${TLL_LIBS} ${SZIP_LIBRARY})
- ELSE() # Windows CMake defines HDF5_LIBRARIES.
- SET(TLL_LIBS ${HDF5_LIBRARIES} ${TLL_LIBS} ${SZIP_LIBRARY})
- ENDIF()
+ SET(TLL_LIBS ${HDF5_LIBRARIES} ${TLL_LIBS} ${SZIP_LIBRARY})
ENDIF()

IF(USE_DAP)

0 comments on commit 4ee187a

Please sign in to comment.