Skip to content

Commit b7d0007

Browse files
committed
netcdf-c: code review
1 parent 0b3e7fd commit b7d0007

15 files changed

+314
-464
lines changed

Diff for: recipes/netcdf-c/all/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(cmake_wrapper)
3+
4+
include(conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
add_subdirectory("source_subfolder")

Diff for: recipes/netcdf-c/all/conandata.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sources:
2+
"4.7.4":
3+
url: "https://github.com/Unidata/netcdf-c/archive/v4.7.4.tar.gz"
4+
sha256: "99930ad7b3c4c1a8e8831fb061cb02b2170fc8e5ccaeda733bd99c3b9d31666b"
5+
patches:
6+
"4.7.4":
7+
- patch_file: "patches/fix-cmake.patch"
8+
base_path: "source_subfolder"

Diff for: recipes/netcdf-c/all/conanfile.py

+200
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
import glob
2+
import os
3+
4+
from conans import ConanFile, CMake, tools
5+
from conans.errors import ConanInvalidConfiguration
6+
7+
class NetcdfConan(ConanFile):
8+
name = "netcdf-c"
9+
description = "The Unidata network Common Data Form (netCDF) is an interface " \
10+
"for scientific data access and a freely-distributed software " \
11+
"library that provides an implementation of the interface."
12+
license = "BSD-3-Clause"
13+
topics = ("conan", "netcdf-c", "netcdf", "array", "dataset", "scientific")
14+
homepage = "https://www.unidata.ucar.edu/software/netcdf"
15+
url = "https://github.com/conan-io/conan-center-index"
16+
exports_sources = ["CMakeLists.txt", "patches/**"]
17+
generators = "cmake", "cmake_find_package"
18+
settings = "os", "arch", "compiler", "build_type"
19+
options = {
20+
"shared": [True, False],
21+
"fPIC": [True, False],
22+
"build_utilities": [True, False],
23+
"netcdf4": [True, False],
24+
"with_hdf4": [True, False],
25+
"with_hdf5": [True, False],
26+
"dap": [True, False],
27+
"parallel": [True, False],
28+
}
29+
default_options = {
30+
"shared": False,
31+
"fPIC": True,
32+
"build_utilities": True,
33+
"netcdf4": True,
34+
"with_hdf4": False,
35+
"with_hdf5": True,
36+
"dap": True,
37+
"parallel": False,
38+
}
39+
40+
_cmake = None
41+
42+
@property
43+
def _source_subfolder(self):
44+
return "source_subfolder"
45+
46+
@property
47+
def _build_subfolder(self):
48+
return "build_subfolder"
49+
50+
def config_options(self):
51+
if self.settings.os == "Windows":
52+
del self.options.fPIC
53+
54+
def configure(self):
55+
if self.options.shared:
56+
del self.options.fPIC
57+
del self.settings.compiler.cppstd
58+
del self.settings.compiler.libcxx
59+
60+
if self.options.netcdf4 and not self.options.with_hdf5:
61+
raise ConanInvalidConfiguration("netcdf4 requires hdf5")
62+
if not self.options.netcdf4:
63+
if self.options.with_hdf4:
64+
raise ConanInvalidConfiguration("netcdf4 is required for hdf4 features")
65+
if self.options.parallel:
66+
raise ConanInvalidConfiguration("netcdf4 is required for parallel IO")
67+
self._strict_options_requirements()
68+
69+
def _strict_options_requirements(self):
70+
if self.options.with_hdf5:
71+
self.options["hdf5"].with_zlib = True
72+
self.options["hdf5"].hl = True
73+
if self.options.parallel:
74+
raise ConanInvalidConfiguration("parallel option requires openmpi which is not yet available in CCI")
75+
self.options["hdf5"].parallel = True # TODO: option not yet available in hdf5 recipe, requires openmpi in CCI
76+
77+
def requirements(self):
78+
if self.options.with_hdf4:
79+
self.requires("hdf4/4.2.15")
80+
if self.options.with_hdf5:
81+
self.requires("hdf5/1.12.0")
82+
if self.options.dap:
83+
self.requires("libcurl/7.72.0")
84+
if self.options.parallel:
85+
self.requires("openmpi/4.0.3")
86+
87+
def _validate_dependency_graph(self):
88+
if self.options.with_hdf5:
89+
if not (self.options["hdf5"].with_zlib and self.options["hdf5"].hl):
90+
raise ConanInvalidConfiguration("netcdf-c requires hdf5 with zlib and hl")
91+
if self.options.parallel and not self.options["hdf5"].parallel:
92+
raise ConanInvalidConfiguration("netcdf-c parallel requires hdf5 parallel")
93+
94+
def source(self):
95+
tools.get(**self.conan_data["sources"][self.version])
96+
os.rename(self.name + "-" + self.version, self._source_subfolder)
97+
98+
def build(self):
99+
self._validate_dependency_graph()
100+
for patch in self.conan_data.get("patches", {}).get(self.version, []):
101+
tools.patch(**patch)
102+
cmake = self._configure_cmake()
103+
cmake.build()
104+
105+
def _configure_cmake(self):
106+
if self._cmake:
107+
return self._cmake
108+
cmake = CMake(self)
109+
if self.settings.compiler == "Visual Studio":
110+
cmake.definitions["NC_USE_STATIC_CRT"] = str(self.settings.compiler.runtime).startswith("MT")
111+
cmake.definitions["ENABLE_V2_API"] = True
112+
cmake.definitions["BUILD_UTILITIES"] = self.options.build_utilities
113+
cmake.definitions["ENABLE_MMAP"] = True
114+
cmake.definitions["ENABLE_EXAMPLES"] = False
115+
cmake.definitions["ENABLE_HDF4"] = self.options.with_hdf4
116+
if self.options.with_hdf4:
117+
cmake.definitions["ENABLE_HDF4_FILE_TESTS"] = False
118+
cmake.definitions["ENABLE_NETCDF_4"] = self.options.netcdf4
119+
cmake.definitions["ENABLE_LOGGING"] = False
120+
cmake.definitions["ENABLE_SET_LOG_LEVEL_FUNC"] = True
121+
cmake.definitions["ENABLE_STRICT_NULL_BYTE_HEADER_PADDING"] = False
122+
cmake.definitions["ENABLE_RPC"] = False
123+
cmake.definitions["USE_HDF5"] = self.options.with_hdf5
124+
if self.options.with_hdf5:
125+
cmake.definitions["NC_ENABLE_HDF_16_API"] = True
126+
cmake.definitions["ENABLE_DAP"] = self.options.dap
127+
cmake.definitions["ENABLE_BYTERANGE"] = False
128+
cmake.definitions["ENABLE_DAP_LONG_TESTS"] = False
129+
cmake.definitions["ENABLE_DAP_REMOTE_TESTS"] = False
130+
cmake.definitions["ENABLE_EXTRA_TESTS"] = False
131+
if self.settings.compiler == "Visual Studio":
132+
cmake.definitions["ENABLE_XGETOPT"] = True
133+
if self.settings.os != "Windows":
134+
cmake.definitions["ENABLE_STDIO"] = False
135+
cmake.definitions["ENABLE_FFIO"] = False
136+
cmake.definitions["ENABLE_TESTS"] = False
137+
cmake.definitions["ENABLE_EXTREME_NUMBERS"] = False
138+
cmake.definitions["ENABLE_METADATA_PERF_TESTS"] = False
139+
cmake.definitions["ENABLE_FSYNC"] = False # Option?
140+
cmake.definitions["ENABLE_JNA"] = False
141+
cmake.definitions["ENABLE_LARGE_FILE_SUPPORT"] = True # Option?
142+
cmake.definitions["ENABLE_EXAMPLE_TESTS"] = False
143+
cmake.definitions["ENABLE_PARALLEL4"] = self.options.parallel
144+
cmake.definitions["ENABLE_PNETCDF"] = False
145+
cmake.definitions["ENABLE_ERANGE_FILL"] = False
146+
cmake.definitions["ENABLE_PARALLEL_TESTS"] = False
147+
cmake.definitions["ENABLE_FILTER_TESTING"] = False
148+
cmake.definitions["ENABLE_CLIENTSIDE_FILTERS"] = False
149+
cmake.definitions["ENABLE_DOXYGEN"] = False
150+
cmake.definitions["ENABLE_DISKLESS"] = True
151+
if self.settings.compiler == "Visual Studio":
152+
cmake.definitions["NC_MSVC_STACK_SIZE"] = 40000000 # Option?
153+
cmake.definitions["ENABLE_CDF5"] = True
154+
cmake.definitions["ENABLE_BASH_SCRIPT_TESTING"] = False
155+
cmake.configure(build_folder=self._build_subfolder)
156+
self._cmake = cmake
157+
return self._cmake
158+
159+
def package(self):
160+
self.copy("COPYRIGHT", dst="licenses", src=self._source_subfolder)
161+
cmake = self._configure_cmake()
162+
cmake.install()
163+
if self.options.build_utilities or (self.options.shared and self.settings.os == "Windows"):
164+
os.remove(os.path.join(self.package_folder, "bin", "nc-config"))
165+
else:
166+
tools.rmdir(os.path.join(self.package_folder, "bin"))
167+
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
168+
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
169+
os.remove(os.path.join(self.package_folder, "lib", "libnetcdf.settings"))
170+
tools.rmdir(os.path.join(self.package_folder, "share"))
171+
if self.options.shared and self.settings.compiler == "Visual Studio":
172+
for dll_pattern_to_remove in ["concrt*.dll", "msvcp*.dll", "vcruntime*.dll"]:
173+
for dll_to_remove in glob.glob(os.path.join(self.package_folder, "bin", dll_pattern_to_remove)):
174+
os.remove(dll_to_remove)
175+
176+
def package_info(self):
177+
self.cpp_info.names["cmake_find_package"] = "netCDF"
178+
self.cpp_info.names["cmake_find_package_multi"] = "netCDF"
179+
self.cpp_info.names["pkg_config"] = "netcdf"
180+
self.cpp_info.components["netcdf"].names["cmake_find_package"] = "netcdf"
181+
self.cpp_info.components["netcdf"].names["cmake_find_package_multi"] = "netcdf"
182+
self.cpp_info.components["netcdf"].names["pkg_config"] = "netcdf"
183+
self.cpp_info.components["netcdf"].libs = ["netcdf"]
184+
if self.options.with_hdf4:
185+
self.cpp_info.components["netcdf"].requires.append("hdf4::hdf4")
186+
if self.options.with_hdf5:
187+
self.cpp_info.components["netcdf"].requires.append("hdf5::hdf5") # TODO: when components available in hdf5 recipe => requires.extend([hdf5::hl, hdf5::c])
188+
if self.options.dap:
189+
self.cpp_info.components["netcdf"].requires.append("libcurl::libcurl")
190+
if self.options.parallel:
191+
self.cpp_info.components["netcdf"].requires.append("openmpi::openmpi")
192+
if self.settings.os == "Linux":
193+
self.cpp_info.components["netcdf"].system_libs = ["m"]
194+
if self.settings.os == "Windows" and self.options.shared:
195+
self.cpp_info.components["netcdf"].defines.append("DLL_NETCDF")
196+
197+
if self.options.build_utilities:
198+
bin_path = os.path.join(self.package_folder, "bin")
199+
self.output.info("Appending PATH environment variable: {}".format(bin_path))
200+
self.env_info.PATH.append(bin_path)

Diff for: recipes/netcdf-c/all/patches/fix-cmake.patch

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
--- a/CMakeLists.txt
2+
+++ b/CMakeLists.txt
3+
@@ -85,8 +85,7 @@ IF(MSVC)
4+
ENDIF()
5+
6+
#Add custom CMake Module
7+
-SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/"
8+
- CACHE INTERNAL "Location of our custom CMake modules.")
9+
+SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")
10+
11+
# auto-configure style checks, other CMake modules.
12+
INCLUDE(CheckLibraryExists)
13+
@@ -441,6 +440,11 @@ ENDIF()
14+
OPTION(ENABLE_HDF4 "Build netCDF-4 with HDF4 read capability(HDF4, HDF5 and Zlib required)." OFF)
15+
IF(ENABLE_HDF4)
16+
SET(USE_HDF4 ON)
17+
+ SET(HAVE_LIBMFHDF TRUE)
18+
+ SET(HAVE_LIBJPEG ON)
19+
+ link_libraries(CONAN_PKG::hdf4)
20+
+ENDIF()
21+
+IF(FALSE)
22+
# Check for include files, libraries.
23+
24+
FIND_PATH(MFHDF_H_INCLUDE_DIR mfhdf.h)
25+
@@ -576,13 +580,14 @@ OPTION(USE_HDF5 "Use HDF5." ${ENABLE_NETCDF_4})
26+
IF(USE_HDF5 OR ENABLE_NETCDF_4)
27+
SET(USE_HDF5 ON)
28+
SET(USE_NETCDF4 ON)
29+
+ link_libraries(CONAN_PKG::hdf5)
30+
##
31+
# Accommodate developers who have hdf5 libraries and
32+
# headers on their system, but do not have a the hdf
33+
# .cmake files. If this is the case, they should
34+
# specify HDF5_HL_LIBRARY, HDF5_LIBRARY, HDF5_INCLUDE_DIR manually.
35+
##
36+
- IF(HDF5_C_LIBRARY AND HDF5_HL_LIBRARY AND HDF5_INCLUDE_DIR)
37+
+ IF(TRUE)
38+
SET(HDF5_LIBRARIES ${HDF5_C_LIBRARY} ${HDF5_HL_LIBRARY})
39+
SET(HDF5_C_LIBRARIES ${HDF5_C_LIBRARY})
40+
SET(HDF5_C_LIBRARY_hdf5 ${HDF5_C_LIBRARY})
41+
@@ -717,6 +722,7 @@ IF(USE_HDF5 OR ENABLE_NETCDF_4)
42+
# Use H5Pset_fapl_mpio and H5Pget_fapl_mpio, instead.
43+
# CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5Pget_fapl_mpiposix "" HDF5_IS_PARALLEL_MPIPOSIX)
44+
45+
+ SET(HDF5_C_LIBRARY_hdf5 ${CONAN_LIBS_HDF5})
46+
CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5Pget_fapl_mpio "" HDF5_IS_PARALLEL_MPIO)
47+
IF(HDF5_IS_PARALLEL_MPIO)
48+
SET(HDF5_PARALLEL ON)
49+
@@ -754,6 +760,7 @@ IF(USE_HDF5 OR ENABLE_NETCDF_4)
50+
51+
# Check to see if this is hdf5-1.10.3 or later.
52+
CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5Dread_chunk "" HDF5_SUPPORTS_PAR_FILTERS)
53+
+ SET(HDF5_C_LIBRARY_hdf5)
54+
55+
SET(H5_USE_16_API 1)
56+
OPTION(NC_ENABLE_HDF_16_API "Enable HDF5 1.6.x Compatibility(Required)" ON)
57+
@@ -789,8 +796,10 @@ ENDIF(USE_HDF5 OR ENABLE_NETCDF_4)
58+
59+
# See if we have libcurl
60+
FIND_PACKAGE(CURL)
61+
-ADD_DEFINITIONS(-DCURL_STATICLIB=1)
62+
INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
63+
+if(ENABLE_DAP OR ENABLE_BYTERANGE)
64+
+ link_libraries(CONAN_PKG::libcurl)
65+
+endif()
66+
67+
# Check to see if CURLOPT_USERNAME is defined.
68+
# It is present starting version 7.19.1.
69+
@@ -854,7 +863,7 @@ ENDIF()
70+
# Option to support byte-range reading of remote datasets
71+
OPTION(ENABLE_BYTERANGE "Enable byte-range access to remote datasets.." OFF)
72+
73+
-IF(NOT CURL_LIBRARY)
74+
+IF(NOT CURL_FOUND)
75+
IF(ENABLE_BYTERANGE)
76+
MESSAGE(FATAL_ERROR "Byte-range support specified, CURL libraries are not found.")
77+
ENDIF()

Diff for: recipes/netcdf-c/all/test_package/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(test_package C)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup()
6+
7+
find_package(netCDF REQUIRED CONFIG)
8+
9+
add_executable(${PROJECT_NAME} test_package.c)
10+
target_link_libraries(${PROJECT_NAME} netCDF::netcdf)
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from conans import ConanFile, CMake, tools
22
import os
33

4-
5-
class NetcdfTestConan(ConanFile):
4+
class TestPackageConan(ConanFile):
65
settings = "os", "compiler", "build_type", "arch"
7-
generators = "cmake"
6+
generators = "cmake", "cmake_find_package_multi"
87

98
def build(self):
109
cmake = CMake(self)
@@ -13,5 +12,5 @@ def build(self):
1312

1413
def test(self):
1514
if not tools.cross_building(self.settings):
16-
bin_path = os.path.join("bin", "example")
15+
bin_path = os.path.join("bin", "test_package")
1716
self.run(bin_path, run_environment=True)

Diff for: recipes/netcdf-c/all/test_package/test_package.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <netcdf.h>
2+
3+
#include <stdio.h>
4+
5+
int main() {
6+
printf("NetCDF version: %s\n", nc_inq_libvers());
7+
printf("*** SUCCESS!\n");
8+
return 0;
9+
}
File renamed without changes.

Diff for: recipes/netcdf/all/conandata.yml

-12
This file was deleted.

0 commit comments

Comments
 (0)