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

freexl: conan v2 support #15520

Merged
merged 1 commit into from
Feb 1, 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
3 changes: 0 additions & 3 deletions recipes/freexl/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ sources:
patches:
"1.0.6":
- patch_file: "patches/fix-nmake-1.0.6.patch"
base_path: "source_subfolder"
"1.0.5":
- patch_file: "patches/fix-nmake-1.0.5.patch"
base_path: "source_subfolder"
- patch_file: "patches/msvc-round-lround.patch"
base_path: "source_subfolder"
137 changes: 66 additions & 71 deletions recipes/freexl/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
from conans import ConanFile, AutoToolsBuildEnvironment, VisualStudioBuildEnvironment, tools
import functools
from conan import ConanFile
from conan.tools.apple import fix_apple_shared_install_name
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
import shutil

required_conan_version = ">=1.36.0"
required_conan_version = ">=1.55.0"


class FreexlConan(ConanFile):
name = "freexl"
description = "FreeXL is an open source library to extract valid data " \
"from within an Excel (.xls) spreadsheet."
license = ["MPL-1.0", "GPL-2.0-only", "LGPL-2.1-only"]
topics = ("freexl", "excel", "xls")
topics = ("excel", "xls")
homepage = "https://www.gaia-gis.it/fossil/freexl/index"
url = "https://github.com/conan-io/conan-center-index"

Expand All @@ -25,100 +30,90 @@ class FreexlConan(ConanFile):
"fPIC": True,
}

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _is_msvc(self):
return str(self.settings.compiler) in ["Visual Studio", "msvc"]

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

@property
def _user_info_build(self):
return getattr(self, "user_info_build", self.deps_user_info)

def export_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.cppstd
del self.settings.compiler.libcxx
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

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

def requirements(self):
self.requires("libiconv/1.16")
self.requires("libiconv/1.17")

def build_requirements(self):
if not self._is_msvc:
self.build_requires("gnu-config/cci.20201022")
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
self.build_requires("msys2/cci.latest")
if not is_msvc(self):
self.tool_requires("gnu-config/cci.20210814")
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):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
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):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)

if self._is_msvc:
self._build_msvc()
apply_conandata_patches(self)
if is_msvc(self):
args = "freexl_i.lib FREEXL_EXPORT=-DDLL_EXPORT" if self.options.shared else "freexl.lib"
with chdir(self, self.source_folder):
self.run(f"nmake -f makefile.vc {args}")
else:
shutil.copy(self._user_info_build["gnu-config"].CONFIG_SUB,
os.path.join(self._source_subfolder, "config.sub"))
shutil.copy(self._user_info_build["gnu-config"].CONFIG_GUESS,
os.path.join(self._source_subfolder, "config.guess"))
# relocatable shared lib on macOS
tools.replace_in_file(os.path.join(self._source_subfolder, "configure"),
"-install_name \\$rpath/",
"-install_name @rpath/")
autotools = self._configure_autotools()
for gnu_config in [
self.conf.get("user.gnu-config:config_guess", check_type=str),
self.conf.get("user.gnu-config:config_sub", check_type=str),
]:
if gnu_config:
copy(self, os.path.basename(gnu_config), src=os.path.dirname(gnu_config), dst=self.source_folder)
autotools = Autotools(self)
autotools.configure()
autotools.make()

def _build_msvc(self):
args = "freexl_i.lib FREEXL_EXPORT=-DDLL_EXPORT" if self.options.shared else "freexl.lib"
with tools.chdir(self._source_subfolder):
with tools.vcvars(self.settings):
with tools.environment_append(VisualStudioBuildEnvironment(self).vars):
self.run("nmake -f makefile.vc {}".format(args))

@functools.lru_cache(1)
def _configure_autotools(self):
autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
yes_no = lambda v: "yes" if v else "no"
args = [
"--enable-shared={}".format(yes_no(self.options.shared)),
"--enable-static={}".format(yes_no(not self.options.shared)),
]
autotools.configure(args=args, configure_dir=self._source_subfolder)
return autotools

def package(self):
self.copy("COPYING", dst="licenses", src=self._source_subfolder)
if self._is_msvc:
self.copy("freexl.h", dst="include", src=os.path.join(self._source_subfolder, "headers"))
self.copy("*.lib", dst="lib", src=self._source_subfolder)
self.copy("*.dll", dst="bin", src=self._source_subfolder)
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
if is_msvc(self):
copy(self, "freexl.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 = self._configure_autotools()
autotools = Autotools(self)
autotools.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
fix_apple_shared_install_name(self)

def package_info(self):
self.cpp_info.set_property("pkg_config_name", "freexl")
suffix = "_i" if self._is_msvc and self.options.shared else ""
self.cpp_info.libs = ["freexl{}".format(suffix)]
suffix = "_i" if is_msvc(self) and self.options.shared else ""
self.cpp_info.libs = [f"freexl{suffix}"]
if self.settings.os in ("FreeBSD", "Linux"):
self.cpp_info.system_libs.append("m")
7 changes: 2 additions & 5 deletions recipes/freexl/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
project(test_package LANGUAGES C)

find_package(freexl REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} freexl::freexl)
target_link_libraries(${PROJECT_NAME} PRIVATE freexl::freexl)
26 changes: 13 additions & 13 deletions recipes/freexl/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
from conans import ConanFile, CMake, tools
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 = "cmake", "cmake_find_package_multi"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def build_requirements(self):
if self.settings.os == "Macos" and self.settings.arch == "armv8":
# Workaround for CMake bug with error message:
# Attempting to use @rpath without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being
# set. This could be because you are using a Mac OS X version less than 10.5
# or because CMake's platform configuration is corrupt.
# FIXME: Remove once CMake on macOS/M1 CI runners is upgraded.
self.build_requires("cmake/3.22.0")
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 not tools.cross_building(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
xls_path = os.path.join(self.source_folder, "simple2003_21.xls")
bin_path = os.path.join("bin", "test_package")
self.run("{0} {1}".format(bin_path, xls_path), run_environment=True)
self.run(f"{bin_path} {xls_path}", env="conanrun")
8 changes: 8 additions & 0 deletions recipes/freexl/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)
18 changes: 18 additions & 0 deletions recipes/freexl/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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")
xls_path = os.path.join(self.source_folder, os.pardir, "test_package", "simple2003_21.xls")
self.run(f"{bin_path} {xls_path}", run_environment=True)