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

Annotation of /trunk/site_scons/dependencies.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5148 - (hide annotations)
Mon Sep 15 01:25:23 2014 UTC (5 years ago) by caltinay
File MIME type: text/x-python
File size: 19003 byte(s)
Merging ripley diagonal storage + CUDA support into trunk.
Options file version has been incremented due to new options
'cuda' and 'nvccflags'.

1 caltinay 4295
2     ##############################################################################
3     #
4 jfenwick 4657 # Copyright (c) 2003-2014 by University of Queensland
5 caltinay 4295 # 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 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
13     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 caltinay 4295 #
15     ##############################################################################
16    
17 jfenwick 4657 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
18 caltinay 4295 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 sshaw 4947 REQUIRED_BOOST = (1, 46)
31    
32 caltinay 4295 def checkCompiler(env):
33     conf = Configure(env.Clone())
34 caltinay 4520 if 'CheckCXX' in dir(conf): # exists since scons 1.1.0
35 caltinay 4295 if not conf.CheckCXX():
36     print("Cannot run C++ compiler '%s' (check config.log)" % (env['CXX']))
37 jfenwick 4323 env.Exit(1)
38 caltinay 4295 else:
39     if not conf.CheckFunc('printf', language='c++'):
40     print("Cannot run C++ compiler '%s' (check config.log)" % (env['CXX']))
41 jfenwick 4323 env.Exit(1)
42 caltinay 4295
43     conf.env['buildvars']['cxx']=conf.env['CXX']
44    
45 caltinay 4520 if conf.CheckFunc('gethostname', language='c++'):
46 caltinay 4295 conf.env.Append(CPPDEFINES = ['HAVE_GETHOSTNAME'])
47    
48 caltinay 4520 if conf.CheckCXXHeader('byteswap.h'):
49 caltinay 5018 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 caltinay 4520 if conf.CheckCXXHeader('sys/endian.h'):
54 caltinay 4337 conf.env.Append(CPPDEFINES = ['HAVE_SYS_ENDIAN_H'])
55 caltinay 4520 if conf.CheckCXXHeader('libkern/OSByteOrder.h'):
56 caltinay 4337 conf.env.Append(CPPDEFINES = ['HAVE_OSBYTEORDER_H'])
57    
58 caltinay 4295 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 caltinay 4419 else: # work it out by calling python
90 caltinay 4295 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 caltinay 4419 p.wait()
107 caltinay 4295 python_inc_path=python_inc_path.strip()
108 caltinay 4419 if env['IS_WINDOWS']:
109     cmd="import os;os.path.join(sysconfig.get_config_var('prefix'), 'libs')"
110 caltinay 4295 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 caltinay 4520 if not conf.CheckCXXHeader('Python.h'):
150 caltinay 4295 print("Cannot find python include files (tried 'Python.h' in directory %s)" % (python_inc_path))
151 jfenwick 4323 env.Exit(1)
152 caltinay 4520 if not conf.CheckFunc('Py_Exit', language='c++'):
153 caltinay 4295 print("Cannot find python library method Py_Main (tried %s in directory %s)" % (python_libs, python_lib_path))
154 jfenwick 4323 env.Exit(1)
155 caltinay 4295
156     return conf.Finish()
157    
158 caltinay 5148 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 caltinay 4295 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 sshaw 4947 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 caltinay 4295 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 jfenwick 4323 env.Exit(1)
211 caltinay 4295
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 checkCppUnit(env):
227     try:
228     cppunit_inc_path,cppunit_lib_path=findLibWithHeader(env, env['cppunit_libs'], 'cppunit/TestFixture.h', env['cppunit_prefix'], lang='c++')
229     env.AppendUnique(CPPPATH = [cppunit_inc_path])
230     env.AppendUnique(LIBPATH = [cppunit_lib_path])
231     env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], cppunit_lib_path)
232     env['cppunit']=True
233     except:
234     env['cppunit']=False
235     return env
236    
237     def checkOptionalModules(env):
238 caltinay 4300 ######## scipy
239     if not detectModule(env, 'scipy'):
240     env['warnings'].append("Cannot import scipy. NetCDF sources will not be available for inversions.")
241    
242 caltinay 4295 ######## sympy
243     if not detectModule(env, 'sympy'):
244 caltinay 4299 env['warnings'].append("Cannot import sympy. Symbolic toolbox and nonlinear PDEs will not be available.")
245 jduplessis 4897 else:
246     import sympy as sp
247     spVer=sp.__version__
248     spl=spVer.split('.')
249 jduplessis 4900 if int(spl[0]) == 0 and int(spl[1]) < 7:
250 jduplessis 4897 env['sympy']=False
251     env['warnings'].append("sympy version too old. Symbolic toolbox and nonlinear PDEs will not be available.")
252 caltinay 4295 ######## pyproj
253     if not detectModule(env, 'pyproj'):
254 caltinay 4299 env['warnings'].append("Cannot import pyproj. Inversions may not work.")
255    
256     ######## gdal
257     if not detectModule(env, 'gdal'):
258     env['warnings'].append("Cannot import gdal. Inversions will not honour WKT coordinate system information.")
259    
260 caltinay 4295 return env
261    
262     def checkOptionalLibraries(env):
263     ######## netCDF
264     netcdf_inc_path=''
265     netcdf_lib_path=''
266     if env['netcdf']:
267     netcdf_inc_path,netcdf_lib_path=findLibWithHeader(env, env['netcdf_libs'], 'netcdf.h', env['netcdf_prefix'], lang='c++')
268     env.AppendUnique(CPPPATH = [netcdf_inc_path])
269     env.AppendUnique(LIBPATH = [netcdf_lib_path])
270     env.AppendUnique(LIBS = env['netcdf_libs'])
271     env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], netcdf_lib_path)
272     env.Append(CPPDEFINES = ['USE_NETCDF'])
273     env['buildvars']['netcdf_inc_path']=netcdf_inc_path
274     env['buildvars']['netcdf_lib_path']=netcdf_lib_path
275     env['buildvars']['netcdf']=int(env['netcdf'])
276    
277     ######## PAPI
278     papi_inc_path=''
279     papi_lib_path=''
280     if env['papi']:
281 caltinay 4520 papi_inc_path,papi_lib_path=findLibWithHeader(env, env['papi_libs'], 'papi.h', env['papi_prefix'], lang='c++')
282 caltinay 4295 env.AppendUnique(CPPPATH = [papi_inc_path])
283     env.AppendUnique(LIBPATH = [papi_lib_path])
284     env.AppendUnique(LIBS = env['papi_libs'])
285     env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], papi_lib_path)
286 caltinay 4870 env.Append(CPPDEFINES = ['PAPI'])
287 caltinay 4295 env['buildvars']['papi_inc_path']=papi_inc_path
288     env['buildvars']['papi_lib_path']=papi_lib_path
289     env['buildvars']['papi']=int(env['papi'])
290    
291     ######## MKL
292     mkl_inc_path=''
293     mkl_lib_path=''
294     if env['mkl']:
295 caltinay 4520 mkl_inc_path,mkl_lib_path=findLibWithHeader(env, env['mkl_libs'], 'mkl_solver.h', env['mkl_prefix'], lang='c++')
296 caltinay 4295 env.AppendUnique(CPPPATH = [mkl_inc_path])
297     env.AppendUnique(LIBPATH = [mkl_lib_path])
298     env.AppendUnique(LIBS = env['mkl_libs'])
299     env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], mkl_lib_path)
300     env.Append(CPPDEFINES = ['MKL'])
301     env['buildvars']['mkl_inc_path']=mkl_inc_path
302     env['buildvars']['mkl_lib_path']=mkl_lib_path
303     env['buildvars']['mkl']=int(env['mkl'])
304    
305     ######## UMFPACK
306     umfpack_inc_path=''
307     umfpack_lib_path=''
308     if env['umfpack']:
309 caltinay 4520 umfpack_inc_path,umfpack_lib_path=findLibWithHeader(env, env['umfpack_libs'], 'umfpack.h', env['umfpack_prefix'], lang='c++')
310 caltinay 4295 env.AppendUnique(CPPPATH = [umfpack_inc_path])
311     env.AppendUnique(LIBPATH = [umfpack_lib_path])
312     env.AppendUnique(LIBS = env['umfpack_libs'])
313     env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], umfpack_lib_path)
314     env.Append(CPPDEFINES = ['UMFPACK'])
315     env['buildvars']['umfpack_inc_path']=umfpack_inc_path
316     env['buildvars']['umfpack_lib_path']=umfpack_lib_path
317     env['buildvars']['umfpack']=int(env['umfpack'])
318    
319     ######## LAPACK
320     if env['lapack']=='mkl' and not env['mkl']:
321     print("mkl_lapack requires MKL!")
322 jfenwick 4323 env.Exit(1)
323 caltinay 4295
324     env['uselapack'] = env['lapack']!='none'
325     lapack_inc_path=''
326     lapack_lib_path=''
327     if env['uselapack']:
328     header='clapack.h'
329     if env['lapack']=='mkl':
330     env.AppendUnique(CPPDEFINES = ['MKL_LAPACK'])
331     header='mkl_lapack.h'
332 caltinay 4520 lapack_inc_path,lapack_lib_path=findLibWithHeader(env, env['lapack_libs'], header, env['lapack_prefix'], lang='c++')
333 caltinay 4295 env.AppendUnique(CPPPATH = [lapack_inc_path])
334     env.AppendUnique(LIBPATH = [lapack_lib_path])
335     env.AppendUnique(LIBS = env['lapack_libs'])
336     env.Append(CPPDEFINES = ['USE_LAPACK'])
337     env['buildvars']['lapack_inc_path']=lapack_inc_path
338     env['buildvars']['lapack_lib_path']=lapack_lib_path
339     env['buildvars']['lapack']=env['lapack']
340    
341     ######## Silo
342     silo_inc_path=''
343     silo_lib_path=''
344     if env['silo']:
345 caltinay 4520 silo_inc_path,silo_lib_path=findLibWithHeader(env, env['silo_libs'], 'silo.h', env['silo_prefix'], lang='c++')
346 caltinay 4295 env.AppendUnique(CPPPATH = [silo_inc_path])
347     env.AppendUnique(LIBPATH = [silo_lib_path])
348     # Note that we do not add the libs since they are only needed for the
349     # weipa library and tools.
350     #env.AppendUnique(LIBS = [env['silo_libs']])
351     env['buildvars']['silo_inc_path']=silo_inc_path
352     env['buildvars']['silo_lib_path']=silo_lib_path
353     env['buildvars']['silo']=int(env['silo'])
354    
355     ######## VisIt
356     visit_inc_path=''
357     visit_lib_path=''
358     if env['visit']:
359 caltinay 4520 visit_inc_path,visit_lib_path=findLibWithHeader(env, env['visit_libs'], 'VisItControlInterface_V2.h', env['visit_prefix'], lang='c++')
360 caltinay 4295 env.AppendUnique(CPPPATH = [visit_inc_path])
361     env.AppendUnique(LIBPATH = [visit_lib_path])
362     env['buildvars']['visit_inc_path']=visit_inc_path
363     env['buildvars']['visit_lib_path']=visit_lib_path
364     env['buildvars']['visit']=int(env['visit'])
365    
366     ######## MPI
367     if env['mpi']=='no':
368     env['mpi']='none'
369    
370     env['usempi'] = env['mpi']!='none'
371     mpi_inc_path=''
372     mpi_lib_path=''
373     if env['usempi']:
374 caltinay 4520 mpi_inc_path,mpi_lib_path=findLibWithHeader(env, env['mpi_libs'], 'mpi.h', env['mpi_prefix'], lang='c++')
375 caltinay 4295 env.AppendUnique(CPPPATH = [mpi_inc_path])
376     env.AppendUnique(LIBPATH = [mpi_lib_path])
377     env.AppendUnique(LIBS = env['mpi_libs'])
378     env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], mpi_lib_path)
379     env.Append(CPPDEFINES = ['ESYS_MPI', 'MPI_NO_CPPBIND', 'MPICH_IGNORE_CXX_SEEK'])
380     # NetCDF 4.1 defines MPI_Comm et al. if MPI_INCLUDED is not defined!
381     # On the other hand MPT and OpenMPI don't define the latter so we have
382     # to do that here
383     if env['netcdf'] and env['mpi'] in ['MPT','OPENMPI']:
384     env.Append(CPPDEFINES = ['MPI_INCLUDED'])
385 caltinay 4296 env['buildvars']['mpi_inc_path']=mpi_inc_path
386     env['buildvars']['mpi_lib_path']=mpi_lib_path
387     env['buildvars']['mpi']=env['mpi']
388 caltinay 4295
389     ######## BOOMERAMG
390     if env['mpi'] == 'none': env['boomeramg'] = False
391     boomeramg_inc_path=''
392     boomeramg_lib_path=''
393     if env['boomeramg']:
394 caltinay 4520 boomeramg_inc_path,boomeramg_lib_path=findLibWithHeader(env, env['boomeramg_libs'], 'HYPRE.h', env['boomeramg_prefix'], lang='c++')
395 caltinay 4295 env.AppendUnique(CPPPATH = [boomeramg_inc_path])
396     env.AppendUnique(LIBPATH = [boomeramg_lib_path])
397     env.AppendUnique(LIBS = env['boomeramg_libs'])
398     env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], boomeramg_lib_path)
399     env.Append(CPPDEFINES = ['BOOMERAMG'])
400     env['buildvars']['boomeramg_inc_path']=boomeramg_inc_path
401     env['buildvars']['boomeramg_lib_path']=boomeramg_lib_path
402     env['buildvars']['boomeramg']=int(env['boomeramg'])
403    
404     ######## ParMETIS
405     if not env['usempi']: env['parmetis'] = False
406     parmetis_inc_path=''
407     parmetis_lib_path=''
408     if env['parmetis']:
409 caltinay 4520 parmetis_inc_path,parmetis_lib_path=findLibWithHeader(env, env['parmetis_libs'], 'parmetis.h', env['parmetis_prefix'], lang='c++')
410 caltinay 4295 env.AppendUnique(CPPPATH = [parmetis_inc_path])
411     env.AppendUnique(LIBPATH = [parmetis_lib_path])
412     env.AppendUnique(LIBS = env['parmetis_libs'])
413     env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], parmetis_lib_path)
414     env.Append(CPPDEFINES = ['USE_PARMETIS'])
415     env['buildvars']['parmetis_inc_path']=parmetis_inc_path
416     env['buildvars']['parmetis_lib_path']=parmetis_lib_path
417     env['buildvars']['parmetis']=int(env['parmetis'])
418    
419     ######## gmsh (for tests)
420     try:
421     p=Popen(['gmsh', '-info'], stderr=PIPE)
422     _,e=p.communicate()
423     if e.split().count("MPI"):
424     env['gmsh']='m'
425     else:
426     env['gmsh']='s'
427     except OSError:
428     env['gmsh']=False
429 sshaw 4738
430    
431     ######## boost::iostreams
432     if env['compressed_files']:
433     try:
434     boost_inc_path, boost_lib_path = findLibWithHeader(env, env['compression_libs'], 'boost/iostreams/filter/gzip.hpp', env['boost_prefix'], lang='c++')
435     env.Append(CPPDEFINES = ['USE_BOOSTIO'])
436     env.AppendUnique(LIBS = env['compression_libs'])
437     except RuntimeError as e:
438     env['compressed_files'] = False
439 sshaw 4740 env['buildvars']['compressed_files']=int(env['compressed_files'])
440 sshaw 4738
441 caltinay 4295 return env
442    
443     def checkPDFLatex(env):
444     if 'PDF' in dir(env) and '.tex' in env.PDF.builder.src_suffixes(env):
445     env['pdflatex']=True
446     else:
447     env['pdflatex']=False
448     return env
449    
450    

  ViewVC Help
Powered by ViewVC 1.1.26