-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscons_common.py
284 lines (204 loc) · 7.25 KB
/
scons_common.py
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
#
# SConscript for himan-lib
import os
import distro
# Should also get compiler version here but it seems to be rather
# complicated with python subprocess -module
env = Environment(ENV = {'PATH' : os.environ['PATH']})
env['OS_NAME'] = distro.name()
env['OS_VERSION'] = float(distro.version())
env['IS_RHEL'] = (env['OS_NAME'] == "Red Hat Enterprise Linux" or env['OS_NAME'] == "CentOS Linux" or env['OS_NAME'] == "Rocky Linux")
env['IS_SLES'] = (env['OS_NAME'] == "SUSE Linux Enterprise Server")
# Get color output from gcc / clang
try:
env['ENV']['TERM'] = os.environ['TERM']
except KeyError:
pass
env['CC'] = 'gcc'
env['CXX'] = 'g++'
if os.environ.get('CC') != None:
env['CC'] = os.environ.get('CC')
if os.environ.get('CXX') != None:
env['CXX'] = os.environ.get('CXX')
IS_GCC = False
IS_CLANG = False
if env['CXX'] == 'g++':
IS_GCC=True
elif env['CXX'] == 'clang++':
IS_CLANG=True
AddOption(
'--debug-build',
dest='debug-build',
action='store_true',
help='debug build',
default=False)
AddOption(
'--no-cuda-build',
dest='no-cuda-build',
action='store_true',
help='no cuda build',
default=False)
# Check build
NOCUDA = GetOption('no-cuda-build')
DEBUG = GetOption('debug-build')
RELEASE = (not DEBUG)
env['DEBUG'] = DEBUG
env['RELEASE'] = RELEASE
# Workspace
env['WORKSPACE'] = "%s/../" % os.getcwd()
# cuda toolkit path
if not NOCUDA:
cuda_toolkit_path = '/usr/local/cuda'
if os.environ.get('CUDA_TOOLKIT_PATH') is not None:
cuda_toolkit_path = os.environ['CUDA_TOOLKIT_PATH']
env['HAVE_CUDA'] = False
if not NOCUDA and os.path.isfile(cuda_toolkit_path + '/lib64/libcudart.so'):
env['HAVE_CUDA'] = True
env['HAVE_S3'] = False
if os.path.isfile('/usr/include/libs3.h'):
env['HAVE_S3'] = True
env['HAVE_CEREAL'] = False
if os.path.isfile('/usr/include/cereal/cereal.hpp'):
env['HAVE_CEREAL'] = True
# Required for scan-build
env["ENV"].update(x for x in os.environ.items() if x[0].startswith("CCC_"))
# Includes
includes = []
try:
includes.extend(os.environ['INCLUDEPATHS'].split(';'))
except:
pass
includes.append(env['WORKSPACE'] + '/himan-lib/include')
includes.append(env['WORKSPACE'] + '/himan-plugins/include')
if env['HAVE_CUDA']:
includes.append(cuda_toolkit_path + '/include')
env.Append(CPPPATH = includes)
# Library paths
librarypaths = []
try:
librarypaths.extend(os.environ['LIBRARYPATHS'].split(';'))
except:
pass
if env['OS_VERSION'] < 9:
librarypaths.append('/usr/lib64/boost169')
librarypaths.append('/usr/gdal38/lib')
env.Append(LIBPATH = librarypaths)
# Libraries
env.Append(LIBS = ['z', 'bz2', 'stdc++fs'])
if env['HAVE_CUDA']:
env.Append(LIBS=env.File(cuda_toolkit_path + '/lib64/libcudart_static.a'))
# CFLAGS
# "Normal" flags
cflags_normal = []
cflags_normal.append('-Wall')
cflags_normal.append('-W')
cflags_normal.append('-Wno-unused-parameter')
cflags_normal.append('-Werror')
cflags_normal.append('-Wno-narrowing')
cflags_normal.append('-Wpointer-arith')
cflags_normal.append('-Wcast-qual')
# Extra flags
cflags_extra = []
cflags_extra.append('-Wcast-align')
cflags_extra.append('-Wwrite-strings')
cflags_extra.append('-Wconversion')
# cflags_extra.append('-Winline')
cflags_extra.append('-Wnon-virtual-dtor')
cflags_extra.append('-Wsign-promo')
cflags_extra.append('-Wchar-subscripts')
cflags_extra.append('-Wold-style-cast')
cflags_extra.append('-Wunreachable-code')
cflags_extra.append('-Wshadow')
if IS_GCC:
cflags_extra.append('-Wno-pmf-conversions')
elif IS_CLANG:
cflags_extra.append('-Wno-int-conversions')
# Difficult flags
cflags_difficult = []
cflags_difficult.append('-pedantic')
cflags_difficult.append('-Weffc++')
cflags_difficult.append('-Wredundant-decls')
cflags_difficult.append('-Woverloaded-virtual')
cflags_difficult.append('-Wctor-dtor-privacy')
# Default flags (common for release/debug)
cpp_standard = 'c++11'
if env['OS_VERSION'] >= 8:
cpp_standard = 'c++17'
env.Append(CCFLAGS = '-std=' + cpp_standard)
env.Append(CCFLAGS = '-fPIC')
env.Append(CCFLAGS = cflags_normal)
env.Append(CCFLAGS = cflags_extra)
if env['OS_VERSION'] < 9:
env.AppendUnique(CCFLAGS=('-isystem', '/usr/include/boost169'))
env.AppendUnique(CCFLAGS=('-isystem', '/usr/gdal38/include'))
env.AppendUnique(CCFLAGS=('-isystem', '/usr/include/eigen3'))
if IS_CLANG:
env.AppendUnique(CCFLAGS=('-isystem', '/usr/include/smartmet/newbase'))
env.AppendUnique(CCFLAGS=('-isystem', '/opt/llvm-5.0.0/include'))
env.AppendUnique(CCFLAGS=('-isystem', '/opt/llvm-5.0.0/include/c++/v1'))
# Linker flags
env.Append(LINKFLAGS = ['-rdynamic','-Wl,--as-needed'])
# Defines
env.Append(CPPDEFINES=['UNIX'])
if env['HAVE_CUDA']:
env.Append(CPPDEFINES=['HAVE_CUDA'])
if env['HAVE_S3']:
env.Append(CPPDEFINES=['HAVE_S3'])
if env['HAVE_CEREAL']:
env.Append(CPPDEFINES=['HAVE_CEREAL'])
env.Append(NVCCDEFINES=['HAVE_CUDA'])
env.Append(NVCCFLAGS = ['-m64', '-Xcompiler', '-fPIC'])
env.Append(NVCCFLAGS = ['-Wno-deprecated-declarations'])
env.Append(NVCCFLAGS = ['-arch=sm_60'])
env.Append(NVCCFLAGS = ['-gencode=arch=compute_60,code=sm_60'])
env.Append(NVCCFLAGS = ['-gencode=arch=compute_61,code=sm_61'])
env.Append(NVCCFLAGS = ['-gencode=arch=compute_70,code=sm_70'])
env.Append(NVCCFLAGS = ['-gencode=arch=compute_75,code=sm_75'])
env.Append(NVCCFLAGS = ['-gencode=arch=compute_80,code=sm_80'])
env.Append(NVCCFLAGS = ['-gencode=arch=compute_86,code=sm_86'])
env.Append(NVCCFLAGS = ['-gencode=arch=compute_87,code=sm_87'])
env.Append(NVCCFLAGS = ['-gencode=arch=compute_90,code=sm_90'])
env.Append(NVCCFLAGS = ['-gencode=arch=compute_90,code=compute_90'])
env.AppendUnique(NVCCFLAGS = ['-std=' + cpp_standard])
if env['OS_VERSION'] < 9:
env.AppendUnique(NVCCFLAGS = ('-isystem', '/usr/include/boost169'))
env.AppendUnique(NVCCFLAGS = ('-isystem', '/usr/gdal38/include'))
for flag in cflags_normal:
if flag == '-Wcast-qual':
continue
env.Append(NVCCFLAGS = ['-Xcompiler', flag])
# thrust and cuda combined producer warnings like:
# warning #20012-D: __device__ annotation is ignored on a function("vector") that is explicitly defaulted on its first declaration
# disable these warnings
env.Append(NVCCFLAGS = ['--diag-suppress', 20012])
env.Append(NVCCPATH = [env['WORKSPACE'] + '/himan-lib/include']) # cuda-helper
env.Append(NVCCPATH = [env['WORKSPACE'] + '/himan-plugins/include'])
env.Append(NVCCPATH = ['/usr/include/smartmet/newbase'])
# Other
build_dir = ""
env.Append(NOCUDA = NOCUDA)
if RELEASE:
env.Append(CPPDEFINES = ['NDEBUG'])
env.Append(CCFLAGS = ['-O2', '-g'])
env.Append(NVCCFLAGS = ['-O2'])
env.Append(NVCCDEFINES = ['NDEBUG'])
build_dir = 'build/release'
if DEBUG:
env.Append(CCFLAGS = ['-O0'])
env.Append(CCFLAGS = ['-ggdb', '-g3'])
#env.Append(CCFLAGS = cflags_difficult)
env.Append(CPPDEFINES = ['DEBUG'])
# Cuda
env.Append(NVCCFLAGS = ['-O0','-g','-G'])
env.Append(NVCCDEFINES = ['DEBUG'])
build_dir = 'build/debug'
#
# https://bitbucket.org/scons/scons/wiki/PhonyTargets
#
def PhonyTargets(env = None, **kw):
if not env: env = DefaultEnvironment()
for target,action in kw.items():
env.AlwaysBuild(env.Alias(target, [], action))
PhonyTargets(CPPCHECK = 'cppcheck --std=c++17 --enable=all -I ./include -I ../himan-lib/include ./')
PhonyTargets(SCANBUILD = 'scan-build make debug')
Export('env build_dir')