-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSConscript
270 lines (229 loc) · 10.9 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
259
260
261
262
263
264
265
266
267
268
269
270
import os
import sys
import platform
Import('env')
# Build environment configuration --------------------------------------------
# Apply CFLAGS, CXXFLAGS, LDFLAGS from the system environment.
flagnames = 'CFLAGS CPPFLAGS CXXFLAGS LDFLAGS'.split()
env.MergeFlags([os.environ.get(n, '') for n in flagnames])
# Insert LIBRARY_PATH explicitly
if env['PLATFORM'] != 'win32':
env.PrependUnique(LIBPATH=env['ENV'].get('LIBRARY_PATH', '').split(':'))
else:
env.PrependUnique(LIBPATH=env['ENV'].get('LIBRARY_PATH', '').split(';'))
# Insert CPPPATH explicitly
if env['PLATFORM'] != 'win32':
env.PrependUnique(CPPPATH=env['ENV'].get('CPPPATH', '').split(':'))
else:
env.PrependUnique(CPPPATH=env['ENV'].get('CPPPATH', '').split(';'))
# Windows specific enviroment
if env['PLATFORM'] == 'win32':
env.PrependUnique(CPATH=env['ENV'].get('CPATH', '').split(';'))
env.PrependUnique(CPPPATH=env['ENV'].get('CPPPATH', '').split(';'))
env['ENV']['TMP'] = os.environ['TMP']
# Use Intel C++ compiler if requested by the user.
icpc = None
if env['tool'] == 'intelc':
icpc = env.WhereIs('icpc')
if not icpc:
print("Cannot find the Intel C/C++ compiler 'icpc'.")
Exit(1)
env.Tool('intelc', topdir=icpc[:icpc.rfind('/bin')])
if env['PLATFORM'] != 'win32':
fast_linkflags = ['-s']
else:
fast_linkflags = []
# Platform specific intricacies.
if env['PLATFORM'] == 'darwin':
env.Append(SHLINKFLAGS=['-install_name', '$TARGET.abspath'])
env.AppendUnique(SHLINKFLAGS='-headerpad_max_install_names')
env.AppendUnique(SHLINKFLAGS=['-undefined', 'dynamic_lookup'])
fast_linkflags[:] = []
# Compiler specific options
if icpc:
# options for Intel C++ compiler on hpc dev-intel07
env.PrependUnique(CCFLAGS=['-w1', '-fp-model', 'precise'])
env.PrependUnique(LIBS=['imf'])
fast_optimflags = ['-fast', '-no-ipo']
else:
# g++ options
env.PrependUnique(CCFLAGS=['-Wall'])
env.PrependUnique(CXXFLAGS=['-std=c++11'])
fast_optimflags = ['-ffast-math']
# Configure build variants
if env['build'] == 'debug':
env.Append(CCFLAGS='-g')
elif env['build'] == 'fast':
env.AppendUnique(CCFLAGS=['-O3'] + fast_optimflags)
#env.AppendUnique(CPPDEFINES={'NDEBUG' : None})
env.AppendUnique(LINKFLAGS=fast_linkflags)
if env['profile']:
env.AppendUnique(CCFLAGS='-pg')
env.AppendUnique(LINKFLAGS='-pg')
# link warnings
if env['PLATFORM'] != 'win32' and env['PLATFORM'] != 'darwin':
env.AppendUnique(LINKFLAGS=['']) # '-Wl,--' does not work with gcc4.8
# REAL=double needed for pyobjcryst
env.AppendUnique(CCFLAGS='-DREAL=double')
# required for boost with MSVC
if env['PLATFORM'] == 'win32':
env.AppendUnique(CPPFLAGS=['/EHsc','/MD','-DBOOST_ALL_DYN_LINK','-D_DLL'])
# link flags for MSVC
if env['PLATFORM'] == 'win32':
env.AppendUnique(LINKFLAGS=['/NODEFAULTLIB:library'])
# Lists for storing built objects and header files
env['newmatobjs'] = []
env['cctbxobjs'] = []
env['objcrystobjs'] = []
env['mstructobjs'] = []
env['binmstructobjs'] = []
env['binxmlmstructobjs'] = []
env['lib_includes'] = []
env['libmstruct_includes'] = []
env['binmstruct_includes'] = []
# Subsidiary SConscripts -----------------------------------------------------
# These will create the built objects and header file lists.
SConscript(["SConscript.cctbx", "SConscript.newmat", "SConscript.objcryst", "SConscript.mstruct"])
# Define sdist target for creating source distribution bundle
# Do so only if required to avoid extra git executions.
# Note: See .gitattributes for files excluded from sdist.
if 'sdist' in COMMAND_LINE_TARGETS:
SConscript('SConscript.sdist')
# Top Level Targets ----------------------------------------------------------
# This retrieves the intermediate objects
newmatobjs = env["newmatobjs"]
cctbxobjs = env["cctbxobjs"]
objcrystobjs = env["objcrystobjs"]
mstructobjs = env["mstructobjs"]
binmstructobjs = env["binmstructobjs"]
binxmlmstructobjs = env["binxmlmstructobjs"]
# This builds the shared library
if env['PLATFORM'] != 'win32':
# Additional library dependencies for ObjCryst
ObjCrystlibs = ['lapack','m']
ObjCrystlibpaths = []
libobjcryst = env.SharedLibrary("libObjCryst",
objcrystobjs + cctbxobjs + newmatobjs,
LIBS=ObjCrystlibs) # LIBPATH=ObjCrystlibpaths
else:
# Additional library dependencies for ObjCryst
ObjCrystlibs = [] # Additional library dependencies for ObjCryst
ObjCrystlibpaths = []
env.AppendUnique(LIBPATH=[env.Dir('../../../win-prebuild/lib/x64')])
libobjcryst = env.Library("libObjCryst",
objcrystobjs + cctbxobjs + newmatobjs,
LIBS=ObjCrystlibs) # LIBPATH=ObjCrystlibpaths
lib = Alias('lib', [libobjcryst, env['lib_includes']])
Default(lib)
conf = Configure(env)
# Boost configuration ----------------------------------------------------------
def find_library(possible_library_names, conf,):
"""
Searches for library with possible different names under different versions.
"""
proper_library_name = ''
for name in possible_library_names:
if conf.CheckLib(name):
return name
raise RuntimeError('Unable to check availability of library name (note this may also indicate other configuration problems, please check ./config.log)', possible_library_names)
boost_python_libs = []
python_libs = []
# Possible boost/numpy library names
boost_python_possible_names = ['boost_python%d%d' % env['python_version'], 'boost_python%d' % env['python_version'][0],'boost_python']
boost_numpy_possible_names = ['boost_numpy%d%d' % env['python_version'], 'boost_numpy%d' % env['python_version'][0], 'boost_numpy']
python_library_possible_names = ['python%d.%d' % env['python_version'], 'python%d.%dm' % env['python_version'], 'python%d%d' % env['python_version']]
if env['PLATFORM'] != 'darwin':
python_libs.extend((find_library(python_library_possible_names, conf),))
boost_python_libs.extend((find_library(boost_python_possible_names, conf), find_library(boost_numpy_possible_names, conf)))
env = conf.Finish()
if env['PLATFORM'] != 'win32':
binMStructlibs = ['fftw3', 'gsl', 'lapack', 'ObjCryst'] + ['boost_program_options',]
libMStructlibs = ['fftw3', 'gsl', 'lapack', 'ObjCryst'] + python_libs + boost_python_libs
else:
binMStructlibs = ['fftw3', 'gsl', 'libObjCryst', 'clapack-3.1.1-md','libf2c-3.1.1-md','blas-3.1.1-md'] + python_libs + boost_python_libs + ['boost_program_options',]
libMStructlibs = ['fftw3', 'gsl', 'libObjCryst', 'clapack-3.1.1-md','libf2c-3.1.1-md','blas-3.1.1-md'] + python_libs + boost_python_libs + ['boost_program_options',]
MStructlibpaths = env['LIBPATH'] + ['/usr/lib', env.Dir('.')]
# This builds the shared MStruct library
libmstruct = env.SharedLibrary("libMStruct", mstructobjs, LIBS=libMStructlibs, LIBPATH=MStructlibpaths)
libms = Alias('libmstruct', [libmstruct,] + env['libmstruct_includes'])
#if env['PLATFORM'] != 'win32':
# Depends(libmstruct, lib)
# This builds mstruct binary executable
binmstruct = env.Program("mstruct_am", binmstructobjs, LIBS=binMStructlibs, LIBPATH=MStructlibpaths)
binms = Alias('mstruct', [binmstruct,] + env['binmstruct_includes'])
# This builds mstruct_xml binary executable
binxmlmstruct = env.Program("mstruct_xml", binxmlmstructobjs, LIBS=binMStructlibs, LIBPATH=MStructlibpaths)
binms_xml = Alias('mstruct_xml', [binxmlmstruct,] + env['binmstruct_includes'])
# Installation targets.
prefix = env['prefix']
# install-lib
libinstall = env.Install(env['libdir'], libobjcryst)
if env['PLATFORM'] == 'darwin':
# DARWIN_INSTALL_NAME can be pre-set in sconscript.local
env.SetDefault(DARWIN_INSTALL_NAME='$TARGET.abspath')
env.AddPostAction(libinstall,
'install_name_tool -id $DARWIN_INSTALL_NAME $TARGET')
if env['PLATFORM'] == 'posix' and WhereIs('ldconfig'):
opts = ''
if os.getuid() != 0: opts = '-n'
env.AddPostAction(libinstall,
'ldconfig %s $TARGET.dir' % opts)
if env['PLATFORM'] != 'win32':
libinstall = env.Install(env['libdir'], libmstruct+libobjcryst)
else:
libinstall = env.Install(env['libdir'], [f for f in libmstruct if f.get_suffix()=='.lib'])
if env['PLATFORM'] == 'darwin':
# DARWIN_INSTALL_NAME can be pre-set in sconscript.local
env.SetDefault(DARWIN_INSTALL_NAME='$TARGET.abspath')
env.AddPostAction(libinstall,
'install_name_tool -id $DARWIN_INSTALL_NAME $TARGET')
if env['PLATFORM'] == 'posix' and WhereIs('ldconfig'):
opts = ''
if os.getuid() != 0: opts = '-n'
env.AddPostAction(libinstall,
'ldconfig %s $TARGET.dir' % opts)
# link *.dylib -> *.so to allow python import
if env['PLATFORM'] == 'darwin':
for f in libmstruct:
if f.get_suffix()=='.dylib':
link_target = os.path.normpath( os.path.join(env['modulepath'], f.rstr()[:-5]+'so') )
link_source = os.path.normpath( os.path.join(env['libdir'], f.rstr()) )
env.AddPostAction(libinstall, 'rm -f ' + link_target + ' 2>/dev/null')
env.AddPostAction(libinstall, 'ln -s ' + link_source + ' ' + link_target)
# link site-packages/python*/*.so -> *.so to allow python import
if env['PLATFORM'] == 'posix':
for f in libmstruct:
if f.get_suffix()=='.so':
link_target = os.path.normpath( os.path.join(env['modulepath'], f.rstr()) )
link_source = os.path.normpath( os.path.join(env['libdir'], f.rstr()) )
env.AddPostAction(libinstall, 'rm -f ' + link_target + ' 2>/dev/null')
env.AddPostAction(libinstall, 'ln -s ' + link_source + ' ' + link_target)
# runtime dll for Windows
dllinstall = []
if env['PLATFORM'] == 'win32':
dllinstall = env.Install(prefix+'/bin', [f for f in libmstruct if f.get_suffix()=='.dll'])
for f in libmstruct:
if f.get_suffix()=='.dll':
link_source = os.path.normpath( os.path.join(env['modulepath'], f.rstr()[:-3]+'pyd') )
link_target = os.path.normpath( os.path.join(prefix+'/bin', f.rstr()) )
env.AddPostAction(dllinstall, 'del ' + link_source + ' 2>NUL')
env.AddPostAction(dllinstall, 'mklink /H ' + link_source + ' ' + link_target)
Alias('install-lib', libinstall + dllinstall)
# install-bin
if env['PLATFORM'] == 'win32':
bininstall = env.InstallAs(prefix+'/bin/mstruct.exe', binmstruct) + env.InstallAs(prefix+'/bin/mstruct_xml.exe', binxmlmstruct)
else:
bininstall = env.InstallAs(prefix+'/bin/mstruct', binmstruct) + env.InstallAs(prefix+'/bin/mstruct_xml', binxmlmstruct)
Alias('install-bin', bininstall)
# install-python
pyinstall = []
Alias('install-modules', pyinstall)
# install-includes
ninc = len(Dir('.').path) + 1
inc_target_path = lambda f: os.path.join(env['includedir'], f.path[ninc:])
include_targets = [inc_target_path(f) for f in env['lib_includes']]
include_targets = include_targets + [inc_target_path(f) for f in env['libmstruct_includes']]
Alias('install-include', InstallAs(include_targets, env['lib_includes']+ env['libmstruct_includes']))
# install
Alias('install', ['install-lib', 'install-include', 'install-bin','install-modules'])
# vim: ft=python