-
Notifications
You must be signed in to change notification settings - Fork 4
/
conanfile.py
311 lines (272 loc) · 11.8 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
from conans import ConanFile, CMake, tools, errors
import os, re
from six import StringIO # Python 2 and 3 compatible
def find_all_headers(root):
result = []
entries = os.walk(root)
for entry in entries:
for file in entry[2]:
if file.endswith('.h'):
result.append(os.path.join(entry[0], file))
return result
def fix(all_headers, src):
f = open(src, "r")
base = os.path.dirname(src)
regex = r'^#include\s*"([^"]*)"'
result = ""
for line in f:
match = re.match(regex, line)
if match:
if not os.path.exists(os.path.join(base, match.group(1))):
matches = [x for x in all_headers if os.path.basename(x) == os.path.basename(match.group(1))]
if len(matches) == 1:
relpath = os.path.relpath(matches[0], base)
result += '#include "%s"\n' % relpath
continue
result += line
f.close()
f = open(src, "w")
f.write(result)
def merge_two_dicts(x, y):
z = x.copy() # start with x's keys and values
z.update(y) # modifies z with y's keys and values & returns None
return z
class SkiaConan(ConanFile):
name = "skia"
version = "master"
license = "<Put the package license here>"
author = "Marcus Tillmanns <[email protected]>"
url = "https://github.com/Maddimax/conan-skia.git"
description = "A 2D/3D Vector rendering engine"
topics = ("render", "vector", "2d", "3d")
settings = "os", "compiler", "build_type", "arch"
skia_options = {
"skia_enable_atlas_text" : [True, False],
"skia_enable_ccpr" : [True, False],
"skia_enable_discrete_gpu" : [True, False],
"skia_enable_flutter_defines" : [True, False],
"skia_enable_fontmgr_android" : [True, False],
"skia_enable_fontmgr_custom" : [True, False],
"skia_enable_fontmgr_custom_empty" : [True, False],
"skia_enable_fontmgr_empty" : [True, False],
"skia_enable_fontmgr_fuchsia" : [True, False],
"skia_enable_fontmgr_win" : [True, False],
"skia_enable_fontmgr_win_gdi" : [True, False],
"skia_enable_gpu" : [True, False],
"skia_enable_nima" : [True, False],
"skia_enable_nvpr" : [True, False],
"skia_enable_particles" : [True, False],
"skia_enable_pdf" : [True, False],
"skia_enable_skottie" : [True, False],
"skia_enable_skpicture" : [True, False],
"skia_enable_skshaper" : [True, False],
"skia_enable_spirv_validation" : [True, False],
"skia_enable_tools" : [True, False],
"skia_enable_vulkan_debug_layers" : [True, False],
"skia_generate_workarounds" : [True, False],
"skia_use_angle" : [True, False],
"skia_use_dng_sdk" : [True, False],
"skia_use_egl" : [True, False],
"skia_use_expat" : [True, False],
"skia_use_fixed_gamma_text" : [True, False],
"skia_use_fontconfig" : [True, False],
"skia_use_fonthost_mac" : [True, False],
"skia_use_freetype" : [True, False],
"skia_use_harfbuzz" : [True, False],
"skia_use_icu" : [True, False],
"skia_use_libheif" : [True, False],
"skia_use_libjpeg_turbo" : [True, False],
"skia_use_libpng" : [True, False],
"skia_use_libwebp" : [True, False],
"skia_use_lua" : [True, False],
"skia_use_metal" : [True, False],
"skia_use_opencl" : [True, False],
"skia_use_piex" : [True, False],
"skia_use_sfntly" : [True, False],
"skia_use_system_expat" : [True, False],
"skia_use_system_harfbuzz" : [True, False],
"skia_use_system_icu" : [True, False],
"skia_use_system_libjpeg_turbo" : [True, False],
"skia_use_system_libpng" : [True, False],
"skia_use_system_libwebp" : [True, False],
"skia_use_system_zlib" : [True, False],
"skia_use_vulkan" : [True, False],
"skia_use_wuffs" : [True, False],
"skia_use_x11" : [True, False],
"skia_use_xps" : [True, False],
"skia_use_zlib" : [True, False],
"is_official_build" : [True, False]
}
options = merge_two_dicts({ "shared": [True, False] }, skia_options)
default_options = {
"shared":False,
"harfbuzz:with_icu" : True,
# Skia options
"skia_enable_atlas_text" : False,
"skia_enable_ccpr" : True,
"skia_enable_discrete_gpu" : True,
"skia_enable_flutter_defines" : False,
"skia_enable_fontmgr_android" : False,
"skia_enable_fontmgr_custom" : False,
"skia_enable_fontmgr_custom_empty" : False,
"skia_enable_fontmgr_empty" : False,
"skia_enable_fontmgr_fuchsia" : False,
"skia_enable_fontmgr_win" : False,
"skia_enable_fontmgr_win_gdi" : False,
"skia_enable_gpu" : False,
"skia_enable_nima" : False,
"skia_enable_nvpr" : True,
"skia_enable_particles" : True,
"skia_enable_pdf" : True,
"skia_enable_skottie" : True,
"skia_enable_skpicture" : True,
"skia_enable_skshaper" : True,
"skia_enable_spirv_validation" : False,
"skia_enable_tools" : False,
"skia_enable_vulkan_debug_layers" : False,
"skia_generate_workarounds" : False,
"skia_use_angle" : False,
"skia_use_dng_sdk" : True,
"skia_use_egl" : False,
"skia_use_expat" : True,
"skia_use_fixed_gamma_text" : False,
"skia_use_fontconfig" : False,
"skia_use_fonthost_mac" : True,
"skia_use_freetype" : False,
"skia_use_harfbuzz" : True,
"skia_use_icu" : True,
"skia_use_libheif" : False,
"skia_use_libjpeg_turbo" : True,
"skia_use_libpng" : True,
"skia_use_libwebp" : True,
"skia_use_lua" : False,
"skia_use_metal" : False,
"skia_use_opencl" : False,
"skia_use_piex" : True,
"skia_use_sfntly" : True,
"skia_use_system_expat" : True,
"skia_use_system_harfbuzz" : True,
"skia_use_system_icu" : True,
"skia_use_system_libjpeg_turbo" : True,
"skia_use_system_libpng" : False,
"skia_use_system_libwebp" : False,
"skia_use_system_zlib" : False,
"skia_use_vulkan" : False,
"skia_use_wuffs" : False,
"skia_use_x11" : False,
"skia_use_xps" : True,
"skia_use_zlib" : True,
"is_official_build" : True
}
generators = "cmake"
build_policy = "missing"
scm = {
"type": "git",
"url": "auto",
"revision": "auto",
"submodule" : "shallow"
}
revision_mode = "scm"
def get_skia_option_value(self, option_name):
buf = StringIO()
self.run('bin/gn args out/conan-build --list=%s --short' % (option_name), output=buf, cwd='skia')
output = buf.getvalue()
pattern = r'%s = (.*)' % (option_name)
match = re.match(pattern, output)
if match:
if match.group(1) == 'true':
return True
elif match.group(1) == 'false':
return False
raise errors.ConanInvalidConfiguration("Could not parse gn comfiguration options")
def requirements(self):
if self.options.skia_use_system_icu and self.options.skia_use_icu:
self.requires("icu/63.1@bincrafters/stable")
if self.options.skia_use_system_libjpeg_turbo and self.options.skia_use_libjpeg_turbo:
self.requires("libjpeg-turbo/1.5.2@bincrafters/stable")
if self.options.skia_use_system_harfbuzz and self.options.skia_use_harfbuzz:
self.requires("harfbuzz/2.4.0@maddimax/stable")
if self.options.skia_use_system_libpng and self.options.skia_use_libpng:
self.requires("libpng/1.6.36@bincrafters/stable")
def source(self):
# Fix include paths ...
self.output.info("Fixing headers:")
all_headers = find_all_headers(os.path.join(self.source_folder, "skia"))
for header in all_headers:
fix(all_headers, header)
if len(all_headers) == 0:
print("Error: No header files found")
exit(1)
self.output.info("Fixed %i files" % (len(all_headers)))
# Fetch dependencies
self.run('/usr/local/bin/python skia/tools/git-sync-deps')
def configure(self):
if self.options.skia_use_metal:
if not self.settings.os == "iOS" and not self.settings.os == "Macos":
raise errors.ConanInvalidConfiguration("Metal is only supported on darwin platforms: %s" % self.settings.os)
if self.settings.os == "iOS":
self.options.skia_use_fonthost_mac = False
self.options.skia_use_system_expat = False
self.options.skia_use_system_expat = False
self.options.skia_use_system_harfbuzz = False
self.options.skia_use_system_icu = False
self.options.skia_use_system_libjpeg_turbo = False
self.options.skia_use_system_libpng = False
self.options.skia_use_system_libwebp = False
self.options.skia_use_system_zlib = False
def build(self):
flags = []
for k,v in self.deps_cpp_info.dependencies:
self.output.info("Adding dependency: %s - %s" %(k, v.rootpath))
flags += ['\\"-I%s/include\\"' % (v.rootpath), '\\"-I%s/include/%s\\"' % (v.rootpath, k)]
flag_str = 'extra_cflags_cc=[%s]' % ",".join(flags)
opts = [flag_str]
for k,v in self.options.items():
if k in self.skia_options:
opts += [("%s=%s" % (k,v)).lower()]
if self.settings.build_type == "Debug":
opts += ["is_debug=true"]
else:
opts += ["is_debug=false"]
if self.settings.os == "iOS":
opts += ['target_os=\\"ios\\"']
if self.settings.arch == "armv8":
opts += ['target_cpu=\\"arm64\\"']
else:
opts += ['target_cpu=\\"x86_64\\"']
if len(opts) > 0:
opts = '"--args=%s"' % " ".join(opts)
else:
opts = ""
self.output.info("gn options: %s" % (opts))
self.run('bin/gn gen out/conan-build %s ' %(opts), cwd="skia")
failed = False
for k,v in self.options.items():
if k in self.skia_options:
actual = self.get_skia_option_value(k)
if not ("%s" % actual) == ("%s" % v):
failed = True
self.output.warn("Mismatch in %s: %s => %s" % ( k, v, actual ))
if failed:
raise errors.ConanInvalidConfiguration("Final gn configuration did not match requested config")
self.run('ninja -C out/conan-build', cwd="skia")
def package(self):
self.copy("*.h", dst="include/skia", src="skia", keep_path=True)
self.copy("*.dll", dst="bin", src="skia/out/conan-build",keep_path=False)
self.copy("*.so", dst="lib", src="skia/out/conan-build",keep_path=False)
self.copy("*.dylib", dst="lib", src="skia/out/conan-build",keep_path=False)
self.copy("*.a", dst="lib", src="skia/out/conan-build", keep_path=False)
# if self.settings.build_type == "Release":
# libs = os.listdir(os.path.join(self.package_folder, "lib"))
# self.output.info("Trying to strip: %s" %(libs))
# for lib in libs:
# self.run('strip -S %s' % (os.path.join(self.package_folder, "lib" ,lib)))
def package_info(self):
libs = os.listdir(os.path.join(self.package_folder, "lib"))
libs = [(x[3:])[:-2] for x in libs]
self.cpp_info.libs = libs
if self.settings.os == "Macos":
self.cpp_info.exelinkflags += ["-framework AppKit"]
if self.options.skia_use_metal:
self.cpp_info.defines += ["SK_METAL=1"]
self.cpp_info.exelinkflags += ["-framework Metal", "-framework MetalKit"]