-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSConscript
More file actions
325 lines (272 loc) · 10.4 KB
/
Copy pathSConscript
File metadata and controls
325 lines (272 loc) · 10.4 KB
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
import os, subprocess, re, platform
from os import path,walk
Import("env", "ccmode")
#---------------------- GENERAL --#
this_module = "reactive"
#------------------------- DEPS --#
# comma separated list for dacteev libs
libdeps = [''];
# comma separated list for external libs
extdeps = [
'curl',
'libboost_regex',
'boost_system',
'boost_thread',
'pthread',
'boost_program_options',
'boost_iostreams',
'cryptopp',
'http_parser',
'uv',
'icuuc'
];
# comma separated list for external libs used by the test suite
testdeps = [
'curl',
'libboost_regex',
'boost_system',
'boost_thread',
'pthread',
'boost_program_options',
'boost_iostreams',
'cryptopp',
'http_parser',
'uv',
'icuuc'
];
def git(cmd):
full_cmd = "git " + cmd
p = subprocess.Popen(
full_cmd,
#cwd = root,
shell = True,
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
close_fds = (os.name != "nt")
)
gitVersion = p.stdout.read()
# error = p.stderr.read()
# if error:
# print "Git error: " + error
p.stdin.close()
return gitVersion if p.wait() == 0 else None
def getGitBuildVersion():
tag = git("describe --always --tag").rstrip()
if tag :
m = re.match("v(\d+).(\d+).(\d+)-(\d+)-([a-f0-9]{8})", tag)
if m :
return {
"major": m.group(1),
"minor": m.group(2),
"patch": m.group(3),
"build": m.group(5)
}
m = re.match("v(\d+).(\d+).(\d+)", tag)
if m :
return {
"major": m.group(1),
"minor": m.group(2),
"patch": m.group(3)
}
return {
"major": "0",
"minor": "0",
"patch": "0",
"build": tag
}
return None
def generate_version(env, target, source):
version = getGitBuildVersion()
if "build" in version:
version_full = "{0}.{1}.{2}+{3}".format(
version["major"],
version["minor"],
version["patch"],
version["build"]
)
else:
version_full = "{0}.{1}.{2}".format(
version["major"],
version["minor"],
version["patch"]
)
data = ""
with open(source[0].path, "r") as fs:
data = str(fs.read())
data = data.replace("@REACTIVE_VERSION_MAJOR@", version["major"])
data = data.replace("@REACTIVE_VERSION_MINOR@", version["minor"])
data = data.replace("@REACTIVE_VERSION_PATCH@", version["patch"])
data = data.replace("@REACTIVE_VERSION@", version_full)
if "build" in version:
data += "#define REACTIVE_VERSION_BUILD \"{0}\"\n".format(version["build"])
with open(target[0].path, "w") as ft:
ft.write(data)
return 0
# The version.cc checking
env.Command(
target = "include/reactive/version.hpp",
source = "include/reactive/version.hpp.in",
action = generate_version
)
import os
from os import path,walk
# --------------------- Routines --- #
def getSuffixedFiles(fpath, fsuffix):
# There must be another way to set things relative to the scons dir
# because here we are in the build dir (variant_dir)
fpath = path.join('..', fpath);
filelist = []
for (dirpath, dirnames, filenames) in walk(fpath):
filelist += Glob(path.join(dirpath, fsuffix))
return filelist
# --------------------- Building --- #
if ("cov" in COMMAND_LINE_TARGETS):
env["CPPFLAGS"] = [
"-std=c++11",
"-pedantic",
"-Wall",
"-pipe",
"-O0",
"-fprofile-arcs",
"-ftest-coverage",
"-DTEST"
]
extdeps += ["gcov"]
testdeps += ["gcov"]
if ("test" in COMMAND_LINE_TARGETS):
env.Append(CPPFLAGS = ["-DTEST"])
common_install_dir = path.join('usr', 'local')
common_abs_lib_dir = path.join('/', common_install_dir, "lib")
common_abs_inc_dir = path.join('/', common_install_dir, "include")
default_test_dir = "unit_tests"
default_bin_dir = "bin"
default_demo_dir = "demo"
this_destdir = ARGUMENTS.get('DESTDIR', 'destdir')
this_testdir = ARGUMENTS.get('TESTDIR', default_test_dir)
this_demodir = ARGUMENTS.get('DEMODIR', default_demo_dir)
this_bindir = ARGUMENTS.get('BINDIR', default_bin_dir)
this_libdir = ARGUMENTS.get('LIBDIR', '')
this_is_portage = ARGUMENTS.get('DAPORTAGE', 'yes')
srcfiles = getSuffixedFiles('src', "*.cpp")
testfiles = getSuffixedFiles("test_suite", "*.cpp")
binsrcfiles = getSuffixedFiles("main_suite", "*.cpp")
demosrcfiles = getSuffixedFiles("demo_suite", "*.cpp")
incfiles = getSuffixedFiles("include", "*.hpp")
reallibdeps = []
print("scons: --- Act as if in portage (build sandbox): " + this_is_portage)
print("scons: --- Compilation mode: " + ccmode)
print("scons: --- Build targets: " + str(COMMAND_LINE_TARGETS))
# --- Directory settings
if ( this_is_portage != "yes" ):
print("scons: --- Installing without portage --- ")
this_destdir = os.sep;
if ( len(this_libdir) > 1 ):
this_installdir = path.join(this_destdir, this_libdir[1:])
else:
this_installdir = path.join(this_destdir, common_install_dir)
this_installdir_bin = path.join(this_installdir, "bin")
this_installdir_lib = path.join(this_installdir, "lib")
this_installdir_inc = path.join(this_installdir, "include")
this_installdir_bin = path.join(this_installdir, "bin")
# --- Lib construction and linking settings
# Path to find headers in the build include dir
env.Append(CPPPATH = ['include'])
# Path to find headers in include dir from previous dacteev installation
env.Append(CPPPATH = [common_abs_inc_dir] )
# Path to find libs in the build lib dir (for multi object modules)
env.Append(LIBPATH = [this_installdir_lib])
# Path to find libs in lib dir from previous dacteev installation
env.Append(LIBPATH = [common_abs_lib_dir])
# Linking against external libs (no custom paths for these)
env.Append(LIBS = extdeps)
if (platform.system() == 'Darwin'):
env.Append(CPPPATH = ['/opt/local/include'])
env.Append(LIBPATH = ['/opt/local/lib'])
# Adding link rules to dacteev's *.so or *.a (simulating a # FindLib)
for ldep in libdeps:
tmp_list = getSuffixedFiles(common_abs_lib_dir, "*" + ldep + ".so*")
tmp_list += getSuffixedFiles(common_abs_lib_dir, "*" + ldep + ".a*")
if (tmp_list != []):
# We can link against this lib
reallibdeps.append(ldep)
env.Append(LIBS = [ldep])
# env['CCCOMSTR'] = "- Compiling $TARGET\n" + env['CCCOM']
# --------------------------------------- #
# --- Installing libs
if (srcfiles != []):
obj_lib_so = env.SharedLibrary(target = this_module, source = srcfiles)
obj_lib_a = env.Library(target = this_module, source = srcfiles)
env.Install(dir = [this_installdir_lib], source = obj_lib_so)
env.Install(dir = [this_installdir_lib], source = obj_lib_a)
env.Alias("install", [this_installdir_lib])
env.Alias("lib", [obj_lib_so, obj_lib_a])
env.Alias("cov", [obj_lib_so, obj_lib_a])
# --- Installing include files
tmp_delimiter = path.join(this_module, 'include') + os.sep
for incf in incfiles:
# Get file name with relative directory
L1 = (str(incf)).split(tmp_delimiter)
tmp_relpath = L1.pop()
L2 = (str(tmp_relpath)).split(os.sep)
# constructing the target directory with all hpps directories
tmp_target_dir = this_installdir_inc
for i in range(len(L2)-1):
tmp_target_dir = path.join(tmp_target_dir, L2.pop(0))
env.Install(dir = [tmp_target_dir], source = incf)
# --- Root directory install target for header files
if (incfiles != []):
aliasinc = env.Alias( "install", [this_installdir_inc])
# --- Unit tests, target: *test* ---
if ("test" in COMMAND_LINE_TARGETS) | ("cov" in COMMAND_LINE_TARGETS):
testenv = env.Clone()
if (testfiles != []):
if (srcfiles != []):
# The shared library of this module is constructed and can be linked
test_libs = [this_module, "boost_unit_test_framework"]
else:
test_libs = ["boost_unit_test_framework"]
test_libs.append(testdeps)
if (this_testdir == default_test_dir):
progtest_o = testenv.Program(target = path.join(this_testdir, "test_" + this_module), source = testfiles, LIBS = test_libs, LIBPATH=[this_installdir_lib])
else:
progtest_o = testenv.Program(target = "test_" + this_module, source = testfiles, LIBS = test_libs, LIBPATH=[this_installdir_lib])
#testenv.Install( dir = [this_testdir], source = progtest_o)
testenv.Alias("test", [this_testdir])
testenv.Alias("cov", [this_testdir])
##--- Main suite compilation
if ("test" not in COMMAND_LINE_TARGETS) and ("demo" not in COMMAND_LINE_TARGETS):
if (binsrcfiles != []):
main_libs = []
if ( srcfiles != [] ):
# The shared library of this module is constructed and can be linked
main_libs = [this_module, reallibdeps, extdeps]
else:
main_libs = [reallibdeps, extdeps]
for binf in binsrcfiles:
L1 = (str(binf)).split(".cpp")
L1 = L1[0].split(os.sep)
binftarget = L1.pop()
if (this_bindir == default_bin_dir):
binftarget = path.join(this_bindir, binftarget)
new_prog_o = env.Program(target = binftarget, source = binf, LIBS = main_libs)
env.Install(dir= [this_installdir_bin], source = new_prog_o)
env.Alias("install", [this_installdir_bin])
##--- Demo suite compilation
if ("demo" in COMMAND_LINE_TARGETS):
if ( demosrcfiles != [] ):
demoenv = env.Clone()
demo_libs = []
if ( srcfiles != [] ):
# The shared library of this module is constructed and can be linked
demo_libs = [this_module, reallibdeps, extdeps]
else:
demo_libs = [reallibdeps, extdeps]
for binf in demosrcfiles:
L1 = (str(binf)).split(".cpp")
L1 = L1[0].split(os.sep)
binftarget = L1.pop()
if (this_demodir == default_demo_dir):
binftarget = path.join(this_demodir, binftarget)
new_demo_o = demoenv.Program(target = binftarget, source = binf, LIBS = demo_libs)
demoenv.Alias("demo", new_demo_o)