From 791e9e2deae5faf15aa3733bec1cb8cb2ab3a5b4 Mon Sep 17 00:00:00 2001 From: Shun Wang Date: Sat, 14 Oct 2023 05:25:18 +0000 Subject: [PATCH] Init add readstat library --- recipes/readstat/all/conandata.yml | 4 + recipes/readstat/all/conanfile.py | 112 ++++++++++++++++++ .../readstat/all/test_package/CMakeLists.txt | 7 ++ .../readstat/all/test_package/conanfile.py | 27 +++++ .../readstat/all/test_package/test_package.c | 12 ++ recipes/readstat/config.yml | 3 + 6 files changed, 165 insertions(+) create mode 100644 recipes/readstat/all/conandata.yml create mode 100644 recipes/readstat/all/conanfile.py create mode 100644 recipes/readstat/all/test_package/CMakeLists.txt create mode 100644 recipes/readstat/all/test_package/conanfile.py create mode 100644 recipes/readstat/all/test_package/test_package.c create mode 100644 recipes/readstat/config.yml diff --git a/recipes/readstat/all/conandata.yml b/recipes/readstat/all/conandata.yml new file mode 100644 index 0000000000000..70dee4a482096 --- /dev/null +++ b/recipes/readstat/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "1.1.9": + url: "https://github.com/WizardMac/ReadStat/releases/download/v1.1.9/readstat-1.1.9.tar.gz" + sha256: "3a232b9e852d10173e2f25da9155afe2e129a30d1fc6c9aac142cdc5cbfe527e" \ No newline at end of file diff --git a/recipes/readstat/all/conanfile.py b/recipes/readstat/all/conanfile.py new file mode 100644 index 0000000000000..4e499f2276e59 --- /dev/null +++ b/recipes/readstat/all/conanfile.py @@ -0,0 +1,112 @@ +from conan import ConanFile +from conan.tools.build import cross_building +from conan.tools.env import VirtualBuildEnv, VirtualRunEnv +from conan.tools.files import apply_conandata_patches, chdir, copy, export_conandata_patches, get, rm, rmdir +from conan.tools.gnu import Autotools, AutotoolsDeps, AutotoolsToolchain +from conan.tools.layout import basic_layout +from conan.tools.microsoft import is_msvc, NMakeDeps, NMakeToolchain +import os + + +required_conan_version = ">=1.55.0" + +class ReadstatConan(ConanFile): + name = "readstat" + description = "Command-line tool (+ C library) for converting SAS, Stata, and SPSS files" + license = "MIT" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/WizardMac/ReadStat" + topics = ("spss", "stata", "sas", "sas7bdat", "readstats") + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } + + @property + def _settings_build(self): + return getattr(self, "settings_build", self.settings) + + def export_sources(self): + export_conandata_patches(self) + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + # for plain C projects only + self.settings.rm_safe("compiler.libcxx") + self.settings.rm_safe("compiler.cppstd") + + def layout(self): + basic_layout(self, src_folder="src") + + def requirements(self): + self.requires("libiconv/1.17") + + # if another tool than the compiler or autotools is required to build the project (pkgconf, bison, flex etc) + def build_requirements(self): + if self._settings_build.os == "Windows": + self.win_bash = True + if not self.conf.get("tools.microsoft.bash:path", check_type=str): + self.tool_requires("msys2/cci.latest") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + if is_msvc(self): + tc = NMakeToolchain(self) + tc.generate() + deps = NMakeDeps(self) + deps.generate() + else: + env = VirtualBuildEnv(self) + env.generate() + if not cross_building(self): + env = VirtualRunEnv(self) + env.generate(scope="build") + tc = AutotoolsToolchain(self) + tc.generate() + deps = AutotoolsDeps(self) + deps.generate() + + def build(self): + apply_conandata_patches(self) + if is_msvc(self): + args = "readstat_i.lib READSTAT_EXPORT=-DDLL_EXPORT" if self.options.shared else "readstat.lib" + with chdir(self, self.source_folder): + self.run(f"nmake -f makefile.vc {args}") + else: + autotools = Autotools(self) + # autotools.autoreconf() + autotools.configure() + autotools.make() + + def package(self): + copy(self, pattern="LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + if is_msvc(self): + copy(self, "readstat.h", src=os.path.join(self.source_folder, "headers"), dst=os.path.join(self.package_folder, "include")) + copy(self, "*.lib", src=self.source_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False) + copy(self, "*.dll", src=self.source_folder, dst=os.path.join(self.package_folder, "bin"), keep_path=False) + else: + autotools = Autotools(self) + autotools.install() + rm(self, "*.la", os.path.join(self.package_folder, "lib")) + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + rmdir(self, os.path.join(self.package_folder, "share")) + + def package_info(self): + self.cpp_info.set_property("pkg_config_name", "readstat") + suffix = "_i" if is_msvc(self) and self.options.shared else "" + self.cpp_info.libs = [f"readstat{suffix}"] + if self.settings.os in ("FreeBSD", "Linux"): + self.cpp_info.system_libs.append("m") diff --git a/recipes/readstat/all/test_package/CMakeLists.txt b/recipes/readstat/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..06f4de29d4007 --- /dev/null +++ b/recipes/readstat/all/test_package/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES C) + +find_package(readstat REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE readstat::readstat) diff --git a/recipes/readstat/all/test_package/conanfile.py b/recipes/readstat/all/test_package/conanfile.py new file mode 100644 index 0000000000000..114fe8234f5db --- /dev/null +++ b/recipes/readstat/all/test_package/conanfile.py @@ -0,0 +1,27 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +# It will become the standard on Conan 2.x +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/readstat/all/test_package/test_package.c b/recipes/readstat/all/test_package/test_package.c new file mode 100644 index 0000000000000..dd7c0cbd64e59 --- /dev/null +++ b/recipes/readstat/all/test_package/test_package.c @@ -0,0 +1,12 @@ +#include +#include +#include "readstat.h" + +int main() { + + readstat_error_t error = READSTAT_OK; + readstat_parser_t *parser = readstat_parser_init(); + + printf("Build test sucess\n"); + return 0; +} \ No newline at end of file diff --git a/recipes/readstat/config.yml b/recipes/readstat/config.yml new file mode 100644 index 0000000000000..691d3c3ad3c9f --- /dev/null +++ b/recipes/readstat/config.yml @@ -0,0 +1,3 @@ +versions: + "1.1.9": + folder: all