From 72326ce2ec049c8f4abac3bdf360e732240fab3a Mon Sep 17 00:00:00 2001 From: Artur Mukhamadiev Date: Sat, 5 Jul 2025 16:57:17 +0000 Subject: [PATCH] example of Conan packages --- glog/0.7.1-unwindfix/conandata.yml | 4 + glog/0.7.1-unwindfix/conanfile.py | 129 +++++++++++++++++++++++ glog/config.yml | 3 + libunwind/1.8.2/conandata.yml | 4 + libunwind/1.8.2/conanfile.py | 161 +++++++++++++++++++++++++++++ libunwind/config.yml | 3 + 6 files changed, 304 insertions(+) create mode 100644 glog/0.7.1-unwindfix/conandata.yml create mode 100644 glog/0.7.1-unwindfix/conanfile.py create mode 100644 glog/config.yml create mode 100644 libunwind/1.8.2/conandata.yml create mode 100644 libunwind/1.8.2/conanfile.py create mode 100644 libunwind/config.yml diff --git a/glog/0.7.1-unwindfix/conandata.yml b/glog/0.7.1-unwindfix/conandata.yml new file mode 100644 index 0000000..6806477 --- /dev/null +++ b/glog/0.7.1-unwindfix/conandata.yml @@ -0,0 +1,4 @@ +sources: + "0.7.1-unwindfix": + url: "https://github.com/google/glog/archive/refs/tags/v0.7.1.tar.gz" + sha256: "00e4a87e87b7e7612f519a41e491f16623b12423620006f59f5688bfd8d13b08" diff --git a/glog/0.7.1-unwindfix/conanfile.py b/glog/0.7.1-unwindfix/conanfile.py new file mode 100644 index 0000000..79ca199 --- /dev/null +++ b/glog/0.7.1-unwindfix/conanfile.py @@ -0,0 +1,129 @@ +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout, CMakeDeps +from conan.tools.env import VirtualBuildEnv +from conan.tools.files import copy, get, rmdir +from conan.tools.scm import Version +from conan.tools.build import check_min_cppstd +import os + +required_conan_version = ">=1.54.0" + + +class GlogConan(ConanFile): + name = "glog" + version = "0.7.1-unwindfix" + description = "Google logging library" + license = "BSD-3-Clause" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/google/glog/" + topics = ("logging",) + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + "with_gflags": [True, False], + "with_threads": [True, False], + "with_unwind": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + "with_gflags": True, + "with_threads": True, + "with_unwind": True, + } + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + if self.settings.os not in ["Linux", "FreeBSD"]: + del self.options.with_unwind + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + if self.options.with_gflags: + self.options["gflags"].shared = self.options.shared + + def layout(self): + cmake_layout(self, src_folder="src") + + def requirements(self): + if self.options.with_gflags: + self.requires("gflags/2.2.2", transitive_headers=True, transitive_libs=True) + # 0.4.0 requires libunwind unconditionally + if self.options.get_safe("with_unwind"): + self.requires("libunwind/1.8.2", transitive_headers=True, transitive_libs=True) + + def validate(self): + if Version(self.version) < "0.7.0": + return + + check_min_cppstd(self, 14) + + def build_requirements(self): + if Version(self.version) >= "0.7.0": + self.tool_requires("cmake/[>=3.22 <4]") + elif Version(self.version) >= "0.6.0": + self.tool_requires("cmake/[>=3.16 <4]") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = VirtualBuildEnv(self) + tc.generate() + + tc = CMakeToolchain(self) + tc.variables["WITH_GFLAGS"] = self.options.with_gflags + tc.variables["WITH_THREADS"] = self.options.with_threads + tc.variables["WITH_PKGCONFIG"] = True + if self.settings.os == "Emscripten": + tc.variables["WITH_SYMBOLIZE"] = False + tc.variables["HAVE_SYSCALL_H"] = False + tc.variables["HAVE_SYS_SYSCALL_H"] = False + else: + tc.variables["WITH_SYMBOLIZE"] = True + tc.variables["WITH_UNWIND"] = self.options.get_safe("with_unwind", default=False) + tc.variables["BUILD_TESTING"] = False + tc.variables["WITH_GTEST"] = False + # TODO: Remove after fixing https://github.com/conan-io/conan/issues/12012 + # Needed for https://github.com/google/glog/blob/v0.7.1/CMakeLists.txt#L81 + # and https://github.com/google/glog/blob/v0.7.1/CMakeLists.txt#L90 + tc.variables["CMAKE_TRY_COMPILE_CONFIGURATION"] = str(self.settings.build_type) + tc.generate() + + tc = CMakeDeps(self) + tc.generate() + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + copy(self, "COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + cmake = CMake(self) + cmake.install() + 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")) + + def package_info(self): + self.cpp_info.set_property("cmake_file_name", "glog") + self.cpp_info.set_property("cmake_target_name", "glog::glog") + self.cpp_info.set_property("pkg_config_name", "libglog") + postfix = "d" if self.settings.build_type == "Debug" else "" + self.cpp_info.libs = ["glog" + postfix] + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.system_libs = ["pthread"] + elif self.settings.os == "Windows": + self.cpp_info.system_libs = ["dbghelp"] + self.cpp_info.defines = ["GLOG_NO_ABBREVIATED_SEVERITIES"] + decl = "__declspec(dllimport)" if self.options.shared else "" + self.cpp_info.defines.append(f"GOOGLE_GLOG_DLL_DECL={decl}") + if self.options.with_gflags and not self.options.shared: + self.cpp_info.defines.extend(["GFLAGS_DLL_DECLARE_FLAG=", "GFLAGS_DLL_DEFINE_FLAG="]) + if Version(self.version) >= "0.7.0": + self.cpp_info.defines.extend(["GLOG_USE_GLOG_EXPORT="]) diff --git a/glog/config.yml b/glog/config.yml new file mode 100644 index 0000000..d35fbe5 --- /dev/null +++ b/glog/config.yml @@ -0,0 +1,3 @@ +versions: + "0.7.1-unwindfix": + folder: 0.7.1-unwindfix diff --git a/libunwind/1.8.2/conandata.yml b/libunwind/1.8.2/conandata.yml new file mode 100644 index 0000000..731028c --- /dev/null +++ b/libunwind/1.8.2/conandata.yml @@ -0,0 +1,4 @@ +sources: + "1.8.2": + url: "https://github.com/libunwind/libunwind/releases/download/v1.8.2/libunwind-1.8.2.tar.gz" + sha256: "7f262f1a1224f437ede0f96a6932b582c8f5421ff207c04e3d9504dfa04c8b82" diff --git a/libunwind/1.8.2/conanfile.py b/libunwind/1.8.2/conanfile.py new file mode 100644 index 0000000..c76da91 --- /dev/null +++ b/libunwind/1.8.2/conanfile.py @@ -0,0 +1,161 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import cross_building +from conan.tools.env import VirtualRunEnv +from conan.tools.files import ( + apply_conandata_patches, + copy, + export_conandata_patches, + get, + rm, + rmdir, +) +from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps +from conan.tools.layout import basic_layout + +import os +import shutil + +required_conan_version = ">=1.53.0" + + +class LiunwindConan(ConanFile): + name = "libunwind" + version = "1.8.2" + description = "Manipulate the preserved state of each call-frame and resume the execution at any point." + license = "MIT" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/libunwind/libunwind" + topics = ("unwind", "debuggers", "exception-handling", "introspection", "setjmp") + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + "coredump": [True, False], + "ptrace": [True, False], + "setjmp": [True, False], + "minidebuginfo": [True, False], + "zlibdebuginfo": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + "coredump": True, + "ptrace": True, + "setjmp": True, + "minidebuginfo": True, + "zlibdebuginfo": True, + } + + def export_sources(self): + export_conandata_patches(self) + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + self.settings.rm_safe("compiler.libcxx") + self.settings.rm_safe("compiler.cppstd") + + def layout(self): + basic_layout(self, src_folder="src") + + def requirements(self): + if self.options.minidebuginfo: + self.requires("xz_utils/5.4.5") + if self.options.zlibdebuginfo: + self.requires("zlib/[>=1.2.11 <2]") + + def validate(self): + if self.settings.os not in ["Linux", "FreeBSD"]: + raise ConanInvalidConfiguration( + "libunwind is only supported on Linux and FreeBSD" + ) + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + if not cross_building(self): + env = VirtualRunEnv(self) + env.generate(scope="build") + + tc = AutotoolsToolchain(self) + yes_no = lambda v: "yes" if v else "no" + tc.configure_args.extend( + [ + f"--enable-coredump={yes_no(self.options.coredump)}", + f"--enable-ptrace={yes_no(self.options.ptrace)}", + f"--enable-setjmp={yes_no(self.options.setjmp)}", + f"--enable-minidebuginfo={yes_no(self.options.minidebuginfo)}", + f"--enable-zlibdebuginfo={yes_no(self.options.zlibdebuginfo)}", + "--disable-tests", + "--disable-documentation", + ] + ) + tc.generate() + + tc = AutotoolsDeps(self) + tc.generate() + + def build(self): + apply_conandata_patches(self) + autotools = Autotools(self) + autotools.configure() + autotools.make() + + def package(self): + copy( + self, + pattern="COPYING", + src=self.source_folder, + dst=os.path.join(self.package_folder, "licenses"), + ) + autotools = Autotools(self) + autotools.install() + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + rm(self, "*.la", os.path.join(self.package_folder, "lib")) + + # In install-exec-hook in Makefile.am, libunwind_generic is linked to libunwind_${arch}. + # As this seems to be unnecessary for the conan package. + # rename the real file to libunwind_generic, + lib_ext = "so" if self.options.shared else "a" + symlink_path = os.path.join( + self.package_folder, "lib", f"libunwind-generic.{lib_ext}" + ) + source_path = os.path.realpath(symlink_path) + rm(self, os.path.basename(symlink_path), os.path.dirname(symlink_path)) + shutil.copy(source_path, symlink_path) + + def package_info(self): + self.cpp_info.components["unwind"].set_property("pkg_config_name", "libunwind") + self.cpp_info.components["unwind"].libs = ["unwind"] + if self.options.minidebuginfo: + self.cpp_info.components["unwind"].requires.append("xz_utils::xz_utils") + if self.options.zlibdebuginfo: + self.cpp_info.components["unwind"].requires.append("zlib::zlib") + if self.settings.os == "Linux": + self.cpp_info.components["unwind"].system_libs.append("pthread") + self.cpp_info.components["generic"].set_property( + "pkg_config_name", "libunwind-generic" + ) + self.cpp_info.components["generic"].libs = ["unwind-generic"] + self.cpp_info.components["generic"].requires = ["unwind"] + if self.options.ptrace: + self.cpp_info.components["ptrace"].set_property( + "pkg_config_name", "libunwind-ptrace" + ) + self.cpp_info.components["ptrace"].libs = ["unwind-ptrace"] + self.cpp_info.components["ptrace"].requires = ["generic", "unwind"] + if self.options.setjmp: + self.cpp_info.components["setjmp"].set_property( + "pkg_config_name", "libunwind-setjmp" + ) + self.cpp_info.components["setjmp"].libs = ["unwind-setjmp"] + self.cpp_info.components["setjmp"].requires = ["unwind"] + if self.options.coredump: + self.cpp_info.components["coredump"].set_property( + "pkg_config_name", "libunwind-coredump" + ) + self.cpp_info.components["coredump"].libs = ["unwind-coredump"] + self.cpp_info.components["coredump"].requires = ["generic", "unwind"] diff --git a/libunwind/config.yml b/libunwind/config.yml new file mode 100644 index 0000000..642819a --- /dev/null +++ b/libunwind/config.yml @@ -0,0 +1,3 @@ +versions: + "1.8.2": + folder: 1.8.2