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

yder: add yder/1.4.18 recipe #13614

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions recipes/yder/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sources:
"1.4.18":
url: "https://github.com/babelouest/yder/archive/refs/tags/v1.4.18.tar.gz"
sha256: "b69cc81f6630f66468595d151446c00c90abed058f03f82e151591b8598a7598"
patches:
"1.4.18":
- patch_file: "patches/1.4.18-0001-shared-static-conan.patch"
patch_description: "Build shared and static libraries"
patch_type: "portability"
149 changes: 149 additions & 0 deletions recipes/yder/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
from conan import ConanFile
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rmdir, save
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.microsoft import is_msvc
import os
import textwrap

required_conan_version = ">=1.52.0"


class YderConan(ConanFile):
name = "yder"
description = "Logging library for C applications"
homepage = "https://github.com/babelouest/yder"
topics = ("logging", "stdout", "file", "journald", "systemd")
license = "LGPL-2.1-or-later"
url = "https://github.com/conan-io/conan-center-index"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_libsystemd": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_libsystemd": True,
}

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
del self.options.with_libsystemd

def configure(self):
if self.options.shared:
try:
del self.options.fPIC
except Exception:
pass
try:
del self.settings.compiler.libcxx
except Exception:
pass
try:
del self.settings.compiler.cppstd
except Exception:
pass

def requirements(self):
self.requires("orcania/2.3.1")
if self.options.get_safe("with_libsystemd"):
self.requires("libsystemd/251.4")

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

def export_sources(self):
export_conandata_patches(self)

def layout(self):
cmake_layout(self, src_folder="src")

def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_SHARED"] = self.options.shared
tc.variables["BUILD_STATIC"] = not self.options.shared
tc.variables["DOWNLOAD_DEPENDENCIES"] = False
tc.variables["WITH_JOURNALD"] = self.options.get_safe("with_libsystemd", False)
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def _patch_sources(self):
apply_conandata_patches(self)
if self.options.shared:
if not self.dependencies["orcania"].options.shared:
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "Orcania::Orcania", "Orcania::Orcania-static")

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

def package(self):
copy(self, "LICENSE", os.path.join(self.source_folder), os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()

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

save(self, os.path.join(self.package_folder, self._variable_file_rel_path),
textwrap.dedent(f"""\
set(YDER_VERSION_STRING "{self.version}")
"""))

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{} if self.options.shared else {"Yder::Yder-static": "Yder::Yder"}
)

def _create_cmake_module_alias_targets(self, module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent(f"""\
if(TARGET {aliased} AND NOT TARGET {alias})
add_library({alias} INTERFACE IMPORTED)
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""")
save(self, module_file, content)

@property
def _module_file_rel_path(self):
return os.path.join("lib", "cmake", f"conan-official-{self.name}-targets.cmake")

@property
def _variable_file_rel_path(self):
return os.path.join("lib", "cmake", f"conan-official-{self.name}-variables.cmake")

def package_info(self):
libname = "yder"
if is_msvc(self) and not self.options.shared:
libname += "-static"
self.cpp_info.libs = [libname]

target_name = "Yder::Yder" if self.options.shared else "Yder::Yder-static"
self.cpp_info.set_property("cmake_file_name", "Yder")
self.cpp_info.set_property("cmake_target_name", target_name)
self.cpp_info.set_property("cmake_module_file_name", "Yder")
self.cpp_info.set_property("cmake_module_target_name", target_name)
self.cpp_info.set_property("pkg_config_name", "libyder")
self.cpp_info.set_property("cmake_build_modules", [self._variable_file_rel_path])

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.filenames["cmake_find_package"] = "Yder"
self.cpp_info.filenames["cmake_find_package_multi"] = "Yder"
self.cpp_info.names["cmake_find_package"] = "Yder"
self.cpp_info.names["cmake_find_package_multi"] = "Yder"
self.cpp_info.names["pkg_config"] = "libyder"
self.cpp_info.builddirs.append(os.path.join("lib", "cmake"))
self.cpp_info.build_modules["cmake_find_package"] = [self._module_file_rel_path, self._variable_file_rel_path]
self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path, self._variable_file_rel_path]
Loading