Skip to content

Commit

Permalink
libsystemd: Include libudev
Browse files Browse the repository at this point in the history
  • Loading branch information
jwillikers committed Oct 2, 2023
1 parent 3706291 commit da2fe83
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 13 deletions.
55 changes: 45 additions & 10 deletions recipes/libsystemd/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class LibsystemdConan(ConanFile):
topics = ("systemd", "service", "manager")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
provides = "libudev"
options = {
"shared": [True, False],
"fPIC": [True, False],
Expand Down Expand Up @@ -55,7 +56,7 @@ def requirements(self):
self.requires("libcap/2.69")
self.requires("libmount/2.39")
if Version(self.version) >= "253.6":
self.requires("libxcrypt/4.4.35")
self.requires("libxcrypt/4.4.36")
if self.options.with_selinux:
self.requires("libselinux/3.3")
if self.options.with_lz4:
Expand All @@ -70,7 +71,7 @@ def validate(self):
raise ConanInvalidConfiguration("Only Linux supported")

def build_requirements(self):
self.tool_requires("meson/1.2.1")
self.tool_requires("meson/1.2.2")
self.tool_requires("m4/1.4.19")
self.tool_requires("gperf/3.1")
if not self.conf.get("tools.gnu:pkg_config", check_type=str):
Expand Down Expand Up @@ -104,10 +105,13 @@ def generate(self):

if self.options.shared:
tc.project_options["static-libsystemd"] = "false"
tc.project_options["static-libudev"] = "false"
elif self.options.fPIC:
tc.project_options["static-libsystemd"] = "pic"
tc.project_options["static-libudev"] = "pic"
else:
tc.project_options["static-libsystemd"] = "no-pic"
tc.project_options["static-libudev"] = "no-pic"

# options unrelated to libsystemd
unrelated = [
Expand Down Expand Up @@ -170,32 +174,63 @@ def build(self):

meson = Meson(self)
meson.configure()
target = ("systemd:shared_library" if self.options.shared
systemd_target = ("systemd:shared_library" if self.options.shared
else "systemd:static_library")
meson.build(target=f"version.h {target}")
udev_target = ("udev:shared_library" if self.options.shared
else "udev:static_library")
meson.build(target=f"version.h {systemd_target} {udev_target}")

def package(self):
copy(self, "LICENSE.LGPL2.1", self.source_folder,
os.path.join(self.package_folder, "licenses"))
copy(self, "*.h", os.path.join(self.source_folder, "src", "systemd"),
os.path.join(self.package_folder, "include", "systemd"))
copy(self, "libudev.h", os.path.join(self.source_folder, "src", "libudev"),
os.path.join(self.package_folder, "include"))

if self.options.shared:
copy(self, "libsystemd.so", self.build_folder,
os.path.join(self.package_folder, "lib"))
copy(self, "libsystemd.so.{}".format(self._so_version.split('.')),
self.build_folder, os.path.join(self.package_folder, "lib"))
copy(self, "libsystemd.so.{}".format(self._so_version),
copy(self, f"libsystemd.so.{self._so_version}",
self.build_folder, os.path.join(self.package_folder, "lib"))
copy(self, "libudev.so", self.build_folder,
os.path.join(self.package_folder, "lib"))
copy(self, "libudev.so.{}".format(self._so_version.split('.')),
self.build_folder, os.path.join(self.package_folder, "lib"))
copy(self, f"libudev.so.{self._so_version}",
self.build_folder, os.path.join(self.package_folder, "lib"))
else:
copy(self, "libsystemd.a", self.build_folder,
os.path.join(self.package_folder, "lib"))
copy(self, "libudev.a", self.build_folder,
os.path.join(self.package_folder, "lib"))

def package_info(self):
self.cpp_info.set_property("pkg_config_name", "libsystemd")
self.cpp_info.set_property("component_version", str(Version(self.version).major))
self.cpp_info.libs = ["systemd"]
self.cpp_info.system_libs = ["rt", "pthread", "dl"]
self.cpp_info.components["libsystemd"].libs = ["systemd"]
self.cpp_info.components["libsystemd"].requires = ["libcap::cap", "libmount::libmount"]
if Version(self.version) >= "253.6":
self.cpp_info.components["libsystemd"].requires.append("libxcrypt::libxcrypt")
if self.options.with_selinux:
self.cpp_info.components["libsystemd"].requires.append("libselinux::selinux")
if self.options.with_lz4:
self.cpp_info.components["libsystemd"].requires.append("lz4::lz4")
if self.options.with_xz:
self.cpp_info.components["libsystemd"].requires.append("xz_utils::xz_utils")
if self.options.with_zstd:
self.cpp_info.components["libsystemd"].requires.append("zstd::zstdlib")
self.cpp_info.components["libsystemd"].set_property("pkg_config_name", "libsystemd")
self.cpp_info.components["libsystemd"].set_property("component_version", str(Version(self.version).major))
self.cpp_info.components["libsystemd"].system_libs = ["rt", "pthread", "dl"]

# TODO: to remove in conan v2
self.cpp_info.components["libsystemd"].version = str(Version(self.version).major)

self.cpp_info.components["libudev"].libs = ["udev"]
self.cpp_info.components["libudev"].requires = ["libcap::cap"]
self.cpp_info.components["libudev"].set_property("pkg_config_name", "libudev")
self.cpp_info.components["libudev"].system_libs = ["rt", "pthread"]

# TODO: to remove in conan v2
self.cpp_info.version = str(Version(self.version).major)
self.cpp_info.components["libudev"].version = str(Version(self.version).major)
2 changes: 1 addition & 1 deletion recipes/libsystemd/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.6)
project(test_package LANGUAGES C)

find_package(PkgConfig REQUIRED)
pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd)
pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd libudev)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::SYSTEMD)
2 changes: 1 addition & 1 deletion recipes/libsystemd/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def requirements(self):

def build_requirements(self):
if not self.conf.get("tools.gnu:pkg_config", check_type=str):
self.tool_requires("pkgconf/1.9.3")
self.tool_requires("pkgconf/2.0.3")

def build(self):
cmake = CMake(self)
Expand Down
21 changes: 21 additions & 0 deletions recipes/libsystemd/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <libudev.h>

#include <systemd/sd-bus.h>

Expand All @@ -11,4 +12,24 @@ int main(void) {
}
puts("failed");
return EXIT_FAILURE;

// Test udev
struct udev *udev;
struct udev_enumerate *enumerate;

udev = udev_new();
if (!udev) {
fprintf(stderr, "Cannot create udev context.\n");
return 1;
}

enumerate = udev_enumerate_new(udev);
if (!enumerate) {
fprintf(stderr, "Cannot create enumerate context.\n");
}

udev_enumerate_unref(enumerate);
udev_unref(udev);

return EXIT_SUCCESS;
}
2 changes: 1 addition & 1 deletion recipes/libsystemd/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TestPackageConan(ConanFile):
generators = "cmake", "pkg_config"

def build_requirements(self):
self.build_requires("pkgconf/1.9.3")
self.build_requires("pkgconf/2.0.3")

def build(self):
cmake = CMake(self)
Expand Down

0 comments on commit da2fe83

Please sign in to comment.