forked from ludocode/mpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
171 lines (134 loc) · 6.47 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
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
import platform, os
def CheckFlags(context, cppflags, linkflags = [], message = None):
if message == None:
message = " ".join(cppflags + ((cppflags != linkflags) and linkflags or []))
context.Message("Checking for " + message + " support... ")
env.Prepend(CPPFLAGS = cppflags, LINKFLAGS = linkflags)
result = context.TryLink("int main(void){return 0;}\n", '.c')
env.Replace(CPPFLAGS = env["CPPFLAGS"][len(cppflags):], LINKFLAGS = env["LINKFLAGS"][len(linkflags):])
context.Result(result)
return result
# Common environment setup
env = Environment()
conf = Configure(env, custom_tests = {'CheckFlags': CheckFlags})
for x in os.environ.keys():
if x in ["CC", "CXX"]:
env[x] = os.environ[x]
if x in ["PATH", "TRAVIS", "TERM"] or x.startswith("CLANG_") or x.startswith("CCC_"):
env["ENV"][x] = os.environ[x]
env.Append(CPPFLAGS = [
"-Wall", "-Wextra", "-Werror",
"-Wconversion", "-Wno-sign-conversion", "-Wundef", "-Wshadow",
"-Isrc", "-Itest",
"-DMPACK_SCONS=1",
"-g",
])
env.Append(LINKFLAGS = [
"-g",
])
if conf.CheckFlags(["-Wmissing-variable-declarations"]):
env.Append(CPPFLAGS = ["-Wmissing-variable-declarations"])
if conf.CheckFlags(["-Wstrict-aliasing=1"]):
env.Append(CPPFLAGS = ["-Wstrict-aliasing=1"]) # use level 1 for maximum false positives
# Additional warning flags are passed in SConscript based on the language (C/C++)
if 'TRAVIS' not in env["ENV"]:
# Travis-CI currently uses Clang 3.4 which does not support this option,
# and it also appears to be incompatible with other GCC options on Travis-CI
env.Append(CPPFLAGS = ["-Wno-float-conversion"])
# Optional flags used in various builds
allfeatures = [
"-DMPACK_READER=1",
"-DMPACK_WRITER=1",
"-DMPACK_EXPECT=1",
"-DMPACK_NODE=1",
]
noioconfigs = [
"-DMPACK_STDLIB=1",
"-DMPACK_MALLOC=test_malloc",
"-DMPACK_FREE=test_free",
]
allconfigs = noioconfigs + ["-DMPACK_STDIO=1"]
hasOg = conf.CheckFlags(["-Og"])
if hasOg:
debugflags = ["-DDEBUG", "-Og"]
else:
debugflags = ["-DDEBUG", "-O0"]
releaseflags = ["-O2"]
cflags = ["-std=c99"]
gcovflags = []
if ARGUMENTS.get('gcov'):
gcovflags = ["-DMPACK_GCOV=1", "--coverage"]
ltoflags = ["-O3", "-flto", "-fuse-linker-plugin", "-fno-fat-lto-objects"]
if conf.CheckFlags(["-Wstrict-aliasing=3"]):
ltoflags.append("-Wstrict-aliasing=3")
elif conf.CheckFlags(["-Wstrict-aliasing=2"]):
ltoflags.append("-Wstrict-aliasing=2")
# -lstdc++ is added in SConscript
cxxflags = ["-x", "c++"]
# Functions to add a variant build. One variant build will build and run the
# entire library and test suite in a given configuration.
def AddBuild(variant_dir, cppflags, linkflags = []):
env.SConscript("SConscript",
variant_dir="build/" + variant_dir,
src="../..",
exports={
'env': env,
'CPPFLAGS': cppflags,
'LINKFLAGS': linkflags
},
duplicate=0)
def AddBuilds(variant_dir, cppflags, linkflags = []):
AddBuild("debug-" + variant_dir, debugflags + cppflags, debugflags + linkflags)
if ARGUMENTS.get('all'):
AddBuild("release-" + variant_dir, releaseflags + cppflags, releaseflags + linkflags)
# The default build, everything in debug. This is the build used
# for code coverage measurement and static analysis.
AddBuild("debug", allfeatures + allconfigs + debugflags + cflags + gcovflags, gcovflags)
# Run "scons more=1" to run a handful of builds that are likely
# to reveal configuration errors.
if ARGUMENTS.get('more') or ARGUMENTS.get('all'):
AddBuild("release", allfeatures + allconfigs + releaseflags + cflags)
AddBuilds("embed", allfeatures + cflags + ["-DMPACK_NO_BUILTINS=1"])
AddBuilds("noio", allfeatures + noioconfigs + cflags)
AddBuild("debug-size", ["-DMPACK_OPTIMIZE_FOR_SIZE=1"] + debugflags + allfeatures + allconfigs + cflags)
# Run "scons all=1" to run all builds. This is what the CI runs.
if ARGUMENTS.get('all'):
# various release builds
AddBuild("release-unopt", allfeatures + allconfigs + cflags + ["-O0"])
AddBuild("release-fastmath", allfeatures + allconfigs + releaseflags + cflags + ["-ffast-math"])
if conf.CheckFlags(ltoflags, ltoflags, "-flto"):
AddBuild("release-lto", allfeatures + allconfigs + ltoflags + cflags, ltoflags)
AddBuild("release-size", ["-Os"] + allfeatures + allconfigs + cflags)
# feature subsets with default configuration
AddBuilds("empty", allconfigs + cflags)
AddBuilds("writer", ["-DMPACK_WRITER=1"] + allconfigs + cflags)
AddBuilds("reader", ["-DMPACK_READER=1"] + allconfigs + cflags)
AddBuilds("expect", ["-DMPACK_READER=1", "-DMPACK_EXPECT=1"] + allconfigs + cflags)
AddBuilds("node", ["-DMPACK_NODE=1"] + allconfigs + cflags)
# no i/o
AddBuilds("noio-writer", ["-DMPACK_WRITER=1"] + noioconfigs + cflags)
AddBuilds("noio-reader", ["-DMPACK_READER=1"] + noioconfigs + cflags)
AddBuilds("noio-expect", ["-DMPACK_READER=1", "-DMPACK_EXPECT=1"] + noioconfigs + cflags)
AddBuilds("noio-node", ["-DMPACK_NODE=1"] + noioconfigs + cflags)
# embedded builds without libc (using builtins)
AddBuilds("embed-writer", ["-DMPACK_WRITER=1"] + cflags)
AddBuilds("embed-reader", ["-DMPACK_READER=1"] + cflags)
AddBuilds("embed-expect", ["-DMPACK_READER=1", "-DMPACK_EXPECT=1"] + cflags)
AddBuilds("embed-node", ["-DMPACK_NODE=1"] + cflags)
# miscellaneous test builds
AddBuilds("notrack", ["-DMPACK_NO_TRACKING=1"] + allfeatures + allconfigs + cflags)
AddBuilds("realloc", allfeatures + allconfigs + debugflags + cflags + ["-DMPACK_REALLOC=test_realloc"])
if hasOg:
AddBuild("debug-O0", allfeatures + allconfigs + ["-DDEBUG", "-O0"] + cflags)
# other language standards (C11, various C++ versions)
if conf.CheckFlags(["-std=c11"]):
AddBuilds("c11", allfeatures + allconfigs + ["-std=c11"])
AddBuilds("cxx", allfeatures + allconfigs + cxxflags + ["-std=c++98"])
if conf.CheckFlags(cxxflags + ["-std=c++11"], [], "-std=c++11"):
AddBuilds("cxx11", allfeatures + allconfigs + cxxflags + ["-std=c++11"])
if conf.CheckFlags(cxxflags + ["-std=c++14"], [], "-std=c++14"):
AddBuilds("cxx14", allfeatures + allconfigs + cxxflags + ["-std=c++14"])
# 32-bit build
if conf.CheckFlags(["-m32"], ["-m32"]):
AddBuilds("32", allfeatures + allconfigs + cflags + ["-m32"], ["-m32"])
AddBuilds("cxx32", allfeatures + allconfigs + cxxflags + ["-std=c++98", "-m32"], ["-m32"])