-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSConstruct
171 lines (129 loc) · 4.79 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
# -*- coding: utf8 -*-
"""
part of phrasit
author: Steve Göring
contact: [email protected]
2015
This file is part of PhrasIt.
PhrasIt is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PhrasIt is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PhrasIt. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import sys
import glob
import multiprocessing
def terminal_width():
rows, columns = os.popen('stty size', 'r').read().split()
return int(columns)
def colorgreen(m):
return "\033[92m" + m + "\033[0m"
def lInfo(msg):
print(colorgreen("[INFO ] ") + str(msg))
def line():
print("-" * terminal_width())
def dline():
print("=" * terminal_width())
SetOption('num_jobs', multiprocessing.cpu_count()) # build with all aviable cpu cores/threads
line()
lInfo("build target(s): " + str(map(str, BUILD_TARGETS)))
lInfo("run with cpus : " + str(multiprocessing.cpu_count()))
line()
stylechecker = Builder(action='./test_convention.sh $SOURCES', suffix='', src_suffix='')
valgrind = Builder(action='valgrind ./$SOURCES', suffix='', src_suffix='')
lInfo("check local installed libs")
dline()
os.system("./prepare.sh")
line()
lInfo("add build infos")
dline()
os.system("./addbuildinfos.sh")
line()
env = Environment(CPPPATH = ["src/", "libs/"],
BUILDERS = {'StyleCheck' : stylechecker, 'Valgrind': valgrind})
# include local installed libs
libspath = 'libs/'
libs = ["boost"]
# TODO: unify this
env.Append(
LIBPATH=['.'] + [libspath + x + "/build/lib" for x in libs],
CPPPATH=[libspath + x + "/build/include" for x in libs]
)
# leveldb
env.Append(
CPPPATH = [libspath + "leveldb/include"],
LIBPATH = [libspath + 'leveldb/build/']
)
# cereal
env.Append(
CPPPATH = [libspath + "cereal/include"]
)
# cpp-httplib
env.Append(
CPPPATH = [libspath + "cpp-httplib/"]
)
# cxxopts
env.Append(
CPPPATH = [libspath + "cxxopts/include"]
)
env.Append(LINKFLAGS=['-pthread',
'-Wl,--rpath,' + libspath + 'leveldb/build/',
'-Wl,--rpath,' + libspath + 'boost/build/lib',
])
# for debugging
# print(env.Dump())
env.Decider('MD5')
conf = Configure(env)
needed_libs = [
'stdc++fs',
'leveldb',
'boost_system',
'boost_unit_test_framework',
'boost_iostreams']
for lib in needed_libs:
if not conf.CheckLib(lib, language="c++"):
print "Unable to find lib: " + lib + ". Exiting."
exit(-1)
def shell_call(cmd):
from subprocess import check_output
return check_output(cmd, shell=True)
includes = shell_call("""find src/ -name "*.?pp" | xargs cat | grep "#include <" | sed "s|>.*|>|g" | sort | uniq """).split("\n")
needed_headers = [x.replace("#include <", "").replace(">", "").strip() for x in includes if x != "" and "//" not in x[0:2]]
env.Append(CXXFLAGS=['-std=c++14'])
for header in sorted(needed_headers):
if not conf.CheckCXXHeader(header):
print "Unable to find header: " + header + ". Exiting."
sys.exit(-1)
# if you call scons debug=1 debug build is activated
if ARGUMENTS.get('debug', 0) != 0:
# more checks
env.Append(CXXFLAGS=['-Wall','-pedantic-errors', '-g'])
# "no" optimization
env.Append(CXXFLAGS=['-O0'])
else:
env.Append(CXXFLAGS=['-march=native']) # use native architecture
#env.Append(CXXFLAGS=['-mavx'])
env.Append(CXXFLAGS=['-Wall'])
env.Append(CXXFLAGS=['-O3'])
# loop unrolling and link time optimization, options should be tested
env.Append(CXXFLAGS=['-funroll-loops', '-flto', '-fwhole-program'])
testcases = set(glob.glob("src/tests/*.cpp"))
header = set(glob.glob("src/*.hpp") + glob.glob("src/*/*.hpp"))
sources = set(glob.glob("src/*.cpp") + glob.glob("src/*/*.cpp")) - set(["src/phrasit.cpp", "src/test.cpp", "src/tests/unittests.cpp"]) - testcases
# check code conventions and build programm
#env.StyleCheck("conventions", ["src/main.cpp"] + list(sources) + list(header) + list(testcases))
phrasit = env.Program('phrasit', ["src/phrasit.cpp"] + list(sources))
test = env.Program('test', ["src/test.cpp"] + list(sources))
unittest = env.Program('unittest', ["src/tests/unittests.cpp"] + list(sources))
Default(phrasit, test, unittest)
#env.ParseConfig('/usr/bin/python3-config --includes --libs')
#env.Append(LIBS=['boost_python3'])
#env.SharedLibrary('positronic.so', ["src/py/positronic.cpp"] + list(sources) + libs, SHLIBPREFIX='')
#env.Valgrind("valgrind" ,'positronic')