/[escript]/trunk/site_scons/dependencies.py
ViewVC logotype

Contents of /trunk/site_scons/dependencies.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5435 - (show annotations)
Tue Jan 27 00:15:26 2015 UTC (4 years, 4 months ago) by caltinay
File MIME type: text/x-python
File size: 20147 byte(s)
option 'thrust_prefix' was never used - updated to cuda_prefix and added
detection code. Updated savanna options.

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

  ViewVC Help
Powered by ViewVC 1.1.26