Skip to content

Commit

Permalink
libcap/all: cross-compatibility conan v1/v2
Browse files Browse the repository at this point in the history
  • Loading branch information
bobrofon committed Aug 15, 2022
1 parent 0b20246 commit aa1caaa
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 94 deletions.
48 changes: 16 additions & 32 deletions recipes/libcap/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,26 @@ sources:

patches:
"2.45":
- base_path: "source_subfolder"
patch_file: "patches/2.45/0001-Make.Rules-Remove-hardcoded-fPIC.patch"
- base_path: "source_subfolder"
patch_file: "patches/2.45/0002-Make.Rules-Make-compile-tools-configurable.patch"
- patch_file: "patches/2.45/0001-Make.Rules-Remove-hardcoded-fPIC.patch"
- patch_file: "patches/2.45/0002-Make.Rules-Make-compile-tools-configurable.patch"
"2.46":
- base_path: "source_subfolder"
patch_file: "patches/2.45/0001-Make.Rules-Remove-hardcoded-fPIC.patch"
- base_path: "source_subfolder"
patch_file: "patches/2.45/0002-Make.Rules-Make-compile-tools-configurable.patch"
- patch_file: "patches/2.45/0001-Make.Rules-Remove-hardcoded-fPIC.patch"
- patch_file: "patches/2.45/0002-Make.Rules-Make-compile-tools-configurable.patch"
"2.48":
- base_path: "source_subfolder"
patch_file: "patches/2.45/0001-Make.Rules-Remove-hardcoded-fPIC.patch"
- base_path: "source_subfolder"
patch_file: "patches/2.45/0002-Make.Rules-Make-compile-tools-configurable.patch"
- patch_file: "patches/2.45/0001-Make.Rules-Remove-hardcoded-fPIC.patch"
- patch_file: "patches/2.45/0002-Make.Rules-Make-compile-tools-configurable.patch"
"2.50":
- base_path: "source_subfolder"
patch_file: "patches/2.45/0001-Make.Rules-Remove-hardcoded-fPIC.patch"
- base_path: "source_subfolder"
patch_file: "patches/2.45/0002-Make.Rules-Make-compile-tools-configurable.patch"
- patch_file: "patches/2.45/0001-Make.Rules-Remove-hardcoded-fPIC.patch"
- patch_file: "patches/2.45/0002-Make.Rules-Make-compile-tools-configurable.patch"
"2.57":
- base_path: "source_subfolder"
patch_file: "patches/2.57/0001-libcap-Remove-hardcoded-fPIC.patch"
- base_path: "source_subfolder"
patch_file: "patches/2.57/0002-Make.Rules-Make-compile-tools-configurable.patch"
- patch_file: "patches/2.57/0001-libcap-Remove-hardcoded-fPIC.patch"
- patch_file: "patches/2.57/0002-Make.Rules-Make-compile-tools-configurable.patch"
"2.58":
- base_path: "source_subfolder"
patch_file: "patches/2.57/0001-libcap-Remove-hardcoded-fPIC.patch"
- base_path: "source_subfolder"
patch_file: "patches/2.57/0002-Make.Rules-Make-compile-tools-configurable.patch"
- patch_file: "patches/2.57/0001-libcap-Remove-hardcoded-fPIC.patch"
- patch_file: "patches/2.57/0002-Make.Rules-Make-compile-tools-configurable.patch"
"2.62":
- base_path: "source_subfolder"
patch_file: "patches/2.57/0001-libcap-Remove-hardcoded-fPIC.patch"
- base_path: "source_subfolder"
patch_file: "patches/2.57/0002-Make.Rules-Make-compile-tools-configurable.patch"
- patch_file: "patches/2.57/0001-libcap-Remove-hardcoded-fPIC.patch"
- patch_file: "patches/2.57/0002-Make.Rules-Make-compile-tools-configurable.patch"
"2.65":
- base_path: "source_subfolder"
patch_file: "patches/2.57/0001-libcap-Remove-hardcoded-fPIC.patch"
- base_path: "source_subfolder"
patch_file: "patches/2.57/0002-Make.Rules-Make-compile-tools-configurable.patch"
- patch_file: "patches/2.57/0001-libcap-Remove-hardcoded-fPIC.patch"
- patch_file: "patches/2.57/0002-Make.Rules-Make-compile-tools-configurable.patch"
107 changes: 55 additions & 52 deletions recipes/libcap/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import os

from conans import ConanFile, tools, AutoToolsBuildEnvironment
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import cross_building
from conan.tools.files import apply_conandata_patches, copy, chdir, get, rmdir
from conan.tools.layout import basic_layout
from conan.tools.gnu import Autotools, AutotoolsToolchain

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.37.0"


class LibcapConan(ConanFile):
Expand All @@ -26,82 +30,81 @@ class LibcapConan(ConanFile):
"psx_syscals": False,
}
exports_sources = "patches/**"
generators = "VirtualBuildEnv", "VirtualRunEnv"

_autotools = None
_autotools_env = None

@property
def _source_subfolder(self):
return "source_subfolder"
def validate(self):
if self.info.settings.os != "Linux":
raise ConanInvalidConfiguration("Only Linux supported")

def configure(self):
if self.settings.os != "Linux":
raise ConanInvalidConfiguration("Only Linux supported")
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
try:
del self.settings.compiler.libcxx
except Exception:
pass
try:
del self.settings.compiler.cppstd
except Exception:
pass

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

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

def _configure_autotools(self):
if self._autotools:
return self._autotools, self._autotools_env
self._autotools = AutoToolsBuildEnvironment(self)
self._autotools.fpic = self.options.get_safe("fPIC", True)
self._autotools_env = self._autotools.vars
self._autotools_env["SHARED"] = \
"yes" if self.options.shared else "no"
self._autotools_env["PTHREADS"] = \
"yes" if self.options.psx_syscals else "no"
self._autotools_env["DESTDIR"] = self.package_folder
self._autotools_env["prefix"] = "/"
self._autotools_env["lib"] = "lib"

if tools.cross_building(self) and not tools.get_env("BUILD_CC"):
native_cc = tools.which("cc")
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = AutotoolsToolchain(self)
tc.fpic = self.options.get_safe("fPIC", True)
env = tc.environment()
env.define("SHARED", "yes" if self.options.shared else "no")
env.define("PTHREADS", "yes" if self.options.psx_syscals else "no")
env.define("DESTDIR", self.package_folder)
env.define("prefix", "/")
env.define("lib", "lib")

if cross_building(self) and not env.vars(self).get("BUILD_CC"):
native_cc = "cc"
self.output.info("Using native compiler '{}'".format(native_cc))
self._autotools_env["BUILD_CC"] = native_cc
env.define("BUILD_CC", native_cc)

return self._autotools, self._autotools_env

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
tc.generate(env)

def build(self):
self._patch_sources()
apply_conandata_patches(self)

with tools.chdir(os.path.join(self._source_subfolder, self.name)):
env_build, env_build_vars = self._configure_autotools()
env_build.make(vars=env_build_vars)
autotools = Autotools(self)
with chdir(self, os.path.join(self.source_folder, self.name)):
autotools.make()

def package(self):
self.copy("License", dst="licenses", src=self._source_subfolder)

with tools.chdir(os.path.join(self._source_subfolder, self.name)):
env_build, env_build_vars = self._configure_autotools()
copy(self, "License", self.source_folder,
os.path.join(self.package_folder, "licenses"), keep_path=False)

env_build.make(target="install-common-cap", vars=env_build_vars)
autotools = Autotools(self)
with chdir(self, os.path.join(self.source_folder, self.name)):
autotools.make(target="install-common-cap")
install_cap = ("install-shared-cap" if self.options.shared
else "install-static-cap")
env_build.make(target=install_cap, vars=env_build_vars)
autotools.make(target=install_cap)

if self.options.psx_syscals:
env_build.make(target="install-common-psx",
vars=env_build_vars)
autotools.make(target="install-common-psx")
install_psx = ("install-shared-psx" if self.options.shared
else "install-static-psx")
env_build.make(target=install_psx, vars=env_build_vars)
autotools.make(target=install_psx)

tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))

def package_info(self):
self.cpp_info.components["cap"].set_property("pkg_config_name",
"libcap")
self.cpp_info.components["cap"].names["pkg_config"] = "libcap"
self.cpp_info.components["cap"].libs = ["cap"]
if self.options.psx_syscals:
self.cpp_info.components["psx"].set_property("pkg_config_name",
"libpsx")
self.cpp_info.components["psx"].names["pkg_config"] = "libpsx"
self.cpp_info.components["psx"].libs = ["psx"]
self.cpp_info.components["psx"].system_libs = ["pthread"]
Expand Down
7 changes: 2 additions & 5 deletions recipes/libcap/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
cmake_minimum_required(VERSION 3.1)
project(PackageTest C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
cmake_minimum_required(VERSION 3.15)
project(PackageTest LANGUAGES C)

find_package(PkgConfig REQUIRED)
pkg_check_modules(CAP REQUIRED IMPORTED_TARGET libcap)
Expand Down
30 changes: 25 additions & 5 deletions recipes/libcap/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
import os

from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake
from conan.tools.env import Environment
from conan.tools.cmake import cmake_layout

required_conan_version = ">=1.38.0"


class LibcapTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "pkg_config"
generators = "CMakeToolchain", "PkgConfigDeps", "VirtualBuildEnv", \
"VirtualRunEnv"
test_type = "explicit"

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

def layout(self):
cmake_layout(self)

def generate(self):
env = Environment()
env.prepend_path("PKG_CONFIG_PATH", self.generators_folder)
envvars = env.vars(self)
envvars.save_script("pkg_config")

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", "example")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "example")
self.run(bin_path, env="conanrun")
11 changes: 11 additions & 0 deletions recipes/libcap/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.1)
project(PackageTest C)

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

find_package(PkgConfig REQUIRED)
pkg_check_modules(CAP REQUIRED IMPORTED_TARGET libcap)

add_executable(example ../test_package/example.c)
target_link_libraries(example PRIVATE PkgConfig::CAP)
20 changes: 20 additions & 0 deletions recipes/libcap/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os

from conan import ConanFile
from conan.tools.build import cross_building
from conans import CMake


class LibcapTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "pkg_config"

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

def test(self):
if not cross_building(self):
bin_path = os.path.join("bin", "example")
self.run(bin_path, run_environment=True)

0 comments on commit aa1caaa

Please sign in to comment.