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

libxls: add recipe #12152

Merged
merged 24 commits into from
Jan 27, 2023
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
9 changes: 9 additions & 0 deletions recipes/libxls/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sources:
"1.6.2":
url: "https://github.com/libxls/libxls/releases/download/v1.6.2/libxls-1.6.2.tar.gz"
sha256: "5dacc34d94bf2115926c80c6fb69e4e7bd2ed6403d51cff49041a94172f5e371"
patches:
"1.6.2":
- patch_file: "patches/1.6.2-0001-fix-ssize_t-msvc.patch"
patch_description: "Solve ssize_t when building on Windows"
patch_type: "conan"
113 changes: 113 additions & 0 deletions recipes/libxls/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps
from conan.tools.layout import basic_layout
from conan.tools.files import export_conandata_patches, apply_conandata_patches, rmdir, copy, save, get, rm
from conan.tools.apple import is_apple_os
from conan.tools.build import cross_building

import os

required_conan_version = ">=1.53.0"

class LibxlsConan(ConanFile):
name = "libxls"
description = "a C library which can read Excel (xls) files."
license = "BSD-2-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/libxls/libxls/"
topics = ("excel", "xls")
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_cli": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_cli": False,
}

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")
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

def layout(self):
basic_layout(self, src_folder='src')

def requirements(self):
if not is_apple_os(self):
self.requires("libiconv/1.17")

def validate(self):
if self.settings.os == "Windows":
raise ConanInvalidConfiguration(f"{self.ref} doesn't support Windows (yet). Contributions are always welcomed")

def build_requirements(self):
if self.settings.os == "Windows":
self.tool_requires("msys2/cci.latest")
self.win_bash = True

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

def generate(self):
toolchain = AutotoolsToolchain(self)
if cross_building(self):
toolchain.configure_args.append("ac_cv_func_malloc_0_nonnull=yes")
toolchain.configure_args.append("ac_cv_func_realloc_0_nonnull=yes")
toolchain.generate()
deps = AutotoolsDeps(self)
deps.generate()

def _patch_sources(self):
config_h_content = """
#define HAVE_ICONV 1
#define ICONV_CONST
#define PACKAGE_VERSION "{}"
""".format(self.version)
if self.settings.os == "Macos":
config_h_content += "#define HAVE_XLOCALE_H 1\n"
save(self, os.path.join(self.source_folder, "include", "config.h"), config_h_content)
apply_conandata_patches(self)

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

def package(self):
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
autotools = Autotools(self)
autotools.install()
rmdir(self, os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))

def package_info(self):
self.cpp_info.libs = ["xlsreader"]

if is_apple_os(self):
self.cpp_info.system_libs.append("iconv")
Comment on lines +101 to +102
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am surprised it's a system lib on Mac 🤔 not usually the case... care to share with me? I am not familar with this project

Suggested change
if is_apple_os(self):
self.cpp_info.system_libs.append("iconv")
if is_apple_os(self):
self.cpp_info.system_libs.append("iconv")
else:
self.cpp_info.requires.append("libiconv::libiconv")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prince-chrismc
Sorry, I neglected it so much that I forgot some of it.
I will investigate again.


self.cpp_info.set_property("cmake_file_name", "libxls")
self.cpp_info.set_property("cmake_target_name", "libxls::libxls")
self.cpp_info.set_property("pkg_config_name", "libxls")

if not is_apple_os(self):
self.cpp_info.requires.append("libiconv::libiconv")

# TODO: Remove in Conan 2.0
Comment on lines +108 to +111
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not is_apple_os(self):
self.cpp_info.requires.append("libiconv::libiconv")
# TODO: Remove in Conan 2.0
# TODO: Remove in Conan 2.0

self.cpp_info.names["cmake_find_package"] = "libxls"
self.cpp_info.names["cmake_find_package_multi"] = "libxls"
14 changes: 14 additions & 0 deletions recipes/libxls/all/patches/1.6.2-0001-fix-ssize_t-msvc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/include/libxls/xlstypes.h b/include/libxls/xlstypes.h
index 52da772..3efba21 100644
--- a/include/libxls/xlstypes.h
+++ b/include/libxls/xlstypes.h
@@ -53,4 +53,9 @@ typedef unsigned __int64 unsigned64_t;
typedef uint64_t unsigned64_t;
#endif

+#ifdef _MSC_VER
+#include <BaseTsd.h>
+typedef SSIZE_T ssize_t;
+#endif
+
#endif
7 changes: 7 additions & 0 deletions recipes/libxls/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES C)

find_package(libxls REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE libxls::libxls)
26 changes: 26 additions & 0 deletions recipes/libxls/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

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.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
12 changes: 12 additions & 0 deletions recipes/libxls/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>

#include "xls.h"

int main() {
struct xlsWorkBook* wb;
struct xlsWorkSheet* ws;

printf("libxls version : %s\n", xls_getVersion());

return 0;
}
8 changes: 8 additions & 0 deletions recipes/libxls/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
16 changes: 16 additions & 0 deletions recipes/libxls/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from conans import ConanFile, CMake, tools
import os

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

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
3 changes: 3 additions & 0 deletions recipes/libxls/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.6.2":
folder: "all"