Skip to content

Commit

Permalink
(#3350) netcdf: add netcdf/4.7.4 recipe
Browse files Browse the repository at this point in the history
* netcdf: add netcdf/4.7.4 recipe

* netcdf: patch find_package(HDF5) for MSVC + remove installed msvcrt dll's

* netcdf: fix shared Debug on Linux

* netcdf: fix license + topics

Co-authored-by: Uilian Ries <[email protected]>

* netcdf: remove unused build_requirements

Co-authored-by: Uilian Ries <[email protected]>
  • Loading branch information
madebr and uilianries authored Jan 7, 2021
1 parent d20f489 commit 04873b0
Show file tree
Hide file tree
Showing 10 changed files with 356 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/netcdf/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory(source_subfolder)
12 changes: 12 additions & 0 deletions recipes/netcdf/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sources:
"4.7.4":
url: "https://github.com/Unidata/netcdf-c/archive/v4.7.4.tar.gz"
sha256: "99930ad7b3c4c1a8e8831fb061cb02b2170fc8e5ccaeda733bd99c3b9d31666b"
patches:
"4.7.4":
- base_path: "source_subfolder"
patch_file: "patches/0001-cmake-subproject.patch"
- base_path: "source_subfolder"
patch_file: "patches/0002-cmake-msvc.patch"
- base_path: "source_subfolder"
patch_file: "patches/0003-cmake-HDF5-cmake-components-wrong.patch"
119 changes: 119 additions & 0 deletions recipes/netcdf/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
from conans import CMake, ConanFile, tools
import glob
import os


class NetcdfConan(ConanFile):
name = "netcdf"
description = "The Unidata network Common Data Form (netCDF) is an interface for scientific data access and a freely-distributed software library that provides an implementation of the interface."
topics = ("unidata", "unidata-netcdf", "networking")
license = "BSD-3-Clause"
homepage = "https://github.com/Unidata/netcdf-c"
url = "https://github.com/conan-io/conan-center-index"
settings = "os", "arch", "compiler", "build_type"
exports_sources = "CMakeLists.txt", "patches/**"
options = {
"shared": [True, False],
"fPIC": [True, False],
"netcdf4": [True, False],
"with_hdf5": [True, False],
"cdf5": [True, False],
"dap": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"netcdf4": True,
"with_hdf5": True,
"cdf5": True,
"dap": True,
}
generators = "cmake_find_package", "cmake_find_package_multi", "cmake"

_cmake = None

@property
def _with_hdf5(self):
return self.options.with_hdf5 or self.options.netcdf4

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd

def requirements(self):
if self._with_hdf5:
self.requires("hdf5/1.12.0")
if self.options.dap:
self.requires("libcurl/7.73.0")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
os.rename("netcdf-c-{}".format(self.version), self._source_subfolder)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_TESTING"] = False
self._cmake.definitions["BUILD_UTILITIES"] = False
self._cmake.definitions["ENABLE_TESTS"] = False

self._cmake.definitions["ENABLE_NETCDF_4"] = self.options.netcdf4
self._cmake.definitions["ENABLE_CDF5"] = self.options.cdf5
self._cmake.definitions["ENABLE_DAP"] = self.options.dap
self._cmake.definitions["USE_HDF5"] = self.options.with_hdf5
self._cmake.definitions["NC_FIND_SHARED_LIBS"] = self.options.with_hdf5 and self.options["hdf5"].shared
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)

cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy("COPYRIGHT", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
cmake.install()

os.unlink(os.path.join(self.package_folder, "bin", "nc-config"))
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.settings")
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "share"))
for fn in glob.glob(os.path.join(self.package_folder, "bin", "*")):
if "netcdf" not in os.path.basename(fn):
os.unlink(fn)

def package_info(self):
self.cpp_info.names["pkg_config"] = "netcdf"
self.cpp_info.names["cmake_find_package"] = "netCDF"
self.cpp_info.names["cmake_find_package_multi"] = "netCDF"
self.cpp_info.components["libnetcdf"].libs = ["netcdf"]
self.cpp_info.components["libnetcdf"].names["cmake_find_package"] = "netcdf"
self.cpp_info.components["libnetcdf"].names["cmake_find_package_multi"] = "netcdf"
if self._with_hdf5:
self.cpp_info.components["libnetcdf"].requires.append("hdf5::hdf5")
if self.options.dap:
self.cpp_info.components["libnetcdf"].requires.append("libcurl::libcurl")
if self.settings.os == "Linux":
self.cpp_info.components["libnetcdf"].system_libs = ["dl", "m"]
elif self.settings.os == "Windows":
if self.options.shared:
self.cpp_info.components["libnetcdf"].defines.append("DLL_NETCDF")
157 changes: 157 additions & 0 deletions recipes/netcdf/all/patches/0001-cmake-subproject.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -85,8 +85,8 @@ IF(MSVC)
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)
@@ -393,17 +393,17 @@ IF(NOT MSVC)
SET(BUILD_FORTRAN ON)
ENDIF()
IF(BUILD_FORTRAN)
- CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/postinstall.sh.in"
- "${CMAKE_BINARY_DIR}/postinstall.sh"
+ CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/postinstall.sh.in"
+ "${PROJECT_BINARY_DIR}/postinstall.sh"
@ONLY)

ADD_CUSTOM_TARGET(build-netcdf-fortran
- COMMAND sh -c "${CMAKE_BINARY_DIR}/postinstall.sh -t cmake -a build"
+ COMMAND sh -c "${PROJECT_BINARY_DIR}/postinstall.sh -t cmake -a build"
DEPENDS netcdf
)

ADD_CUSTOM_TARGET(install-netcdf-fortran
- COMMAND sh -c "${CMAKE_BINARY_DIR}/postinstall.sh -t cmake -a install"
+ COMMAND sh -c "${PROJECT_BINARY_DIR}/postinstall.sh -t cmake -a install"
DEPENDS build-netcdf-fortran
)

@@ -788,7 +788,7 @@
ENDIF(USE_HDF5 OR ENABLE_NETCDF_4)

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

@@ -854,4 +854,4 @@
# 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()
@@ -1193,8 +1193,8 @@ IF(ENABLE_DOXYGEN)
###
OPTION(ENABLE_DOXYGEN_BUILD_RELEASE_DOCS "Build release documentation. This is of interest only to the netCDF developers." OFF)
IF(ENABLE_DOXYGEN_BUILD_RELEASE_DOCS)
- SET(DOXYGEN_CSS_FILE "${CMAKE_SOURCE_DIR}/docs/release.css" CACHE STRING "")
- SET(DOXYGEN_HEADER_FILE "${CMAKE_SOURCE_DIR}/docs/release_header.html" CACHE STRING "")
+ SET(DOXYGEN_CSS_FILE "${PROJECT_SOURCE_DIR}/docs/release.css" CACHE STRING "")
+ SET(DOXYGEN_HEADER_FILE "${PROJECT_SOURCE_DIR}/docs/release_header.html" CACHE STRING "")
SET(DOXYGEN_SEARCHENGINE "NO" CACHE STRING "")
SET(ENABLE_DOXYGEN_SERVER_BASED_SEARCH NO CACHE STRING "")
ELSE()
@@ -1499,7 +1499,7 @@ MACRO(add_bin_env_temp_large_test prefix F)
)
ENDIF()

- ADD_TEST(${prefix}_${F} bash "-c" "TEMP_LARGE=${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${prefix}_${F}")
+ ADD_TEST(${prefix}_${F} bash "-c" "TEMP_LARGE=${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${prefix}_${F}")
IF(MSVC)
SET_PROPERTY(TARGET ${prefix}_${F} PROPERTY FOLDER "tests")
SET_TARGET_PROPERTIES(${prefix}_${F} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
@@ -1680,7 +1680,7 @@ ENDIF(ENABLE_BASH_SCRIPT_TESTING)

MACRO(add_sh_test prefix F)
IF(HAVE_BASH)
- ADD_TEST(${prefix}_${F} bash "-c" "export srcdir=${CMAKE_CURRENT_SOURCE_DIR};export TOPSRCDIR=${CMAKE_SOURCE_DIR};${CMAKE_CURRENT_BINARY_DIR}/${F}.sh")
+ ADD_TEST(${prefix}_${F} bash "-c" "export srcdir=${CMAKE_CURRENT_SOURCE_DIR};export TOPSRCDIR=${PROJECT_SOURCE_DIR};${CMAKE_CURRENT_BINARY_DIR}/${F}.sh")
ENDIF()
ENDMACRO()

--- cmake/modules/FindMakeDist.cmake
+++ cmake/modules/FindMakeDist.cmake
@@ -153,9 +153,9 @@ macro(enable_makedist)
get_source_file_property(__makedist_extradist "${__makedist_source}" EXTRADIST)

if(NOT __makedist_generated)
- file(RELATIVE_PATH __makedist_cur_path "${CMAKE_SOURCE_DIR}" "${__makedist_full_cur_path}")
+ file(RELATIVE_PATH __makedist_cur_path "${PROJECT_SOURCE_DIR}" "${__makedist_full_cur_path}")
elseif(__makedist_extradist)
- file(RELATIVE_PATH __makedist_cur_path "${CMAKE_BINARY_DIR}" "${__makedist_full_cur_path}")
+ file(RELATIVE_PATH __makedist_cur_path "${PROJCT_BINARY_DIR}" "${__makedist_full_cur_path}")
else(__makedist_extradist)
set(__makedist_cur_path)
endif(NOT __makedist_generated)
--- docs/CMakeLists.txt
+++ docs/CMakeLists.txt
@@ -11,12 +11,12 @@
IF(ENABLE_DOXYGEN)
# The following is redundant but does not hurt anything.

- FILE(GLOB COPY_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.html ${CMAKE_CURRENT_SOURCE_DIR}/images ${CMAKE_CURRENT_SOURCE_DIR}/*.doc ${CMAKE_CURRENT_SOURCE_DIR}/*.xml ${CMAKE_CURRENT_SOURCE_DIR}/*.m4 ${CMAKE_CURRENT_SOURCE_DIR}/*.texi ${CMAKE_SOURCE_DIR}/oc2/auth.html.in)
+ FILE(GLOB COPY_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.html ${CMAKE_CURRENT_SOURCE_DIR}/images ${CMAKE_CURRENT_SOURCE_DIR}/*.doc ${CMAKE_CURRENT_SOURCE_DIR}/*.xml ${CMAKE_CURRENT_SOURCE_DIR}/*.m4 ${CMAKE_CURRENT_SOURCE_DIR}/*.texi ${PROJECT_SOURCE_DIR}/oc2/auth.html.in)
FILE(COPY ${COPY_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)

# Set abs_top_srcdir to work with the autotools
# doxyfile template.
- SET(abs_top_srcdir ${CMAKE_SOURCE_DIR})
+ SET(abs_top_srcdir ${PROJECT_SOURCE_DIR})
SET(abs_builddir ${CMAKE_CURRENT_BINARY_DIR})

# Create general and guide doxyfiles.
@@ -34,7 +34,7 @@ IF(ENABLE_DOXYGEN)
# Create auth.html with some sed commands.
ADD_CUSTOM_TARGET(oc2-auth

- cat ${CMAKE_SOURCE_DIR}/oc2/auth.html.in | sed -e "/<OC>/d" | sed -e "s|^<NC>||" | sed -e "s|zz|netcdf|g" -e "s|ZZ|netCDF|g" | sed -e "/stylesheet/r${CMAKE_SOURCE_DIR}/oc2/oc.css" -e "/stylesheet/d" > ${CMAKE_CURRENT_SOURCE_DIR}/auth.html
+ cat ${PROJECT_SOURCE_DIR}/oc2/auth.html.in | sed -e "/<OC>/d" | sed -e "s|^<NC>||" | sed -e "s|zz|netcdf|g" -e "s|ZZ|netCDF|g" | sed -e "/stylesheet/r${PROJECT_SOURCE_DIR}/oc2/oc.css" -e "/stylesheet/d" > ${CMAKE_CURRENT_SOURCE_DIR}/auth.html
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/auth.html ${CMAKE_CURRENT_BINARY_DIR}/html
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
--- nc_test/CMakeLists.txt
+++ nc_test/CMakeLists.txt
@@ -5,15 +5,15 @@

# See netcdf-c/COPYRIGHT file for more info.

-message(STATUS "CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR}")
-message(STATUS "CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}")
+message(STATUS "PROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}")
+message(STATUS "PROJECT_BINARY_DIR=${PROJECT_BINARY_DIR}")
message(STATUS "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}")

-add_definitions(-D"TOPSRCDIR=${CMAKE_SOURCE_DIR}")
-add_definitions(-D"TOPBINDIR=${CMAKE_BINARY_DIR}")
+add_definitions(-D"TOPSRCDIR=${PROJECT_SOURCE_DIR}")
+add_definitions(-D"TOPBINDIR=${PROJECT_BINARY_DIR}")

-INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/include)
+INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR}/include)

SET (nc_test_m4_SOURCES test_get test_put test_read test_write)
FOREACH (F ${nc_test_m4_SOURCES})
--- liblib/CMakeLists.txt
+++ 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)
11 changes: 11 additions & 0 deletions recipes/netcdf/all/patches/0002-cmake-msvc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -615,7 +615,7 @@
# examples, even though the previous version of what we
# had worked.
#####
- IF(MSVC)
+ IF(0)#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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
conan-center-index is currently not able to correctly the components of HDF5.

--- liblib/CMakeLists.txt
+++ liblib/CMakeLists.txt
@@ -81,7 +81,7 @@
# 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})
+ 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()
10 changes: 10 additions & 0 deletions recipes/netcdf/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup(TARGETS)

find_package(netCDF REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} netCDF::netcdf)
17 changes: 17 additions & 0 deletions recipes/netcdf/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
7 changes: 7 additions & 0 deletions recipes/netcdf/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "netcdf.h"
#include <stdio.h>

int main() {
printf("netcdf version: %s\n", nc_inq_libvers());
return 0;
}
3 changes: 3 additions & 0 deletions recipes/netcdf/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"4.7.4":
folder: "all"

0 comments on commit 04873b0

Please sign in to comment.