forked from uentity/bluesky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scons_tools
275 lines (237 loc) · 7.92 KB
/
scons_tools
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
# -*- coding: utf-8 -*
import os
def list_suffix (list, suffix) :
return [x + suffix for x in list];
def list_prefix(in_list, what) :
return [what + x for x in in_list];
def add_suffix (x, suffix) :
if (len (x) == 0) :
return x
else :
return x + suffix
class files :
def __init__ (self, root = ["."], excludes = [], ext = ["*.cpp"]) :
def super_glob (inc = Split ("."), excludes = []) :
file_list = []
for e in ext :
for p in inc :
file_list.extend ([str (x) for x in Glob (os.path.join (p, e))])
for f in excludes :
if (f in file_list) :
file_list.remove (f)
file_list.sort ()
return file_list
self.root = ""
for p in root :
if (p <> ".") :
self.root = os.path.join (self.root, p)
sources = super_glob ([os.path.join (self.root, "src")], [str (Glob (os.path.join (self.root, "src", ex))[0]) for ex in excludes])
self.sources = [os.path.join ("src", os.path.split (x)[1]) for x in sources]
def bs_common_defines(custom_env) :
custom_env.AppendUnique(CPPDEFINES = ["BS_EXPORTING_PLUGIN"]);
if custom_env['py'] == '1' :
custom_env.AppendUnique(CPPDEFINES = ["BSPY_EXPORTING_PLUGIN"]);
def print_config(msg, two_dee_iterable):
# this function is handy and can be used for other configuration-printing tasks
print
print msg
print
for key, val in two_dee_iterable:
print " %-20s %s" % (key, val)
print
def config_h_build(target, source, config_h_defines, env):
config_h_defines = {};
if "config_h_defines" in env :
config_h_defines = env["config_h_defines"];
print_config("Generating " + target + " with the following settings:",
config_h_defines.items())
if len(config_h_defines) == 0 : return;
for a_target, a_source in zip(target, source):
config_h = file(str(a_target), "w")
config_h_in = file(str(a_source), "r")
config_h.write(config_h_in.read() % config_h_defines)
config_h_in.close()
config_h.close()
Export ("list_prefix")
Export ("list_suffix")
Export ("add_suffix")
Export ("files")
Export ("bs_common_defines")
Export ("print_config")
Export ("config_h_build")
#---------------- configure
# Boost library aliases (short names)
boost_libalias = [
'system', 'filesystem', 'regex', 'thread', 'signals', 'serialization', 'date_time', 'python', 'locale'
];
boost_libnames = dict(zip(boost_libalias, ['']*len(boost_libalias)));
boost_libnames_d = dict(zip(boost_libalias, ['']*len(boost_libalias)));
def CheckBoostVersion(context, version):
# Boost versions are in format major.minor.subminor
v_arr = version.split(".")
version_n = 0
if len(v_arr) > 0:
version_n += int(v_arr[0])*100000
if len(v_arr) > 1:
version_n += int(v_arr[1])*100
if len(v_arr) > 2:
version_n += int(v_arr[2])
context.Message('Checking for Boost version >= %s... ' % (version))
ret = context.TryCompile("""
#include <boost/version.hpp>
#if BOOST_VERSION < %d
#error Installed boost is too old!
#endif
int main()
{
return 0;
}
""" % version_n, '.cpp')
context.Result(ret)
return ret
def CheckBoostLibrary(context, library, header = '') :
if not header :
header = "version.hpp";
context.Message('Checking Boost library %s... ' % (library))
test_src = """
#include <boost/%s>
int main()
{
return 0;
}
""" % header;
#context.AppendLIBS(library);
#print test_src
ret = context.TryCompile(test_src, '.cpp')
if ret :
ret = context.TryLink(test_src, '.cpp');
context.Result(ret)
return ret
def FindBoostLibrary(context, lib, path = '', postfix = '', header = ''):
def libfinder(lib, path, postfix) :
def select_fname(files) :
# FIXME: choose the best one.
# select fname with shortest length
lib_fname = '';
min_fname = 0;
#print files;
for i in range(len(files)) :
if min_fname == 0 or len(files[i]) < min_fname :
lib_fname = os.path.basename(files[i])[3:-3];
min_fname = len(files[i]);
return lib_fname;
import glob;
# direct form: e.g. libboost_iostreams.so
files = glob.glob(os.path.join(path, 'lib{0}{1}.so'.format(lib, postfix)));
if len(files) > 0 :
return select_fname(files);
# check things like libboost_iostreams-gcc.so
files = glob.glob(os.path.join(path, 'lib{0}*{1}.so'.format(lib, postfix)));
if len(files) > 0 :
return select_fname(files);
# nothing is found
return '';
# ensure we have "boost_" prefix
if not lib.startswith("boost_") :
lib = "boost_" + lib;
# check if we have suffix for Boost libs set
if len(postfix) == 0 and "boost_suffix" in context.env :
postfix = context.env["boost_suffix"];
# check if we have BOOST_PATH variable and can extract path
if len(path) == 0 and 'BOOST_PATH' in os.environ :
path = os.path.join(os.environ['BOOST_PATH'], 'lib');
# look for boost libraries
context.Message('Looking for Boost library {0}{1}... '.format(lib, postfix))
# for help just return successfully
#if context.env.GetOption('help') :
# context.Result(True);
# return lib;
# try to find library in given path
lib_fname = '';
if len(path) > 0 :
# first check as is
lib_fname = libfinder(lib, path, postfix);
if len(lib_fname) == 0 :
# try search without postfix
lib_fname = libfinder(lib, path, '');
if len(lib_fname) == 0 :
print "Warning! " + lib + " wasn't found in " + path;
if len(lib_fname) == 0 :
# fallback
lib_fname = lib;
else :
print lib + ' -> ' + lib_fname;
# check that we can link with library
res = CheckBoostLibrary(context, lib_fname, header);
#context.Result(res)
if not res :
# raise error
print 'Error! ' + lib + ' library is required to build BlueSky!';
Exit(1);
return lib_fname;
def CheckBoost(conf) :
# Add some Boost-related test
conf.AddTest('CheckBoostVersion', CheckBoostVersion);
conf.AddTest('CheckBoostLibrary', CheckBoostLibrary);
conf.AddTest('FindBoostLibrary', FindBoostLibrary);
boost_libpath = '';
# if BOOST_PATH env variable present, it overrides system path check
if 'BOOST_PATH' in os.environ :
print "BOOST_PATH found!";
print "Assume Boost headers in $BOOST_PATH, libraries in $BOOST_PATH/lib";
boost_libpath = os.path.join(os.environ['BOOST_PATH'], 'lib');
conf.env.AppendUnique(
CPPPATH = [os.environ['BOOST_PATH']],
LIBPATH = [boost_libpath],
RPATH = [boost_libpath]
);
# check Boost version
if not conf.CheckBoostVersion('1.46') :
print 'Boost version >= 1.46 required to build BlueSky!'
Exit(1);
# make persistent dictionary of alias -> full library name
# both for release and debug builds
#boost_libalias = ['filesystem', 'regex', 'thread', 'signals', 'serialization', 'date_time'];
#if (conf.env['py'] == '1') :
# boost_libalias += ['python'];
# make dictionaries for debug and release builds
# for release build
for L in boost_libnames.keys() :
boost_libnames[L] = conf.FindBoostLibrary(L);
# for debug builds
if ('build_kinds' in conf.env and 'debug' in conf.env['build_kinds']) or \
("debug" in conf.env and conf.env["debug"] == "1") :
for L in boost_libnames_d.keys() :
boost_libnames_d[L] = conf.FindBoostLibrary(L, postfix = "-d");
def CheckLoki(conf) :
if 'LOKI_PATH' in os.environ :
print "LOKI_PATH found!";
print "Assume Loki headers in $LOKI_PATH/include, libraries in $LOKI_PATH/lib";
loki_libpath = os.path.join(os.environ['LOKI_PATH'], 'lib');
conf.env.AppendUnique(
CPPPATH = [os.path.join(os.environ['LOKI_PATH'], 'include')]
, LIBPATH = [loki_libpath]
, RPATH = [loki_libpath]
);
# Check headers
if not conf.CheckCXXHeader('loki/TypeManip.h') :
print "loki/TypeManip.h required to build BlueSky";
Exit(1);
if not conf.CheckCXXHeader('loki/Singleton.h') :
print "loki/Singleton.h required to build BlueSky";
Exit(1);
# CheckLib makes LIBS dirty, so save and restore it
orig_LIBS = conf.env.subst('$LIBS');
check_res = conf.CheckLib('loki', language='CXX');
conf.env.Replace(LIBS = orig_LIBS);
if not check_res :
print 'Loki library link check failed!'
Exit(1);
Export('boost_libalias');
Export('boost_libnames');
Export('boost_libnames_d');
Export('CheckBoostVersion')
Export('CheckBoostLibrary')
Export('FindBoostLibrary')
Export("CheckBoost");
Export("CheckLoki");