-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSConstruct
140 lines (110 loc) · 3.99 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
# -*- 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 = {},
CPPFLAGS = ['-Wall', '-Werror'],
CPPPATH = ['#/include'],
CFLAGS = ['-std=c11'],
CXXFLAGS = ['-std=c++14'],
LIBPATH = [],
LIBS = [],
LINKFLAGS = [],
)
# ------------- 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 apidoc/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 :