-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.scons
145 lines (127 loc) · 5.16 KB
/
main.scons
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
#SetOption('implicit_cache', 1)
############
# Settings #
############
libPath = ['/usr/local/lib/', '/usr/local/boost/lib/', '/usr/lib/', '/usr/local/gtest-1.6.0/lib/']
cppPath = ['/usr/local/include/', '/usr/local/boost/include/', '/usr/include/', '/usr/local/gtest-1.6.0/include/', '/usr/include/python2.7/']
requiredLibs = ['netcdf', 'netcdf_c++', 'm']
boostLibs = ['boost_system', 'boost_filesystem']
optionalLibs = ['grib_api', 'jasper', 'ncurses', 'gtest']
requiredHeaders = ['netcdf.hh', 'stdio.h', 'boost/shared_ptr.hpp']
cppFlags = '-Wall -Wno-reorder -Wno-sign-compare'
###########################
def missingLib(lib, env):
print 'ERROR: Cannot find library ' + lib + " in the search directories: [" + ', '.join(env["LIBPATH"]) + ']'
exit()
def missingHeader(header, env):
print 'ERROR: Cannot find header ' + header + " in the search directories: [" + ', '.join(env["CPPPATH"]) + ']'
exit()
Import('env')
Import('exeDir')
Import('debug')
SConscript("local.scons", exports={'env': env})
libs = requiredLibs + optionalLibs
# Set environment variables
env.Append(LIBPATH = libPath)
env.Append(CPPFLAGS = cppFlags)
env.Append(CPPPATH = cppPath)
env.Append(RPATH = env["LIBPATH"])
env.Append(CXXCOMSTR = "\033[31mCompiling $TARGET\033[0m")
env.Append(LINKCOMSTR = "\033[32mLinking $TARGET\033[0m")
########################
# Configuration checks #
########################
if not env.GetOption('clean'):
# Check for headers
config = Configure(env)
for header in requiredHeaders:
if not config.CheckCXXHeader(header):
missingHeader(header, env)
# Check for libraries
for lib in requiredLibs:
if not config.CheckLib(lib):
missingLib(lib, env)
# Check for boost libraries
for lib in boostLibs:
if not config.CheckLib(lib):
if not config.CheckLib(lib + '-mt'):
missingLib(lib, env)
# Check for GRIB
if config.CheckLib('jasper'):
if not config.CheckLib('grib_api'):
print "WARNING: 'grib_api' library not found. Compiling without GRIB support."
else:
config.env.Append(CPPDEFINES = '-DWITH_GRIB')
else:
print "WARNING: 'jasper' library not found. Compiling without GRIB support."
# Check for gtest
if config.CheckLib('gtest'):
print "Compiling with Google test suite."
config.env.Append(CPPDEFINES = '-DWITH_GTEST')
# Check for python
if config.CheckLib('python2.7'):
if config.CheckHeader("Python.h"):
print "Compiling with python support."
config.env.Append(CPPDEFINES = '-DWITH_PYTHON')
# Check for NCurses
if not config.CheckLib('ncurses'):
print "WARNING: 'ncurses' library not found. Compiling without ncurses support."
else:
config.env.Append(CPPDEFINES = '-DWITH_NCURSES')
env = config.Finish()
# Components
folders = Split('Inputs Correctors Selectors Downscalers DetMetrics Averagers Calibrators Configurations Continuous Discretes BaseDistributions Estimators Metrics Outputs ParameterIos Transforms Variables Uncertainties Smoothers Updaters Interpolators Measures Loggers Qcs Poolers Spreaders Neighbourhoods')
objs =[]
for folder in folders:
obj = env.Object(Glob('src/' + folder + '/*.cpp'))
objs = objs + [obj]
core = env.Object(Glob('src/*.cpp'))
# Test targets
testTargets = Glob('src/Tests/*.cpp')
for testTarget in testTargets:
obj = env.Object(testTarget)
testTarget = str(testTarget)
# Determine the name of the test target
slashIndex = 0
dotIndex = 0
for i in range(1,len(testTarget)):
if(testTarget[i] == '/'):
slashIndex = i
if(testTarget[i] == '.'):
dotIndex = i
testTarget = testTarget[(slashIndex+1):dotIndex]
if(debug):
testName = exeDir + '/tests/' + testTarget + '_debug.exe'
else:
testName = exeDir + '/tests/' + testTarget + '.exe'
testObjects = [obj] + objs + [core]
testProgram = env.Program(testName, testObjects)
compsDriver = env.Object(Glob('src/Drivers/Comps.cpp'))
convertDriver = env.Object(Glob('src/Drivers/Convert.cpp'))
infoDriver = env.Object(Glob('src/Drivers/Info.cpp'))
hoodDriver = env.Object(Glob('src/Drivers/Hood.cpp'))
namelistDriver = env.Object(Glob('src/Drivers/Namelist.cpp'))
comps = [compsDriver] + objs + [core]
convert = [convertDriver] + objs + [core]
info = [infoDriver] + objs + [core]
hood = [hoodDriver] + objs + [core]
namelist = [namelistDriver] + objs + [core]
if(debug):
compsName = exeDir + '/comps_debug.exe'
convertName = exeDir + '/convert_debug.exe'
infoName = exeDir + '/info_debug.exe'
hoodName = exeDir + '/hood_debug.exe'
namelistName= exeDir + '/namelist_debug.exe'
else:
compsName = exeDir + '/comps.exe'
convertName = exeDir + '/convert.exe'
infoName = exeDir + '/info.exe'
hoodName = exeDir + '/hood.exe'
namelistName= exeDir + '/namelist.exe'
compsExe = env.Program(compsName, comps)
convertExe = env.Program(convertName, convert)
infoExe = env.Program(infoName, info)
hoodExe = env.Program(hoodName, hood)
namelistExe= env.Program(namelistName, namelist)
if(not debug):
Default(compsExe, infoExe, convertExe)