-
Notifications
You must be signed in to change notification settings - Fork 7
/
SConstruct
executable file
·266 lines (203 loc) · 6.97 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
#! /bin/python
# Graphics Language Renderer (glr) SConstruct file
import subprocess, sys, os
import platform
import platform
import glob
import json
import shutil
import shlex
import argparse
from colorizer import colorizer
from BuildHelper import *
setup(ARGUMENTS)
def setupDependencies():
### Set our libraries
glLib = 'GL'
glewLib = 'GLEW'
libPThread = 'pthread'
cefLib = 'cef'
cefDllWrapperLib = 'cef_dll_wrapper'
boostLogLib = 'boost_log'
boostLogSetupLib = 'boost_log_setup'
boostDateTimeLib = 'boost_date_time'
boostChronoLib = 'boost_chrono'
boostThreadLib = 'boost_thread'
boostWaveLib = 'boost_wave'
boostRegexLib = 'boost_regex'
boostFilesystemLib = 'boost_filesystem'
boostSystemLib = 'boost_system'
boostSerializationLib = 'boost_serialization'
if (isWindows):
glLib = 'opengl32'
glewLib = 'glew32'
libPThread = ''
cefLib = 'libcef'
cefDllWrapperLib = 'libcef_dll_wrapper'
boostLogLib = 'libboost_log-vc120-mt-1_55'
boostLogSetupLib = 'libboost_log_setup-vc120-mt-1_55'
boostDateTimeLib = 'libboost_date_time-vc120-mt-1_55'
boostChronoLib = 'libboost_chrono-vc120-mt-1_55'
boostThreadLib = 'libboost_thread-vc120-mt-1_55'
boostWaveLib = 'libboost_wave-vc120-mt-1_55'
boostRegexLib = 'libboost_regex-vc120-mt-1_55'
boostFilesystemLib = 'libboost_filesystem-vc120-mt-1_55'
boostSystemLib = 'libboost_system-vc120-mt-1_55'
boostSerializationLib = 'libboost_serialization-vc120-mt-1_55'
# Set our required libraries
libraries.append(glLib)
libraries.append(glewLib)
libraries.append(libPThread)
if (buildFlags['useCef']):
libraries.append(cefLib)
libraries.append(cefDllWrapperLib)
libraries.append('assimp')
libraries.append('freeimage')
libraries.append(boostLogLib)
libraries.append(boostLogSetupLib)
libraries.append(boostDateTimeLib)
libraries.append(boostChronoLib)
libraries.append(boostThreadLib)
libraries.append(boostWaveLib)
libraries.append(boostRegexLib)
libraries.append(boostFilesystemLib)
libraries.append(boostSystemLib)
libraries.append(boostSerializationLib)
if (not isWindows):
# XInput for linux
libraries.append( 'Xi' )
### Set our library paths
library_paths.append(dependenciesDirectory + 'assimp/lib')
library_paths.append(dependenciesDirectory + 'boost/lib')
library_paths.append(dependenciesDirectory + 'freeimage/lib')
library_paths.append(dependenciesDirectory + 'cef3/Release')
library_paths.append(dependenciesDirectory + 'glew/lib')
library_paths.append('./lib')
#library_paths.append('./lib_d')
def setupEnvironment(env):
col = colorizer()
col.colorize(env)
### Set our environment variables
env.Append( CPPFLAGS = cpp_flags )
env.Append( CPPDEFINES = cpp_defines )
env.Append( CPPPATH = cpp_paths )
env.Append( LINKFLAGS = link_flags )
env.SetOption('num_jobs', buildFlags['num_jobs'])
if isLinux:
# Set our runtime library locations
env.Append( RPATH = env.Literal(os.path.join('\\$$ORIGIN', '.')))
# include cflags and libs for gtk+-2.0
if (buildFlags['useCef']):
env.ParseConfig('pkg-config --cflags --libs gtk+-2.0')
def parseShadersIntoHeader():
"""Parse the OpenGL Shader files into a single C++ Header file."""
print('Parsing Shaders into header ShaderData.h')
shaderDataOutputFilename = "ShaderData.hpp"
# Will ultimately give something like 'data/shaders/' or 'data\shaders\'
# Note that the last '\' or '/' is important, as we use this to strip the filename of directory information
shaderListLocation = os.path.join("data", "shaders", "")
fileList = glob.glob( os.path.join(shaderListLocation, '*') )
file = open(fileList[0], 'r')
data = file.read()
# Save shader data as a map of std::string objects in the file ShaderData.h
shaderDataFile = open( os.path.join('include/glw/shaders', shaderDataOutputFilename), 'w' )
cpp = """
/**
* This file is automatically generated. Changes made to this file will
* not be reflected after compiling.
*
* If you wish to make changes to shader information for Glr, edit the shaders
* and shader programs in the 'data/shaders/' directory.
*
*/
#include <map>
namespace glr {
namespace shaders {
static std::map<std::string, std::string> SHADER_DATA = {
"""
current = 0
for filename in fileList:
file = open(filename, 'r')
data = file.read()
if (current > 0):
cpp += ", "
cpp += """
{\""""
filename = filename.replace(shaderListLocation, "")
filename = filename.replace(".glsl", "")
cpp += filename
cpp +="""\", std::string(
R"<STRING>(
"""
cpp += data
cpp += """
)<STRING>"
)}
"""
current += 1
cpp += """
};
}
}
"""
shaderDataFile.write(cpp)
shaderDataFile.close()
print('Done parsing Shaders into header ShaderData.h')
def compileCefClient(compiler):
os.chdir( 'cef_client' )
buildCommand = 'scons'
if (compiler):
buildCommand = buildCommand + " --compiler="+compiler
if (buildFlags['clean']):
buildCommand = buildCommand + " --clean"
buildCommand = buildCommand + " --build=" + buildFlags['build']
result = subprocess.call( buildCommand, shell=True )
os.chdir( '..' )
return result
### Clear the screen
clear()
if (not isWindows):
os.system( 'echo' )
os.system( 'echo' )
os.system( 'echo' )
### Prepare code for comilation
if buildFlags['beautify']:
print("Beautifying Code")
beautifyCode()
print("Done")
print("")
### Compile our client for CEF
if (buildFlags['useCef']):
print("Compiling CEF Client")
exitOnError( compileCefClient(buildFlags['compiler']) )
print("")
# Parse our shader programs and create .h files out of them
parseShadersIntoHeader()
# Tell SCons to create our build files in the 'build' directory
VariantDir('build', 'src', duplicate=0)
### Set our source files
source_files = Glob('build/*.cpp')
source_files = source_files + Glob('build/common/compatibility/*.cpp')
source_files = source_files + Glob('build/common/math/*.cpp')
source_files = source_files + Glob('build/common/logger/*.cpp')
source_files = source_files + Glob('build/common/utilities/*.cpp')
source_files = source_files + Glob('build/exceptions/*.cpp')
source_files = source_files + Glob('build/gui/*.cpp')
source_files = source_files + Glob('build/gui/cef/*.cpp')
source_files = source_files + Glob('build/models/*.cpp')
source_files = source_files + Glob('build/environment/*.cpp')
source_files = source_files + Glob('build/terrain/*.cpp')
source_files = source_files + Glob('build/terrain/dual_contouring/*.cpp')
source_files = source_files + Glob('build/terrain/marching_cubes/*.cpp')
source_files = source_files + Glob('build/serialize/*.cpp')
# OpenGL Wrapper stuff
source_files = source_files + Glob('build/glw/*.cpp')
source_files = source_files + Glob('build/glw/shaders/*.cpp')
setupDependencies()
### Create our environment
env = Environment(ENV = os.environ, TOOLS = [buildFlags['compiler']])
setupEnvironment(env)
print("Build type: " + buildFlags['build'])
### Tell SCons the library to build
#env.SharedLibrary('build/glr', source_files, LIBS = libraries, LIBPATH = library_paths)
env.StaticLibrary('build/glr', source_files, LIBS = libraries, LIBPATH = library_paths)