-
Notifications
You must be signed in to change notification settings - Fork 2
/
SConstruct
665 lines (510 loc) · 22.4 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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
# -*- python -*-
# ------------------- configuration section -------------------
build_dir = Dir('build')
# ------------------- implementation section -------------------
import distutils.spawn
import io
import imp
import os
import random
import re
import subprocess
import sys
import urllib.request
import zipfile
import SCons
SCons.Warnings.suppressWarningClass(SCons.Warnings.DuplicateEnvironmentWarning)
def default_environment():
"""
The environment that is used to build everything.
"""
env = Environment(ENV = os.environ)
env['CC'] = os.environ.get('CC', env['CC'])
env['CXX'] = os.environ.get('CXX', env['CXX'])
env['ENV'].update(val for val in os.environ.items() if val[0].startswith('CCC_'))
env['bin_dir'] = Dir('bin')
env['lib_dir'] = Dir('lib')
env['pylib_dir'] = env['lib_dir']
env['top_level'] = Dir('.')
env.Append(source_file_globs = ['*.cc', '*.cpp', '*.cxx', '*.c++', '*.C++',
'*.c', '*.C', '*.cu'])
# Because scons behaves poorly if these aren't initialized as lists
env['CPPPATH'] = []
env['LIBPATH'] = []
env['RPATH'] = []
env['LIBS'] = []
if 'VERBOSE' not in ARGUMENTS:
brief_output(env)
if 'NOCOLOR' not in ARGUMENTS:
ansi_colors(env)
# OSX errors if there are undefined symbols in a shared library.
# This is not desirable, because the symbols could be present in a
# different library, or in the main executable.
if sys.platform=='darwin' and 'clang' in env['CC']:
env.Append(SHLINKFLAGS=['-undefined','dynamic_lookup'])
env.Append(CCFLAGS=['-pthread','-Wall','-Wextra','-pedantic'])
env.Append(CXXFLAGS=['-std=c++14'])
env.Append(LINKFLAGS=['-pthread'])
if 'CODE_COVERAGE' in ARGUMENTS:
env.Append(CPPFLAGS=['--coverage'])
env.Append(LINKFLAGS=['--coverage'])
elif 'OPTIMIZE' in ARGUMENTS:
env.Append(CCFLAGS=['-O'+ARGUMENTS['OPTIMIZE']])
else:
env.Append(CCFLAGS=['-O3'])
if 'RELEASE' in ARGUMENTS and ARGUMENTS['RELEASE'] != '0':
env.Append(CPPDEFINES=['NDEBUG'])
env.Append(CPPFLAGS=['-s'])
else:
env.Append(CPPFLAGS=['-g'])
if 'PYTHON_VERSION' in ARGUMENTS:
env['PYTHON_VERSION'] = ARGUMENTS['PYTHON_VERSION']
enable_system_header_support(env)
env.AddMethod(shared_library_dir, 'SharedLibraryDir')
env.AddMethod(python_library_dir, 'PythonLibraryDir')
env.AddMethod(main_dir, 'MainDir')
env.AddMethod(unit_test_dir, 'UnitTestDir')
env.AddMethod(compile_folder_dwim, 'CompileFolderDWIM')
env.AddMethod(irrlicht_lib, 'IrrlichtLib')
env.AddMethod(is_special_dir, '_is_special_dir')
env.AddMethod(glob_src_dir, 'GlobSrcDir')
env.AddMethod(non_variant_dir, 'NonVariantDir')
env.AddMethod(find_libraries, 'FindLibraries')
return env
def enable_system_header_support(env):
'''Add support for system headers
System headers are useful, because no warnings are issued within
them. Implementation taken from
http://scons-users.scons.narkive.com/Dzj1kRym/support-of-the-isystem-option-for-gcc
'''
# declare and use a new PATH variable for system headers : CPPSYSTEMPATH
env['CPPSYSTEMPATH'] = []
env['SYSTEMINCPREFIX'] = '-isystem '
env['SYSTEMINCSUFFIX'] = ''
env['_CPPSYSTEMINCFLAGS'] = '$( ${_concat(SYSTEMINCPREFIX,CPPSYSTEMPATH, SYSTEMINCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
env['_CCCOMCOM'] += ' $_CPPSYSTEMINCFLAGS'
# add this variable to the C scanner search path
env['_CPPPATHS'] = ['$CPPPATH', '$CPPSYSTEMPATH']
setattr(SCons.Tool.CScanner, 'path_function',
SCons.Scanner.FindPathDirs('_CPPPATHS'))
def ansi_colors(env):
env['RESET_COLOR'] = '\033[39;49m'
env['BLUE'] = '\033[1;34m'
env['YELLOW'] = '\033[1;33m'
env['GREEN'] = '\033[1;32m'
env['RED'] = '\033[1;31m'
env['BLACK'] = '\033[1;30m'
env['MAGENTA'] = '\033[1;35m'
env['CYAN'] = '\033[1;36m'
env['WHITE'] = '\033[1;37m'
env['DBLUE'] = '\033[0;34m'
env['DYELLOW'] = '\033[0;33m'
env['DGREEN'] = '\033[0;32m'
env['DRED'] = '\033[0;31m'
env['DBLACK'] = '\033[0;30m'
env['DMAGENTA'] = '\033[0;35m'
env['DCYAN'] = '\033[0;36m'
env['DWHITE'] = '\033[0;37m'
env['BG_WHITE'] = '\033[47m'
env['BG_RED'] = '\033[41m'
env['BG_GREEN'] = '\033[42m'
env['BG_YELLOW'] = '\033[43m'
env['BG_BLUE'] = '\033[44m'
env['BG_MAGENTA'] = '\033[45m'
env['BG_CYAN'] = '\033[46m'
def brief_output(env):
"""
Edits the various command strings printed to screen to be briefer.
"""
env['CCCOMSTR'] = '${DBLUE}Compiling C object ${DCYAN}${TARGETS}${RESET_COLOR}'
env['CXXCOMSTR'] = '${DBLUE}Compiling C++ object ${DCYAN}${TARGETS}${RESET_COLOR}'
env['NVCCCOMSTR'] = '${DBLUE}Compiling C++ CUDA object ${DCYAN}${TARGETS}${RESET_COLOR}'
env['ARCOMSTR'] = '${DBLUE}Packing static library ${DCYAN}${TARGETS}${RESET_COLOR}'
env['RANLIBCOMSTR'] = '${DBLUE}Indexing static library ${DCYAN}${TARGETS}${RESET_COLOR}'
env['SHCCCOMSTR'] = '${DBLUE}Compiling shared C object ${DCYAN}${TARGETS}${RESET_COLOR}'
env['SHCXXCOMSTR'] = '${DBLUE}Compiling shared C++ object ${DCYAN}${TARGETS}${RESET_COLOR}'
env['SHNVCCCOMSTR'] = '${DBLUE}Compiling shared C++ CUDA object ${DCYAN}${TARGETS}${RESET_COLOR}'
env['LINKCOMSTR'] = '${DBLUE}Linking ${DCYAN}${TARGETS}${RESET_COLOR}'
env['SHLINKCOMSTR'] = '${DBLUE}Linking shared ${DCYAN}${TARGETS}${RESET_COLOR}'
all_libs = {}
def shared_library_dir(env, target=None, source=None, is_python_lib=False,
dependencies=None, requires=None, optional=None):
if source is None:
source = target
target = None
if optional is None:
optional = []
env = env.Clone()
source = Dir(source)
if target is None:
lib_name = source.name
if is_python_lib and lib_name.startswith('py'):
lib_name = lib_name[2:]
target = os.path.join(str(source), lib_name)
else:
lib_name = os.path.splitext(os.path.split(str(target))[1])[0]
if is_python_lib:
optional.append(lib_name)
libs_before = len(env['LIBS'])
transitive = add_dependencies(env, dependencies, requires, optional)
depends_on_libs = (len(env['LIBS']) != libs_before)
if depends_on_libs:
from_dir = env['pylib_dir'] if is_python_lib else env['lib_dir']
rel_path = from_dir.rel_path(env['lib_dir'])
env.Append(RPATH=[Literal(os.path.join('\\$$ORIGIN',rel_path))])
if is_python_lib:
env.Append(CPPPATH=get_pybind11_dir().Dir('include'))
env.Append(CPPPATH=find_python_include(env.get('PYTHON_VERSION',None)))
env['SHLIBPREFIX'] = ''
if source.glob('include'):
inc_dir = source.glob('include')[0]
else:
inc_dir = source
inc_dir = inc_dir.RDirs('.')
env.Append(CPPPATH=inc_dir)
if source.glob('src'):
src_dir = source.glob('src')[0]
else:
src_dir = source
src_files = env.GlobSrcDir(src_dir)
shlib = env.SharedLibrary(target, src_files)[0]
prefix = env.subst(env['SHLIBPREFIX'])
suffix = env.subst(env['SHLIBSUFFIX'])
shlib_name = shlib.name[len(prefix):-len(suffix)]
shlib.attributes.usage = {
'CPPPATH':inc_dir + transitive['CPPPATH'],
'CPPSYSTEMPATH': transitive['CPPSYSTEMPATH'],
'CPPDEFINES': transitive['CPPDEFINES'],
'LIBPATH':[shlib.dir],
'LIBS':[shlib_name],
}
if is_python_lib:
env.Install(env['pylib_dir'], shlib)
else:
env.Install(env['lib_dir'], shlib)
all_libs[shlib_name.lower()] = shlib.attributes.usage
return shlib
def find_libraries(env, lib_names, required=True):
lib_names = [name.lower() for name in lib_names]
output = []
for lib_name in lib_names:
try:
lib = all_libs[lib_name]
except KeyError:
lib = download_compile_dependency(env, lib_name, required)
if lib is None:
lib = {}
elif not isinstance(lib, dict):
lib = lib.attributes.usage
all_libs[lib_name] = lib
if lib is not None:
output.append(lib)
return output
def download_compile_dependency(env, lib_name, required):
disabled = ARGUMENTS.get('disable-{}'.format(lib_name), 0)
if disabled:
if required:
raise RuntimeError('"{}" is a required library, and cannot be disabled'.format(lib_name))
else:
return None
try:
tool = download_tool(lib_name)
except urllib.error.HTTPError as e:
if required:
e.msg = (e.msg +
'\nCould not download required library "{}"'.format(lib_name))
raise
else:
return None
if not tool.exists(env):
if required:
raise RuntimeError('Cannot install "{}" library, missing requirements'.format(lib_name))
else:
return None
return tool.generate(env)
def python_library_dir(env, target=None, source=None,
dependencies=None, requires=None, optional=None):
return env.SharedLibraryDir(target, source, is_python_lib=True,
dependencies=dependencies,
requires=requires,
optional=optional)
def find_python_include(python_version = None):
"""
Find the include directory for Python.h
If python_version is specied, look for that one.
Otherwise, search for python3, then python, then python2.
"""
if python_version is None:
python_versions = ['python3','python','python2']
else:
python_versions = [python_version]
for version in python_versions:
exe = distutils.spawn.find_executable(version)
if exe:
break
else:
raise RuntimeError("Could not find python executable")
output = subprocess.check_output([exe, '-c',
'from distutils.sysconfig import get_python_inc;'
'print (get_python_inc())'])
return output.decode('utf-8').strip()
def get_pybind11_dir():
"""
Returns the directory to pybind11.
If it already exists, just return.
Otherwise, download it from github and unzip.
"""
folder = dep_dir.Dir('pybind11-master')
if folder.exists():
return folder
response = urllib.request.urlopen('https://github.com/pybind/pybind11/archive/master.zip')
contents = io.BytesIO(response.read())
zipped = zipfile.ZipFile(contents)
members = [filename for filename in zipped.namelist()
if 'include' in filename or 'LICENSE' in filename]
zipped.extractall(dep_dir.abspath,members)
return folder
def unit_test_dir(env, target=None, source=None,
extra_inc_dir=None, extra_src_dir=None,
dependencies=None, requires=None, optional=None):
env = env.Clone()
add_dependencies(env, dependencies, requires, optional)
if source is None:
source = target
target = None
source = Dir(source)
if target is None:
target = os.path.join(str(source), 'run_tests')
for dep in all_libs.values():
env.Append(**dep)
if all_libs:
env.Append(RPATH=[Literal(os.path.join('\\$$ORIGIN',
env['bin_dir'].rel_path(env['lib_dir'])))])
googletest_dir = get_googletest_dir()
env.Append(CPPPATH=googletest_dir.Dir('googletest').RDirs('.'))
env.Append(CPPPATH=googletest_dir.Dir('googletest/include').RDirs('.'))
src_files = env.GlobSrcDir(source)
src_files.extend(googletest_dir.glob('main.cc'))
src_files.extend(googletest_dir.glob('googletest/src/gtest-all.cc'))
if extra_inc_dir is not None:
env.Append(CPPPATH=Dir(extra_inc_dir).RDirs('.'))
if extra_src_dir is not None:
extra_src_dir = Dir(extra_src_dir)
src_files.extend(env.GlobSrcDir(extra_src_dir))
src_files = [env.Object(src.abspath) for src in Flatten(src_files)]
prog = env.Program(target, src_files)
env.Install(env['bin_dir'], prog)
def get_googletest_dir():
folder = dep_dir.Dir('googletest-master')
if folder.exists():
return folder
response = urllib.request.urlopen('https://github.com/google/googletest/archive/master.zip')
contents = io.BytesIO(response.read())
zipped = zipfile.ZipFile(contents)
members = [filename for filename in zipped.namelist() if
'googletest/include' in filename or
'googletest/src' in filename or
'googletest/LICENSE' in filename]
zipped.extractall(dep_dir.abspath,members)
with open(os.path.join(folder.abspath, 'main.cc'),'w') as f:
f.write("""
#include <gtest/gtest.h>
int main(int argc, char** argv){
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}""")
return folder
def irrlicht_lib(env):
env = env.Clone()
irrlicht_dir = get_irrlicht_dir()
inc_dir = irrlicht_dir.Dir('include')
internal_inc_dir = [irrlicht_dir.Dir(dname) for dname in
['source/Irrlicht/zlib', 'source/Irrlicht/jpeglib',
'source/Irrlicht/libpng']]
src_dir = irrlicht_dir.Dir('source/Irrlicht')
src_files = env.GlobSrcDir(src_dir)
lzma_files = ['lzma/LzmaDec.c']
zlib_files = ['zlib/adler32.c', 'zlib/compress.c', 'zlib/crc32.c', 'zlib/deflate.c',
'zlib/inffast.c', 'zlib/inflate.c', 'zlib/inftrees.c', 'zlib/trees.c',
'zlib/uncompr.c', 'zlib/zutil.c']
jpeglib_files = ['jpeglib/jcapimin.c', 'jpeglib/jcapistd.c', 'jpeglib/jccoefct.c', 'jpeglib/jccolor.c',
'jpeglib/jcdctmgr.c', 'jpeglib/jchuff.c', 'jpeglib/jcinit.c', 'jpeglib/jcmainct.c',
'jpeglib/jcmarker.c', 'jpeglib/jcmaster.c', 'jpeglib/jcomapi.c', 'jpeglib/jcparam.c',
'jpeglib/jcprepct.c', 'jpeglib/jcsample.c', 'jpeglib/jctrans.c', 'jpeglib/jdapimin.c',
'jpeglib/jdapistd.c', 'jpeglib/jdatadst.c', 'jpeglib/jdatasrc.c', 'jpeglib/jdcoefct.c',
'jpeglib/jdcolor.c', 'jpeglib/jddctmgr.c', 'jpeglib/jdhuff.c', 'jpeglib/jdinput.c',
'jpeglib/jdmainct.c', 'jpeglib/jdmarker.c', 'jpeglib/jdmaster.c', 'jpeglib/jdmerge.c',
'jpeglib/jdpostct.c', 'jpeglib/jdsample.c', 'jpeglib/jdtrans.c', 'jpeglib/jerror.c',
'jpeglib/jfdctflt.c', 'jpeglib/jfdctfst.c', 'jpeglib/jfdctint.c', 'jpeglib/jidctflt.c',
'jpeglib/jidctfst.c', 'jpeglib/jidctint.c', 'jpeglib/jmemmgr.c', 'jpeglib/jmemnobs.c',
'jpeglib/jquant1.c', 'jpeglib/jquant2.c', 'jpeglib/jutils.c', 'jpeglib/jcarith.c',
'jpeglib/jdarith.c', 'jpeglib/jaricom.c']
png_files = ['libpng/png.c', 'libpng/pngerror.c', 'libpng/pngget.c', 'libpng/pngmem.c',
'libpng/pngpread.c', 'libpng/pngread.c', 'libpng/pngrio.c', 'libpng/pngrtran.c',
'libpng/pngrutil.c', 'libpng/pngset.c', 'libpng/pngtrans.c', 'libpng/pngwio.c',
'libpng/pngwrite.c', 'libpng/pngwtran.c', 'libpng/pngwutil.c']
aesGladman_files = ['aesGladman/aescrypt.cpp', 'aesGladman/aeskey.cpp', 'aesGladman/aestab.cpp', 'aesGladman/fileenc.cpp',
'aesGladman/hmac.cpp', 'aesGladman/prng.cpp', 'aesGladman/pwd2key.cpp', 'aesGladman/sha1.cpp',
'aesGladman/sha2.cpp']
bzip2_files = ['bzip2/blocksort.c', 'bzip2/huffman.c', 'bzip2/crctable.c', 'bzip2/randtable.c',
'bzip2/bzcompress.c', 'bzip2/decompress.c', 'bzip2/bzlib.c']
all_lib_files = [src_dir.File(f) for f in
Flatten([lzma_files, zlib_files, jpeglib_files, png_files, aesGladman_files, bzip2_files])]
defines = {'IRRLICHT_EXPORTS': 1,
'PNG_THREAD_UNSAFE_OK': '',
'PNG_NO_MMX_CODE': '',
'PNG_NO_MNG_FEATURES': '',
}
env.Append(CCFLAGS=['-w']) # Because irrlicht has too many warnings.
env.Append(CPPPATH=[inc_dir,internal_inc_dir])
env.Append(LIBS=['GL','Xxf86vm','Xext','X11','Xcursor'])
env.Append(CPPDEFINES=defines)
env.Append(CCFLAGS=['-U__STRICT_ANSI__'])
shlib = env.SharedLibrary('Irrlicht', [src_files, all_lib_files])[0]
shlib.attributes.usage = {
'CPPSYSTEMPATH': [inc_dir],
'LIBPATH': shlib.dir,
'LIBS': ['Irrlicht'],
'CPPDEFINES': defines,
}
all_libs['irrlicht'] = shlib.attributes.usage
env.Install(env['lib_dir'], shlib)
return shlib
def get_irrlicht_dir():
folder = dep_dir.glob('irrlicht*')
if folder:
return folder[0]
response = urllib.request.urlopen('https://downloads.sourceforge.net/project/irrlicht/Irrlicht%20SDK/1.8/1.8.4/irrlicht-1.8.4.zip')
contents = io.BytesIO(response.read())
zipped = zipfile.ZipFile(contents)
members = [filename for filename in zipped.namelist() if
'source/Irrlicht' in filename or
'include' in filename or
'license' in filename]
zipped.extractall(dep_dir.abspath,members)
return dep_dir.glob('irrlicht*')[0]
def add_dependencies(env, dependencies, requires, optional):
if requires is None:
requires = []
elif isinstance(requires, str):
requires = [requires]
if optional is None:
optional = []
elif isinstance(optional, str):
optional = [optional]
if dependencies is not None:
if isinstance(dependencies, str):
requires.append(dependencies)
else:
requires.extend(dependencies)
transitive = {'CPPPATH': [],
'CPPSYSTEMPATH': [],
'CPPDEFINES': [],
}
requires = find_libraries(env, requires, required=True)
optional = find_libraries(env, optional, required=False)
for dep in requires+optional:
env.Append(**dep)
for key in transitive:
if key in dep:
transitive[key].extend(dep[key])
return transitive
def main_dir(env, main, inc_dir='include', src_dir='src',
dependencies=None, requires=None, optional=None):
env = env.Clone()
add_dependencies(env, dependencies, requires, optional)
main = Dir(main)
inc_dir = main.Dir(inc_dir).RDirs('.')
src_files = env.GlobSrcDir(main.Dir(src_dir))
main_files = env.GlobSrcDir(main)
env.Append(CPPPATH=inc_dir)
env.Append(RPATH=[Literal(os.path.join('\\$$ORIGIN',
env['bin_dir'].rel_path(env['lib_dir'])))])
for shlib in all_libs.values():
env.Append(**shlib)
progs = [env.Program([main_file] + src_files)
for main_file in Flatten(main_files)]
env.Install(env['bin_dir'], progs)
return progs
def compile_folder_dwim(env, base_dir,
dependencies=None, requires=None, optional=None):
base_dir = Dir(base_dir)
sconscript = base_dir.glob('SConscript')
# The extra "base_dir != Dir('.')" is to prevent infinite
# recursion, if a SConscript calls CompileFolderDWIM.
if sconscript and base_dir != Dir('.'):
env_bak = env
env = env.Clone()
add_dependencies(env, dependencies, requires, optional)
output = env.SConscript(sconscript, exports=['env'])
env = env_bak
try:
shlib_name = output.attributes.usage['LIBS'][0]
except (AttributeError,IndexError):
pass
else:
env.Install(lib_dir, output)
all_libs[shlib_name.lower()] = output.attributes.usage
else:
for dir in base_dir.glob('lib*'):
if not env._is_special_dir(dir):
env.SharedLibraryDir(dir, dependencies=dependencies, requires=requires, optional=optional)
for dir in base_dir.glob('py*'):
if not env._is_special_dir(dir):
env.PythonLibraryDir(dir, dependencies=dependencies, requires=requires, optional=optional)
env.MainDir(base_dir, dependencies=dependencies, requires=requires, optional=optional)
if base_dir.glob('tests'):
env.UnitTestDir(base_dir.glob('tests')[0],
extra_inc_dir=base_dir.Dir('include'),
extra_src_dir=base_dir.Dir('src'),
dependencies=dependencies, requires=requires, optional=optional,
)
def is_special_dir(env, query):
query = Dir(query)
top_level = env['top_level']
bin_dir = env['bin_dir']
lib_dir = env['lib_dir']
special_paths = [build_dir,
dep_dir,
bin_dir,
lib_dir,
]
if bin_dir.is_under(top_level):
special_paths.append(build_dir.Dir(top_level.rel_path(bin_dir)))
if lib_dir.is_under(top_level):
special_paths.append(build_dir.Dir(top_level.rel_path(lib_dir)))
return query in special_paths
def download_tool(tool_name):
# If scons-tools is present, use it instead of downloading a copy.
output_file = File('#/scons-tools/{}.py'.format(tool_name)).abspath
if os.path.exists(output_file):
return open_module(output_file)
# If a downloaded copy exists, use it.
output_dir = dep_dir.Dir('scons-tools').abspath
output_file = '{}/{}.py'.format(output_dir,tool_name)
if os.path.exists(output_file):
return open_module(output_file)
# Otherwise, download the tool.
full_path = ('https://raw.githubusercontent.com/Lunderberg/'
'magic_cpp_makefile/master/scons-tools/'
'{}.py').format(tool_name)
resp = urllib.request.urlopen(full_path)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
with open(output_file,'wb') as f:
f.write(resp.read())
return open_module(output_file)
def open_module(filename):
dummy_name = ''.join(random.choice('abcdefghijklmnopqrstuvwxyz')
for _ in range(10))
return imp.load_source(dummy_name, filename)
def glob_src_dir(env, dir):
result = Flatten([dir.glob(g) for g in env['source_file_globs']])
return Flatten([dir.glob(g) for g in env['source_file_globs']])
def non_variant_dir(env, dir):
return Dir(dir).RDirs('.')[-1]
env = default_environment()
env.VariantDir(build_dir,'.',duplicate=False)
dep_dir = build_dir.Dir('.dependencies')
env['dep_dir'] = dep_dir
env.CompileFolderDWIM(build_dir)