-
-
Save tbeu/f0541f60151b92be8d2295036f896f6f to your computer and use it in GitHub Desktop.
Conan recipe for matio (in development)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from conans import ConanFile, CMake, tools | |
from conans.errors import ConanInvalidConfiguration | |
import os | |
class MatioConan(ConanFile): | |
name = "matio" | |
version = "1.5.17" | |
license = "BSD-2-Clause License" | |
author = "t-beu@users.sourceforge.net" | |
url = "https://sourceforge.net/projects/matio/" | |
description = "Matio is a C library for reading and writing binary MATLAB MAT files." | |
topics = ("conan", "matlab", "mat-file", "file-format", "hdf5") | |
settings = "os", "compiler", "build_type", "arch" | |
generators = "cmake" | |
options = { | |
"shared": [True, False], | |
"extended_sparse": [True, False], | |
"fPIC": [True, False], | |
"mat73": [True, False], | |
"with_hdf5": [None, "shared", "static"], | |
"with_zlib": [None, "shared", "static"] | |
} | |
default_options = { | |
"shared": False, | |
"extended_sparse": True, | |
"fPIC": True, | |
"mat73": True, | |
"with_hdf5": "static", | |
"with_zlib": "static" | |
} | |
_cmake = None | |
@property | |
def _source_subfolder(self): | |
return "source_subfolder" | |
@property | |
def _build_subfolder(self): | |
return "build_subfolder" | |
def source(self): | |
tools.get(**self.conan_data["sources"][self.version]) | |
os.rename(self.name + "-" + self.version, self._source_subfolder) | |
def requirements(self): | |
if self.options.with_zlib: | |
self.requires("zlib/[>=1.2.3]") | |
if self.options.with_hdf5: | |
self.requires("hdf5/[>=1.8 <1.13]") | |
def _patch_sources(self): | |
for patch in self.conan_data["patches"][self.version]: | |
tools.patch(**patch) | |
def config_options(self): | |
if self.settings.os == "Windows": | |
del self.options.fPIC | |
def configure(self): | |
if self.options.with_hdf5: | |
self.options["hdf5"].shared = self.options.with_hdf5 == "shared" | |
if self.options.with_zlib: | |
self.options["zlib"].shared = self.options.with_zlib == "shared" | |
def _configure_cmake(self): | |
if self._cmake: | |
return self._cmake | |
# self._patch_sources() | |
self._cmake = CMake(self) | |
self._cmake.definitions["MATIO_EXTENDED_SPARSE"] = self.options.extended_sparse | |
if self.settings.os != "Windows": | |
self._cmake.definitions["MATIO_PIC"] = self.options.fPIC | |
self._cmake.definitions["MATIO_SHARED"] = self.options.shared | |
self._cmake.definitions["MATIO_MAT73"] = self.options.mat73 | |
self._cmake.definitions["MATIO_WITH_HDF5"] = bool(self.options.with_hdf5) | |
self._cmake.definitions["MATIO_WITH_ZLIB"] = bool(self.options.with_zlib) | |
if self.options.with_hdf5: | |
self._cmake.definitions["HDF5_USE_STATIC_LIBRARIES"] = self.options.with_hdf5 == "static" | |
self._cmake.definitions["CMAKE_PREFIX_PATH"] = self.deps_cpp_info["hdf5"].rootpath | |
if self.options.with_zlib: | |
self._cmake.definitions["ZLIB_ROOT"] = self.deps_cpp_info["zlib"].rootpath | |
self._cmake.configure(source_folder=self._source_subfolder, build_folder=self._build_subfolder) | |
return self._cmake | |
def build(self): | |
if not self.options.with_hdf5 and self.options.mat73: | |
raise ConanInvalidConfiguration("Support of version 7.3 MAT files requires HDF5") | |
cmake = self._configure_cmake() | |
cmake.build() | |
def package(self): | |
self.copy("COPYING", dst="licenses", src=self._source_subfolder) | |
cmake = self._configure_cmake() | |
cmake.install() | |
def package_info(self): | |
if self.settings.compiler == "Visual Studio": | |
self.cpp_info.libs = ["libmatio"] | |
else: | |
self.cpp_info.libs = ["matio"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment