-
Notifications
You must be signed in to change notification settings - Fork 27
/
SConscript
261 lines (216 loc) · 7.96 KB
/
SConscript
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
import os
import sys
import re
import commands
import datetime
import multiprocessing
jcore_count = multiprocessing.cpu_count() * 1.5
unitTestOutputDir = './test_cases'
AddOption('--unit_tests', default=None, dest='unit_test')
AddOption('--test', action='store_true', dest='test')
AddOption('--gui', action='store_true', dest='gui')
debug = GetOption('debug_build')
testmode = GetOption('unit_test')
build_gui = GetOption('gui')
test_option = GetOption('test')
build_unit_tests = False
run_unit_tests = False
if test_option:
testmode = 'run'
if testmode is not None:
if testmode == 'run':
build_unit_tests = True
run_unit_tests = True
elif testmode == 'build':
build_unit_tests = True
print 'Targets: '+', '.join(BUILD_TARGETS)
def detectLatestQtDir(operating_system, compiler_type):
if os.environ.get('QTDIR') is not None:
print 'Using env variable QTDIR: '+os.environ.get('QTDIR')
return os.environ.get('QTDIR')
elif operating_system.startswith('linux'):
return '/usr' #use the system qt install
elif operating_system == 'win32':
qtbase = 'c:\\QtSDK\\Desktop\\Qt'
elif operating_system == 'darwin':
qtbase = '~/QtSDK/Desktop/Qt'
versions = re.compile('4\.(\d+)\.(\d+)')
minor = 0
release = 0
for dir in os.listdir(qtbase):
match = versions.match(dir)
if match is not None:
if int(match.group(1)) > minor:
minor = int(match.group(1))
release = int(match.group(2))
elif (int(match.group(1)) == minor) \
and (int(match.group(2)) > release):
release = int(match.group(2))
qtver = '4.{minor}.{release}'.format(minor=minor, release=release)
qtdir = None
if operating_system == 'win32':
qtdir = '{base}\\{ver}\\{compiler}'.format(base=qtbase, ver=qtver,
compiler=compiler_type)
elif operating_system == 'darwin':
print "Darwin!"
qtdir = '{base}/{ver}/gcc'.format(base=qtbase, ver=qtver)
print 'Found latest qt at {dir}'.format(dir=qtdir)
return qtdir
#end def detectLatestQtDir(...)
def get_environment_flag(flag_name, default):
flag = default
try:
flag = os.environ[flag_name]
if int(flag):
flag = True
except:
flag = False
return flag
#end def get_environment_flag(...)
def runThisTest(testname):
sts,text = commands.getstatusoutput(
'bin/unit_tests/{}UnitTest'.format(testname))
print(text)
#end def runThisTest(...)
def runUnitTest(env,target,source):
""" runs a unit test in a separate process. Not build-aware,
but it does set a flag-file to signify the test ran to success
@target dummy target file, writes 'passed' if tests return no error code
@source unit test program to run """
import subprocess
app = str(source[0].abspath)
retCode = subprocess.call(app)
if not retCode == 0:
print "passed!"
open(str(target[0]),'w').write("PASSED\n")
else:
print("runUnitTest failed testing " + str(source[0]) )
#Message('runing unit test' + source[0].abspath)
Exit(1)
#end def runUnitTest(...)
def mix(*args):
""" mash items/lists together into a single list, no duplicates"""
l = []
for arg_list in args:
l += arg_list
no_duplicates = list(set(l)) # remove duplicates
#print "***", no_duplicates
scons_list = [env.Object(x) for x in no_duplicates]
return scons_list
#end def mix(*)
print ""
print "======================================================="
print "Miracle-Grue build script"
print " * it is now", datetime.datetime.now(), " (Qt and cppUnit are sold separately)"
print
operating_system = sys.platform
print "Operating system: [" + operating_system + "]"
default_libs = []
default_includes = [
'submodule/EzCppLog',
'submodule/optionparser/src',
'src/eigen']
if operating_system.startswith("linux"):
print " ** CPPUNIT version checK:", commands.getoutput("dpkg -l|grep cppunit-dev")
default_libs_path = ['/usr/lib', '/usr/local/lib', './bin/lib']
compiler_type = None
env = Environment(ENV = os.environ, CPPPATH=['./src', './src/mgl'],
LIBPATH=['./bin/lib'])
env.Tool('default')
if operating_system == "darwin":
default_includes.append('/opt/local/include')
default_includes.append(
'/System/Library/Frameworks/CoreFoundation.framework/Versions/Current/Headers')
default_libs_path = ['/opt/local/lib', './bin/lib']
env['FRAMEWORKS'] = ['CoreFoundation']
if operating_system == "win32":
AddOption('--compiler_type', dest="compiler_type", default="mingw" )
compiler_type = GetOption('compiler_type')
if compiler_type == "mingw":
env.Replace(CCFLAGS=[])
env.Tool('mingw', toolpath=[Dir('submodule/mw-scons-tools')])
elif compiler_type == "cl":
pass
else:
print "Unknown compiler {}: Only mingw or cl supported on windows".format(compiler_type)
exit(1)
default_libs_path = ['./bin/lib']
env.Append(CCFLAGS = ['-Wall', '-Wextra'])
debug_profile = False
if debug:
if debug_profile:
env.Append(CCFLAGS = '-pg')
env.Append(CCFLAGS = '-fprofile-arcs')
env.Append(LINKFLAGS = '-pg')
env.Append(LINKFLAGS = '-fprofile-arcs')
env.Append(LINKFLAGS = '-fprofile-arcs')
env.Append(LIBS = 'gcov')
else:
env.Append(CCFLAGS = '-g')
else:
env.Append(CCFLAGS = '-O2')
#env.Append(CCFLAGS = '-j'+ str(int(jcore_count)))
multi_thread = False
if multi_thread:
env.Append(CCFLAGS = '-fopenmp -DOMPFF')
env.Append(LINKFLAGS = '-fopenmp')
mgl_cc = Glob('src/mgl/*.cc')
toolpathviz_cc = Glob('submodule/toolpathviz/*.cpp')
toolpathviz_ui = ['submodule/toolpathviz/mainwindow.ui']
env.Tool('mb_install', toolpath=[Dir('submodule/mw-scons-tools')])
env.MBAddDevelLibPath('#/../json-cpp/obj')
env.MBAddDevelIncludePath('#/../json-cpp/include')
l = env.Library('./bin/lib/mgl', mgl_cc)
env.Clean(l, '#/obj/')
libraries = [l]
unit_test = [
'src/unit_tests/UnitTestMain.cc',
'src/unit_tests/UnitTestUtils.cc']
default_libs.extend(['mgl'])
debug_libs = ['cppunit']
debug_libs_path = ['',]
env.Append(CPPPATH = default_includes)
env.Append(LIBS = default_libs)
env.Append(LIBPATH = default_libs_path)
env.MBAddLib('jsoncpp')
p = env.Program('./bin/miracle_grue',
mix(['src/miracle_grue/miracle_grue.cc'] ))
env.Clean(p, '#/obj/')
binaries = [p]
j = env.Program('./bin/get_slice',
mix(['src/miracle_grue/get_slice.cc'] ))
if build_gui:
print "Building miracle_gui"
qtEnv = env.Clone()
qtEnv['QT4DIR'] = detectLatestQtDir(operating_system, compiler_type)
qtEnv['ENV']['PKG_CONFIG_PATH'] = '/usr/lib/pkgconfig'
qtEnv.Tool('qt4', toolpath=[Dir('submodule/mw-scons-tools')])
qtEnv.EnableQt4Modules(['QtGui',
'QtCore',
'QtOpenGL'])
ui = qtEnv.Uic4(toolpathviz_ui)
p = qtEnv.Program('bin/miracle_gui',
toolpathviz_cc)
binaries.append(p)
gettestname = re.compile('^(.*)TestCase\.cc')
tests = []
for filename in os.listdir(str(Dir('#/src/unit_tests'))):
match = gettestname.match(filename)
if match is not None:
testname = match.group(1)
tests.append(testname)
if build_unit_tests:
testEnv = env.Clone()
testEnv.Append(LIBS = debug_libs)
testEnv.Append(LIBSPATH = debug_libs_path)
for testname in tests:
p = testEnv.Program('bin/unit_tests/{}UnitTest'.format(testname),
mix(['src/unit_tests/{}TestCase.cc'.format(testname)],
unit_test))
if run_unit_tests:
for testname in tests:
testfile = 'bin/unit_tests/{}UnitTest'.format(testname)
testEnv.Command('runtest_'+testname, testfile, testfile)
env.MBInstallResources(env.MBGlob("#/*.config"))
env.MBInstallBin(binaries)
env.MBCreateInstallTarget()