|
| 1 | +from conan import ConanFile |
| 2 | +from conan.errors import ConanInvalidConfiguration |
| 3 | +from conan.tools.files import copy, get, rm, rmdir |
| 4 | +from conan.tools.gnu import Autotools, AutotoolsToolchain |
| 5 | +from conan.tools.layout import basic_layout |
| 6 | +import os |
| 7 | + |
| 8 | + |
| 9 | +required_conan_version = ">=2.4.0" |
| 10 | + |
| 11 | + |
| 12 | +class PackageConan(ConanFile): |
| 13 | + name = "libsocketcan" |
| 14 | + description = "Library to control some basic functions in SocketCAN from userspace" |
| 15 | + license = "LGPL-2.1-or-later" |
| 16 | + url = "https://github.com/conan-io/conan-center-index" |
| 17 | + homepage = "https://github.com/linux-can/libsocketcan" |
| 18 | + topics = ("socket", "socketcan", "canbus") |
| 19 | + package_type = "library" |
| 20 | + settings = "os", "arch", "compiler", "build_type" |
| 21 | + languages = "C" |
| 22 | + options = { |
| 23 | + "shared": [True, False], |
| 24 | + "fPIC": [True, False], |
| 25 | + } |
| 26 | + default_options = { |
| 27 | + "shared": False, |
| 28 | + "fPIC": True, |
| 29 | + } |
| 30 | + implements = ["auto_shared_fpic"] |
| 31 | + |
| 32 | + def layout(self): |
| 33 | + basic_layout(self, src_folder="src") |
| 34 | + |
| 35 | + def validate(self): |
| 36 | + if self.settings.os not in ["Linux", "FreeBSD", "Android"]: |
| 37 | + raise ConanInvalidConfiguration("Only supported on Linux, FreeBSD and Android.") |
| 38 | + |
| 39 | + def build_requirements(self): |
| 40 | + self.tool_requires("libtool/2.4.7") |
| 41 | + if not self.conf.get("tools.gnu:pkg_config", check_type=str): |
| 42 | + self.tool_requires("pkgconf/[>=2.2 <3]") |
| 43 | + |
| 44 | + def source(self): |
| 45 | + get(self, **self.conan_data["sources"][self.version], strip_root=True) |
| 46 | + |
| 47 | + def generate(self): |
| 48 | + tc = AutotoolsToolchain(self) |
| 49 | + tc.generate() |
| 50 | + |
| 51 | + def build(self): |
| 52 | + autotools = Autotools(self) |
| 53 | + autotools.autoreconf() |
| 54 | + autotools.configure() |
| 55 | + autotools.make() |
| 56 | + |
| 57 | + def package(self): |
| 58 | + copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) |
| 59 | + autotools = Autotools(self) |
| 60 | + autotools.install() |
| 61 | + |
| 62 | + rm(self, "*.la", os.path.join(self.package_folder, "lib")) |
| 63 | + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) |
| 64 | + rmdir(self, os.path.join(self.package_folder, "share")) |
| 65 | + |
| 66 | + def package_info(self): |
| 67 | + self.cpp_info.libs = ["socketcan"] |
| 68 | + self.cpp_info.set_property("pkg_config_name", "libsocketcan") |
0 commit comments