forked from logcabin/logcabin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConstruct
133 lines (117 loc) · 4.54 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
import sys
import os
opts = Variables('Local.sc')
opts.AddVariables(
("CC", "C Compiler"),
("CPPPATH", "The list of directories that the C preprocessor "
"will search for include directories", []),
("CXX", "C++ Compiler"),
("CXXFLAGS", "Options that are passed to the C++ compiler", []),
("AS", "Assembler"),
("LIBPATH", "Library paths that are passed to the linker", []),
("LINK", "Linker"),
("BUILDTYPE", "Build type (RELEASE or DEBUG)", "DEBUG"),
("VERBOSE", "Show full build information (0 or 1)", "0"),
("NUMCPUS", "Number of CPUs to use for build (0 means auto).", "0"),
)
env = Environment(options = opts,
tools = ['default', 'protoc'],
ENV = os.environ)
Help(opts.GenerateHelpText(env))
env.Prepend(CXXFLAGS = [
"-std=c++0x",
"-Wall",
"-Wextra",
"-Wcast-align",
"-Wcast-qual",
"-Wconversion",
"-Weffc++",
"-Wformat=2",
"-Wmissing-format-attribute",
"-Wno-non-template-friend",
"-Wno-unused-parameter",
"-Woverloaded-virtual",
"-Wwrite-strings",
"-DSWIG", # For some unknown reason, this suppresses some definitions in
# headers generated by protobuf 1.6 (but not 1.5) that we don't
# use and that cause warnings with -Weffc++.
])
if env["BUILDTYPE"] == "DEBUG":
env.Append(CPPFLAGS = [ "-g", "-DDEBUG" ])
elif env["BUILDTYPE"] == "RELEASE":
env.Append(CPPFLAGS = [ "-DNDEBUG", "-O2" ])
else:
print "Error BUILDTYPE must be RELEASE or DEBUG"
sys.exit(-1)
if env["VERBOSE"] == "0":
env["CCCOMSTR"] = "Compiling $SOURCE"
env["CXXCOMSTR"] = "Compiling $SOURCE"
env["SHCCCOMSTR"] = "Compiling $SOURCE"
env["SHCXXCOMSTR"] = "Compiling $SOURCE"
env["ARCOMSTR"] = "Creating library $TARGET"
env["LINKCOMSTR"] = "Linking $TARGET"
env.Append(CPPPATH = '#')
env.Append(CPPPATH = '#/include')
# Define protocol buffers builder to simplify SConstruct files
def Protobuf(env, source):
# First build the proto file
cc = env.Protoc(os.path.splitext(source)[0] + '.pb.cc',
source,
PROTOCPROTOPATH = ["."],
PROTOCPYTHONOUTDIR = None,
PROTOCOUTDIR = ".")[1]
# Then build the resulting C++ file with no warnings
return env.StaticObject(cc,
CXXFLAGS = "-std=c++0x -Ibuild")
env.AddMethod(Protobuf)
def GetNumCPUs():
if env["NUMCPUS"] != "0":
return int(env["NUMCPUS"])
if os.sysconf_names.has_key("SC_NPROCESSORS_ONLN"):
cpus = os.sysconf("SC_NPROCESSORS_ONLN")
if isinstance(cpus, int) and cpus > 0:
return 2*cpus
else:
return 2
return 2*int(os.popen2("sysctl -n hw.ncpu")[1].read())
env.SetOption('num_jobs', GetNumCPUs())
object_files = {}
Export('object_files')
Export('env')
SConscript('Core/SConscript', variant_dir='build/Core')
SConscript('Event/SConscript', variant_dir='build/Event')
SConscript('RPC/SConscript', variant_dir='build/RPC')
SConscript('Protocol/SConscript', variant_dir='build/Protocol')
SConscript('Tree/SConscript', variant_dir='build/Tree')
SConscript('Client/SConscript', variant_dir='build/Client')
SConscript('Storage/SConscript', variant_dir='build/Storage')
SConscript('Server/SConscript', variant_dir='build/Server')
SConscript('test/SConscript', variant_dir='build/test')
SConscript('Examples/SConscript', variant_dir='build/Examples')
# This function is taken from http://www.scons.org/wiki/PhonyTargets
def PhonyTargets(env = None, **kw):
if not env: env = DefaultEnvironment()
for target,action in kw.items():
env.AlwaysBuild(env.Alias(target, [], action))
PhonyTargets(check = "scripts/cpplint.py")
PhonyTargets(lint = "scripts/cpplint.py")
PhonyTargets(doc = "doxygen docs/Doxyfile")
PhonyTargets(docs = "doxygen docs/Doxyfile")
PhonyTargets(tags = "ctags -R --exclude=build --exclude=docs .")
env.StaticLibrary("build/logcabin",
(object_files['Client'] +
object_files['Tree'] +
object_files['Protocol'] +
object_files['RPC'] +
object_files['Event'] +
object_files['Core']))
env.Program("build/LogCabin",
(["build/Server/Main.cc"] +
object_files['Server'] +
object_files['Storage'] +
object_files['Tree'] +
object_files['Protocol'] +
object_files['RPC'] +
object_files['Event'] +
object_files['Core']),
LIBS = [ "pthread", "protobuf", "rt", "cryptopp" ])