Skip to content

hdf5: bump dependencies + modernize #10552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion recipes/hdf5/all/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.13)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
conan_basic_setup(TARGETS KEEP_RPATHS)

if (MSVC)
add_compile_options("$<$<CONFIG:DEBUG>:/Z7>")
Expand Down
165 changes: 86 additions & 79 deletions recipes/hdf5/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import os
import textwrap

from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import functools
import os
import textwrap

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.43.0"


class Hdf5Conan(ConanFile):
name = "hdf5"
description = "HDF5 is a data model, library, and file format for storing and managing data."
license = "BSD-3-Clause"
topics = ("conan", "hdf5", "hdf", "data")
topics = ("hdf5", "hdf", "data")
homepage = "https://portal.hdfgroup.org/display/HDF5/HDF5"
url = "https://github.com/conan-io/conan-center-index"
exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -26,7 +25,7 @@ class Hdf5Conan(ConanFile):
"with_zlib": [True, False],
"szip_support": [None, "with_libaec", "with_szip"],
"szip_encoding": [True, False],
"parallel": [True, False]
"parallel": [True, False],
}
default_options = {
"shared": False,
Expand All @@ -37,10 +36,10 @@ class Hdf5Conan(ConanFile):
"with_zlib": True,
"szip_support": None,
"szip_encoding": False,
"parallel": False
"parallel": False,
}

_cmake = None
generators = "cmake"

@property
def _source_subfolder(self):
Expand All @@ -50,13 +49,10 @@ def _source_subfolder(self):
def _build_subfolder(self):
return "build_subfolder"

@property
def _module_subfolder(self):
return os.path.join("lib", "cmake")

@property
def _module_file(self):
return "conan-official-{}-targets.cmake".format(self.name)
def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])

def config_options(self):
if self.settings.os == "Windows":
Expand All @@ -72,10 +68,16 @@ def configure(self):
del self.options.threadsafe
if not bool(self.options.szip_support):
del self.options.szip_encoding
elif self.options.szip_support == "with_szip" and \
self.options.szip_encoding and \
not self.options["szip"].enable_encoding:
raise ConanInvalidConfiguration("encoding must be enabled in szip dependency (szip:enable_encoding=True)")

def requirements(self):
if self.options.with_zlib:
self.requires("zlib/1.2.12")
if self.options.szip_support == "with_libaec":
self.requires("libaec/1.0.6")
elif self.options.szip_support == "with_szip":
self.requires("szip/2.1.1")
if self.options.parallel:
self.requires("openmpi/4.1.0")

def validate(self):
if hasattr(self, "settings_build") and tools.cross_building(self, skip_x64_x86=True):
Expand All @@ -86,16 +88,9 @@ def validate(self):
raise ConanInvalidConfiguration("Parallel and C++ options are mutually exclusive")
if self.options.get_safe("threadsafe", False):
raise ConanInvalidConfiguration("Parallel and Threadsafe options are mutually exclusive")

def requirements(self):
if self.options.with_zlib:
self.requires("zlib/1.2.11")
if self.options.szip_support == "with_libaec":
self.requires("libaec/1.0.4")
elif self.options.szip_support == "with_szip":
self.requires("szip/2.1.1")
if self.options.parallel:
self.requires("openmpi/4.1.0")
if self.options.szip_support == "with_szip" and self.options.szip_encoding and \
not self.options["szip"].enable_encoding:
raise ConanInvalidConfiguration("encoding must be enabled in szip dependency (szip:enable_encoding=True)")

def source(self):
tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True)
Expand All @@ -106,61 +101,60 @@ def build(self):
cmake.build()

def _patch_sources(self):
for patch in self.conan_data["patches"][self.version]:
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
# Do not force PIC
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
"set (CMAKE_POSITION_INDEPENDENT_CODE ON)", "")

@functools.lru_cache(1)
def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["HDF5_EXTERNALLY_CONFIGURED"] = True
self._cmake.definitions["HDF5_EXTERNAL_LIB_PREFIX"] = ""
self._cmake.definitions["HDF5_USE_FOLDERS"] = False
self._cmake.definitions["HDF5_NO_PACKAGES"] = True
self._cmake.definitions["ALLOW_UNSUPPORTED"] = False
cmake = CMake(self)
cmake.definitions["HDF5_EXTERNALLY_CONFIGURED"] = True
cmake.definitions["HDF5_EXTERNAL_LIB_PREFIX"] = ""
cmake.definitions["HDF5_USE_FOLDERS"] = False
cmake.definitions["HDF5_NO_PACKAGES"] = True
cmake.definitions["ALLOW_UNSUPPORTED"] = False
if tools.Version(self.version) >= "1.10.6":
self._cmake.definitions["ONLY_SHARED_LIBS"] = self.options.shared
self._cmake.definitions["BUILD_STATIC_EXECS"] = False
self._cmake.definitions["HDF5_ENABLE_COVERAGE"] = False
self._cmake.definitions["HDF5_ENABLE_USING_MEMCHECKER"] = False
cmake.definitions["ONLY_SHARED_LIBS"] = self.options.shared
cmake.definitions["BUILD_STATIC_EXECS"] = False
cmake.definitions["HDF5_ENABLE_COVERAGE"] = False
cmake.definitions["HDF5_ENABLE_USING_MEMCHECKER"] = False
if tools.Version(self.version) >= "1.10.0":
self._cmake.definitions["HDF5_MEMORY_ALLOC_SANITY_CHECK"] = False
cmake.definitions["HDF5_MEMORY_ALLOC_SANITY_CHECK"] = False
if tools.Version(self.version) >= "1.10.5":
self._cmake.definitions["HDF5_ENABLE_PREADWRITE"] = True
self._cmake.definitions["HDF5_ENABLE_DEPRECATED_SYMBOLS"] = True
self._cmake.definitions["HDF5_BUILD_GENERATORS"] = False
self._cmake.definitions["HDF5_ENABLE_TRACE"] = False
cmake.definitions["HDF5_ENABLE_PREADWRITE"] = True
cmake.definitions["HDF5_ENABLE_DEPRECATED_SYMBOLS"] = True
cmake.definitions["HDF5_BUILD_GENERATORS"] = False
cmake.definitions["HDF5_ENABLE_TRACE"] = False
if self.settings.build_type == "Debug":
self._cmake.definitions["HDF5_ENABLE_INSTRUMENT"] = False # Option?
self._cmake.definitions["HDF5_ENABLE_PARALLEL"] = self.options.parallel
self._cmake.definitions["HDF5_ENABLE_Z_LIB_SUPPORT"] = self.options.with_zlib
self._cmake.definitions["HDF5_ENABLE_SZIP_SUPPORT"] = bool(self.options.szip_support)
cmake.definitions["HDF5_ENABLE_INSTRUMENT"] = False # Option?
cmake.definitions["HDF5_ENABLE_PARALLEL"] = self.options.parallel
cmake.definitions["HDF5_ENABLE_Z_LIB_SUPPORT"] = self.options.with_zlib
cmake.definitions["HDF5_ENABLE_SZIP_SUPPORT"] = bool(self.options.szip_support)
if bool(self.options.szip_support):
self._cmake.definitions["CONAN_SZIP_LIBNAME"] = self._get_szip_lib() # this variable is added by conanize-link-szip*.patch
self._cmake.definitions["HDF5_ENABLE_SZIP_ENCODING"] = self.options.get_safe("szip_encoding") or False
self._cmake.definitions["HDF5_PACKAGE_EXTLIBS"] = False
self._cmake.definitions["HDF5_ENABLE_THREADSAFE"] = self.options.get_safe("threadsafe") or False
self._cmake.definitions["HDF5_ENABLE_DEBUG_APIS"] = False # Option?
self._cmake.definitions["BUILD_TESTING"] = False
self._cmake.definitions["HDF5_INSTALL_INCLUDE_DIR"] = os.path.join(self.package_folder, "include", "hdf5")
self._cmake.definitions["HDF5_BUILD_TOOLS"] = False
self._cmake.definitions["HDF5_BUILD_EXAMPLES"] = False
self._cmake.definitions["HDF5_BUILD_HL_LIB"] = self.options.hl
self._cmake.definitions["HDF5_BUILD_FORTRAN"] = False
self._cmake.definitions["HDF5_BUILD_CPP_LIB"] = self.options.enable_cxx
cmake.definitions["CONAN_SZIP_LIBNAME"] = self._get_szip_lib() # this variable is added by conanize-link-szip*.patch
cmake.definitions["HDF5_ENABLE_SZIP_ENCODING"] = self.options.get_safe("szip_encoding", False)
cmake.definitions["HDF5_PACKAGE_EXTLIBS"] = False
cmake.definitions["HDF5_ENABLE_THREADSAFE"] = self.options.get_safe("threadsafe", False)
cmake.definitions["HDF5_ENABLE_DEBUG_APIS"] = False # Option?
cmake.definitions["BUILD_TESTING"] = False
cmake.definitions["HDF5_INSTALL_INCLUDE_DIR"] = os.path.join(self.package_folder, "include", "hdf5")
cmake.definitions["HDF5_BUILD_TOOLS"] = False
cmake.definitions["HDF5_BUILD_EXAMPLES"] = False
cmake.definitions["HDF5_BUILD_HL_LIB"] = self.options.hl
cmake.definitions["HDF5_BUILD_FORTRAN"] = False
cmake.definitions["HDF5_BUILD_CPP_LIB"] = self.options.enable_cxx
if tools.Version(self.version) >= "1.10.0":
self._cmake.definitions["HDF5_BUILD_JAVA"] = False
cmake.definitions["HDF5_BUILD_JAVA"] = False

self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
cmake.configure(build_folder=self._build_subfolder)
return cmake

def _get_szip_lib(self):
return {
"with_libaec": "libaec",
"with_szip": "szip"
"with_szip": "szip",
}.get(str(self.options.szip_support))

def _components(self):
Expand All @@ -178,7 +172,7 @@ def _components(self):
"hdf5_c": {"component": "C", "alias_target": "hdf5", "requirements": hdf5_requirements},
"hdf5_hl": {"component": "HL", "alias_target": "hdf5_hl", "requirements": ["hdf5_c"]},
"hdf5_cpp": {"component": "CXX", "alias_target": "hdf5_cpp", "requirements": ["hdf5_c"]},
"hdf5_hl_cpp": {"component": "HL_CXX", "alias_target": "hdf5_hl_cpp", "requirements": ["hdf5_c", "hdf5_cpp", "hdf5_hl"]}
"hdf5_hl_cpp": {"component": "HL_CXX", "alias_target": "hdf5_hl_cpp", "requirements": ["hdf5_c", "hdf5_cpp", "hdf5_hl"]},
}

@staticmethod
Expand All @@ -202,6 +196,11 @@ def _create_cmake_module_alias_targets(module_file, targets, is_parallel):
content += textwrap.dedent("set(HDF5_IS_PARALLEL {})".format("ON" if is_parallel else "OFF"))
tools.save(module_file, content)

@property
def _module_file_rel_path(self):
return os.path.join("lib", "cmake",
"conan-official-{}-targets.cmake".format(self.name))

def package(self):
self.copy("COPYING", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
Expand All @@ -212,7 +211,7 @@ def package(self):
# but component targets have a lower case namespace prefix. hdf5::hdf5 refers to the C library only
components = self._components()
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_subfolder, self._module_file),
os.path.join(self.package_folder, self._module_file_rel_path),
{"hdf5::{}".format(component["alias_target"]): "HDF5::{}".format(component["component"]) for component in components.values()},
self.options.get_safe("parallel", False)
)
Expand All @@ -228,17 +227,21 @@ def _config_libname(lib):
# See config/cmake_ext_mod/HDFMacros.cmake
return lib

self.cpp_info.components[component_name].names["cmake_find_package"] = component
self.cpp_info.components[component_name].names["cmake_find_package_multi"] = component
self.cpp_info.components[component_name].set_property("cmake_target_name", f"hdf5::{alias_target}")
self.cpp_info.components[component_name].set_property("pkg_config_name", alias_target)
self.cpp_info.components[component_name].libs = [_config_libname(alias_target)]
self.cpp_info.components[component_name].requires = requirements
self.cpp_info.components[component_name].builddirs.append(self._module_subfolder)
module_file_rel_path = os.path.join(self.package_folder, self._module_subfolder, self._module_file)
self.cpp_info.components[component_name].build_modules["cmake_find_package"] = [module_file_rel_path]
self.cpp_info.components[component_name].build_modules["cmake_find_package_multi"] = [module_file_rel_path]

self.cpp_info.names["cmake_find_package"] = "HDF5"
self.cpp_info.names["cmake_find_package_multi"] = "HDF5"
# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.components[component_name].names["cmake_find_package"] = component
self.cpp_info.components[component_name].names["cmake_find_package_multi"] = component
self.cpp_info.components[component_name].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components[component_name].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]

self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_file_name", "HDF5")
self.cpp_info.set_property("cmake_target_name", "HDF5::HDF5")
self.cpp_info.set_property("pkg_config_name", "hdf5-all-do-not-use") # to avoid conflict with hdf5_c component

components = self._components()
add_component("hdf5_c", **components["hdf5_c"])
Expand All @@ -256,3 +259,7 @@ def _config_libname(lib):
add_component("hdf5_hl", **components["hdf5_hl"])
if self.options.get_safe("enable_cxx"):
add_component("hdf5_hl_cpp", **components["hdf5_hl_cpp"])

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.names["cmake_find_package"] = "HDF5"
self.cpp_info.names["cmake_find_package_multi"] = "HDF5"
20 changes: 10 additions & 10 deletions recipes/hdf5/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.1)

project(test_package LANGUAGES C CXX)

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

set(HDF5_COMPONENTS C)
if (HDF5_HL)
list(APPEND HDF5_COMPONENTS HL)
Expand All @@ -13,16 +13,16 @@ if (HDF5_CXX)
endif()
find_package(HDF5 COMPONENTS ${HDF5_COMPONENTS})

add_executable(${CMAKE_PROJECT_NAME} test_package.c)
add_executable(${PROJECT_NAME} test_package.c)

if (TARGET hdf5::hdf5_cpp)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE CONAN_HDF5_CXX)
target_sources(${CMAKE_PROJECT_NAME} PRIVATE test_package.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE hdf5::hdf5_cpp)
target_compile_definitions(${PROJECT_NAME} PRIVATE CONAN_HDF5_CXX)
target_sources(${PROJECT_NAME} PRIVATE test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE hdf5::hdf5_cpp)
elseif (HDF5_IS_PARALLEL)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE CONAN_HDF5_PARALLEL)
target_sources(${CMAKE_PROJECT_NAME} PRIVATE test_parallel.c)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE hdf5::hdf5)
target_compile_definitions(${PROJECT_NAME} PRIVATE CONAN_HDF5_PARALLEL)
target_sources(${PROJECT_NAME} PRIVATE test_parallel.c)
target_link_libraries(${PROJECT_NAME} PRIVATE hdf5::hdf5)
else()
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE hdf5::hdf5)
target_link_libraries(${PROJECT_NAME} PRIVATE hdf5::hdf5)
endif()
14 changes: 7 additions & 7 deletions recipes/hdf5/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import os.path
from conans import ConanFile, CMake, tools
import os

from conans import ConanFile, CMake


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

def build(self):
Expand All @@ -17,5 +16,6 @@ def build(self):
cmake.build()

def test(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)