conan-io / wishlist

This repo is to propose libraries, frameworks, and code in general that users would like to have in conan
MIT License
49 stars 5 forks source link

HDF5 #248

Closed Morwenn closed 4 years ago

Morwenn commented 4 years ago

As a part of my job I've had to use HDF5 in a growing number of libraries: it seems quite fundamental in many scientific toolkits and it would probably help if it was more generally available through Conan.

I do have a recipe but I can't guarantee that I will have any time to maintain it in the future, especially since I'm supposed to change projects in a few months, so here is a basic recipe for whoever feels like properly supporting and maintaining it in the future. The recipe was meant to support either 1.8.x or 1.10.x versions of the HDF5 library, adapt as needed.

# -*- coding: utf-8 -*-

from pathlib import Path

from conans import CMake, ConanFile, tools

class LibHdf5Conan(ConanFile):
    name = "hdf5"
    version = "1.8.21"
    description = "HDF5 is a data model, library, and file format for storing and managing data"
    homepage = "https://portal.hdfgroup.org/display/support"
    url = "https://bitbucket.hdfgroup.org/projects/HDFFV/repos/hdf5/browse"
    exports = ["CMakeLists.txt"]
    generators = "cmake"

    settings = "os", "arch", "compiler", "build_type"
    options = {
        "shared": [True, False],
        "fPIC": [True, False],
        "hl": [True, False]
    }
    default_options = {
        "shared": False,
        "fPIC": True,
        "hl": True
    }
    short_paths = True
    no_copy_source = True

    _source_subfolder = "source_subfolder"
    _build_subfolder = "build_subfolder"

    scm = {
        "type": "git",
        "subfolder": _source_subfolder,
        "url": "https://github.com/live-clones/hdf5.git",
        "revision": f"hdf5-{version.replace('.', '_')}",
    }

    def config_options(self):
        if self.settings.compiler == 'Visual Studio':
            del self.options.fPIC

    def source(self):
        root = Path(self._source_subfolder)
        if int(self.version.split('.')[1]) < 10:
            tools.replace_in_file(
                root / "CMakeLists.txt",
                "PROJECT (HDF5 C CXX)",
                """PROJECT (HDF5 C CXX)
                   include(${CMAKE_BINARY_DIR}/../conanbuildinfo.cmake)
                   conan_basic_setup()"""
            )
        else:
            tools.replace_in_file(
                root / "CMakeLists.txt",
                "project (HDF5 C)",
                """project (HDF5 C)
                   include(${CMAKE_BINARY_DIR}/../conanbuildinfo.cmake)
                   conan_basic_setup()"""
            )

    def requirements(self):
        self.requires("zlib/1.2.11@conan/stable")

    def _configure_cmake(self):
        cmake = CMake(self)

        cmake.definitions["BUILD_TESTING"] = "OFF"
        cmake.definitions["HDF5_BUILD_CPP_LIB"] = "ON"
        cmake.definitions["HDF5_BUILD_EXAMPLES"] = "OFF"
        cmake.definitions["HDF5_BUILD_HL_LIB"] = self.options.hl
        cmake.definitions["HDF5_BUILD_TOOLS"] = "OFF"
        cmake.definitions["HDF5_ENABLE_Z_LIB_SUPPORT"] = "ON"

        cmake.configure(source_folder=self._source_subfolder, build_folder=self._build_subfolder)
        return cmake

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

    def package(self):
        cmake = self._configure_cmake()
        cmake.install()

        self.copy("COPYING", src=self._source_subfolder, dst="licenses", keep_path=False)

    def package_info(self):
        self.cpp_info.libs = tools.collect_libs(self)
        if self.settings.os != 'Windows':
            self.cpp_info.libs.append('dl')
SSE4 commented 4 years ago

hi @Morwenn if you already have a working recipe, would you like to try to submit your recipe into the conan-center-index? thanks

Morwenn commented 4 years ago

@SSE4 It works for Ubuntu 18 x8_64 but I haven't tried it anywhere else though. Also, I'm ok with trying to submit it to conan-center-index, but as far as I know I don't have the rights nor nor can I really commit to maintenance. If it isn't a major issue then I can try :)

SSE4 commented 4 years ago

@Morwenn I think it's not an issue. first, request the access here: https://github.com/conan-io/conan-center-index/issues/4

Morwenn commented 4 years ago

I updated the recipe above and pushed a best effort if incomplete version at conan-io/conan-center-index#285

Morwenn commented 4 years ago

I got the 1.8.21 and 1.10.5 versions into CCI so I'm closing the issue.

@danimtb I guess that we can change the tag now that this is done :)

danimtb commented 4 years ago

Sure! thanks a lot @Morwenn 😄

steven-varga commented 4 years ago

I am working on H5CPP the modern header only C++ library for HDF5 with cooperation/support of The HDFGroup. For new projects it is highly recommended to use H5CPP instead of the currently shipped but somewhat outdated internal C++. ISC'19 BOF presentation slides are here and for documentation follow the this link.

The project is of two components: header only library, and LLVM based compiler assisted reflection tool: h5cpp-compiler. Together they provided seamless persistence much similar to interpreted languages, without trade-offs.

best wishes: steven

Croydon commented 4 years ago

@steven-varga H5CPP would be a different package. If you wish it please create an issue here: https://github.com/conan-io/conan-center-index (this wishlist here is getting phased-out)