|
| 1 | +import os |
| 2 | +import shutil |
| 3 | + |
| 4 | +from conan import ConanFile |
| 5 | +from conan.tools.env import VirtualBuildEnv |
| 6 | +from conan.tools.files import copy, get, replace_in_file, rmdir |
| 7 | +from conan.tools.gnu import PkgConfigDeps |
| 8 | +from conan.tools.layout import basic_layout |
| 9 | +from conan.tools.meson import Meson, MesonToolchain |
| 10 | +from conan.errors import ConanInvalidConfiguration |
| 11 | + |
| 12 | +required_conan_version = ">=1.53.0" |
| 13 | + |
| 14 | + |
| 15 | +class libdecorConan(ConanFile): |
| 16 | + name = "libdecor" |
| 17 | + package_type = "shared-library" |
| 18 | + description = "libdecor is a library that can help Wayland clients draw window decorations for them." |
| 19 | + topics = ("decoration", "wayland", "window") |
| 20 | + url = "https://github.com/conan-io/conan-center-index" |
| 21 | + homepage = "https://gitlab.freedesktop.org/libdecor/libdecor" |
| 22 | + license = "MIT" |
| 23 | + settings = "os", "arch", "compiler", "build_type" |
| 24 | + options = { |
| 25 | + "with_dbus": [True, False], |
| 26 | + "with_gtk": [True, False], |
| 27 | + } |
| 28 | + default_options = { |
| 29 | + "with_dbus": True, |
| 30 | + "with_gtk": True, |
| 31 | + } |
| 32 | + |
| 33 | + @property |
| 34 | + def _settings_build(self): |
| 35 | + return getattr(self, "settings_build", self.settings) |
| 36 | + |
| 37 | + def configure(self): |
| 38 | + self.settings.rm_safe("compiler.cppstd") |
| 39 | + self.settings.rm_safe("compiler.libcxx") |
| 40 | + if self.options.get_safe("with_gtk"): |
| 41 | + self.options["gtk"].version = "3" |
| 42 | + self.options["pango"].with_cairo = True |
| 43 | + |
| 44 | + # https://gitlab.freedesktop.org/libdecor/libdecor/-/issues/66 |
| 45 | + if self.options.get_safe("wayland"): |
| 46 | + self.options["shared"].version = True |
| 47 | + |
| 48 | + def layout(self): |
| 49 | + basic_layout(self, src_folder="src") |
| 50 | + |
| 51 | + def requirements(self): |
| 52 | + self.requires("cairo/1.18.0 ") |
| 53 | + if self.options.get_safe("with_dbus"): |
| 54 | + self.requires("dbus/1.15.8") |
| 55 | + if self.options.get_safe("with_gtk"): |
| 56 | + self.requires("gtk/system") |
| 57 | + self.requires("pango/1.50.10") |
| 58 | + self.requires("wayland/1.22.0") |
| 59 | + self.requires("wayland-protocols/1.32") |
| 60 | + |
| 61 | + def validate(self): |
| 62 | + if self.settings.os != "Linux": |
| 63 | + raise ConanInvalidConfiguration(f"{self.ref} only supports Linux") |
| 64 | + if self.options.get_safe("with_gtk") and not self.dependencies["gtk"].options.version == "3": |
| 65 | + raise ConanInvalidConfiguration(f"{self.ref} requires the version option of gtk to be set to 3") |
| 66 | + if not self.dependencies["pango"].options.with_cairo: |
| 67 | + raise ConanInvalidConfiguration(f"{self.ref} requires the with_cairo option of pango to be enabled") |
| 68 | + |
| 69 | + # https://gitlab.freedesktop.org/libdecor/libdecor/-/issues/66 |
| 70 | + if not self.dependencies["wayland"].options.shared: |
| 71 | + raise ConanInvalidConfiguration(f"{self.ref} requires the shared option of wayland to be enabled due to a bug in libdecor") |
| 72 | + |
| 73 | + def build_requirements(self): |
| 74 | + self.tool_requires("meson/1.3.1") |
| 75 | + if not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str): |
| 76 | + self.tool_requires("pkgconf/2.1.0") |
| 77 | + self.tool_requires("wayland/<host_version>") |
| 78 | + |
| 79 | + def source(self): |
| 80 | + get(self, **self.conan_data["sources"][self.version], strip_root=True) |
| 81 | + |
| 82 | + def _patch_sources(self): |
| 83 | + replace_in_file( |
| 84 | + self, |
| 85 | + os.path.join(self.source_folder, "src", "plugins", "meson.build"), |
| 86 | + "gtk_dep = dependency('gtk+-3.0', required: get_option('gtk'))", |
| 87 | + "gtk_dep = dependency('gtk', required: get_option('gtk'))", |
| 88 | + ) |
| 89 | + |
| 90 | + def generate(self): |
| 91 | + feature = ( |
| 92 | + lambda option: "enabled" if self.options.get_safe(option) else "disabled" |
| 93 | + ) |
| 94 | + |
| 95 | + tc = MesonToolchain(self) |
| 96 | + tc.project_options["dbus"] = feature("with_dbus") |
| 97 | + tc.project_options["demo"] = False |
| 98 | + tc.project_options["gtk"] = feature("with_gtk") |
| 99 | + tc.generate() |
| 100 | + pkg_config_deps = PkgConfigDeps(self) |
| 101 | + pkg_config_deps.generate() |
| 102 | + # Work around a bug in the pango package for which fixes have not been merged in yet. |
| 103 | + shutil.copy2(os.path.join(self.generators_folder, "pango-pangocairo.pc"), os.path.join(self.generators_folder, "pangocairo.pc")) |
| 104 | + virtual_build_env = VirtualBuildEnv(self) |
| 105 | + virtual_build_env.generate() |
| 106 | + |
| 107 | + def build(self): |
| 108 | + self._patch_sources() |
| 109 | + meson = Meson(self) |
| 110 | + meson.configure() |
| 111 | + meson.build() |
| 112 | + |
| 113 | + def package(self): |
| 114 | + copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) |
| 115 | + meson = Meson(self) |
| 116 | + meson.install() |
| 117 | + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) |
| 118 | + |
| 119 | + def package_info(self): |
| 120 | + libdecor_soversion = "0" |
| 121 | + self.cpp_info.libs = [f"decor-{libdecor_soversion}"] |
| 122 | + self.cpp_info.set_property("pkg_config_name", f"libdecor-{libdecor_soversion}") |
| 123 | + |
| 124 | + plugins_soversion = "1" |
| 125 | + self.runenv_info.define("LIBDECOR_PLUGIN_DIR", os.path.join(self.package_folder, "lib", "libdecor", f"plugins-{plugins_soversion}")) |
0 commit comments