-
Notifications
You must be signed in to change notification settings - Fork 195
/
SConstruct
144 lines (123 loc) · 4.63 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
"""
Copyright (c) 2016 Doyub Kim
"""
import os, sys
root_dir = os.path.dirname(File('SConstruct').rfile().abspath)
sys.path.append(os.path.join(root_dir, 'scripts'))
import header_gen
import json
import utils
Export('os', 'sys', 'utils')
if utils.is_windows():
print 'Use Visual Studio for Windows build.'
quit()
# Fire up all cylinders
if GetOption('num_jobs') <= 1:
SetOption('num_jobs', utils.detect_num_cpus())
# Configure the envinronment
env = Environment(ENV = os.environ, tools=['default'])
AddOption(
'--cfg',
dest='config',
type='string',
nargs=1,
action='store',
help='Specify build config file')
config_filename = GetOption('config')
if not config_filename:
if utils.is_mac():
config_filename = 'build/config-osx-x86_64.json'
else:
config_filename = 'build/config-linux-x86_64.json'
if 'CC' in os.environ:
env['CC'] = os.environ['CC']
if 'CXX' in os.environ:
env['CXX'] = os.environ['CXX']
with open(config_filename, 'r') as config_file:
config = json.load(config_file)
if 'BUILDDIR' in config:
env['BUILDDIR'] = '#' + config['BUILDDIR']
else:
env['BUILDDIR'] = '#obj'
if 'CC' in config and 'CC' not in os.environ:
env['CC'] = config['CC']
if 'CXX' in config and 'CXX' not in os.environ:
env['CXX'] = config['CXX']
if 'CXXFLAGS' in config:
env.Append(CXXFLAGS=config['CXXFLAGS'])
if 'CPPDEFINES' in config:
env.Append(CPPDEFINES=config['CPPDEFINES'])
if 'CPPPATH' in config:
env.Append(CPPPATH=config['CPPPATH'])
if 'LIBS' in config:
env.Append(LIBS=config['LIBS'])
if 'LINKFLAGS' in config:
env.Append(LINKFLAGS=config['LINKFLAGS'])
if 'LIBPATH' in config:
env.Append(LIBPATH=config['LIBPATH'])
Export('env')
# Configure install location
AddOption(
'--dist',
dest='dist',
type='string',
nargs=1,
action='store',
help='Manually specify the install location')
def build(script_file, exports = [], duplicate = 0):
dir_name = os.path.dirname(script_file)
return SConscript(
script_file,
exports,
variant_dir = os.path.join(env['BUILDDIR'], dir_name), duplicate=duplicate)
def build_app(subdir, name, dependencies = []):
app_env, app = build(os.path.join('src', subdir, name, 'SConscript'))
Requires(app, jet)
for dep in dependencies:
Requires(app, os.path.join(env['BUILDDIR'], dep))
env.Alias(name, app)
option = '%s_args' % name
AddOption('--' + option, dest=option, type='string', nargs=1, action='store', help='Arguments to be passed to %s.' % name)
args = GetOption(option)
args = '' if not args else args
if 'run_' + name in COMMAND_LINE_TARGETS:
action = os.path.join(env['BUILDDIR'][1:], os.path.join('src', subdir, name, name)) + ' ' + args
run_app_cmd = env.Command(target='run_' + name, source=None, action=action)
Requires(run_app_cmd, app)
env.Alias('run_' + name, run_app_cmd)
# Pre-build steps
header_gen.main()
# External libraries
cnpy_env, cnpy = build('external/src/cnpy/SConscript')
gtest_env, gtest = build('external/src/gtest/SConscript')
pystring_env, gtest = build('external/src/pystring/SConscript')
libobj_env, libobj = build('external/src/obj/SConscript')
# Core libraries
jet_env, jet = build('src/jet/SConscript')
Requires(jet, os.path.join(env['BUILDDIR'], 'external/src/obj'))
# Examples
build_app('examples', 'hello_fluid_sim')
build_app('examples', 'hybrid_liquid_sim', ['src/jet', 'external/src/pystring'])
build_app('examples', 'level_set_liquid_sim', ['src/jet', 'external/src/pystring'])
build_app('examples', 'obj2sdf', ['src/jet'])
build_app('examples', 'particles2obj', ['src/jet'])
build_app('examples', 'particles2xml', ['src/jet'])
build_app('examples', 'smoke_sim', ['src/jet', 'external/src/cnpy', 'external/src/pystring'])
build_app('examples', 'sph_sim', ['src/jet', 'external/src/cnpy', 'external/src/pystring'])
# Tests
build_app('tests', 'manual_tests', ['external/src/cnpy', 'external/src/gtest', 'src/jet', 'external/src/pystring'])
build_app('tests', 'unit_tests', ['external/src/gtest', 'external/src/jet'])
build_app('tests', 'perf_tests', ['external/src/gtest', 'external/src/jet'])
# Install
if 'install' in COMMAND_LINE_TARGETS:
dist_dir = GetOption('dist')
if dist_dir == None:
dist_dir = env.GetBuildPath(env['DISTDIR'])
else:
dist_dir = '#' + dist_dir
lib_inst = env.Install(os.path.join(dist_dir, 'lib'), jet)
inc_inst = env.Install(dist_dir, ['include'])
env.Depends(lib_inst, inc_inst)
env.Depends(lib_inst, jet)
env.Depends(inc_inst, jet)
env.Alias("install", lib_inst)