Skip to content

Commit

Permalink
netcdf: add patches, fix MSVC build
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Aug 7, 2024
1 parent 268473e commit 345a256
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/netcdf/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ sources:
url: "https://github.com/Unidata/netcdf-c/archive/v4.7.4.tar.gz"
sha256: "99930ad7b3c4c1a8e8831fb061cb02b2170fc8e5ccaeda733bd99c3b9d31666b"
patches:
"4.9.2":
- patch_file: "patches/4.9.2-0001-fix-cmake.patch"
patch_description: "fixes for cmake target_link_libraries and using deps"
patch_type: "conan"
- patch_file: "patches/4.9.2-0002-fix-cross-compile.patch"
patch_description: "fixes 'Unable to find the math library' when cross compiling"
patch_type: "conan"
"4.8.1":
- patch_file: "patches/4.8.1-0001-fix-cmake.patch"
patch_description: "fixes for cmake target_link_libraries and using deps"
Expand Down
5 changes: 5 additions & 0 deletions recipes/netcdf/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ def generate(self):
tc.variables["ENABLE_BYTERANGE"] = self.options.byterange
tc.variables["USE_HDF5"] = self.options.with_hdf5
tc.variables["NC_FIND_SHARED_LIBS"] = self.options.with_hdf5 and self.dependencies["hdf5"].options.shared

tc.variables["CMAKE_TRY_COMPILE_CONFIGURATION"] = self.settings.build_type
# The compilation check incorrectly fails on MSVC otherwise:
# error C2168: 'memmove': too few actual parameters for intrinsic function
tc.variables["HAVE_MEMMOVE"] = True
tc.generate()

tc = CMakeDeps(self)
Expand Down
121 changes: 121 additions & 0 deletions recipes/netcdf/all/patches/4.9.2-0001-fix-cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6b39f0e4..76f69653 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -109,8 +109,7 @@
ENDIF()

#Add custom CMake Module
-SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/"
- CACHE INTERNAL "Location of our custom CMake modules.")
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")

# auto-configure style checks, other CMake modules.
INCLUDE(CheckLibraryExists)
@@ -681,10 +680,10 @@
# 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})
+ SET(HDF5_LIBRARIES hdf5::hdf_c hdf5::hdf_hl)
+ SET(HDF5_C_LIBRARIES hdf5::hdf_c)
+ SET(HDF5_C_LIBRARY_hdf5 hdf5::hdf_c)
+ SET(HDF5_HL_LIBRARIES hdf5::hdf_hl)
INCLUDE_DIRECTORIES(${HDF5_INCLUDE_DIR})
MESSAGE(STATUS "Using HDF5 C Library: ${HDF5_C_LIBRARY}")
MESSAGE(STATUS "Using HDF5 HL LIbrary: ${HDF5_HL_LIBRARY}")
@@ -738,7 +737,7 @@
# examples, even though the previous version of what we
# had worked.
#####
- IF(MSVC)
+ IF(0)
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)
@@ -985,11 +984,10 @@

# See if we have libcurl
FIND_PACKAGE(CURL)
-ADD_DEFINITIONS(-DCURL_STATICLIB=1)
INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})

# Define a test flag for have curl library
-IF(CURL_LIBRARIES OR CURL_LIBRARY)
+IF(CURL_LIBRARIES OR CURL_LIBRARIES)
SET(FOUND_CURL TRUE)
ELSE()
SET(FOUND_CURL FALSE)
@@ -2277,6 +2275,8 @@
#####
SET(netCDF_LIB_CORENAME "netcdf")

+add_subdirectory(liblib)
+
#####
# Set the true names of all the libraries, if customized by external project
#####
@@ -2334,8 +2334,6 @@
DESTINATION ${netCDF_BINARY_DIR}/nczarr_test/)
ENDIF()

-add_subdirectory(liblib)
-
IF(ENABLE_PLUGINS)
add_subdirectory(plugins)
ENDIF()
@@ -2403,7 +2401,7 @@
# install them in the binary dir. Grab all of the .libs, put them
# in the libdir.
##
-IF(MSVC)
+IF(0)
FILE(GLOB COPY_FILES ${CMAKE_PREFIX_PATH}/lib/*.lib)
INSTALL(FILES ${COPY_FILES}
DESTINATION ${CMAKE_INSTALL_LIBDIR}

diff --git a/liblib/CMakeLists.txt b/liblib/CMakeLists.txt
index be72612c..e0edb4ca 100644
--- a/liblib/CMakeLists.txt
+++ b/liblib/CMakeLists.txt
@@ -116,7 +116,7 @@
# 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})
+ SET(TLL_LIBS ${HDF5_HL_LIBRARIES} ${HDF5_LIBRARIES} ${TLL_LIBS} ${SZIP_LIBRARY})
ELSE() # Windows CMake defines HDF5_LIBRARIES.
SET(TLL_LIBS ${HDF5_LIBRARIES} ${TLL_LIBS} ${SZIP_LIBRARY})
ENDIF()
@@ -208,3 +208,5 @@
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}")
+
+SET(TLL_LIBS ${TLL_LIBS} PARENT_SCOPE)
diff -ru a/libdap4/CMakeLists.txt b/libdap4/CMakeLists.txt
--- a/libdap4/CMakeLists.txt 2021-08-19 01:49:05.000000000 +0800
+++ b/libdap4/CMakeLists.txt 2022-12-14 15:03:47.416608700 +0800
@@ -7,6 +7,7 @@
SET(dap4_SOURCES d4curlfunctions.c d4fix.c d4data.c d4file.c d4parser.c d4meta.c d4varx.c d4dump.c d4swap.c d4chunk.c d4printer.c d4read.c d4http.c d4util.c d4odom.c d4cvt.c d4debug.c ncd4dispatch.c)

add_library(dap4 OBJECT ${dap4_SOURCES})
+target_link_libraries(dap4 ${TLL_LIBS})

###
# Options related to the man page generation.

diff -ru a/oc2/CMakeLists.txt b/oc2/CMakeLists.txt
--- a/oc2/CMakeLists.txt 2021-08-19 01:49:05.000000000 +0800
+++ b/oc2/CMakeLists.txt 2022-12-14 15:05:29.788474600 +0800
@@ -8,6 +8,7 @@


add_library(oc2 OBJECT ${oc_SOURCES})
+target_link_libraries(oc2 ${TLL_LIBS})

# Apparently fails under cmake
#set(ocprint_FILES ocprint.c )
17 changes: 17 additions & 0 deletions recipes/netcdf/all/patches/4.9.2-0002-fix-cross-compile.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fd6713d..c6312b2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1079,7 +1079,11 @@

# Check for the math library so it can be explicitly linked.
IF(NOT WIN32)
- FIND_LIBRARY(HAVE_LIBM NAMES math m libm)
+ INCLUDE(CheckLibraryExists)
+ CHECK_LIBRARY_EXISTS(m log "" CAN_LINK_LIBM)
+ IF(CAN_LINK_LIBM)
+ SET(HAVE_LIBM m)
+ ENDIF()
IF(NOT HAVE_LIBM)
CHECK_FUNCTION_EXISTS(exp HAVE_LIBM_FUNC)
IF(NOT HAVE_LIBM_FUNC)

0 comments on commit 345a256

Please sign in to comment.