-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSConscript
258 lines (234 loc) · 7.31 KB
/
SConscript
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
#
# Fabric Engine 2.1.0-alpha
# SCons build 'header' for Fabric Engine EDK
#
# Copyright 2010-2015 Fabric Software Inc. All rights reserved.
#
import os, platform, sys
print(sys.version)
buildOS = os.environ.get('FABRIC_BUILD_OS', platform.system())
supportedOSes = ['Windows', 'Linux', 'Darwin']
try:
if not buildOS in supportedOSes:
raise Exception("Unrecognized OS '" + buildOS + "'")
except Exception as e:
print(e)
print("You can set FABRIC_BUILD_OS in your environment to override.")
print("Can be one of: " + ', '.join(supportedOSes))
sys.exit(1)
buildArch = os.environ.get('FABRIC_BUILD_ARCH', platform.architecture()[0])
pythonArchToFabricArch = {
"Darwin": {
"x86_64": "x86_64",
"64bit": "x86_64",
"universal": "x86_64",
},
"Linux": {
"i686": "i686",
"i386": "i686",
"32bit": "i686",
"amd64": "x86_64",
"x86_64": "x86_64",
"64bit": "x86_64",
},
"Windows": {
"x86": "x86",
"32bit": "x86",
"x86_64": "x86_64",
"x64": "x86_64",
"64bit": "x86_64",
},
}
try:
buildArch = pythonArchToFabricArch[buildOS][buildArch]
except:
print("Unrecognized architecture '" + buildArch + "' for OS '" + buildOS + "'")
print("You can set FABRIC_BUILD_ARCH in your environment to override.")
print("Can be one of: " + ', '.join(keys(pythonArchToFabricArch[buildOS])))
sys.exit(1)
buildType = os.environ.get('FABRIC_BUILD_TYPE', 'Debug')
print("Building type: " + buildType)
fabricBuildEnv = Environment(
ENV = { 'PATH': os.environ['PATH'] },
FABRIC_VERSION_MAJ = '2',
FABRIC_VERSION_MIN = '1',
FABRIC_VERSION_REV = '0',
FABRIC_VERSION_NO_SUFFIX = '2.1.0',
FABRIC_VERSION = '2.1.0-alpha',
FABRIC_VERSION_SUFFIX = '-alpha',
FABRIC_DESC = 'Dedicated Platform for High-Performance Graphics Applications',
FABRIC_BUILD_OS = buildOS,
FABRIC_BUILD_ARCH = buildArch,
FABRIC_BUILD_TYPE = buildType,
# TARGET_ARCH must be set when the Environment() is created in order
# to pull in correct x86 vs x64 paths on Windows
TARGET_ARCH = buildArch
)
if buildOS == 'Windows':
fabricBuildEnv.Append(ENV = {"APPDATA": os.environ['APPDATA']})
else:
fabricBuildEnv.Append(ENV = {"HOME": os.environ['HOME']})
SetOption('num_jobs', int(os.environ.get('FABRIC_BUILD_JOBS', 1)))
print("Running SCons with -j" + str(GetOption('num_jobs')))
if not ARGUMENTS.get('VERBOSE'):
fabricBuildEnv['CCCOMSTR'] = 'Compiling $SOURCE'
fabricBuildEnv['CXXCOMSTR'] = 'Compiling $SOURCE'
fabricBuildEnv['SHCCCOMSTR'] = 'Compiling $SOURCE'
fabricBuildEnv['SHCXXCOMSTR'] = 'Compiling $SOURCE'
fabricBuildEnv['ARCOMSTR'] = 'StaticLibrary $TARGET'
fabricBuildEnv['SHLINKCOMSTR'] = 'SharedLibrary $TARGET'
fabricBuildEnv['RANLIBCOMSTR'] = 'Ranlib $TARGET'
fabricBuildEnv['LINKCOMSTR'] = 'Linking $TARGET'
fabricBuildEnv['LDMODULECOMSTR'] = 'LoadableModule $TARGET'
if buildType == 'Release':
fabricBuildEnv.Append(CPPDEFINES = ['NDEBUG'])
if buildOS == 'Windows' and buildType == 'Debug':
fabricBuildEnv.Append(PDB = '${TARGET.base}.pdb')
fabricBuildEnv.Append(CXXFLAGS = ['/DEBUG'])
if buildOS == 'Windows':
fabricBuildEnv['ENV']['TMP'] = os.environ.get('TMP', os.environ.get('TEMP', "C:\\TEMP"))
try:
fabricDir = fabricBuildEnv.Dir(os.environ['FABRIC_DIR'])
except:
print("You must set FABRIC_DIR in your environment.")
print("Normally, this is set as part of the installation of")
print("Fabric Engine; perhaps try reinstallation?")
sys.exit(1)
fabricBuildEnv.Append(CPPPATH = [
fabricDir.Dir('include'),
])
try:
fabricDir = fabricBuildEnv.Dir(os.environ['FABRIC_DIR'])
except:
print("You must set FABRIC_DIR in your environment.")
print("Normally, this is set as part of the installation of")
print("Fabric Engine; perhaps try reinstallation?")
sys.exit(1)
# check for buildOS specific flags
buildFlags = {
# === OSX ===
'Darwin': {
'ccflags': [
'-Wall',
'-fvisibility=hidden',
'-mmacosx-version-min=10.7',
'-fno-omit-frame-pointer',
],
'linkflags': ['-w', '-mmacosx-version-min=10.7'],
'x86_64' : {
'ccflags': ['-arch', 'x86_64'],
'linkflags': ['-arch', 'x86_64']
},
'Debug' : {
'ccflags': [ '-g' ]
},
'Release' : {
'ccflags': [ '-O2' ]
},
},
# === LINUX ===
'Linux': {
'ccDefs': [
'__STDC_LIMIT_MACROS',
'__STDC_CONSTANT_MACROS'
],
'ccflags': ['-fPIC', '-fno-omit-frame-pointer'],
'i686' : {
'ccflags': [ '-m32' ],
'linkflags': [ '-m32' ]
},
'x86_64' : {
'ccflags': [ '-m64' ],
'linkflags': [ '-m64' ]
},
'Debug' : {
'ccflags': [ '-g' ]
},
'Release' : {
'ccflags': [ '-O2' ]
},
},
# === WINDOWS ===
'Windows': {
'ccDefs': [
'_SCL_SECURE_NO_WARNINGS=1',
'_ITERATOR_DEBUG_LEVEL=0',
'_SECURE_SCL=0',
'_WIN32_WINNT=0x0600',
'COMPILER_MSVC'
],
'ccflags': [
'/EHsc',
'/wd4624',
'/FC' ],
'linkflags': [ 'chkstk.obj' ],
'x86' : {
'ccflags': [ ],
'linkflags': [ ]
},
'x86_64' : {
'ccDefs': [ 'WIN64' ],
'ccflags': [ ],
'linkflags': [ ]
},
'Debug' : {
'ccflags': [ '/Od', '/Zi', '/MTd' ]
},
'Release' : {
'ccflags': [ '/Ox', '/MT' ]
},
}
}
osFlags = buildFlags[buildOS]
if 'ccDefs' in osFlags:
fabricBuildEnv.Append( CPPDEFINES = osFlags['ccDefs'] )
if 'ccflags' in osFlags:
fabricBuildEnv.Append( CCFLAGS = osFlags['ccflags'] )
if 'cxxflags' in osFlags:
fabricBuildEnv.Append( CXXFLAGS = osFlags['cxxflags'] )
if 'linkflags' in osFlags:
fabricBuildEnv.Append( LINKFLAGS = osFlags['linkflags'] )
subTypes = [ buildArch, buildType ]
for subType in subTypes:
if subType in osFlags:
osSubFlags = osFlags[subType]
if 'ccDefs' in osSubFlags:
fabricBuildEnv.Append( CPPDEFINES = osSubFlags['ccDefs'] )
if 'ccflags' in osSubFlags:
fabricBuildEnv.Append( CCFLAGS = osSubFlags['ccflags'] )
if 'cxxflags' in osSubFlags:
fabricBuildEnv.Append( CXXFLAGS = osSubFlags['cxxflags'] )
if 'linkflags' in osSubFlags:
fabricBuildEnv.Append( LINKFLAGS = osSubFlags['linkflags'] )
# Produce one .PDB file per .OBJ when compiling, then merge them when linking.
# Doing this enables parallel builds to work properly (the -j parameter).
# See: http://www.scons.org/doc/HTML/scons-man.html section CCPDBFLAGS
#
fabricBuildEnv['CCPDBFLAGS'] = '/Zi /Fd${TARGET}.pdb'
def buildExtension(env, target, sources):
env.Append(CPPPATH = [env.Dir('.')])
cppSources = []
klSources = []
for source in Flatten(sources):
if str(source)[-3:] == '.kl':
klSources.append(source)
elif str(source)[-4:] == '.cpp':
cppSources.append(source)
if buildOS == 'Windows':
kl2edkBin = fabricDir.Dir('bin').File('kl2edk.exe')
else:
if 'LD_LIBRARY_PATH' in os.environ:
env['ENV']['LD_LIBRARY_PATH'] = os.environ['LD_LIBRARY_PATH']
kl2edkBin = fabricDir.Dir('bin').File('kl2edk')
# cppHeader = env.Command(
# [env.File(target + '.h')],
# klSources,
# [[kl2edkBin, "-o", "${TARGET.dir}"] + klSources]
# )
# env.Depends(cppSources, cppHeader)
return env.SharedLibrary(
'-'.join([target, buildOS, buildArch]),
cppSources
)
fabricBuildEnv.AddMethod(buildExtension, 'Extension')
Export('fabricBuildEnv')