-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
274 lines (222 loc) · 6.71 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# carefree-objects
#
# a thread-safe object manager extension for c++
#
# Copyright (C) 2011-2015 Stefan Zimmermann <[email protected]>
#
# carefree-objects is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# carefree-objects 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with carefree-objects. If not, see <http://www.gnu.org/licenses/>.
import imp
import os
import re
import sys
from subprocess import Popen, PIPE
import jinja2
from jinjatools.scons import JinjaBuilder
from path import Path
sys.path.insert(0, Path('.').realpath().dirname())
import cfo.jinja
import cfo.jinja.macros
from cfo.scons import Environment
env = Environment('carefree-objects')
env.Prepend(
CPPPATH = [
'include',
],
)
env.Append(
JINJACONTEXT = cfo.jinja.CONTEXT,
CPPDEFINES = [
env['DEBUG'] and 'DEBUG' or 'NDEBUG',
],
)
conf = Configure(env)
BOOST_LIBS = []
for lib in [
'boost_system',
'boost_thread',
]:
lib_mt = lib + '-mt'
if conf.CheckLib(lib_mt):
BOOST_LIBS.append(lib_mt)
break
if not conf.CheckLib(lib):
raise RuntimeError("Can't find %s or %s library."
% (repr(lib_mt), repr(lib)))
BOOST_LIBS.append(lib)
del lib
env = conf.Finish()
del conf
SOURCE_PATH = Path('src')
INCLUDE_SOURCE_PATH = SOURCE_PATH / 'include'
INCLUDE_PATH = Path('include')
BUILD_PATH = Path('build')
LIB_PATH = Path('lib')
SOURCE_DEPENDS = [SOURCE_PATH / 'context.py']
from src import context
context = {name: getattr(context, name) for name in context.__all__}
env.Append(JINJACONTEXT=context)
INCLUDES = []
for path in INCLUDE_SOURCE_PATH.walkfiles():
if path.ext in ['.hpp', '.inl']:
subpath, ext = path.splitext()
subpath /= ext.strip('.')
incenv = env.Clone()
try:
modinfo = imp.find_module('context', [subpath])
except ImportError:
depends = []
else:
depends = [subpath / 'context.py']
context = imp.load_module('context', *modinfo)
context = {name: getattr(context, name)
for name in context.__all__}
incenv.Append(
JINJACONTEXT=context,
)
loader = jinja2.ChoiceLoader([
incenv['JINJALOADER'],
jinja2.FileSystemLoader(subpath),
])
target = INCLUDE_PATH / INCLUDE_SOURCE_PATH.relpathto(path)
INCLUDES.append(
incenv.Depends(
incenv.Jinja(
target, source=path,
JINJALOADER=loader,
),
SOURCE_DEPENDS + depends))
OBJECTS = []
for path in SOURCE_PATH.walkfiles():
if not 'python' in path and path.ext == '.cpp':
OBJECTS.append(env.Requires(
env.SharedObject(
env.Jinja(
BUILD_PATH / SOURCE_PATH.relpathto(path),
source=path,
)),
INCLUDES))
if env['SHARED']:
LIB_CAREFREE_TYPES = env.SharedLibrary(
LIB_PATH / 'carefree-types',
source=OBJECTS,
LIBS=BOOST_LIBS,
)
if env['STATIC']:
env.StaticLibrary(
LIB_PATH / 'carefree-types',
source=OBJECTS,
)
if env['TESTS']:
TEST_OBJECTS = []
for path in (SOURCE_PATH / 'test').walkfiles():
if path.ext == '.cpp':
TEST_OBJECTS.append(env.Requires(
env.SharedObject(
env.Jinja(
BUILD_PATH / SOURCE_PATH.relpathto(path),
source=path,
)),
INCLUDES))
if env['SHARED']:
LIB_CAREFREE_TYPES_TEST = env.SharedLibrary(
LIB_PATH / 'carefree-types-test',
source=TEST_OBJECTS,
)
if env['STATIC']:
env.StaticLibrary(
LIB_PATH / 'carefree-types-test',
source=TEST_OBJECTS,
)
env.Requires(
env.Program(
'test', source='test.cpp',
LIBPATH=[LIB_PATH],
LIBS=BOOST_LIBS + [
LIB_CAREFREE_TYPES,
LIB_CAREFREE_TYPES_TEST,
],
),
[LIB_CAREFREE_TYPES,
LIB_CAREFREE_TYPES_TEST,
])
CAREFREE_PYTHON_SOURCE_NAMES = [
'import',
'functions',
'convert',
'object/iterator',
'object/check',
]
CAREFREE_PYTHON_SOURCES = [
env.Jinja(
'build/python/%s.cpp' % name,
source = ['src/python/%s.cpp' % name]
)
for name in CAREFREE_PYTHON_SOURCE_NAMES]
PYTHON = env['PYTHON']
if PYTHON is True:
PYTHON = 'python'
for pybin in PYTHON and PYTHON.split(',') or []:
out = (Popen([pybin, '--version'],
stdout=PIPE, stderr=PIPE, universal_newlines=True)
.communicate())
out = out[0] or out[1]
pyversion = out.split()[1].split('.', 2)
pyversionsuffix = ''.join(pyversion[:2])
pybuildpath = 'build/python' + pyversionsuffix
Mkdir(pybuildpath)
pyenv = env.Clone()
pyenv.MergeFlags(
Popen([pybin + '-config', '--includes', '--libs'],
stdout = PIPE, universal_newlines=True)
.communicate()[0])
pyconf = Configure(pyenv)
BOOST_PYTHON_LIB = 'boost_python'
suffixes = [
'-py%s' % pyversionsuffix,
str(pyversion[0]) + '-mt',
str(pyversion[0]),
'']
for suffix in suffixes:
if pyconf.CheckLib(BOOST_PYTHON_LIB + suffix):
BOOST_PYTHON_LIB += suffix
break
else:
raise RuntimeError("Can't find %s library."
% ' or '.join(map(repr, suffixes)))
pyenv = pyconf.Finish()
pyenv.Append(
LIBS=BOOST_LIBS + [
BOOST_PYTHON_LIB,
],
)
OBJECTS = [
env.Requires(
pyenv.SharedObject(
'%s/%s' % (pybuildpath, name),
source=['build/python/%s.cpp' % name],
),
[CAREFREE_PYTHON_SOURCES,
INCLUDES,
])
for name in CAREFREE_PYTHON_SOURCE_NAMES]
if env['SHARED']:
pyenv.SharedLibrary(
'lib/carefree-python-py' + pyversionsuffix,
source=OBJECTS,
)
if env['STATIC']:
pyenv.StaticLibrary(
'lib/carefree-python-py' + pyversionsuffix,
source=OBJECTS,
)