forked from conan-io/conan-center-index
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconanfile.py
172 lines (151 loc) · 7.54 KB
/
conanfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import os
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.build import cross_building
from conan.tools.env import Environment
from conan.tools.files import copy, get, replace_in_file, rmdir
from conan.tools.gnu import PkgConfigDeps
from conan.tools.layout import basic_layout
from conan.tools.meson import Meson, MesonToolchain
from conan.tools.scm import Version
required_conan_version = ">=1.60.0 <2 || >=2.0.5"
class XkbcommonConan(ConanFile):
name = "xkbcommon"
package_type = "library"
description = "keymap handling library for toolkits and window systems"
topics = ("keyboard", "wayland", "x11", "xkb")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/xkbcommon/libxkbcommon"
license = "MIT"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_x11": [True, False],
"with_wayland": [True, False],
"xkbregistry": [True, False],
"use_xorg_system": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_x11": True,
"with_wayland": True,
"xkbregistry": True,
"use_xorg_system": True,
}
@property
def _has_xkbregistry_option(self):
return Version(self.version) >= "1.0.0"
def config_options(self):
if not self._has_xkbregistry_option:
del self.options.xkbregistry
if self.settings.os != "Linux":
del self.options.with_wayland
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")
if not self.options.with_x11:
del self.options.use_xorg_system
def layout(self):
basic_layout(self, src_folder="src")
def requirements(self):
if self.options.use_xorg_system:
self.requires("xkeyboard-config/system")
else:
self.requires("xkeyboard-config/2.43")
if self.options.with_x11:
if self.options.use_xorg_system:
self.requires("xorg/system")
else:
self.requires("libxcb/1.17.0")
if self.options.get_safe("xkbregistry"):
self.requires("libxml2/[>=2.12.5 <3]")
if self.options.get_safe("with_wayland"):
self.requires("wayland/1.22.0")
def validate(self):
if self.settings.os not in ["Linux", "FreeBSD"]:
raise ConanInvalidConfiguration(f"{self.ref} is only compatible with Linux and FreeBSD")
def build_requirements(self):
self.tool_requires("meson/[>=1.2.3 <2]")
self.tool_requires("bison/3.8.2")
if not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str):
self.tool_requires("pkgconf/[>=2.2 <3]")
if self.options.get_safe("with_wayland"):
self.tool_requires("wayland/<host_version>")
self.tool_requires("wayland-protocols/1.33")
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def generate(self):
tc = MesonToolchain(self)
if Version(self.version) >= "1.6":
tc.project_options["enable-bash-completion"] = False
tc.project_options["enable-docs"] = False
tc.project_options["enable-wayland"] = self.options.get_safe("with_wayland", False)
tc.project_options["enable-x11"] = self.options.with_x11
if self._has_xkbregistry_option:
tc.project_options["enable-xkbregistry"] = self.options.xkbregistry
tc.generate()
pkg_config_deps = PkgConfigDeps(self)
if self.options.get_safe("with_wayland"):
pkg_config_deps.build_context_activated = ["wayland", "wayland-protocols"]
pkg_config_deps.build_context_suffix = {"wayland": "_BUILD"}
pkg_config_deps.generate()
if cross_building(self):
# required for dependency(..., native: true) in meson.build
env = Environment()
env.define_path("PKG_CONFIG_FOR_BUILD", self.conf.get("tools.gnu:pkg_config", default="pkgconf", check_type=str))
env.define_path("PKG_CONFIG_PATH_FOR_BUILD", self.generators_folder)
env.vars(self).save_script("pkg_config_for_build_env.sh")
def _patch_sources(self):
if self.options.get_safe("with_wayland"):
# Patch the build system to use the pkg-config files generated for the build context.
meson_build_file = os.path.join(self.source_folder, "meson.build")
replace_in_file(
self,
meson_build_file,
"wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)",
"wayland_scanner_dep = dependency('wayland-scanner_BUILD', required: false, native: true)",
)
def build(self):
self._patch_sources()
meson = Meson(self)
meson.configure()
meson.build()
def package(self):
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
meson = Meson(self)
meson.install()
rmdir(self, os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
fix_apple_shared_install_name(self)
def package_info(self):
self.cpp_info.components["libxkbcommon"].set_property("pkg_config_name", "xkbcommon")
self.cpp_info.components["libxkbcommon"].set_property("cmake_target_aliases", ["X11::xkbcommon"])
self.cpp_info.components["libxkbcommon"].libs = ["xkbcommon"]
self.cpp_info.components["libxkbcommon"].requires = ["xkeyboard-config::xkeyboard-config"]
self.cpp_info.components["libxkbcommon"].resdirs = ["res"]
if self.options.with_x11:
self.cpp_info.components["libxkbcommon-x11"].set_property("pkg_config_name", "xkbcommon-x11")
self.cpp_info.components["libxkbcommon-x11"].set_property("cmake_target_aliases", ["X11::xkbcommon_X11"])
self.cpp_info.components["libxkbcommon-x11"].libs = ["xkbcommon-x11"]
self.cpp_info.components["libxkbcommon-x11"].requires = ["libxkbcommon"]
if self.options.use_xorg_system:
self.cpp_info.components["libxkbcommon-x11"].requires.extend(["xorg::xcb", "xorg::xcb-xkb"])
else:
self.cpp_info.components["libxkbcommon-x11"].requires.extend(["libxcb::xcb", "libxcb::xcb-xkb"])
if self.options.get_safe("xkbregistry"):
self.cpp_info.components["libxkbregistry"].set_property("pkg_config_name", "xkbregistry")
self.cpp_info.components["libxkbregistry"].set_property("cmake_target_aliases", ["X11::xkbregistry"])
self.cpp_info.components["libxkbregistry"].libs = ["xkbregistry"]
self.cpp_info.components["libxkbregistry"].requires = ["libxml2::libxml2"]
if self.options.get_safe("with_wayland", False):
self.cpp_info.components["xkbcli-interactive-wayland"].libs = []
self.cpp_info.components["xkbcli-interactive-wayland"].includedirs = []
self.cpp_info.components["xkbcli-interactive-wayland"].requires = ["wayland::wayland-client"]
# unofficial, but required to avoid side effects (libxkbcommon component
# "steals" the default global pkg_config name)
self.cpp_info.set_property("pkg_config_name", "xkbcommon_all_do_not_use")