forked from osechet/conan-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conanfile.py
275 lines (245 loc) · 11.4 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
import os
from distutils.spawn import find_executable
from conans import AutoToolsBuildEnvironment, ConanFile, tools, VisualStudioBuildEnvironment
from conans.tools import cpu_count, os_info, SystemPackageTool
def which(program):
"""
Locate a command.
"""
def is_exe(fpath):
"""
Check if a path is executable.
"""
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, _ = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
class QtConan(ConanFile):
""" Qt Conan package """
name = "Qt"
version = "5.6.2"
description = "Conan.io package for Qt library."
source_dir = "qt5"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"opengl": ["desktop", "dynamic"],
"canvas3d": [True, False],
"gamepad": [True, False],
"graphicaleffects": [True, False],
"imageformats": [True, False],
"location": [True, False],
"serialport": [True, False],
"svg": [True, False],
"tools": [True, False],
"webengine": [True, False],
"websockets": [True, False],
"xmlpatterns": [True, False],
"openssl": ["no", "yes", "linked"]
}
default_options = "shared=True", "opengl=desktop", "canvas3d=False", "gamepad=False", "graphicaleffects=False", "imageformats=False", "location=False", "serialport=False", "svg=False", "tools=False", "webengine=False", "websockets=False", "xmlpatterns=False", "openssl=no"
url = "http://github.com/osechet/conan-qt"
license = "http://doc.qt.io/qt-5/lgpl.html"
short_paths = True
def system_requirements(self):
pack_names = None
if os_info.linux_distro == "ubuntu":
pack_names = ["libgl1-mesa-dev", "libxcb1", "libxcb1-dev",
"libx11-xcb1", "libx11-xcb-dev", "libxcb-keysyms1",
"libxcb-keysyms1-dev", "libxcb-image0", "libxcb-image0-dev",
"libxcb-shm0", "libxcb-shm0-dev", "libxcb-icccm4",
"libxcb-icccm4-dev", "libxcb-sync1", "libxcb-sync-dev",
"libxcb-xfixes0-dev", "libxrender-dev", "libxcb-shape0-dev",
"libxcb-randr0-dev", "libxcb-render-util0", "libxcb-render-util0-dev",
"libxcb-glx0-dev", "libxcb-xinerama0", "libxcb-xinerama0-dev"]
if self.settings.arch == "x86":
full_pack_names = []
for pack_name in pack_names:
full_pack_names += [pack_name + ":i386"]
pack_names = full_pack_names
if pack_names:
installer = SystemPackageTool()
installer.update() # Update the package database
installer.install(" ".join(pack_names)) # Install the package
def config_options(self):
if self.settings.os != "Windows":
del self.options.opengl
del self.options.openssl
def requirements(self):
if self.settings.os == "Windows":
if self.options.openssl == "yes":
self.requires("OpenSSL/1.0.2l@conan/stable", dev=True)
elif self.options.openssl == "linked":
self.requires("OpenSSL/1.0.2l@conan/stable")
def source(self):
submodules = ["qtbase"]
if self.options.canvas3d:
submodules.append("qtcanvas3d")
if self.options.gamepad:
submodules.append("qtgamepad")
if self.options.graphicaleffects:
submodules.append("qtgraphicaleffects")
if self.options.imageformats:
submodules.append("qtimageformats")
if self.options.location:
submodules.append("qtlocation")
if self.options.serialport:
submodules.append("qtserialport")
if self.options.svg:
submodules.append("qtsvg")
if self.options.tools:
submodules.append("qttools")
if self.options.webengine:
submodules.append("qtwebengine")
if self.options.websockets:
submodules.append("qtwebsockets")
if self.options.xmlpatterns:
submodules.append("qtxmlpatterns")
major = ".".join(self.version.split(".")[:2])
self.run("git clone https://code.qt.io/qt/qt5.git")
self.run("cd %s && git checkout %s" % (self.source_dir, major))
self.run("cd %s && perl init-repository --no-update --module-subset=%s"
% (self.source_dir, ",".join(submodules)))
self.run("cd %s && git checkout v%s && git submodule update"
% (self.source_dir, self.version))
if self.settings.os != "Windows":
self.run("chmod +x ./%s/configure" % self.source_dir)
else:
# Fix issue with sh.exe and cmake on Windows
# This solution isn't good at all but I cannot find anything else
sh_path = which("sh.exe")
if sh_path:
fpath, _ = os.path.split(sh_path)
self.run("ren \"%s\" _sh.exe" % os.path.join(fpath, "sh.exe"))
def build(self):
""" Define your project building. You decide the way of building it
to reuse it later in any other project.
"""
args = ["-opensource", "-confirm-license", "-nomake examples", "-nomake tests",
"-prefix %s" % self.package_folder]
if not self.options.shared:
args.insert(0, "-static")
if self.settings.build_type == "Debug":
args.append("-debug")
else:
args.append("-release")
if self.settings.os == "Windows":
if self.settings.compiler == "Visual Studio":
self._build_msvc(args)
else:
self._build_mingw(args)
else:
self._build_unix(args)
def _build_msvc(self, args):
build_command = find_executable("jom.exe")
if build_command:
build_args = ["-j", str(cpu_count())]
else:
build_command = "nmake.exe"
build_args = []
self.output.info("Using '%s %s' to build" % (build_command, " ".join(build_args)))
env = {}
env.update({'PATH': ['%s/qtbase/bin' % self.conanfile_directory,
'%s/gnuwin32/bin' % self.conanfile_directory,
'%s/qtrepotools/bin' % self.conanfile_directory]})
# it seems not enough to set the vcvars for older versions
if self.settings.compiler == "Visual Studio":
if self.settings.compiler.version == "15":
env.update({'QMAKESPEC': 'win32-msvc2017'})
args += ["-platform win32-msvc2017"]
if self.settings.compiler.version == "14":
env.update({'QMAKESPEC': 'win32-msvc2015'})
args += ["-platform win32-msvc2015"]
if self.settings.compiler.version == "12":
env.update({'QMAKESPEC': 'win32-msvc2013'})
args += ["-platform win32-msvc2013"]
if self.settings.compiler.version == "11":
env.update({'QMAKESPEC': 'win32-msvc2012'})
args += ["-platform win32-msvc2012"]
if self.settings.compiler.version == "10":
env.update({'QMAKESPEC': 'win32-msvc2010'})
args += ["-platform win32-msvc2010"]
env_build = VisualStudioBuildEnvironment(self)
env.update(env_build.vars)
with tools.environment_append(env):
vcvars = tools.vcvars_command(self.settings)
args += ["-opengl %s" % self.options.opengl]
if self.options.openssl == "no":
args += ["-no-openssl"]
elif self.options.openssl == "yes":
args += ["-openssl"]
else:
args += ["-openssl-linked"]
self.run("cd %s && %s && set" % (self.source_dir, vcvars))
#self.run("cd %s && %s && .\configure.bat %s"
# % (self.source_dir, vcvars, " ".join(args)))
self.run("cd %s && %s"
% (self.source_dir, vcvars))
self.run("%s\configure.bat %s" % (self.source_dir, " ".join(args)))
self.run("cd %s && %s && %s %s"
% (self.source_dir, vcvars, build_command, " ".join(build_args)))
self.run("cd %s && %s && %s install" % (self.source_dir, vcvars, build_command))
def _build_mingw(self, args):
env_build = AutoToolsBuildEnvironment(self)
env = {'PATH': ['%s/bin' % self.conanfile_directory,
'%s/qtbase/bin' % self.conanfile_directory,
'%s/gnuwin32/bin' % self.conanfile_directory,
'%s/qtrepotools/bin' % self.conanfile_directory],
'QMAKESPEC': 'win32-g++'}
env.update(env_build.vars)
with tools.environment_append(env):
# 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
args += ["-developer-build",
"-opengl %s" % self.options.opengl,
"-platform win32-g++"]
self.output.info("Using '%s' threads" % str(cpu_count()))
self.run("cd %s && configure.bat %s"
% (self.source_dir, " ".join(args)))
self.run("cd %s && mingw32-make -j %s"
% (self.source_dir, str(cpu_count())))
self.run("cd %s && mingw32-make install" % (self.source_dir))
def _build_unix(self, args):
if self.settings.os == "Linux":
args += ["-v", "-qt-xcb"]
if self.settings.arch == "x86":
args += ["-platform linux-g++-32"]
else:
args += ["-silent", "-no-framework"]
if self.settings.arch == "x86":
args += ["-platform macx-clang-32"]
self.output.info("Using '%s' threads" % str(cpu_count()))
self.run("cd %s && ./configure %s" % (self.source_dir, " ".join(args)))
self.run("cd %s && make -j %s" % (self.source_dir, str(cpu_count())))
self.run("cd %s && make install" % (self.source_dir))
def package_info(self):
libs = ['Concurrent', 'Core', 'DBus',
'Gui', 'Network', 'OpenGL',
'Sql', 'Test', 'Widgets', 'Xml']
self.cpp_info.libs = []
self.cpp_info.includedirs = ["include"]
for lib in libs:
if self.settings.os == "Windows" and self.settings.build_type == "Debug":
suffix = "d"
elif self.settings.os == "Macos" and self.settings.build_type == "Debug":
suffix = "_debug"
else:
suffix = ""
self.cpp_info.libs += ["Qt5%s%s" % (lib, suffix)]
self.cpp_info.includedirs += ["include/Qt%s" % lib]
if self.settings.os == "Windows":
# Some missing shared libs inside QML and others, but for the test it works
self.env_info.path.append(os.path.join(self.package_folder, "bin"))