-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconanfile.py
255 lines (226 loc) · 8.44 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
'''
@author: René Ferdinand Rivera Morell
@copyright: Copyright René Ferdinand Rivera Morell 2022
@license:
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
'''
from conan import ConanFile, tools
import os
required_conan_version = ">=1.53.0"
class Package(ConanFile):
name = "b2-conan"
version = "1.0.4"
homepage = "https://github.com/bfgroup/b2-conan"
description = "Build utility tool to invoke b2 for building packages."
topics = ("b2", "tool", "build")
license = "BSL-1.0"
url = "https://github.com/bfgroup/b2-conan"
barbarian = {
"description": {
"format": "asciidoc",
"file": "README.adoc"
}
}
exports = ("README.adoc", "LICENSE.txt")
settings = []
no_copy_source = True
class B2():
def __init__(self, conanfile):
self.conanfile = conanfile
self.flags = []
for name in dir(self):
if name.startswith('_add_flags_'):
getattr(self, name)()
def build(self, args=None, build_dir=None, target=None):
'''
Invoke b2 to build the default, or given target.
* args (Optional, Defaulted to `None`) Extra arguments to invoke B2
with.
* build_dir (Optional, Defaulted to `None`) The intermediate output
build directory.
* target (Optional, Defaulted to `None`) A set of one or more targets
to build. These are added to the command line invocation directly.
And must use the B2 target syntax.
'''
if not self.conanfile.should_build:
return
command = ["b2"]
if args:
command.extend(args)
if build_dir:
command.append('--build-dir="%"' % (build_dir))
command.extend(self.flags)
if target:
if isinstance(target, str):
command.append(target)
else:
command.extend(target)
self.conanfile.output.info('"{}"'.format('" "'.join(command)))
return self.conanfile.run(command, run_environment=True)
@property
def toolset(self):
return {
'apple-clang': 'clang',
'clang': 'clang',
'gcc': 'gcc',
'sun-cc': 'sun',
'Visual Studio': 'msvc',
'msvc': 'msvc'
}.get(self.conanfile.settings.get_safe('compiler'))+'-'+self.toolset_version
@property
def toolset_version(self):
if self.conanfile.settings.compiler == 'Visual Studio':
return {
"8": "8.0",
"9": "9.0",
"10": "10.0",
"11": "11.0",
"12": "12.0",
"14": "14.0",
"15": "14.1",
"16": "14.2",
"17": "14.3",
}.get(str(self.conanfile.settings.compiler.version))
if self.conanfile.settings.compiler == 'msvc':
msvc_version = self.conanfile.settings.compiler.version
return {
"140": "8.0",
"150": "9.0",
"160": "10.0",
"170": "11.0",
"180": "12.0",
"190": "14.0",
"191": "14.1",
"192": "14.2",
"193": "14.3",
}.get('{}'.format(msvc_version))
if self.conanfile.settings.compiler == 'apple-clang':
return str(self.conanfile.settings.compiler.version).split('.')[0]
return str(self.conanfile.settings.compiler.version)
@property
def os(self):
return {
"AIX": "aix",
"Android": "android",
"FreeBSD": "freebsd",
"iOS": "iphone",
"Linux": "linux",
"Macos": "darwin",
"SunOS": "solaris",
"tvOS": "appletv",
"watchOS": "iphone",
"Windows": "windows",
"WindowsStore": "windows",
"WindowsCE": "windows",
}.get(str(self.conanfile.settings.os))
@property
def address_model(self):
if self.conanfile.settings.arch in ("x86_64", "ppc64", "ppc64le", "mips64", "armv8", "armv8.3", "sparcv9"):
return "64"
else:
return "32"
@property
def architecture(self):
arch = {
"arm": "arm",
"mips": "mips1",
"mips64": "mips64",
"ppc": "power",
"s390": "s390x",
"sparc": "sparc",
"x86": "x86",
}
for i in arch.items():
if str(self.conanfile.settings.arch).startswith(i[0]):
return i[1]
return None
@property
def variant(self):
return {
'Debug': 'debug',
'MinSizeRel': 'minsizerel',
'Release': 'release',
'RelWithDebInfo': 'relwithdebinfo',
}.get(str(self.conanfile.settings.get_safe('build_type')), "debug")
@property
def cxxstd(self):
if self.conanfile.settings.compiler.get_safe('cppstd'):
return str(self.conanfile.settings.compiler.get_safe('cppstd')).replace("gnu", "")
else:
None
@property
def cxxstd_dialect(self):
return 'gnu' if str(self.conanfile.settings.compiler.get_safe('cppstd')).startswith('gnu') else None
@property
def stdlib(self):
return {
"libstdc++": "gnu",
"libstdc++11": "gnu11",
"libc++": "libc++",
"libstlport": "sun-stlport",
}.get(str(self.conanfile.settings.compiler.get_safe("libcxx")), "native")
@property
def link(self):
return "shared" if self.conanfile.options.get_safe(
"shared", self.conanfile.default_options["shared"]) else "static"
def _add_flags_os(self):
self.flags.append("target-os=%s" % (self.os))
def _add_flags_address_model(self):
self.flags.append("address-model=%s" % (self.address_model))
def _add_flags_architecture(self):
self.flags.append("architecture=%s" % (self.architecture))
def _add_flags_toolset(self):
self.flags.append("toolset=%s" % (self.toolset))
def _add_flags_variant(self):
if self.variant == "debug":
self.flags.append("variant=debug")
elif self.variant == "release":
self.flags.append("variant=release")
elif self.variant == "minsizerel":
self.flags.extend([
"optimization=space",
"debug-symbols=off",
"inlining=full",
"runtime-debugging=off",
])
elif self.variant == "relwithdebinfo":
self.flags.extend([
"optimization=speed",
"debug-symbols=off",
"inlining=full",
"runtime-debugging=off",
])
def _add_flags_cxxstd(self):
if self.cxxstd:
self.flags.append("cxxstd=%s" % (self.cxxstd))
def _add_flags_cxxstd_dialect(self):
if self.cxxstd_dialect:
self.flags.append("cxxstd-dialect=%s" % (self.cxxstd_dialect))
def _add_flags_runtime_link(self):
if self.toolset == "msvc":
self.flags.append("runtime-link=%s" % ("static" if "MT" in str(
self.conanfile.settings.compiler.runtime) else "shared"))
def _add_flags_runtime_debugging(self):
if self.toolset == "msvc":
self.flags.append("runtime-debugging=%" % ("on" if "d" in str(
self.conanfile.settings.compiler.runtime) else "off"))
def _add_flags_stdlib(self):
self.flags.append("stdlib=%s" % (self.stdlib))
def _add_flags_link(self):
self.flags.append("link=%s" % (self.link))
def _add_flags_other(self):
cxxflags = []
linkflags = []
if tools.apple.is_apple_os(self.conanfile):
if self.conanfile.settings.get_safe("os.version"):
cxxflags.append(tools.apple.apple_min_version_flag(
self.conanfile))
if self.conanfile.settings.get_safe("os.subsystem") == "catalyst":
cxxflags.append("--target=arm64-apple-ios-macabi")
link_flags.append("--target=arm64-apple-ios-macabi")
if self.conanfile.options.get_safe("fPIC", self.conanfile.default_options["fPIC"]):
cxxflags.append("-fPIC")
self.flags.extend(["cxxflags=%s" % (f) for f in cxxflags])
self.flags.extend(["linkflags=%s" % (f) for f in linkflags])