Skip to content

Commit 6818b22

Browse files
committed
yder: add yder/1.4.18 recipe
1 parent 111b041 commit 6818b22

File tree

9 files changed

+655
-0
lines changed

9 files changed

+655
-0
lines changed

recipes/yder/all/conandata.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
sources:
2+
"1.4.18":
3+
url: "https://github.com/babelouest/yder/archive/refs/tags/v1.4.18.tar.gz"
4+
sha256: "b69cc81f6630f66468595d151446c00c90abed058f03f82e151591b8598a7598"
5+
patches:
6+
"1.4.18":
7+
- patch_file: "patches/1.4.18-0001-shared-static-conan.patch"
8+
patch_description: "Build shared and static libraries"
9+
patch_type: "portability"

recipes/yder/all/conanfile.py

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
from conan import ConanFile
2+
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir, save
3+
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
4+
from conan.tools.microsoft import is_msvc
5+
import os
6+
import textwrap
7+
8+
required_conan_version = ">=1.52.0"
9+
10+
11+
class YderConan(ConanFile):
12+
name = "yder"
13+
description = "Logging library for C applications"
14+
homepage = "https://github.com/babelouest/yder"
15+
topics = ("logging", "stdout", "file", "journald", "systemd")
16+
license = "LGPL-2.1-or-later"
17+
url = "https://github.com/conan-io/conan-center-index"
18+
settings = "os", "arch", "compiler", "build_type"
19+
options = {
20+
"shared": [True, False],
21+
"fPIC": [True, False],
22+
"with_libsystemd": [True, False],
23+
}
24+
default_options = {
25+
"shared": False,
26+
"fPIC": True,
27+
"with_libsystemd": True,
28+
}
29+
30+
def config_options(self):
31+
if self.settings.os == "Windows":
32+
del self.options.fPIC
33+
del self.options.with_libsystemd
34+
35+
def configure(self):
36+
if self.options.shared:
37+
try:
38+
del self.options.fPIC
39+
except Exception:
40+
pass
41+
try:
42+
del self.settings.compiler.libcxx
43+
except Exception:
44+
pass
45+
try:
46+
del self.settings.compiler.cppstd
47+
except Exception:
48+
pass
49+
50+
def requirements(self):
51+
self.requires("orcania/2.3.1")
52+
if self.options.get_safe("with_libsystemd"):
53+
self.requires("libsystemd/251.4")
54+
55+
def source(self):
56+
get(self, **self.conan_data["sources"][self.version],
57+
destination=self.source_folder, strip_root=True)
58+
59+
def export_sources(self):
60+
export_conandata_patches(self)
61+
62+
def layout(self):
63+
cmake_layout(self, src_folder="src")
64+
65+
def generate(self):
66+
tc = CMakeToolchain(self)
67+
tc.variables["BUILD_SHARED"] = self.options.shared
68+
tc.variables["BUILD_STATIC"] = not self.options.shared
69+
tc.variables["DOWNLOAD_DEPENDENCIES"] = False
70+
tc.variables["WITH_JOURNALD"] = self.options.get_safe("with_libsystemd", False)
71+
tc.generate()
72+
deps = CMakeDeps(self)
73+
deps.generate()
74+
75+
def _patch_sources(self):
76+
apply_conandata_patches(self)
77+
78+
def build(self):
79+
self._patch_sources()
80+
cmake = CMake(self)
81+
cmake.configure()
82+
cmake.build()
83+
84+
def package(self):
85+
copy(self, "LICENSE", os.path.join(self.source_folder), os.path.join(self.package_folder, "licenses"))
86+
cmake = CMake(self)
87+
cmake.install()
88+
89+
rmdir(self, os.path.join(self.package_folder, "cmake"))
90+
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
91+
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
92+
rmdir(self, os.path.join(self.package_folder, "share"))
93+
94+
save(self, os.path.join(self.package_folder, self._variable_file_rel_path),
95+
textwrap.dedent(f"""\
96+
set(YDER_VERSION_STRING "{self.version}")
97+
"""))
98+
99+
# TODO: to remove in conan v2 once cmake_find_package* generators removed
100+
self._create_cmake_module_alias_targets(
101+
os.path.join(self.package_folder, self._module_file_rel_path),
102+
{} if self.options.shared else {"Yder::Yder-static": "Yder::Yder"}
103+
)
104+
105+
def _create_cmake_module_alias_targets(self, module_file, targets):
106+
content = ""
107+
for alias, aliased in targets.items():
108+
content += textwrap.dedent(f"""\
109+
if(TARGET {aliased} AND NOT TARGET {alias})
110+
add_library({alias} INTERFACE IMPORTED)
111+
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
112+
endif()
113+
""")
114+
save(self, module_file, content)
115+
116+
@property
117+
def _module_file_rel_path(self):
118+
return os.path.join("lib", "cmake", f"conan-official-{self.name}-targets.cmake")
119+
120+
@property
121+
def _variable_file_rel_path(self):
122+
return os.path.join("lib", "cmake", f"conan-official-{self.name}-variables.cmake")
123+
124+
def package_info(self):
125+
libname = "yder"
126+
if is_msvc(self) and not self.options.shared:
127+
libname += "-static"
128+
self.cpp_info.libs = [libname]
129+
130+
target_name = "Yder::Yder" if self.options.shared else "Yder::Yder-static"
131+
self.cpp_info.set_property("cmake_file_name", "Yder")
132+
self.cpp_info.set_property("cmake_target_name", target_name)
133+
self.cpp_info.set_property("cmake_module_file_name", "Yder")
134+
self.cpp_info.set_property("cmake_module_target_name", target_name)
135+
self.cpp_info.set_property("pkg_config_name", "libyder")
136+
self.cpp_info.set_property("cmake_build_modules", [self._variable_file_rel_path])
137+
138+
# TODO: to remove in conan v2 once cmake_find_package_* generators removed
139+
self.cpp_info.filenames["cmake_find_package"] = "Yder"
140+
self.cpp_info.filenames["cmake_find_package_multi"] = "Yder"
141+
self.cpp_info.names["cmake_find_package"] = "Yder"
142+
self.cpp_info.names["cmake_find_package_multi"] = "Yder"
143+
self.cpp_info.names["pkg_config"] = "libyder"
144+
self.cpp_info.builddirs.append(os.path.join("lib", "cmake"))
145+
self.cpp_info.build_modules["cmake_find_package"] = [self._module_file_rel_path, self._variable_file_rel_path]
146+
self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path, self._variable_file_rel_path]

0 commit comments

Comments
 (0)