-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConstruct.py
124 lines (106 loc) · 3.59 KB
/
SConstruct.py
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
#!python
# These import lines are not really needed, but it helps intellisense within VS when editing the script
import SCons.Script
from SCons.Environment import Environment
# ---
from shutil import copyfile
import os.path
import os
env = Environment(TARGET_ARCH= 'x86') # Create an environmnet for 32 bit version
# Make env global
Export('env')
# This will be shown with flag -h
Help('''
usage: scons [OPTION] ...
SCons Options (case insensitive):
release=1 Build the release version
verbose=1 Build with all information
unit test:
test Build all unit tests
testName Build single unit test called 'testName'
test=on Turns on building unit tests (default)
test=off Turns off building unit tests
test=all Run all unit tests
test=testName Run unit tests whose name contains 'testName'
''')
# Keys to lower case (for case insensitiveness)
ARGUMENTS = dict((k.lower(), v) for (k,v) in ARGUMENTS.items())
# Generator expressions, see: https://www.python.org/dev/peps/pep-0289/
class bcolors:
CYAN = '\033[36m'
LRED = '\033[91m'
LGREEN = '\033[92m'
LYELLOW = '\033[93m'
LBLUE = '\033[94m'
LMAGENTA = '\033[95m'
LCYAN = '\033[96m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
# Replace long comment for short version
if ARGUMENTS.get('verbose') != '1':
env.Append(CCCOMSTR = [bcolors.CYAN + 'Compiling ' + bcolors.ENDC + '$TARGET'])
env.Append(CXXCOMSTR = [bcolors.CYAN + 'Compiling ' + bcolors.ENDC + '$TARGET'])
env.Append(ARCOMSTR = [bcolors.LCYAN + 'Archiving ' + bcolors.ENDC + '$TARGET'])
env.Append(LINKCOMSTR = [bcolors.LBLUE + 'Linking ' + bcolors.ENDC + '$TARGET'])
# Run PocoDir.py for configuration
SConscript('config/PocoDir.py')
PocoBase = env['POCOBASE']
# Get current path
WGCProjectBase = [os.getcwd()]
env.Append(CPPPATH = WGCProjectBase)
# Names of the libraries.
# Letter 'd' for debug, and suffix .lib or .so will be added automatically
LibS = Split('''
PocoFoundation
PocoNet
PocoUtil
PocoXML
PocoJSON
''')
# Path in PocoBase directory where can be found header files
PocoHeaders = Split('''
/Foundation/include
/Util/include
/Net/include
/JSON/include
''')
PocoHeaders = [PocoBase + x for x in PocoHeaders]
env.Append(CPPPATH = PocoHeaders)
# Detect the build mode
platform = ARGUMENTS.get('os', Platform())
if ARGUMENTS.get('release', '0') == '1':
variant = 'Release'
else:
variant = 'Debug'
# Add flags for detected platform and build mode
if platform.name == 'win32':
if variant == 'Debug':
env.Append(CPPDEFINES = ['DEBUG', '_DEBUG'])
env.Append(CCFLAGS=['-W3', '-EHsc', '-D_DEBUG', '/MDd', '/Z7'])
#env.Append(CCPDBFLAGS=['/Zi', '/Fd${TARGET}.pdb'])
env.Append(LINKFLAGS = ['/DEBUG', '/INCREMENTAL:NO'])
LibS = [ x + 'd.lib' for x in LibS]
else:
env.Append(CPPDEFINES = ['NDEBUG'])
env.Append(CCFLAGS=['-O2', '-EHsc', '-DNDEBUG', '/MD'])
LibS = [ x + '.lib' for x in LibS]
else: #posix and linux
env.Append(CCFLAGS=['-std=c++14'])
env.Append(ARFLAGS=['-T'])
if variant == 'Debug':
env.Append(CCFLAGS=['-g'])
LibS = [ x + 'd.so' for x in LibS]
else:
LibS = [ x + '.so' for x in LibS]
env.Append(LIBS = LibS)
env.Append(LIBPATH = [PocoBase + '/lib'])
# Initial unit test
testEnv = env.Clone()
Export('testEnv')
testEnv.SConscript('src/Server/UnitTest/SConscript.py', variant_dir='build/'+variant+'/UnitTest', duplicate=0)
# Save argument in testEnv
testEnv.SetDefault(test = [ARGUMENTS.get('test', 'on')])
# Hierarchical Builds
if not GetOption('help'):
env.SConscript('src/Server/SConscript.py', variant_dir='build/'+variant, duplicate=0)