-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSConstruct
More file actions
152 lines (120 loc) · 4.47 KB
/
SConstruct
File metadata and controls
152 lines (120 loc) · 4.47 KB
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
# -*- mode:python -*-
import os
# ------------- OPTIONS ------------- #
AddOption('--prefix',
help="Installation prefix. [Default: /usr/local]",
metavar='DIR',
default="/usr/local",
)
AddOption('--release',
help="Release build target configuration (full optimizations).",
action='store_true',
default=False,
)
AddOption('--harden',
help="Enable hardening compiler flags.",
action='store_true',
default=False,
)
AddOption('--dbgopt',
help="Debug build with some optimizations.",
action='store_true',
default=False,
)
AddOption('--sanitize',
help="Debug build with sanitizers.",
action='store_true',
default=False,
)
AddOption('--compile_commands',
help="Emit compilation database.",
action='store_true',
default=False,
)
# ------------- COMMON ------------- #
main = Environment(
ENV = os.environ,
PREFIX = GetOption('prefix'),
)
main['CXX'] = os.environ.get('CXX', 'g++')
main['CC'] = os.environ.get('CC', 'gcc')
main['DOXYGEN'] = os.environ.get('DOXYGEN', 'doxygen')
main['CLANG_TIDY'] = os.environ.get('CLANG_TIDY', 'clang-tidy')
main['CLANG_FORMAT'] = os.environ.get('CLANG_FORMAT', 'clang-format')
main['CPPLINT'] = os.environ.get('CPPLINT', 'cpplint')
main.Append(
CPPDEFINES = {'GSL_THROW_ON_CONTRACT_VIOLATION' : 1},
CPPFLAGS = [
'-Wall', #'-Werror',
'-isystem', Dir('#/third_party/gflags/include'),
'-isystem', Dir('#/third_party/mc2lib/include'),
'-isystem', Dir('#/third_party/GSL')
],
CPPPATH = ['#/include', '#/src', '#/build/src'],
CFLAGS = ['-std=c11', '-pthread'],
CXXFLAGS = ['-std=c++14', '-pthread'],
LIBPATH = [
'#/third_party/gflags/lib'
],
LIBS = ['gflags'],
LINKFLAGS = ['-pthread'],
)
# Optional dependencies
# TCMalloc gives noticable performance boost for some use-cases.
main.ParseConfig("pkg-config libtcmalloc --cflags --libs 2>/dev/null || true")
# ------------- BUILD VARIANTS ------------- #
main.VariantDir('build/src', 'src', duplicate=False)
main.VariantDir('build/test', 'test', duplicate=False)
if GetOption('release'):
main.Append(CPPDEFINES = ['NDEBUG'],
CPPFLAGS = ['-O2'])
if GetOption('harden'):
main.Append(CPPDEFINES = {'_FORTIFY_SOURCE' : 2})
else:
main.Append(CPPFLAGS = ['-g'])
if GetOption('dbgopt'):
main.Append(CPPFLAGS = ['-O'])
if GetOption('sanitize'):
sanitizers = ['undefined', 'address']
san_flags = ['-fsanitize={}'.format(s) for s in sanitizers]
main.Append(CPPFLAGS = san_flags, LINKFLAGS = san_flags)
if GetOption('harden'):
main.Append(CPPFLAGS = [
# More warnings
'-Wconversion', '-Wsign-conversion', '-Wformat',
'-Wformat-security',
# Stack protection
'-fstack-protector-strong', '--param', 'ssp-buffer-size=4',
# Signed integer overflow checks
'-ftrapv'
],
# Enable Full RELRO
LINKFLAGS = ['-Wl,-z,relro,-z,now'])
# ------------- COLLECT SOURCES/TARGETS ------------- #
if GetOption('compile_commands'):
main.Tool('compile_commands')
main.CompileCommands('build')
if BUILD_TARGETS and 'build/compile_commands.json' not in BUILD_TARGETS:
BUILD_TARGETS.append('build/compile_commands.json')
main.SConscript('build/src/SConscript' , {'env' : main})
main.SConscript('build/test/SConscript', {'env' : main})
# ------------- ALIASES/COMMANDS------------- #
def Phony(env = main, deps = [], **kw):
if not env: env = DefaultEnvironment()
for target, action in kw.items():
env.AlwaysBuild(env.Alias(target, deps, action))
Phony(
cleanall = "rm -rf build",
doc = "rm -rf doc/api/html && $DOXYGEN Doxyfile",
format = "@echo 'Modifying files in-place...'\n"
"$CLANG_FORMAT -style=file -i "
"$$(git ls-files | grep -E '\.(hpp|hh|cpp|cc|cxx|h|c)$$')",
lint = "$CPPLINT --extensions=hpp,hh,cpp,cc,cxx "
"--filter=-build/c++11,-whitespace,-legal/copyright "
"$$(git ls-files | grep -E '\.(hpp|hh|cpp|cc|cxx)$$')",
tidy = "$CLANG_TIDY -header-filter='.*' "
"-checks='-*,clang-analyzer-*,google*,misc*,-misc-unused-parameters,performance*,modernize*' "
"-p build/compile_commands.json "
"$$(git ls-files | grep -E '\.(cpp|cc|cxx|c)$$')",
)
# vim: set ft=python :