-
Notifications
You must be signed in to change notification settings - Fork 2
/
SConstruct
264 lines (218 loc) · 9.19 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
# ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
#
# Copyright (C) 2014, 2015 CNRS
# Copyright (C) 2013, 2014, 2015 Inria
# Copyright (C) 2015 Universite de Montreal
#
# This file is part of ALTA.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import os
import sys
import SCons.SConf as C
# Arrange so that the 'obtain' module can always be imported.
top_srcdir = Dir('.').srcnode().abspath
sys.path += [ top_srcdir + '/external' ]
## Build the documentation. This is independant of everything else and
## should return afterwards, speeding-up the process of generating doc.
##
if 'doc' in COMMAND_LINE_TARGETS:
os.chdir('documents')
Alias('doc', os.system('doxygen doxygen.conf'))
Exit(0)
## Add ALTA custom cmd configurations
##
AddOption('--cfg', help='Specify a configuration file')
AddOption('--no-externals', action="store_false", dest="obtain_externals", default=True, help='Do not download and build externals')
## Import configuration from a config file
##
configFile = GetOption('cfg')
if configFile == None:
if sys.platform == 'win32':
configFile = "./configs/scons/config-windows-cl.py"
elif sys.platform == 'darwin':
configFile = "./configs/scons/config-macos-clang.py"
elif sys.platform == 'linux2':
configFile = "./configs/scons/config-linux-gcc.py"
else:
print '<<ERROR>> You need to specify a configuration file using:'
print '<<ERROR>> scons --cfg=[filename]'
print '<<ERROR>> Please find example of configuration files in ${ALTA}/configs/scons/'
Exit(1)
#end
if not os.path.exists(configFile):
print '<<ERROR>> the config file you specified \"' + configFile + '\" does not exists'
Exit(1)
else:
print '<<INFO>> Using config file \"' + configFile + '\"'
#end
# List of C++ compilers we look for by default.
cxx_compilers = [ 'g++', 'c++', 'clang++', 'cl' ]
# List of Python 2.x interpreter names to look for.
python_programs = [ 'python2.7', 'python2', 'python', sys.executable ]
def program_file_name(choices):
"""
Look for the programs listed in CHOICES. Return the absolute file
name of one that matches, or the first element of CHOICES.
"""
for program in choices:
full = WhereIs(program)
if full != None:
return full
return choices[0]
vars = Variables(configFile)
vars.Add('CXX', 'C++ compiler',
default = program_file_name(cxx_compilers))
vars.Add('CCFLAGS', 'Compiler\'s flags',
default = ['-g', '-O2', '-Wall'])
vars.Add('LINKFLAGS', 'Linker\'s flags',
default = [])
vars.Add('PLUGIN_LIB', 'Special links for ALTA plugin')
vars.Add('EIGEN_INC', 'Eigen include directory (mandatory)')
vars.Add('PYTHON_INC', 'Python and boost-python include directory')
vars.Add('PYTHON_DIR', 'Python and boost-python libraries directory')
vars.Add('PYTHON_LIB', 'Python and boost-python libraries', default = [])
vars.Add('OPENEXR_INC', 'OpenEXR include directory', default=[])
vars.Add('OPENEXR_LIB', 'OpenEXR libraries', default = [])
vars.Add('OPENEXR_DIR', 'OpenEXR libraries directory', default=[])
vars.Add('FLANN_INC', 'FLANN include directory')
vars.Add('FLANN_DIR', 'FLANN libraries directory')
vars.Add('FLANN_LIB', 'FLANN libraries')
vars.Add('OPENMP_FLAG', 'OpenMP required flags')
vars.Add('OPENMP_LIB', 'OpenMP libraries')
vars.Add('QUADPROG_INC', 'QUADPROG include directory')
vars.Add('QUADPROG_DIR', 'QUADPROG libraries directory')
vars.Add('QUADPROG_LIB', 'QUADPROG libraries')
vars.Add('CERES_INC', 'CERES include directory')
vars.Add('CERES_DIR', 'CERES libraries directory')
vars.Add('CERES_LIB', 'CERES libraries')
vars.Add('CERES_OPT_LIB', 'CERES optional libraries')
vars.Add('NLOPT_INC', 'NLOPT include directory')
vars.Add('NLOPT_DIR', 'NLOPT libraries directory')
vars.Add('NLOPT_LIB', 'NLOPT libraries', default = [])
vars.Add('NLOPT_OPT_LIB', 'NLOPT optional libraries', default = [])
vars.Add('IPOPT_INC', 'IPOPT include directory')
vars.Add('IPOPT_DIR', 'IPOPT libraries directory')
vars.Add('IPOPT_LIB', 'IPOPT libraries', default = [])
vars.Add('IPOPT_OPT_LIB', 'IPOPT optional libraries')
vars.Add('MATLAB_INC', 'MATLAB include directory')
vars.Add('MATLAB_DIR', 'MATLAB directory')
vars.Add('MATLAB_LIB', 'MATLAB libraries')
vars.Add('PYTHON', 'Python interpreter',
default = program_file_name(python_programs))
##
# Copy the system environment.
#
# Update the PKG_CONFIG_PATH variable to add the package configuration
# files contained is #external/build/lib/pkgconfig
##
envVars = {}
for var in [ 'PATH', 'CPATH', 'LIBRARY_PATH', 'PKG_CONFIG_PATH', 'TMP', 'TMPDIR' ]:
if var in os.environ:
envVars[var] = os.environ[var]
else:
envVars[var] = '';
if len(envVars['PKG_CONFIG_PATH']) > 0:
envVars['PKG_CONFIG_PATH'] += ':'
envVars['PKG_CONFIG_PATH'] += os.path.abspath('external' + os.sep + 'build' + os.sep + 'lib' + os.sep + 'pkgconfig')
env = Environment(variables = vars, ENV = envVars)
env['DL_EXTERNALS'] = GetOption('obtain_externals')
# Generate help text for the build variables.
Help(vars.GenerateHelpText(env))
C.progress_display('the current platform is: ' + env['PLATFORM'])
## PLATFORM dependant section
##
if env['PLATFORM'] == 'darwin':
# Adding the /usr/local/lib directory used to store libraries of
# MacPorts or Brew.
env.AppendUnique(LIBPATH = ['/usr/local/lib'])
env.AppendUnique(CPPPATH = ['/usr/local/include'])
env.AppendUnique(LIBPATH = ['/opt/local/lib/'])
env.AppendUnique(CPPPATH = ['/opt/local/include/'])
def CheckPKG(context, name):
"""Return True if package NAME can be found with 'pkg-config'."""
context.Message('Checking for %s using pkg-config... ' % name)
ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0]
context.Result(ret)
return ret
def library_available(env, pkgspec='', lib='', header='',
language='c++', inc_var='', lib_var=''):
"""Return True if the given library is available.
First look for the LIB_VAR and INC_VAR construction variables,
honoring them if they are defined. Then look for PKGSPEC using
pkg-config. Last, try to build LIB with HEADER. Configure ENV
accordingly.
"""
conf = Configure(env, custom_tests = { 'CheckPKG' : CheckPKG })
# If a XXX_LIB is specified in the environment, add the various path
# and link flags. Check if the library is correctly compiling and
# linking with the header.
if (lib in env) and (len(env[lib]) > 0):
env.AppendUnique(LIBPATH = env[lib_var])
env.AppendUnique(CPPPATH = env[inc_var])
env.AppendUnique(LIBS = env[lib])
# Check whether the library is usable.
result = conf.CheckLibWithHeader(env[lib], header, language)
elif conf.CheckPKG(pkgspec):
env.ParseConfig('pkg-config --cflags --libs "' + pkgspec + '"')
# XXX: We can't use 'CheckLibWithHeader' to verify that
# everything's alright because we don't know the library name. So
# assume that pkg-config got it right.
result = True
else:
result = conf.CheckLibWithHeader(pkgspec, header, language)
conf.Finish()
return result
def openexr_available(env):
"""Return True if OpenEXR is available."""
return library_available(env, pkgspec='OpenEXR',
inc_var='OPENEXR_INC',
lib_var='OPENEXR_DIR',
lib='OPENEXR_LIB',
header='ImfRgbaFile.h')
# Export these for use in SConscripts.
Export('CheckPKG', 'library_available', 'openexr_available')
conf = Configure(env)
# Determine the extra libraries that libcore (and thus everything
# else) depends on. Plugins need to specify it in addition to -lcore
# because libcore is not a shared library.
ALTA_LIBS = []
# Libcore's uses 'dlopen', which is in libdl in GNU libc.
if conf.CheckLibWithHeader('dl', 'dlfcn.h', 'c++'):
ALTA_LIBS = ['dl']
# Libcore uses 'clock_gettime', which is in librt in GNU libc.
if conf.CheckLibWithHeader('rt', 'sched.h', 'c++'):
ALTA_LIBS = ALTA_LIBS + ['rt']
Export('ALTA_LIBS')
env = conf.Finish()
## Load the configuration file if it exists. The configuration file
## is a python script that updates the env variable with different
## paths.
##
env.AppendUnique(LIBPATH = ['#external/build/lib'])
env.AppendUnique(LIBPATH = ['#sources/build'])
env.AppendUnique(CPPPATH = ['#external/build/include'])
env.AppendUnique(CPPPATH = ['#sources'])
# Consider files changed as soon as their modification time changes.
env.Decider('timestamp-newer')
## Launch the compilations
##
Export('env')
external = env.SConscript('external/SConscript')
core = env.SConscript('sources/core/SConscript')
plugins = env.SConscript('sources/plugins/SConscript')
softs = env.SConscript('sources/softs/SConscript')
if 'python' in COMMAND_LINE_TARGETS:
python = env.SConscript('sources/python/SConscript')
env.Depends(python, core)
env.Depends(core, external)
env.Depends(plugins, core)
env.Depends(softs, core)
if 'tests' in COMMAND_LINE_TARGETS:
tests = env.SConscript('sources/tests/SConscript')
env.Depends(tests, core)
env.Depends(tests, plugins)
if 'python' in COMMAND_LINE_TARGETS:
env.Depends(tests, python)