-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSConstruct
290 lines (254 loc) · 8.47 KB
/
SConstruct
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
##
# @author Luca-Philipp Grumbach
# @author Richard Hofmann
#
# # Description
# Entry-point for builds.
##
import SCons
import platform
import os
print( '####################################' )
print( '### Tsunami Lab ###' )
print( '### ###' )
print( '### https://scalable.uni-jena.de ###' )
print( '####################################' )
print()
print('running build script')
#####################
# GET OS #
#####################
OS = platform.system()
#####################
# READ ARGUMENTS #
#####################
vars = Variables()
vars.AddVariables(
EnumVariable( 'mode',
'compile modes, option \'san\' enables address and undefined behavior sanitizers',
'release',
allowed_values=('release', 'debug', 'release+san', 'debug+san', 'benchmark')
),
EnumVariable( 'opt',
'optimization flag',
'-O2',
allowed_values=('-O0',
'-O1',
'-O2',
'-O3',
'-Ofast')
),
EnumVariable( 'report',
'flag for enabling reports',
'none',
allowed_values=('none',
'-qopt-report=0',
'-qopt-report=1',
'-qopt-report=2',
'-qopt-report=3',
'-qopt-report=4',
'-qopt-report=5')
),
EnumVariable( 'omp',
'flag for enabling openmp',
'none',
allowed_values=('none',
'gnu',
'intel')
),
EnumVariable( 'gui',
'enables the GUI',
'yes',
allowed_values=('yes', 'no')
),
EnumVariable( 'use_filesystem',
'enables or disabled the filesystem usage',
'yes',
allowed_values=('yes', 'no')
)
)
# exit in the case of unknown variables
if vars.UnknownVariables():
print( "build configuration corrupted, don't know what to do with: " + str(vars.UnknownVariables().keys()) )
exit(1)
#####################
# SET ENVIRONMENT #
#####################
env = Environment( variables = vars )
# set local env
env['ENV'] = os.environ
#####################
# COMPILER OPTION #
#####################
if 'CXX' in os.environ:
env['CXX'] = os.environ['CXX']
print("Using ", env['CXX'], " compiler.")
#####################
# LOAD LIBRARIES #
#####################
# macOS magic for finding libraries with gcc
if OS == "Darwin":
env.Append( CXXFLAGS = [ '-I/usr/local/include/' ] )
env.Append ( LIBPATH = [ '/usr/local/lib' ])
conf = Configure(env)
# NETCDF library
if not conf.CheckLibWithHeader('netcdf', 'netcdf.h','CXX'):
print ('Did not find the c++ netcdf library, will try C.')
if not conf.CheckLibWithHeader('netcdf', 'netcdf.h','C'):
print ('Did not find the C netcdf library, exiting!')
exit(1)
# GUI libraries
if 'yes' in env['gui']:
if OS == "Linux":
if not conf.CheckLib('glfw'):
print ('Did not find the glfw library!')
exit(1)
elif not conf.CheckLib('GL'):
print ('Did not find the GL library!')
exit(1)
elif OS == "Darwin":
if not conf.CheckLib('glfw'):
print ('Did not find the glfw library!')
exit(1)
elif OS == "Windows":
if not conf.CheckLib('glfw3'):
print ('Did not find the glfw3 library!')
exit(1)
elif not conf.CheckLib('gdi32'):
print ('Did not find the gdi32 library!')
exit(1)
elif not conf.CheckLib('opengl32'):
print ('Did not find the opengl32 library!')
exit(1)
elif not conf.CheckLib('imm32'):
print ('Did not find the imm32 library!')
exit(1)
env = conf.Finish()
# generate help message
Help( vars.GenerateHelpText( env ) )
####################
# ENABLE THREADS #
####################
env.Append( LINKFLAGS = [ '-lpthread' ] )
if OS != "Darwin":
env.Append( CXXFLAGS = [ '-pthread' ] )
#####################
# DEFAULT FLAGS #
#####################
if OS == "Darwin":
env.Append( CXXFLAGS = [ '-std=c++17',
'-Wall',
'-Wextra',
'-g' ] )
else:
env.Append( CXXFLAGS = [ '-std=c++17',
'-Wall',
'-Wextra',
'-Werror',
'-Wpedantic',
'-g' ] )
#####################
# OPTIMIZATION MODE #
#####################
if 'debug' in env['mode']:
env.Append( CXXFLAGS = [ '-g',
'-O0' ] )
else:
env.Append( CXXFLAGS = [ env['opt'] ] )
#####################
# REPORTS #
#####################
if 'report' in env['report']:
env.Append( CXXFLAGS = [ env['report'] ] )
#####################
# OPENMP #
#####################
if 'gnu' in env['omp']:
if OS == "Darwin":
env.Append( CXXFLAGS = [ '-Xpreprocessor', '-fopenmp' ] )
env.Append( LINKFLAGS = [ '-Xpreprocessor', '-fopenmp' ] )
env.Append( CXXFLAGS = [ '-DUSEOMP' ] )
else:
env.Append( CXXFLAGS = [ '-fopenmp' ] )
env.Append( LINKFLAGS = [ '-fopenmp' ] )
env.Append( CXXFLAGS = [ '-DUSEOMP' ] )
if 'intel' in env['omp']:
env.Append( CXXFLAGS = [ '-qopenmp' ] )
env.Append( LINKFLAGS = [ '-qopenmp' ] )
env.Append( CXXFLAGS = [ '-DUSEOMP' ] )
if OS == "Darwin":
env.Append( CXXFLAGS = [ '-I/usr/local/opt/libomp/include' ] )
env.Append( LINKFLAGS = [ '-L/usr/local/opt/libomp/lib' ] )
env.Append( LINKFLAGS = [ '-lomp' ] )
#####################
# SANITIZERS #
#####################
if 'san' in env['mode']:
env.Append( CXXFLAGS = [ '-g',
'-fsanitize=float-divide-by-zero',
'-fsanitize=bounds',
'-fsanitize=address',
'-fsanitize=undefined',
'-fno-omit-frame-pointer' ] )
env.Append( LINKFLAGS = [ '-g',
'-fsanitize=address',
'-fsanitize=undefined' ] )
#####################
# NO FILESYSTEM #
#####################
if 'no' in env['use_filesystem']:
env.Append( CXXFLAGS = [ '-DNOFILESYSTEM' ] )
env.Append( CXXFLAGS = [ '-isystem', 'lib' ] )
#####################
# CATCH 2 SUBMODULE #
#####################
env.Append( CXXFLAGS = [ '-isystem', 'submodules/Catch2/single_include' ] )
#####################
# JSON SUBMODULE #
#####################
env.Append( CXXFLAGS = [ '-isystem', 'submodules/json/single_include' ] )
#####################
# IMGUI SUBMODULE #
#####################
if 'yes' in env['gui']:
env.Append( CXXFLAGS = [ '-isystem', 'submodules/imgui/' ] )
env.Append( CXXFLAGS = [ '-isystem', 'submodules/imgui/backends/' ] )
env.Append( CXXFLAGS = [ '-isystem', 'submodules/implot/' ] )
# add other OS specific flags
if OS == "Darwin":
env.AppendUnique(FRAMEWORKS=Split('OpenGL Cocoa IOKit CoreVideo'))
#####################
# GET SOURCE FILES #
#####################
VariantDir( variant_dir = 'build/src',
src_dir = 'src' )
env.sources = []
env.tests = []
env.sanitychecks = []
env.gui = []
Export('env')
SConscript( 'build/src/SConscript' )
Import('env')
if 'yes' in env['gui']:
env.imguiSources = ['submodules/imgui/imgui.cpp',
'submodules/imgui/imgui_demo.cpp',
'submodules/imgui/imgui_draw.cpp',
'submodules/imgui/imgui_tables.cpp',
'submodules/imgui/imgui_widgets.cpp',
'submodules/imgui/backends/imgui_impl_glfw.cpp',
'submodules/imgui/backends/imgui_impl_opengl3.cpp',
'submodules/implot/implot_demo.cpp',
'submodules/implot/implot_items.cpp',
'submodules/implot/implot.cpp',]
#####################
# SPECIFY TARGETS #
#####################
env.Program( target = 'build/tsunami_lab',
source = env.sources + env.standalone )
env.Program( target = 'build/tests',
source = env.sources + env.tests)
env.Program( target = 'build/sanitychecks',
source = env.sources + env.sanitychecks)
if 'yes' in env['gui']:
env.Program( target = 'build/gui',
source = env.sources + env.gui + env.imguiSources )