-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathconanfile.py
179 lines (158 loc) · 8.31 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
173
174
175
176
177
178
179
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import can_run
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv
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
import os
required_conan_version = ">=1.53.0"
class WaylandConan(ConanFile):
name = "wayland"
description = (
"Wayland is a project to define a protocol for a compositor to talk to "
"its clients as well as a library implementation of the protocol"
)
topics = "protocol", "compositor", "display"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://wayland.freedesktop.org"
license = "MIT"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"enable_libraries": [True, False],
"enable_dtd_validation": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"enable_libraries": True,
"enable_dtd_validation": True,
}
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")
def layout(self):
basic_layout(self, src_folder="src")
def requirements(self):
if self.options.enable_libraries:
self.requires("libffi/3.4.4")
if self.options.enable_dtd_validation:
self.requires("libxml2/[>=2.12.5 <3]")
self.requires("expat/[>=2.6.2 <3]")
def validate(self):
if self.settings.os not in ("Linux", "Android"):
raise ConanInvalidConfiguration(f"{self.ref} only supports Linux or Android")
def build_requirements(self):
self.tool_requires("meson/[>=1.4.0 <2]")
if not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str):
self.tool_requires("pkgconf/[>=2.2 <3]")
if not can_run(self):
self.tool_requires(str(self.ref))
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def generate(self):
env = VirtualBuildEnv(self)
env.generate()
if can_run(self):
env = VirtualRunEnv(self)
env.generate(scope="build")
pkg_config_deps = PkgConfigDeps(self)
if not can_run(self):
pkg_config_deps.build_context_activated = ["wayland"]
elif self.dependencies["expat"].is_build_context: # wayland is being built as build_require
# If wayland is the build_require, all its dependencies are treated as build_requires
pkg_config_deps.build_context_activated = [dep.ref.name for _, dep in self.dependencies.host.items()]
pkg_config_deps.generate()
tc = MesonToolchain(self)
tc.project_options["libdir"] = "lib"
tc.project_options["datadir"] = "res"
tc.project_options["libraries"] = self.options.enable_libraries
tc.project_options["dtd_validation"] = self.options.enable_dtd_validation
tc.project_options["documentation"] = False
if not can_run(self):
tc.project_options["build.pkg_config_path"] = self.generators_folder
if Version(self.version) >= "1.18.91":
tc.project_options["scanner"] = True
tc.generate()
def _patch_sources(self):
replace_in_file(self, os.path.join(self.source_folder, "meson.build"),
"subdir('tests')", "#subdir('tests')")
def build(self):
self._patch_sources()
meson = Meson(self)
meson.configure()
meson.build()
def package(self):
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
meson = Meson(self)
meson.install()
pkg_config_dir = os.path.join(self.package_folder, "lib", "pkgconfig")
rmdir(self, pkg_config_dir)
def package_info(self):
self.cpp_info.components["wayland-scanner"].set_property("pkg_config_name", "wayland-scanner")
self.cpp_info.components["wayland-scanner"].resdirs = ["res"]
self.cpp_info.components["wayland-scanner"].includedirs = []
self.cpp_info.components["wayland-scanner"].libdirs = []
self.cpp_info.components["wayland-scanner"].set_property("component_version", self.version)
self.cpp_info.components["wayland-scanner"].requires = ["expat::expat"]
if self.options.enable_dtd_validation:
self.cpp_info.components["wayland-scanner"].requires.append("libxml2::libxml2")
pkgconfig_variables = {
'datarootdir': '${prefix}/res',
'pkgdatadir': '${datarootdir}/wayland',
'bindir': '${prefix}/bin',
'wayland_scanner': '${bindir}/wayland-scanner',
}
self.cpp_info.components["wayland-scanner"].set_property(
"pkg_config_custom_content",
"\n".join(f"{key}={value}" for key,value in pkgconfig_variables.items()))
if self.options.enable_libraries:
self.cpp_info.components["wayland-server"].libs = ["wayland-server"]
self.cpp_info.components["wayland-server"].set_property("pkg_config_name", "wayland-server")
self.cpp_info.components["wayland-server"].requires = ["libffi::libffi"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["wayland-server"].system_libs = ["pthread", "m"]
self.cpp_info.components["wayland-server"].resdirs = ["res"]
if self.version >= Version("1.21.0") and self.settings.os == "Linux":
self.cpp_info.components["wayland-server"].system_libs += ["rt"]
self.cpp_info.components["wayland-server"].set_property("component_version", self.version)
pkgconfig_variables = {
'datarootdir': '${prefix}/res',
'pkgdatadir': '${datarootdir}/wayland',
}
self.cpp_info.components["wayland-server"].set_property(
"pkg_config_custom_content",
"\n".join(f"{key}={value}" for key, value in pkgconfig_variables.items()))
self.cpp_info.components["wayland-client"].libs = ["wayland-client"]
self.cpp_info.components["wayland-client"].set_property("pkg_config_name", "wayland-client")
self.cpp_info.components["wayland-client"].requires = ["libffi::libffi"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["wayland-client"].system_libs = ["pthread", "m"]
self.cpp_info.components["wayland-client"].resdirs = ["res"]
if self.version >= Version("1.21.0") and self.settings.os == "Linux":
self.cpp_info.components["wayland-client"].system_libs += ["rt"]
self.cpp_info.components["wayland-client"].set_property("component_version", self.version)
pkgconfig_variables = {
'datarootdir': '${prefix}/res',
'pkgdatadir': '${datarootdir}/wayland',
}
self.cpp_info.components["wayland-client"].set_property(
"pkg_config_custom_content",
"\n".join(f"{key}={value}" for key, value in pkgconfig_variables.items()))
self.cpp_info.components["wayland-cursor"].libs = ["wayland-cursor"]
self.cpp_info.components["wayland-cursor"].set_property("pkg_config_name", "wayland-cursor")
self.cpp_info.components["wayland-cursor"].requires = ["wayland-client"]
self.cpp_info.components["wayland-cursor"].set_property("component_version", self.version)
self.cpp_info.components["wayland-egl"].libs = ["wayland-egl"]
self.cpp_info.components["wayland-egl"].set_property("pkg_config_name", "wayland-egl")
self.cpp_info.components["wayland-egl"].requires = ["wayland-client"]
self.cpp_info.components["wayland-egl"].set_property("component_version", "18.1.0")
self.cpp_info.components["wayland-egl-backend"].set_property("pkg_config_name", "wayland-egl-backend")
self.cpp_info.components["wayland-egl-backend"].set_property("component_version", "3")