forked from bincrafters/conan-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conanfile.py
291 lines (253 loc) · 12.7 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from conans import ConanFile, tools
import os
import shutil
import configparser
class QtConan(ConanFile):
def getsubmodules():
config = configparser.ConfigParser()
config.read('qtmodules.conf')
res = {}
assert config.sections()
for s in config.sections():
section = str(s)
assert section.startswith("submodule ")
assert section.count('"') == 2
modulename = section[section.find('"') + 1 : section.rfind('"')]
status = str(config.get(section, "status"))
if status != "obsolete" and status != "ignore":
res[modulename] = {"branch":str(config.get(section, "branch")), "status":status, "path":str(config.get(section, "path"))}
if config.has_option(section, "depends"):
res[modulename]["depends"] = [str(i) for i in config.get(section, "depends").split()]
else:
res[modulename]["depends"] = []
return res
submodules = getsubmodules()
name = "Qt"
version = "5.11.1"
description = "Conan.io package for Qt library."
url = "https://github.com/bincrafters/conan-qt"
homepage = "https://www.qt.io/"
license = "http://doc.qt.io/qt-5/lgpl.html"
author = "Bincrafters <[email protected]>"
exports = ["LICENSE.md", "qtmodules.conf", "*.diff"]
settings = "os", "arch", "compiler", "build_type"
options = dict({
"shared": [True, False],
"opengl": ["no", "es2", "desktop", "dynamic"],
"openssl": [True, False],
"GUI": [True, False],
"widgets": [True, False],
"config": "ANY",
}, **{module: [True,False] for module in submodules}
)
no_copy_source = True
default_options = ("shared=True", "opengl=desktop", "openssl=False", "GUI=True", "widgets=True", "config=None") + tuple(module + "=False" for module in submodules)
short_paths = True
build_policy = "missing"
def build_requirements(self):
if self.options.GUI:
pack_names = []
if tools.os_info.linux_distro == "ubuntu" or tools.os_info.linux_distro == "debian":
pack_names = ["libxcb1-dev", "libx11-dev", "libc6-dev"]
if self.options.opengl == "desktop":
pack_names.append("libgl1-mesa-dev")
elif tools.os_info.is_linux and tools.os_info.linux_distro not in ["arch", "manjaro"]:
pack_names = ["libxcb-devel", "libX11-devel", "glibc-devel"]
if self.options.opengl == "desktop":
pack_names.append("mesa-libGL-devel")
if self.settings.arch == "x86":
pack_names = [item+":i386" for item in pack_names]
if pack_names:
installer = tools.SystemPackageTool()
installer.install(" ".join(pack_names)) # Install the package
if tools.os_info.is_windows and self.settings.compiler == "Visual Studio":
self.build_requires("jom_installer/1.1.2@bincrafters/stable")
def configure(self):
if self.options.openssl:
self.requires("OpenSSL/1.1.0g@conan/stable")
self.options["OpenSSL"].no_zlib = True
if self.options.widgets == True:
self.options.GUI = True
if not self.options.GUI:
self.options.opengl = "no"
if self.settings.os == "Android" and self.options.opengl == "desktop":
self.output.error("OpenGL desktop is not supported on Android. Consider using OpenGL es2")
assert QtConan.version == QtConan.submodules['qtbase']['branch']
def enablemodule(self, module):
setattr(self.options, module, True)
for req in QtConan.submodules[module]["depends"]:
enablemodule(self, req)
self.options.qtbase = True
for module in QtConan.submodules:
if getattr(self.options, module):
enablemodule(self, module)
def system_requirements(self):
if self.options.GUI:
pack_names = []
if tools.os_info.linux_distro == "ubuntu" or tools.os_info.linux_distro == "debian":
pack_names = ["libxcb1", "libx11-6"]
elif tools.os_info.is_linux and tools.os_info.linux_distro != "opensuse":
pack_names = ["libxcb"]
if self.settings.arch == "x86":
pack_names = [item+":i386" for item in pack_names]
if pack_names:
installer = tools.SystemPackageTool()
installer.install(" ".join(pack_names)) # Install the package
def source(self):
url = "http://download.qt.io/official_releases/qt/{0}/{1}/single/qt-everywhere-src-{1}"\
.format(self.version[:self.version.rfind('.')], self.version)
if tools.os_info.is_windows:
tools.get("%s.zip" % url)
else:
self.run("wget -qO- %s.tar.xz | tar -xJ " % url)
shutil.move("qt-everywhere-src-%s" % self.version, "qt5")
for patch in ["3e201d645e1276c5168d7fef6943f95cc67d8643.diff", "0ef66e98ccf4946a0e4513ab5fc157df0f0aca4e.diff", "cc04651dea4c4678c626cb31b3ec8394426e2b25.diff"]:
tools.patch("qt5/qtbase", patch)
def xplatform(self):
if self.settings.os == "Linux":
if self.settings.compiler == "gcc":
return {"x86": "linux-g++-32",
"armv6": "linux-arm-gnueabi-g++",
"armv7": "linux-arm-gnueabi-g++",
"armv8": "linux-aarch64-gnu-g++"}.get(str(self.settings.arch), "linux-g++")
elif self.settings.compiler == "clang":
if self.settings.arch == "x86":
return "linux-clang-libc++-32" if self.settings.compiler.libcxx == "libc++" else "linux-clang-32"
elif self.settings.arch == "x86_64":
return "linux-clang-libc++" if self.settings.compiler.libcxx == "libc++" else "linux-clang"
elif self.settings.os == "Macos":
return {"clang": "macx-clang",
"gcc": "macx-g++"}.get(str(self.settings.compiler))
elif self.settings.os == "iOS":
if self.settings.compiler == "clang":
return "macx-ios-clang"
elif self.settings.os == "watchOS":
if self.settings.compiler == "clang":
return "macx-watchos-clang"
elif self.settings.os == "tvOS":
if self.settings.compiler == "clang":
return "macx-tvos-clang"
elif self.settings.os == "Android":
return {"clang": "android-clang",
"gcc": "android-g++"}.get(str(self.settings.compiler))
elif self.settings.os == "Windows":
return {"Visual Studio": "win32-msvc",
"gcc": "win32-g++",
"clang": "win32-clang-g++"}.get(str(self.settings.compiler))
elif self.settings.os == "WindowsStore":
if self.settings.compiler == "Visual Studio":
return {"14":{ "armv7": "winrt-arm-msvc2015",
"x86": "winrt-x86-msvc2015",
"x86_64": "winrt-x64-msvc2015"},
"15":{ "armv7": "winrt-arm-msvc2017",
"x86": "winrt-x86-msvc2017",
"x86_64": "winrt-x64-msvc2017"}
}.get(str(self.settings.compiler.version)).get(str(self.settings.arch))
elif self.settings.os == "FreeBSD":
return {"clang": "freebsd-clang",
"gcc": "freebsd-g++"}.get(str(self.settings.compiler))
elif self.settings.os == "SunOS":
if self.settings.compiler == "sun-cc":
if self.settings.arch == "sparc":
return "solaris-cc-stlport" if self.settings.compiler.libcxx == "libstlport" else "solaris-cc"
elif self.settings.arch == "sparcv9":
return "solaris-cc64-stlport" if self.settings.compiler.libcxx == "libstlport" else "solaris-cc64"
elif self.settings.compiler == "gcc":
return {"sparc": "solaris-g++",
"sparcv9": "solaris-g++-64"}.get(str(self.settings.arch))
return None
def build(self):
args = ["-opensource", "-confirm-license", "-silent", "-nomake examples", "-nomake tests",
"-prefix %s" % self.package_folder]
if not self.options.GUI:
args.append("-no-gui")
if not self.options.widgets:
args.append("-no-widgets")
if not self.options.shared:
args.insert(0, "-static")
if self.settings.os == "Windows":
if self.settings.compiler.runtime == "MT" or self.settings.compiler.runtime == "MTd":
args.append("-static-runtime")
else:
args.insert(0, "-shared")
if self.settings.build_type == "Debug":
args.append("-debug")
else:
args.append("-release")
for module in QtConan.submodules:
if not getattr(self.options, module) and os.path.isdir(os.path.join(self.source_folder, 'qt5', QtConan.submodules[module]['path'])):
args.append("-skip " + module)
# openGL
if self.options.opengl == "no":
args += ["-no-opengl"]
elif self.options.opengl == "es2":
args += ["-opengl es2"]
elif self.options.opengl == "desktop":
args += ["-opengl desktop"]
if self.settings.os == "Windows":
if self.options.opengl == "dynamic":
args += ["-opengl dynamic"]
# openSSL
if not self.options.openssl:
args += ["-no-openssl"]
else:
if self.options["OpenSSL"].shared:
args += ["-openssl-linked"]
else:
args += ["-openssl"]
args += ["-I %s" % i for i in self.deps_cpp_info["OpenSSL"].include_paths]
libs = self.deps_cpp_info["OpenSSL"].libs
lib_paths = self.deps_cpp_info["OpenSSL"].lib_paths
os.environ["OPENSSL_LIBS"] = " ".join(["-L"+i for i in lib_paths] + ["-l"+i for i in libs])
if self.settings.os == "Linux":
if self.options.GUI:
args.append("-qt-xcb")
elif self.settings.os == "Macos":
args += ["-no-framework"]
elif self.settings.os == "Android":
args += ["-android-ndk-platform android-%s" % self.settings.os.api_level]
args += ["-android-arch %s" % {"armv6": "armeabi",
"armv7": "armeabi-v7a",
"armv8": "arm64-v8a",
"x86": "x86",
"x86_64": "x86_64",
"mips": "mips",
"mips64": "mips64"}.get(str(self.settings.arch))]
# args += ["-android-toolchain-version %s" % self.settings.compiler.version]
xplatform_val = self.xplatform()
if xplatform_val:
args += ["-xplatform %s" % xplatform_val]
else:
self.output.warn("host not supported: %s %s %s %s" % (self.settings.os, self.settings.compiler, self.settings.compiler.version, self.settings.arch))
if self.options.config:
args.append(str(self.options.config))
def _build(self, make, args):
with tools.environment_append({"MAKEFLAGS":"j%d" % tools.cpu_count()}):
self.run("%s/qt5/configure %s" % (self.source_folder, " ".join(args)))
self.run(make)
self.run("%s install" % make)
if tools.os_info.is_windows:
if self.settings.compiler == "Visual Studio":
with tools.vcvars(self.settings):
_build(self, "jom", args)
else:
# Workaround for configure using clang first if in the path
new_path = []
for item in os.environ['PATH'].split(';'):
if item != 'C:\\Program Files\\LLVM\\bin':
new_path.append(item)
os.environ['PATH'] = ';'.join(new_path)
# end workaround
_build(self, "mingw32-make", args)
else:
_build(self, "make", args)
with open('qtbase/bin/qt.conf', 'w') as f:
f.write('[Paths]\nPrefix = ..')
def package(self):
self.copy("bin/qt.conf", src="qtbase")
def package_info(self):
if self.settings.os == "Windows":
self.env_info.path.append(os.path.join(self.package_folder, "bin"))
self.env_info.CMAKE_PREFIX_PATH.append(self.package_folder)