-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconanfile.py
293 lines (258 loc) · 11 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
from conans.model.conan_generator import Generator
from conans import ConanFile, os, tools, load
import glob
# This is the normal packaging info since generators
# get published just like other packages. Although
# most of the standard package methods are overridden
# when there is another class derived from "generator" present.
class BoostGenerator(ConanFile):
name = "Boost.Generator"
version = "0.0.1"
url = "https://github.com/bincrafters/conan-boost-generator"
description = "Conan build generator for boost libraries http://www.boost.org/doc/libs/1_64_0/libs/libraries.htm"
license = "BSL"
boost_version = "1.64.0"
exports = "boostcpp.jam", "jamroot.template", "project-config.template.jam"
requires = "Boost.Build/1.64.0@bincrafters/testing"
def package_info(self):
self.user_info.b2_command = "b2 -j%s -a --hash=yes --debug-configuration"%(tools.cpu_count())
# Below is the actual generator code
class boost(Generator):
@property
def filename(self):
pass # in this case, filename defined in return value of content method
@property
def content(self):
jam_include_paths = ' '.join('"' + path + '"' for path in self.conanfile.deps_cpp_info.includedirs).replace('\\','/')
libraries_to_build = " ".join(self.conanfile.lib_short_names)
jamroot_content = self.get_template_content() \
.replace("{{{toolset}}}", self.b2_toolset) \
.replace("{{{libraries}}}", libraries_to_build) \
.replace("{{{boost_version}}}", self.conanfile.version) \
.replace("{{{deps.include_paths}}}", jam_include_paths) \
.replace("{{{os}}}", self.b2_os) \
.replace("{{{address_model}}}", self.b2_address_model) \
.replace("{{{architecture}}}", self.b2_architecture) \
.replace("{{{deps_info}}}", self.get_deps_info_for_jamfile()) \
.replace("{{{variant}}}", self.b2_variant) \
.replace("{{{name}}}", self.conanfile.name) \
.replace("{{{link}}}", self.b2_link) \
.replace("{{{runtime_link}}}", self.b2_runtime_link) \
.replace("{{{toolset_version}}}", self.b2_toolset_version) \
.replace("{{{toolset_exec}}}", self.b2_toolset_exec) \
.replace("{{{libcxx}}}", self.b2_libcxx)
return {
"jamroot" : jamroot_content,
"boostcpp.jam" : self.get_boostcpp_content(),
"project-config.jam" : self.get_project_config_content(),
"short_path.cmd" : "@echo off\nECHO %~s1"
}
def get_template_content(self):
template_file_path = os.path.join(self.get_boost_generator_source_path(), "jamroot.template")
template_content = load(template_file_path)
return template_content
def get_boostcpp_content(self):
boostcpp_file_path = os.path.join(self.get_boost_generator_source_path(), "boostcpp.jam")
boostcpp_content = load(boostcpp_file_path)
return boostcpp_content
def get_boost_generator_source_path(self):
boost_generator = self.conanfile.deps_cpp_info["Boost.Generator"]
boost_generator_root_path = boost_generator.rootpath
boost_generator_source_path = os.path.join(boost_generator_root_path, os.pardir, os.pardir, "export")
return boost_generator_source_path
def get_deps_info_for_jamfile(self):
deps_info = []
for dep_name, dep_cpp_info in self.deps_build_info.dependencies:
dep_libdir = os.path.join(dep_cpp_info.rootpath, dep_cpp_info.libdirs[0])
if os.path.isfile(os.path.join(dep_libdir,"jamroot.jam")):
deps_info.append(
"use-project /" + dep_name + " : " + dep_libdir.replace('\\','/') + " ;")
try:
dep_short_names = self.conanfile.deps_user_info[dep_name].lib_short_names.split(",")
for dep_short_name in dep_short_names:
deps_info.append(
'LIBRARY_DIR(' + dep_short_name + ') = "' + dep_libdir.replace('\\','/') + '" ;')
except KeyError:
pass
deps_info = "\n".join(deps_info)
return deps_info
def get_project_config_content(self):
project_config_content_file_path = os.path.join(self.get_boost_generator_source_path(), "project-config.template.jam")
project_config_content = load(project_config_content_file_path)
return project_config_content \
.replace("{{{toolset}}}", self.b2_toolset) \
.replace("{{{toolset_version}}}", self.b2_toolset_version) \
.replace("{{{toolset_exec}}}", self.b2_toolset_exec) \
.replace("{{{zlib_lib_paths}}}", self.zlib_lib_paths) \
.replace("{{{zlib_include_paths}}}", self.zlib_include_paths) \
.replace("{{{bzip2_lib_paths}}}", self.bzip2_lib_paths) \
.replace("{{{bzip2_include_paths}}}", self.bzip2_include_paths) \
.replace("{{{python_exec}}}", self.b2_python_exec) \
.replace("{{{python_version}}}", self.b2_python_version)
@property
def b2_os(self):
b2_os = {
'Windows': 'windows',
'Linux': 'linux',
'Macos': 'darwin',
'Android': 'android',
'iOS': 'iphone',
'FreeBSD': 'freebsd',
'SunOS': 'solaris'}
return b2_os[str(self.settings.os)]
@property
def b2_address_model(self):
b2_address_model = {
'x86': '32',
'x86_64': '64',
'ppc64le': '64',
'ppc64': '64',
'armv6': '32',
'armv7': '32',
'armv7hf': '32',
'armv8': '64'}
return b2_address_model[str(self.settings.arch)]
@property
def b2_architecture(self):
if str(self.settings.arch).startswith('x86'):
return 'x86'
elif str(self.settings.arch).startswith('ppc'):
return 'power'
elif str(self.settings.arch).startswith('arm'):
return 'arm'
else:
return ""
@property
def b2_variant(self):
if str(self.settings.build_type) == "Debug":
return "debug"
else:
return "release"
@property
def b2_toolset(self):
b2_toolsets = {
'gcc': 'gcc',
'Visual Studio': 'msvc',
'clang': 'clang',
'apple-clang': 'clang'}
return b2_toolsets[str(self.settings.compiler)]
@property
def b2_toolset_version(self):
if self.settings.compiler == "Visual Studio":
if self.settings.compiler.version == "15":
return "14.1"
else:
return str(self.settings.compiler.version) + ".0"
else:
return "$(DEFAULT)"
@property
def b2_toolset_exec(self):
if self.b2_os == 'linux' or self.b2_os == 'freebsd' or self.b2_os == 'solaris' or self.b2_os == 'darwin':
version = str(self.settings.compiler.version).split('.')
result_x = self.b2_toolset + "-" + version[0]
result_xy = result_x + version[1] if version[1] != '0' else ''
class dev_null(object):
def write(self, message):
pass
try:
self.conanfile.run(result_xy + " --version", output=dev_null())
return result_xy
except:
pass
try:
self.conanfile.run(result_x + " --version", output=dev_null())
return result_x
except:
pass
return "$(DEFAULT)"
elif self.b2_os == "windows":
vs_root = tools.vs_installation_path(str(self.settings.compiler.version))
cl_exe = \
glob.glob(os.path.join(vs_root,"VC","Tools","MSVC","*","bin","*","*","cl.exe")) + \
glob.glob(os.path.join(vs_root,"VC","bin","cl.exe"))
if len(cl_exe) > 0:
return cl_exe[0].replace("\\","/")
else:
return "$(DEFAULT)"
else:
return "$(DEFAULT)"
@property
def b2_link(self):
shared = False
try:
shared = self.conanfile.options.shared
except:
pass
return "shared" if shared else "static"
@property
def b2_runtime_link(self):
if self.settings.compiler == "Visual Studio" and self.settings.compiler.runtime:
return "static" if "MT" in str(self.settings.compiler.runtime) else "$(DEFAULT)"
return "$(DEFAULT)"
@property
def zlib_lib_paths(self):
try:
if self.conanfile.options.use_zlib:
return '"{0}"'.format('" "'.join(self.deps_build_info["zlib"].lib_paths))
except:
pass
return ""
@property
def zlib_include_paths(self):
try:
if self.conanfile.options.use_zlib:
return '"{0}"'.format('" "'.join(self.deps_build_info["zlib"].include_paths))
except:
pass
return ""
@property
def bzip2_lib_paths(self):
try:
if self.conanfile.options.use_zlib:
return '"{0}"'.format('" "'.join(self.deps_build_info["bzip2"].lib_paths))
except:
pass
return ""
@property
def bzip2_include_paths(self):
try:
if self.conanfile.options.use_bzip2:
return '"{0}"'.format('" "'.join(self.deps_build_info["bzip2"].include_paths))
except:
pass
return ""
@property
def b2_libcxx(self):
if self.b2_toolset == 'gcc':
if str(self.settings.compiler.libcxx) == 'libstdc++11':
return '<cflags>-std=c++11 <linkflags>-std=c++11'
elif self.b2_toolset == 'clang':
if str(self.settings.compiler.libcxx) == 'libc++':
return '<cflags>-stdlib=libc++ <linkflags>-stdlib=libc++'
elif str(self.settings.compiler.libcxx) == 'libstdc++11':
return '<cflags>-stdlib=libstdc++ <linkflags>-stdlib=libstdc++ <cflags>-std=c++11 <linkflags>-std=c++11'
else:
return '<cflags>-stdlib=libstdc++ <linkflags>-stdlib=libstdc++'
return ''
@property
def b2_python_exec(self):
try:
return '"'+str(self.conanfile.options.python).replace("\\","/")+'"'
except:
return ""
@property
def b2_python_version(self):
pyexec = self.b2_python_exec
if pyexec:
class get_pyver():
def __init__(self):
self.value = ""
def write(self,m):
self.value = self.value+m.strip()
pyver = get_pyver()
self.conanfile.run(
'''{0} -c "from sys import *; print('%d.%d' % (version_info[0],version_info[1]))"'''.format(pyexec),
output=pyver)
return pyver.value
else:
return ""