Skip to content
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

readstat: add new recipe of readstat/1.1.9 #25181

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions recipes/readstat/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -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"
133 changes: 133 additions & 0 deletions recipes/readstat/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.microsoft import is_msvc
import os

required_conan_version = ">=1.57.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")

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")
self.win_bash = True
self.tool_requires("libtool/2.4.7")

def _sys_compiler(self):
return self.info.settings.compiler

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
env = VirtualBuildEnv(self)
env.generate()

tc = AutotoolsToolchain(self)
if self.settings.os == "Windows" and self.settings.compiler == "gcc":
if self.settings.arch == "x86":
tc.update_configure_args({
"--host": "i686-w64-mingw32",
"RC": "windres --target=pe-i386",
"WINDRES": "windres --target=pe-i386",
})
elif self.settings.arch == "x86_64":
tc.update_configure_args({
"--host": "x86_64-w64-mingw32",
"RC": "windres --target=pe-x86-64",
"WINDRES": "windres --target=pe-x86-64",
})

if cross_building(self) and is_msvc(self):
triplet_arch_windows = {"x86_64": "x86_64", "x86": "i686", "armv8": "aarch64"}
# ICU doesn't like GNU triplet of conan for msvc (see https://github.com/conan-io/conan/issues/12546)
host_arch = triplet_arch_windows.get(str(self.settings.arch))
build_arch = triplet_arch_windows.get(str(self._settings_build.arch))

if host_arch and build_arch:
host = f"{host_arch}-w64-mingw32"
build = f"{build_arch}-w64-mingw32"
tc.configure_args.extend([
f"--host={host}",
f"--build={build}",
])
env = tc.environment()
tc.generate(env)

def build(self):
apply_conandata_patches(self)
autotools = Autotools(self)
autotools.autoreconf()
autotools.configure()
autotools.make()

def package(self):
# upstream didn't pack license file into distribution
copy(self, "NEWS", 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, "*.a", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
copy(self, "*.so", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
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"))
fix_apple_shared_install_name(self)

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")
7 changes: 7 additions & 0 deletions recipes/readstat/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 27 additions & 0 deletions recipes/readstat/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
12 changes: 12 additions & 0 deletions recipes/readstat/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
#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;
}
3 changes: 3 additions & 0 deletions recipes/readstat/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.1.9":
folder: all