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

libpcap: add support for dbus, libnl and rdma #23383

Merged
merged 8 commits into from
Sep 27, 2024
48 changes: 34 additions & 14 deletions recipes/libpcap/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv
from conan.tools.files import chdir, copy, get, rm, rmdir
from conan.tools.gnu import Autotools, AutotoolsDeps, AutotoolsToolchain
from conan.tools.gnu import Autotools, AutotoolsDeps, AutotoolsToolchain, PkgConfigDeps
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
from conan.tools.scm import Version
Expand All @@ -28,21 +28,22 @@ class LibPcapConan(ConanFile):
options = {
"shared": [True, False],
"fPIC": [True, False],
"enable_dbus": [True, False],
"enable_libnl": [True, False],
"enable_libusb": [True, False],
"enable_rdma": [True, False],
"with_snf": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"enable_dbus": False,
"enable_libnl": False,
"enable_libusb": False,
"enable_rdma": False,
"with_snf": False,
}

# TODO: Add dbus-glib when available
# TODO: Add libnl-genl when available
# TODO: Add libbluetooth when available
# TODO: Add libibverbs when available

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)
Expand All @@ -52,6 +53,8 @@ def config_options(self):
del self.options.fPIC
if self.settings.os != "Linux":
del self.options.enable_libusb
del self.options.enable_libnl
del self.options.enable_rdma

def configure(self):
if self.options.shared:
Expand All @@ -68,6 +71,13 @@ def layout(self):
def requirements(self):
if self.options.get_safe("enable_libusb"):
self.requires("libusb/1.0.26")
if self.options.get_safe("enable_libnl"):
self.requires("libnl/3.8.0")
if self.options.get_safe("enable_rdma"):
self.requires("rdma-core/52.0")
if self.options.get_safe("enable_dbus"):
self.requires("dbus/1.15.8")
# TODO: Add libbluetooth when available

def validate(self):
if Version(self.version) < "1.10.0" and self.settings.os == "Macos" and self.options.shared:
Expand All @@ -80,7 +90,7 @@ def validate(self):

def build_requirements(self):
if self._settings_build.os == "Windows":
self.tool_requires("winflexbison/2.5.24")
self.tool_requires("winflexbison/2.5.25")
else:
self.tool_requires("bison/3.8.2")
self.tool_requires("flex/2.6.4")
Expand Down Expand Up @@ -109,16 +119,16 @@ def generate(self):
tc = AutotoolsToolchain(self)
yes_no = lambda v: "yes" if v else "no"
tc.configure_args.extend([
f"--enable-usb={yes_no(self.options.get_safe('enable_libusb'))}",
"--disable-universal",
"--without-libnl",
"--disable-universal", # don't build universal binaries on macOS
"--enable-usb" if self.options.get_safe("enable_libusb") else "--disable-usb",
"--enable-dbus" if self.options.get_safe("enable_dbus") else "--disable-dbus",
"--enable-rdma" if self.options.get_safe("enable_rdma") else "--disable-rdma",
"--with-libnl" if self.options.get_safe("enable_libnl") else "--without-libnl",
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
"--disable-bluetooth",
"--disable-packet-ring",
"--disable-dbus",
"--disable-rdma",
f"--with-snf={yes_no(self.options.get_safe('with_snf'))}",
])

if Version(self.version) < "1.10":
tc.configure_args.append("--disable-packet-ring")
if cross_building(self):
target_os = "linux" if self.settings.os == "Linux" else "null"
tc.configure_args.append(f"--with-pcap={target_os}")
Expand All @@ -127,6 +137,8 @@ def generate(self):
tc.generate()

AutotoolsDeps(self).generate()
deps = PkgConfigDeps(self)
deps.generate()

def build(self):
if self.settings.os == "Windows":
Expand Down Expand Up @@ -175,5 +187,13 @@ def package_info(self):
self.cpp_info.libs = [f"pcap{suffix}"]
if self.settings.os == "Windows":
self.cpp_info.system_libs = ["ws2_32"]
if self.options.get_safe("enable_libusb"):
self.cpp_info.requires.append("libusb::libusb")
if self.options.get_safe("enable_libnl"):
self.cpp_info.requires.append("libnl::nl-genl")
if self.options.get_safe("enable_rdma"):
self.cpp_info.requires.append("rdma-core::libibverbs")
if self.options.get_safe("enable_dbus"):
self.cpp_info.requires.append("dbus::dbus")
if self.options.get_safe("with_snf"):
self.cpp_info.system_libs.append("snf")
Loading