-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
80 lines (70 loc) · 2.38 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
# SCons build script for ML project on Linux.
# (C) 2020 Roman Werpachowski.
import os
import SCons
# Parse command line arguments.
# Build mode:
build_mode = ARGUMENTS.get('mode', 'debug')
if not (build_mode in ['debug', 'release']):
print("Error: expected 'debug' or 'release' for 'build_mode' parameter, found: " + build_mode)
Exit(1)
Export('build_mode')
print('**** Compiling in %s mode ****' % build_mode)
# Extra compile flags for debug mode.
debugcflags = ['-g']
# Extra compile flags for release mode.
releasecflags = ['-O2', '-flto', '-DNDEBUG']
# Paths for Ubuntu LTS.
EIGEN_PATH = '/usr/include/eigen3/'
system_include_paths = [('-isystem' + path) for path in [EIGEN_PATH]] # no space after -isystem!
compilation_options = ['-fno-strict-overflow', '-fdiagnostics-color', '-march=native']
enabled_warnings = ['-Wall', '-Werror', '-Wfatal-errors', '-Wpedantic', '-Wformat', '-Wextra', '-Wconversion']
disabled_warnings = ['-Wno-missing-field-initializers']
c_flags = system_include_paths + compilation_options + enabled_warnings + disabled_warnings
linkflags = []
# We support 64-bit only.
arch_switch = '-m64'
c_flags.append(arch_switch)
linkflags.append(arch_switch)
flags = ["-std=c++17"] + c_flags
BUILD_DIR = os.path.join('build', build_mode.capitalize())
if build_mode == 'debug':
flags += debugcflags
else:
flags += releasecflags
Export('BUILD_DIR')
cpp_path = ['#']
ar = 'ar'
ranlib = 'ranlib'
env = Environment(CPPPATH=cpp_path,
CXXFLAGS=flags,
CFLAGS=c_flags,
LINKFLAGS=linkflags,
AR=ar,
RANLIB=ranlib,
ENV={'PATH' : os.environ['PATH'],
'TERM' : os.environ['TERM'],
'HOME' : os.environ['HOME']}
)
Export('env')
# Linked libraries.
OTHER_LIBS = []
Export('OTHER_LIBS')
def call(subdir, name='SConscript'):
return SConscript(os.path.join(subdir, name), variant_dir = os.path.join(subdir, BUILD_DIR), duplicate = 0)
# Build libraries.
ML, MLObjs = call('ML')
Export('ML')
Export('MLObjs')
call('Demo')
call('cppyml')
if build_mode == 'debug':
top_dir = Dir('#').abspath
env.Append(CXXFLAGS=['-isystem' + os.path.join(top_dir, 'googletest/include')])
gtest = call('googletest', 'SConscript-gtest')
Export('gtest')
GTEST_LIBS = ['pthread']
Export('GTEST_LIBS')
call('Tests')
else:
call('Benchmarks')