forked from TUM-I5/PUML
/
SConstruct
207 lines (164 loc) · 5.48 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
#! /usr/bin/python
# @file
# This file is part of PUML
#
# For conditions of distribution and use, please see the copyright
# notice in the file 'COPYING' at the root directory of this package
# and the copyright notice at https://github.com/TUM-I5/PUML
#
# @copyright 2013 Technische Universitaet Muenchen
# @author Sebastian Rettenberger <rettenbs@in.tum.de>
#
import os
import sys
#
# set possible variables
#
vars = Variables()
# read parameters from a file if given
vars.AddVariables(
PathVariable( 'buildVariablesFile', 'location of the python file, which contains the build variables', None, PathVariable.PathIsFile )
)
env = Environment(variables=vars)
if 'buildVariablesFile' in env:
vars = Variables(env['buildVariablesFile'])
# PUML specific variables
vars.AddVariables(
PathVariable( 'buildDir', 'where to build the code', 'build', PathVariable.PathIsDirCreate ),
EnumVariable( 'compileMode', 'mode of the compilation', 'release',
allowed_values=('debug', 'release')
),
EnumVariable( 'parallelization', 'level of parallelization', 'none',
allowed_values=('none', 'mpi')
),
BoolVariable( 'unitTests', 'builds additional unit tests',
False
),
EnumVariable( 'logLevel',
'logging level. \'debug\' prints all information available, \'info\' prints information at runtime (time step, plot number), \'warning\' prints warnings during runtime, \'error\' is most basic and prints errors only',
'info',
allowed_values=('debug', 'info', 'warning', 'error')
)
)
env.Tool('PrefixPathTool')
# external variables
vars.AddVariables(
env['PREFIX_PATH_VARIABLE'],
PathVariable( 'cc',
'C compiler (default: gcc (serial), mpicc (parallel))',
None,
PathVariable.PathAccept ),
PathVariable( 'cxx',
'C++ compiler (default: g++ (serial), mpiCC (parallel))',
None,
PathVariable.PathAccept ),
BoolVariable( 'useEnv',
'set variables set in the execution environment',
True )
)
# generate help text
Help(vars.GenerateHelpText(env))
if '-h' in sys.argv or '--help' in sys.argv:
import SCons
print SCons.Script.help_text
env.Exit()
# handle unknown, maybe misspelled variables
unknownVariables = vars.UnknownVariables()
# remove the buildVariablesFile from the list of unknown variables (used before)
if 'buildVariablesFile' in unknownVariables:
unknownVariables.pop('buildVariablesFile')
# exit in the case of unknown variables
if unknownVariables:
print "*** The following build variables are unknown: " + str(unknownVariables.keys())
env.Exit(1)
# set environment
env = Environment(variables=vars)
# Set environment
if env['useEnv']:
env['ENV'] = os.environ
#
# precompiler, compiler and linker flags
#
# set compiler
if 'cc' in env:
env['CC'] = env['cxx']
else:
if env['parallelization'] in ['mpi']:
env['CC'] = 'mpicc'
else:
env['CC'] = 'gcc'
if 'cxx' in env:
env['CXX'] = env['cxx']
else:
if env['parallelization'] in ['mpi']:
env['CXX'] = 'mpicxx'
else:
env['CXX'] = 'g++'
# add parallel flag for mpi
if env['parallelization'] in ['mpi']:
env.Append(CPPDEFINES=['PARALLEL'])
# set level of logger
if env['logLevel'] == 'debug':
env.Append(CPPDEFINES=['LOG_LEVEL=3'])
elif env['logLevel'] == 'info':
env.Append(CPPDEFINES=['LOG_LEVEL=2'])
elif env['logLevel'] == 'warning':
env.Append(CPPDEFINES=['LOG_LEVEL=1'])
elif env['logLevel'] == 'error':
env.Append(CPPDEFINES=['LOG_LEVEL=0'])
else:
assert(false)
# compiler flags for generated kernels
env.Append(CXXFLAGS = ['-Wall', '-ansi', '-std=c++0x'])
if env['compileMode'] == 'debug':
env.Append(CXXFLAGS=['-O0','-g'])
elif env['compileMode'] == 'release':
env.Append(CXXFLAGS = ['-DNDEBUG', '-O2'])
# add pathname to the list of directories which are search for include
env.Append(CPPPATH=['#/src'])
# Add prefix path
env.Tool('PrefixPathTool')
#
# add libraries
#
# netCDF
env.Tool('NetcdfTool', parallel=(env['parallelization'] in ['mpi']), required=True)
#
# setup the library name and the build directory
#
lib_name = 'puml'
# Parallelization?
if env['parallelization'] != 'mpi':
lib_name += '_nompi'
# build directory
env['libFile'] = env['buildDir']+'/'+lib_name
env['buildDir'] = env['buildDir']+'/build_'+lib_name
# get the source files
env.sourceFiles = []
Export('env')
SConscript('src/SConscript', variant_dir='#/'+env['buildDir'], src_dir='#/', duplicate=0)
Import('env')
# build standard version
env.StaticLibrary('#/'+env['libFile'], env.sourceFiles)
# build unit tests
if env['unitTests']:
# Anything done here should only affect tests
env = env.Clone()
# define location of cxxtest
env['CXXTEST'] = 'submodules/cxxtest'
# Continue testing if tests fail
env['CXXTEST_SKIP_ERRORS'] = True
# Parallel tests?
if env['parallelization'] in ['mpi']:
env['CXXTEST_COMMAND'] = 'mpiexec -np 2 %t'
env['CXXTEST_OPTS'] = ['--main=cxxtest_main']
# add cxxtest-tool
env.Tool('cxxtest', toolpath=[env['CXXTEST']+'/build_tools/SCons'])
# Get test source files
env.testSourceFiles = []
Export('env')
SConscript('tests/SConscript', variant_dir='#/'+env['buildDir']+'/tests', src_dir='#/')
Import('env')
# build unit tests
env.CxxTest(target='#/'+env['buildDir']+'/tests/cxxtest_runner',
source=env.sourceFiles+env.testSourceFiles)