-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConstruct.py
130 lines (103 loc) · 4.13 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
125
126
127
128
129
130
import platform
import os
#----------------------------------------------------------
#---------------------- Preparation -----------------------
#----------------------------------------------------------
# Build constants
LINUX_BOOST_INCLUDE_PATH = '/usr/local/include/boost'
LINUX_BOOST_LIB_PATH = '/usr/local/lib'
LINUX_CPPPATH = [ \
Dir(LINUX_BOOST_INCLUDE_PATH),
]
LINUX_LIBPATH = [ \
Dir(LINUX_BOOST_LIB_PATH), \
]
#----------------------------------------------------------
#------------- Get include directories list ---------------
#----------------------------------------------------------
# Get path to src folder
includePath = str(Dir('include').srcnode().abspath)
# List all subdirectories in include/
for root, dirnames, filenames in os.walk(includePath):
LINUX_CPPPATH.append(Dir(root))
#----------------------------------------------------------
#---------------------- Preparation -----------------------
#----------------------------------------------------------
# Check if debug build (command-line argument 'debug=1')
# Default value for debug: 0
debug = int(ARGUMENTS.get('debug', 0))
# Export debug to submodules
Export({'DEBUG': debug})
# Empty environment
env = Environment()
#----------------------------------------------------------
#---------- Src/test folder depths calculation ------------
#----------------------------------------------------------
# Depths are used to establish number of Glob() objects
# passed to the builders, where every Glob represents
# */*/.../*.cc pattern for an appropriate depth in src/test
# folder's structure
def getDepth(path, depth=0):
if not os.path.isdir(path): return depth
maxdepth = depth
for entry in os.listdir(path):
fullpath = os.path.join(path, entry)
maxdepth = max(maxdepth, getDepth(fullpath, depth + 1))
return maxdepth
srcDepth = getDepth('src')
testDepth = getDepth('test')
#----------------------------------------------------------
#--------------- Linux Common Environment -----------------
#----------------------------------------------------------
if(platform.system() == "Linux"):
env.Append( CPPPATH = LINUX_CPPPATH )
env.Append( LIBPATH = LINUX_LIBPATH )
env.Append( LIBS = [] )
# Custom compiller flags
env.Append( CPPFLAGS = '-Wall -pedantic -std=c++17 ' )
# Custom linker flags
env.Append( LINKFLAGS = '-Wall -Wl,-rpath={} '.format(LINUX_BOOST_LIB_PATH) )
# Compile-time ROOT constant is used by the programm
# to be aware about it's structure's localization
env.Append( CPPFLAGS = '-D ROOT=\\\"{}\\\" '.format(Dir('.').abspath) )
# Debug-dependant configuration
if debug == 1:
env.Append( CPPFLAGS = '-g ')
env.Append( CPPFLAGS = '-D DEBUG ')
# Export required variables to submodules
Export('env')
#----------------------------------------------------------
#-------------- Windows Common Environment ----------------
#----------------------------------------------------------
elif(platform.system() == "Windows"):
env.Append( CPPPATH = [ Dir( ) ] )
env.Append( LIBPATH = [ Dir( ) ] )
# Custom compiller flags
env.Append( CPPFLAGS = ' /EHsc /MD /D "WIN32" /D "_CONSOLE" /W4' )
# Custom linker flags
env.Append( LINKFLAGS = [ ] )
# Debug-dependant configuration
if debug == 1:
pass
#----------------------------------------------------------
#------------------------- Build --------------------------
#----------------------------------------------------------
def version(debug):
if debug == 1:
return 'debug'
else:
return 'release'
# Build app
VariantDir('obj/' + version(debug) + '/app', 'src', duplicate = 0)
srcObjects = SConscript('obj/' + version(debug) + '/app/SConscript.py', exports='srcDepth')
# Build test
VariantDir('obj/' + version(debug) + '/test', 'test', duplicate = 0)
SConscript('obj/' + version(debug) + '/test/SConscript.py', exports = ['srcObjects', 'testDepth'])
#----------------------------------------------------------
#----------------------- Utilities ------------------------
#----------------------------------------------------------
# Help printed to the terminal after typing 'scons -h'
Help("""
Type: 'scons ' to build the production program,
'scons debug=1' to build the debug version.
""")