/[escript]/branches/postrelease-csirofixes/site_scons/dependencies.py
ViewVC logotype

Contents of /branches/postrelease-csirofixes/site_scons/dependencies.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4952 - (show annotations)
Tue May 20 03:43:04 2014 UTC (4 years, 11 months ago) by caltinay
File MIME type: text/x-python
File size: 18050 byte(s)
Copy of 3.4.2

1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2014 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22 __url__="https://launchpad.net/escript-finley"
23
24 import os, re, sys
25 from distutils import sysconfig
26 from subprocess import PIPE, Popen
27 from SCons.Script.SConscript import Configure
28 from site_init import findLibWithHeader, detectModule
29
30 def checkCompiler(env):
31 conf = Configure(env.Clone())
32 if 'CheckCXX' in dir(conf): # exists since scons 1.1.0
33 if not conf.CheckCXX():
34 print("Cannot run C++ compiler '%s' (check config.log)" % (env['CXX']))
35 env.Exit(1)
36 else:
37 if not conf.CheckFunc('printf', language='c++'):
38 print("Cannot run C++ compiler '%s' (check config.log)" % (env['CXX']))
39 env.Exit(1)
40
41 conf.env['buildvars']['cxx']=conf.env['CXX']
42
43 if conf.CheckFunc('gethostname', language='c++'):
44 conf.env.Append(CPPDEFINES = ['HAVE_GETHOSTNAME'])
45
46 if conf.CheckCXXHeader('byteswap.h'):
47 conf.env.Append(CPPDEFINES = ['HAVE_BYTESWAP_H'])
48 if conf.CheckCXXHeader('sys/endian.h'):
49 conf.env.Append(CPPDEFINES = ['HAVE_SYS_ENDIAN_H'])
50 if conf.CheckCXXHeader('libkern/OSByteOrder.h'):
51 conf.env.Append(CPPDEFINES = ['HAVE_OSBYTEORDER_H'])
52
53 return conf.Finish()
54
55 def checkPython(env):
56 # First we check to see if the config file has specified
57 # where to find the file. Ideally, this should be automatic
58 # but we need to deal with the case where python is not in its INSTALL
59 # directory.
60 # Use the python scons is running
61 if env['pythoncmd']=='python':
62 python_inc_path=sysconfig.get_python_inc()
63 if env['IS_WINDOWS']:
64 python_lib_path=os.path.join(sysconfig.get_config_var('prefix'), 'libs')
65 elif env['PLATFORM']=='darwin':
66 python_lib_path=sysconfig.get_config_var('LIBPL')
67 else:
68 python_lib_path=sysconfig.get_config_var('LIBDIR')
69
70 #python_libs=[sysconfig.get_config_var('LDLIBRARY')] # only on linux
71 if env['IS_WINDOWS']:
72 python_libs=['python%s%s'%(sys.version_info[0], sys.version_info[1])]
73 else:
74 python_libs=['python'+sysconfig.get_python_version()]
75
76 env['buildvars']['python']=sys.executable
77 env['buildvars']['python_version']=str(sys.version_info[0])+"."+str(sys.version_info[1])+"."+str(sys.version_info[2])
78
79 #if we want to use a python other than the one scons is running
80 else:
81 initstring='from __future__ import print_function;from distutils import sysconfig;'
82 if env['pythonlibname']!='':
83 python_libs=env['pythonlibname']
84 else: # work it out by calling python
85 if ['IS_WINDOWS']:
86 cmd='print("python%s%s"%(sys.version_info[0], sys.version_info[1]))'
87 else:
88 cmd='print("python"+sysconfig.get_python_version())'
89 p=Popen([env['pythoncmd'], '-c', initstring+cmd], stdout=PIPE)
90 python_libs=p.stdout.readline()
91 if env['usepython3']: # This is to convert unicode str into py2 string
92 python_libs=python_libs.encode() # If scons runs on py3 then this must be rethought
93 p.wait()
94 python_libs=python_libs.strip()
95
96 # Now we know whether we are using python3 or not
97 p=Popen([env['pythoncmd'], '-c', initstring+'print(sysconfig.get_python_inc())'], stdout=PIPE)
98 python_inc_path=p.stdout.readline()
99 if env['usepython3']:
100 python_inc_path=python_inc_path.encode()
101 p.wait()
102 python_inc_path=python_inc_path.strip()
103 if env['IS_WINDOWS']:
104 cmd="import os;os.path.join(sysconfig.get_config_var('prefix'), 'libs')"
105 elif env['PLATFORM']=='darwin':
106 cmd="sysconfig.get_config_var(\"LIBPL\")"
107 else:
108 cmd="sysconfig.get_config_var(\"LIBDIR\")"
109
110 p=Popen([env['pythoncmd'], '-c', initstring+'print('+cmd+')'], stdout=PIPE)
111 python_lib_path=p.stdout.readline()
112 if env['usepython3']:
113 python_lib_path=python_lib_path.decode()
114 p.wait()
115 python_lib_path=python_lib_path.strip()
116
117 env['buildvars']['python']=env['pythoncmd']
118 p=Popen([env['pythoncmd'], '-c', 'from __future__ import print_function;import sys;print(str(sys.version_info[0])+"."+str(sys.version_info[1])+"."+str(sys.version_info[2]))'], stdout=PIPE)
119 verstring=p.stdout.readline().strip()
120 p.wait()
121 env['buildvars']['python_version']=verstring
122
123 # Check for an override from the config file.
124 # Ideally, this should be automatic but we need to deal with the case
125 # where python is not in its INSTALL directory
126 if env['pythonlibpath']!='':
127 python_lib_path=env['pythonlibpath']
128
129 if env['pythonincpath']!='':
130 python_inc_path=env['pythonincpath']
131
132 conf = Configure(env.Clone())
133
134 if env['sysheaderopt'] == '':
135 conf.env.AppendUnique(CPPPATH = [python_inc_path])
136 else:
137 conf.env.Append(CCFLAGS = [env['sysheaderopt'], python_inc_path])
138
139 conf.env.AppendUnique(LIBPATH = [python_lib_path])
140 conf.env.AppendUnique(LIBS = python_libs)
141 # The wrapper script needs to find the libs
142 conf.env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], python_lib_path)
143
144 if not conf.CheckCXXHeader('Python.h'):
145 print("Cannot find python include files (tried 'Python.h' in directory %s)" % (python_inc_path))
146 env.Exit(1)
147 if not conf.CheckFunc('Py_Exit', language='c++'):
148 print("Cannot find python library method Py_Main (tried %s in directory %s)" % (python_libs, python_lib_path))
149 env.Exit(1)
150
151 return conf.Finish()
152
153 def checkBoost(env):
154 boost_inc_path,boost_lib_path=findLibWithHeader(env, env['boost_libs'], 'boost/python.hpp', env['boost_prefix'], lang='c++')
155 if env['sysheaderopt'] == '':
156 env.AppendUnique(CPPPATH = [boost_inc_path])
157 else:
158 # This is required because we can't -isystem /usr/include since it
159 # breaks std includes
160 if os.path.normpath(boost_inc_path) == '/usr/include':
161 env.Append(CCFLAGS=[env['sysheaderopt'], os.path.join(boost_inc_path,'boost')])
162 else:
163 env.Append(CCFLAGS=[env['sysheaderopt'], boost_inc_path])
164
165 env.AppendUnique(LIBPATH = [boost_lib_path])
166 env.AppendUnique(LIBS = env['boost_libs'])
167 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], boost_lib_path)
168
169 # Try to extract the boost version from version.hpp
170 boosthpp=open(os.path.join(boost_inc_path, 'boost', 'version.hpp'))
171 boostversion='unknown'
172 try:
173 for line in boosthpp:
174 ver=re.match(r'#define BOOST_VERSION (\d+)',line)
175 if ver:
176 boostversion=ver.group(1)
177 except StopIteration:
178 pass
179 boosthpp.close()
180 env['buildvars']['boost_inc_path']=boost_inc_path
181 env['buildvars']['boost_lib_path']=boost_lib_path
182 env['buildvars']['boostversion']=boostversion
183 return env
184
185 def checkNumpy(env):
186 if not detectModule(env, 'numpy'):
187 print("Cannot import numpy. If it is installed try setting your PYTHONPATH and probably %s"%env['LD_LIBRARY_PATH_KEY'])
188 env.Exit(1)
189
190 ## check for numpy header (optional)
191 conf = Configure(env.Clone())
192 if env['usepython3']:
193 # FIXME: This is until we can work out how to make the checks in python 3
194 conf.env['numpy_h']=False
195 else:
196 if conf.CheckCXXHeader(['Python.h','numpy/ndarrayobject.h']):
197 conf.env.Append(CPPDEFINES = ['HAVE_NUMPY_H'])
198 conf.env['numpy_h']=True
199 else:
200 conf.env['numpy_h']=False
201
202 return conf.Finish()
203
204 def checkCppUnit(env):
205 try:
206 cppunit_inc_path,cppunit_lib_path=findLibWithHeader(env, env['cppunit_libs'], 'cppunit/TestFixture.h', env['cppunit_prefix'], lang='c++')
207 env.AppendUnique(CPPPATH = [cppunit_inc_path])
208 env.AppendUnique(LIBPATH = [cppunit_lib_path])
209 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], cppunit_lib_path)
210 env['cppunit']=True
211 except:
212 env['cppunit']=False
213 return env
214
215 def checkOptionalModules(env):
216 ######## scipy
217 if not detectModule(env, 'scipy'):
218 env['warnings'].append("Cannot import scipy. NetCDF sources will not be available for inversions.")
219
220 ######## sympy
221 if not detectModule(env, 'sympy'):
222 env['warnings'].append("Cannot import sympy. Symbolic toolbox and nonlinear PDEs will not be available.")
223 else:
224 import sympy as sp
225 spVer=sp.__version__
226 spl=spVer.split('.')
227 if int(spl[0]) == 0 and int(spl[1]) < 7:
228 env['sympy']=False
229 env['warnings'].append("sympy version too old. Symbolic toolbox and nonlinear PDEs will not be available.")
230 ######## pyproj
231 if not detectModule(env, 'pyproj'):
232 env['warnings'].append("Cannot import pyproj. Inversions may not work.")
233
234 ######## gdal
235 if not detectModule(env, 'gdal'):
236 env['warnings'].append("Cannot import gdal. Inversions will not honour WKT coordinate system information.")
237
238 return env
239
240 def checkOptionalLibraries(env):
241 ######## netCDF
242 netcdf_inc_path=''
243 netcdf_lib_path=''
244 if env['netcdf']:
245 netcdf_inc_path,netcdf_lib_path=findLibWithHeader(env, env['netcdf_libs'], 'netcdf.h', env['netcdf_prefix'], lang='c++')
246 env.AppendUnique(CPPPATH = [netcdf_inc_path])
247 env.AppendUnique(LIBPATH = [netcdf_lib_path])
248 env.AppendUnique(LIBS = env['netcdf_libs'])
249 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], netcdf_lib_path)
250 env.Append(CPPDEFINES = ['USE_NETCDF'])
251 env['buildvars']['netcdf_inc_path']=netcdf_inc_path
252 env['buildvars']['netcdf_lib_path']=netcdf_lib_path
253 env['buildvars']['netcdf']=int(env['netcdf'])
254
255 ######## PAPI
256 papi_inc_path=''
257 papi_lib_path=''
258 if env['papi']:
259 papi_inc_path,papi_lib_path=findLibWithHeader(env, env['papi_libs'], 'papi.h', env['papi_prefix'], lang='c++')
260 env.AppendUnique(CPPPATH = [papi_inc_path])
261 env.AppendUnique(LIBPATH = [papi_lib_path])
262 env.AppendUnique(LIBS = env['papi_libs'])
263 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], papi_lib_path)
264 env.Append(CPPDEFINES = ['PAPI'])
265 env['buildvars']['papi_inc_path']=papi_inc_path
266 env['buildvars']['papi_lib_path']=papi_lib_path
267 env['buildvars']['papi']=int(env['papi'])
268
269 ######## MKL
270 mkl_inc_path=''
271 mkl_lib_path=''
272 if env['mkl']:
273 mkl_inc_path,mkl_lib_path=findLibWithHeader(env, env['mkl_libs'], 'mkl_solver.h', env['mkl_prefix'], lang='c++')
274 env.AppendUnique(CPPPATH = [mkl_inc_path])
275 env.AppendUnique(LIBPATH = [mkl_lib_path])
276 env.AppendUnique(LIBS = env['mkl_libs'])
277 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], mkl_lib_path)
278 env.Append(CPPDEFINES = ['MKL'])
279 env['buildvars']['mkl_inc_path']=mkl_inc_path
280 env['buildvars']['mkl_lib_path']=mkl_lib_path
281 env['buildvars']['mkl']=int(env['mkl'])
282
283 ######## UMFPACK
284 umfpack_inc_path=''
285 umfpack_lib_path=''
286 if env['umfpack']:
287 umfpack_inc_path,umfpack_lib_path=findLibWithHeader(env, env['umfpack_libs'], 'umfpack.h', env['umfpack_prefix'], lang='c++')
288 env.AppendUnique(CPPPATH = [umfpack_inc_path])
289 env.AppendUnique(LIBPATH = [umfpack_lib_path])
290 env.AppendUnique(LIBS = env['umfpack_libs'])
291 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], umfpack_lib_path)
292 env.Append(CPPDEFINES = ['UMFPACK'])
293 env['buildvars']['umfpack_inc_path']=umfpack_inc_path
294 env['buildvars']['umfpack_lib_path']=umfpack_lib_path
295 env['buildvars']['umfpack']=int(env['umfpack'])
296
297 ######## LAPACK
298 if env['lapack']=='mkl' and not env['mkl']:
299 print("mkl_lapack requires MKL!")
300 env.Exit(1)
301
302 env['uselapack'] = env['lapack']!='none'
303 lapack_inc_path=''
304 lapack_lib_path=''
305 if env['uselapack']:
306 header='clapack.h'
307 if env['lapack']=='mkl':
308 env.AppendUnique(CPPDEFINES = ['MKL_LAPACK'])
309 header='mkl_lapack.h'
310 lapack_inc_path,lapack_lib_path=findLibWithHeader(env, env['lapack_libs'], header, env['lapack_prefix'], lang='c++')
311 env.AppendUnique(CPPPATH = [lapack_inc_path])
312 env.AppendUnique(LIBPATH = [lapack_lib_path])
313 env.AppendUnique(LIBS = env['lapack_libs'])
314 env.Append(CPPDEFINES = ['USE_LAPACK'])
315 env['buildvars']['lapack_inc_path']=lapack_inc_path
316 env['buildvars']['lapack_lib_path']=lapack_lib_path
317 env['buildvars']['lapack']=env['lapack']
318
319 ######## Silo
320 silo_inc_path=''
321 silo_lib_path=''
322 if env['silo']:
323 silo_inc_path,silo_lib_path=findLibWithHeader(env, env['silo_libs'], 'silo.h', env['silo_prefix'], lang='c++')
324 env.AppendUnique(CPPPATH = [silo_inc_path])
325 env.AppendUnique(LIBPATH = [silo_lib_path])
326 # Note that we do not add the libs since they are only needed for the
327 # weipa library and tools.
328 #env.AppendUnique(LIBS = [env['silo_libs']])
329 env['buildvars']['silo_inc_path']=silo_inc_path
330 env['buildvars']['silo_lib_path']=silo_lib_path
331 env['buildvars']['silo']=int(env['silo'])
332
333 ######## VisIt
334 visit_inc_path=''
335 visit_lib_path=''
336 if env['visit']:
337 visit_inc_path,visit_lib_path=findLibWithHeader(env, env['visit_libs'], 'VisItControlInterface_V2.h', env['visit_prefix'], lang='c++')
338 env.AppendUnique(CPPPATH = [visit_inc_path])
339 env.AppendUnique(LIBPATH = [visit_lib_path])
340 env['buildvars']['visit_inc_path']=visit_inc_path
341 env['buildvars']['visit_lib_path']=visit_lib_path
342 env['buildvars']['visit']=int(env['visit'])
343
344 ######## MPI
345 if env['mpi']=='no':
346 env['mpi']='none'
347
348 env['usempi'] = env['mpi']!='none'
349 mpi_inc_path=''
350 mpi_lib_path=''
351 if env['usempi']:
352 mpi_inc_path,mpi_lib_path=findLibWithHeader(env, env['mpi_libs'], 'mpi.h', env['mpi_prefix'], lang='c++')
353 env.AppendUnique(CPPPATH = [mpi_inc_path])
354 env.AppendUnique(LIBPATH = [mpi_lib_path])
355 env.AppendUnique(LIBS = env['mpi_libs'])
356 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], mpi_lib_path)
357 env.Append(CPPDEFINES = ['ESYS_MPI', 'MPI_NO_CPPBIND', 'MPICH_IGNORE_CXX_SEEK'])
358 # NetCDF 4.1 defines MPI_Comm et al. if MPI_INCLUDED is not defined!
359 # On the other hand MPT and OpenMPI don't define the latter so we have
360 # to do that here
361 if env['netcdf'] and env['mpi'] in ['MPT','OPENMPI']:
362 env.Append(CPPDEFINES = ['MPI_INCLUDED'])
363 env['buildvars']['mpi_inc_path']=mpi_inc_path
364 env['buildvars']['mpi_lib_path']=mpi_lib_path
365 env['buildvars']['mpi']=env['mpi']
366
367 ######## BOOMERAMG
368 if env['mpi'] == 'none': env['boomeramg'] = False
369 boomeramg_inc_path=''
370 boomeramg_lib_path=''
371 if env['boomeramg']:
372 boomeramg_inc_path,boomeramg_lib_path=findLibWithHeader(env, env['boomeramg_libs'], 'HYPRE.h', env['boomeramg_prefix'], lang='c++')
373 env.AppendUnique(CPPPATH = [boomeramg_inc_path])
374 env.AppendUnique(LIBPATH = [boomeramg_lib_path])
375 env.AppendUnique(LIBS = env['boomeramg_libs'])
376 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], boomeramg_lib_path)
377 env.Append(CPPDEFINES = ['BOOMERAMG'])
378 env['buildvars']['boomeramg_inc_path']=boomeramg_inc_path
379 env['buildvars']['boomeramg_lib_path']=boomeramg_lib_path
380 env['buildvars']['boomeramg']=int(env['boomeramg'])
381
382 ######## ParMETIS
383 if not env['usempi']: env['parmetis'] = False
384 parmetis_inc_path=''
385 parmetis_lib_path=''
386 if env['parmetis']:
387 parmetis_inc_path,parmetis_lib_path=findLibWithHeader(env, env['parmetis_libs'], 'parmetis.h', env['parmetis_prefix'], lang='c++')
388 env.AppendUnique(CPPPATH = [parmetis_inc_path])
389 env.AppendUnique(LIBPATH = [parmetis_lib_path])
390 env.AppendUnique(LIBS = env['parmetis_libs'])
391 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], parmetis_lib_path)
392 env.Append(CPPDEFINES = ['USE_PARMETIS'])
393 env['buildvars']['parmetis_inc_path']=parmetis_inc_path
394 env['buildvars']['parmetis_lib_path']=parmetis_lib_path
395 env['buildvars']['parmetis']=int(env['parmetis'])
396
397 ######## gmsh (for tests)
398 try:
399 p=Popen(['gmsh', '-info'], stderr=PIPE)
400 _,e=p.communicate()
401 if e.split().count("MPI"):
402 env['gmsh']='m'
403 else:
404 env['gmsh']='s'
405 except OSError:
406 env['gmsh']=False
407
408
409 ######## boost::iostreams
410 if env['compressed_files']:
411 try:
412 boost_inc_path, boost_lib_path = findLibWithHeader(env, env['compression_libs'], 'boost/iostreams/filter/gzip.hpp', env['boost_prefix'], lang='c++')
413 env.Append(CPPDEFINES = ['USE_BOOSTIO'])
414 env.AppendUnique(LIBS = env['compression_libs'])
415 except RuntimeError as e:
416 env['compressed_files'] = False
417 env['buildvars']['compressed_files']=int(env['compressed_files'])
418
419 return env
420
421 def checkPDFLatex(env):
422 if 'PDF' in dir(env) and '.tex' in env.PDF.builder.src_suffixes(env):
423 env['pdflatex']=True
424 else:
425 env['pdflatex']=False
426 return env
427
428

  ViewVC Help
Powered by ViewVC 1.1.26