-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConstruct
236 lines (199 loc) · 8.34 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
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
import sys
import os
import multiprocessing
import SCons.Util
## Helper Functions
def CheckPkgConfig(context):
context.Message('Checking for pkg-config... ')
ret = context.TryAction('pkg-config --version')[0]
context.Result(ret)
return ret
def CheckPkg(context, name):
context.Message('Checking for %s... ' % name)
ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0]
context.Result(ret)
return ret
def CheckPkgMinVersion(context, name, version):
context.Message('Checking %s-%s or greater... ' % (name, version))
ret = context.TryAction('pkg-config --atleast-version \'%s\' \'%s\'' % (version, name))[0]
context.Result(ret)
return ret
## Configuration
opts = Variables('Local.sc')
opts.AddVariables(
("CC", "C Compiler", "cc"),
("CXX", "C++ Compiler", "c++"),
("AS", "Assembler"),
("LINK", "Linker"),
("CLANGTIDY", "Clang checker", "clang-tidy80"),
("CTAGS", "Ctags", "exctags"),
("DOXYGEN", "Doxygen doc builder", "doxygen"),
("NUMCPUS", "Number of CPUs to use for build (0 means auto)", 0, None, int),
EnumVariable("BUILDTYPE", "Build type", "RELEASE", ["RELEASE", "DEBUG", "PERF"]),
BoolVariable("VERBOSE", "Show full build information", 0),
BoolVariable("WITH_GPROF", "Include gprof profiling", 0),
BoolVariable("WITH_GOOGLEHEAP", "Link to Google Heap Cheker", 0),
BoolVariable("WITH_GOOGLEPROF", "Link to Google CPU Profiler", 0),
BoolVariable("WITH_TSAN", "Enable Clang ThreadSanitizer", 0),
BoolVariable("WITH_ASAN", "Enable Clang AddressSanitizer", 0),
BoolVariable("WITH_USAN", "Enable Clang UndefinedBehaviorSanitizer", 0),
BoolVariable("BUILD_BINARIES", "Build binaries", 1),
BoolVariable("CROSSCOMPILE", "Cross compile", 0),
PathVariable("PREFIX", "Installation target directory", "/usr/local/bin/", PathVariable.PathAccept),
PathVariable("DESTDIR", "The root directory to install into. Useful mainly for binary package building", "", PathVariable.PathAccept),
)
env = Environment(options = opts,
tools = ['default'], #, 'compilation_db', 'clangtidy'],
ENV = os.environ)
Help("""TARGETS:
scons Build celestis
scons testbench Run test suite
scons compiledb Generate compile database
scons docs Generate documentation
scons check Clang static analyzers
scons tags Ctags\n""")
Help(opts.GenerateHelpText(env))
# Copy environment variables
if 'CC' in os.environ:
env["CC"] = os.getenv('CC')
if 'CXX' in os.environ:
env["CXX"] = os.getenv('CXX')
if 'AS' in os.environ:
env["AS"] = os.getenv('AS')
if 'LD' in os.environ:
env["LINK"] = os.getenv('LD')
if 'CFLAGS' in os.environ:
env.Append(CCFLAGS = SCons.Util.CLVar(os.environ['CFLAGS']))
if 'CPPFLAGS' in os.environ:
env.Append(CPPFLAGS = SCons.Util.CLVar(os.environ['CPPFLAGS']))
if 'CXXFLAGS' in os.environ:
env.Append(CXXFLAGS = SCons.Util.CLVar(os.environ['CXXFLAGS']))
if 'LDFLAGS' in os.environ:
env.Append(LINKFLAGS = SCons.Util.CLVar(os.environ['LDFLAGS']))
env["ENV"].update(x for x in os.environ.items() if x[0].startswith("CCC_"))
env.Append(CPPFLAGS = [ "-Wall", "-Wformat=2", "-Wwrite-strings",
"-Wno-unused-parameter", "-Wmissing-format-attribute",
"-Wno-format-nonliteral",
"-Werror" ])
#env.Append(CFLAGS = [ "-Wmissing-prototypes", "-Wmissing-declarations",
# "-Wshadow", "-Wbad-function-cast", "-Werror" ])
#env.Append(CXXFLAGS = [ "-Wno-non-template-friend", "-Woverloaded-virtual",
# "-Wcast-qual", "-Wcast-align", "-Wconversion",
# "-Weffc++", "-std=c++0x", "-Werror" ])
if env["WITH_GPROF"]:
env.Append(CPPFLAGS = [ "-pg" ])
env.Append(LINKFLAGS = [ "-pg" ])
env.Append(CFLAGS = ["-std=c11"])
env.Append(CXXFLAGS = ["-std=c++17"])
env.Append(CPPFLAGS = ["-Wno-potentially-evaluated-expression" ])
# "-Wsign-compare", "-Wsign-conversion", "-Wcast-align"
if env["BUILDTYPE"] == "DEBUG":
env.Append(CPPFLAGS = [ "-g", "-DCELESTIS_DEBUG", "-O0" ])
env.Append(LINKFLAGS = [ "-g", "-rdynamic" ])
elif env["BUILDTYPE"] == "PERF":
env.Append(CPPFLAGS = [ "-g", "-DNDEBUG", "-DCELESTIS_PERF", "-O2"])
env.Append(LDFLAGS = [ "-g", "-rdynamic" ])
elif env["BUILDTYPE"] == "RELEASE":
env.Append(CPPFLAGS = ["-DNDEBUG", "-DCELESTIS_RELEASE", "-O2"])
else:
print("Error BUILDTYPE must be RELEASE or DEBUG")
sys.exit(-1)
if not env["VERBOSE"]:
env["CCCOMSTR"] = "Compiling $SOURCE"
env["CXXCOMSTR"] = "Compiling $SOURCE"
env["SHCCCOMSTR"] = "Compiling $SOURCE"
env["SHCXXCOMSTR"] = "Compiling $SOURCE"
env["ARCOMSTR"] = "Creating library $TARGET"
env["RANLIBCOMSTR"] = "Indexing library $TARGET"
env["LINKCOMSTR"] = "Linking $TARGET"
env["SHLINKCOMSTR"] = "Linking $TARGET"
env["ASCOMSTR"] = "Assembling $TARGET"
env["ASPPCOMSTR"] = "Assembling $TARGET"
env["ARCOMSTR"] = "Creating library $TARGET"
env["RANLIBCOMSTR"] = "Indexing library $TARGET"
def GetNumCPUs(env):
if env["NUMCPUS"] > 0:
return int(env["NUMCPUS"])
return 2*multiprocessing.cpu_count()
env.SetOption('num_jobs', GetNumCPUs(env))
# Modify CPPPATH and LIBPATH
env.Append(CPPPATH = [ "/usr/local/include" ])
env.Append(LIBPATH = [ "$LIBPATH", "/usr/local/lib" ])
# FreeBSD requires libexecinfo
# Linux and darwin have the header
if sys.platform.startswith("freebsd"):
env.Append(LIBS = ['execinfo'])
env.Append(CPPFLAGS = "-DHAVE_EXECINFO")
elif sys.platform == "linux2" or sys.platform == "darwin":
env.Append(CPPFLAGS = "-DHAVE_EXECINFO")
env.Append(CPPFLAGS = "-D_XOPEN_SOURCE=700L")
# XXX: Hack to support clang static analyzer
def CheckFailed():
if os.getenv('CCC_ANALYZER_OUTPUT_FORMAT') != None:
return
Exit(1)
# Configuration
conf = env.Configure(custom_tests = { 'CheckPkgConfig' : CheckPkgConfig,
'CheckPkg' : CheckPkg,
'CheckPkgMinVersion' : CheckPkgMinVersion })
if not conf.CheckCC():
print('Your C compiler and/or environment is incorrectly configured.')
CheckFailed()
env.AppendUnique(CXXFLAGS = ['-std=c++17'])
if not conf.CheckCXX():
print('Your C++ compiler and/or environment is incorrectly configured.')
CheckFailed()
if (sys.platform == "win32") or env["CROSSCOMPILE"]:
env["HAS_PKGCONFIG"] = False
else:
env["HAS_PKGCONFIG"] = True
if not conf.CheckPkgConfig():
print('pkg-config not found!')
Exit(1)
if sys.platform.startswith("freebsd"):
if not conf.CheckLib('execinfo'):
print('FreeBSD requires libexecinfo to build.')
Exit(1)
conf.Finish()
Export('env')
# Set compile options for binaries
env.Append(CPPPATH = ['#include', '#.'])
env.Append(LIBPATH = ['#build/liblog', '#build/libcorelog'])
if sys.platform != "win32" and sys.platform != "darwin":
env.Append(CPPFLAGS = ['-pthread'])
env.Append(LIBS = ["pthread"])
# Debugging Tools
if env["WITH_GOOGLEHEAP"]:
env.Append(LIBS = ["tcmalloc"])
if env["WITH_GOOGLEPROF"]:
env.Append(LIBS = ["profiler"])
if env["WITH_TSAN"]:
env.Append(CPPFLAGS = ["-fsanitize=thread", "-fPIE"])
env.Append(LINKFLAGS = ["-fsanitize=thread", "-pie"])
if env["WITH_ASAN"]:
env.Append(CPPFLAGS = ["-fsanitize=address"])
env.Append(LINKFLAGS = ["-fsanitize=address"])
if env["WITH_USAN"]:
env.Append(CPPFLAGS = ["-fsanitize=undefined"])
env.Append(LINKFLAGS = ["-fsanitize=undefined"])
if env["WITH_TSAN"] and env["WITH_ASAN"]:
print("Cannot set both WITH_TSAN and WITH_ASAN!")
sys.exit(-1)
# Libraries
SConscript('libcorelog/SConscript', variant_dir='build/libcorelog')
SConscript('liblog/SConscript', variant_dir='build/liblog')
# Tools
SConscript('corelog/SConscript', variant_dir='build/corelog')
# Tests
SConscript('tests/SConscript', variant_dir='build/tests')
# Clang Check
#compileDb = env.Alias("compiledb",
# env.CompilationDatabase('compile_commands.json'))
#if ("check" in BUILD_TARGETS):
# Alias('check', AlwaysBuild(env.ClangCheckAll(["compile_commands.json"])))
if ("tags" in BUILD_TARGETS):
env.Command("tags", ["lib", "include", "tools"],
'$CTAGS -R -f $TARGET $SOURCES')
#if ("docs" in BUILD_TARGETS):
# env.Command("docs", ["lib", "include", "doxygen.config", "README.md"],
# "$DOXYGEN doxygen.config")