/[escript]/branches/4.0fordebian/site_scons/dependencies.py
ViewVC logotype

Contents of /branches/4.0fordebian/site_scons/dependencies.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5566 - (show annotations)
Fri Mar 27 00:35:24 2015 UTC (4 years, 1 month ago) by jfenwick
File MIME type: text/x-python
File size: 19744 byte(s)
Branch for changes dealing with hopefully debian packaging.

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 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 ######## scipy
239 if not detectModule(env, 'scipy'):
240 env['warnings'].append("Cannot import scipy. NetCDF sources will not be available for inversions.")
241
242 ######## pyproj
243 if not detectModule(env, 'pyproj'):
244 env['warnings'].append("Cannot import pyproj. Inversions may not work.")
245
246 ######## gdal
247 if not detectModule(env, 'gdal'):
248 env['warnings'].append("Cannot import gdal. Inversions will not honour WKT coordinate system information.")
249
250 ######## sympy
251 if not detectModule(env, 'sympy'):
252 env['warnings'].append("Cannot import sympy. Symbolic toolbox and nonlinear PDEs will not be available.")
253 else:
254 import sympy as sp
255 spVer=sp.__version__
256 spl=spVer.split('.')
257 if int(spl[0]) == 0 and int(spl[1]) < 7:
258 env['sympy']=False
259 env['warnings'].append("sympy version too old. Symbolic toolbox and nonlinear PDEs will not be available.")
260
261 ######## gmshpy
262 env['gmshpy'] = detectModule(env, 'gmshpy')
263
264 return env
265
266 def checkOptionalLibraries(env):
267 ######## netCDF
268 netcdf_inc_path=''
269 netcdf_lib_path=''
270 if env['netcdf']:
271 netcdf_inc_path,netcdf_lib_path=findLibWithHeader(env, env['netcdf_libs'], 'netcdf.h', env['netcdf_prefix'], lang='c++')
272 env.AppendUnique(CPPPATH = [netcdf_inc_path])
273 env.AppendUnique(LIBPATH = [netcdf_lib_path])
274 env.AppendUnique(LIBS = env['netcdf_libs'])
275 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], netcdf_lib_path)
276 env.Append(CPPDEFINES = ['USE_NETCDF'])
277 env['buildvars']['netcdf_inc_path']=netcdf_inc_path
278 env['buildvars']['netcdf_lib_path']=netcdf_lib_path
279 env['buildvars']['netcdf']=int(env['netcdf'])
280
281 ######## PAPI
282 papi_inc_path=''
283 papi_lib_path=''
284 if env['papi']:
285 papi_inc_path,papi_lib_path=findLibWithHeader(env, env['papi_libs'], 'papi.h', env['papi_prefix'], lang='c++')
286 env.AppendUnique(CPPPATH = [papi_inc_path])
287 env.AppendUnique(LIBPATH = [papi_lib_path])
288 env.AppendUnique(LIBS = env['papi_libs'])
289 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], papi_lib_path)
290 env.Append(CPPDEFINES = ['PAPI'])
291 env['buildvars']['papi_inc_path']=papi_inc_path
292 env['buildvars']['papi_lib_path']=papi_lib_path
293 env['buildvars']['papi']=int(env['papi'])
294
295 ######## MKL
296 mkl_inc_path=''
297 mkl_lib_path=''
298 if env['mkl']:
299 mkl_inc_path,mkl_lib_path=findLibWithHeader(env, env['mkl_libs'], 'mkl_solver.h', env['mkl_prefix'], lang='c++')
300 env.AppendUnique(CPPPATH = [mkl_inc_path])
301 env.AppendUnique(LIBPATH = [mkl_lib_path])
302 env.AppendUnique(LIBS = env['mkl_libs'])
303 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], mkl_lib_path)
304 env.Append(CPPDEFINES = ['MKL'])
305 env['buildvars']['mkl_inc_path']=mkl_inc_path
306 env['buildvars']['mkl_lib_path']=mkl_lib_path
307 env['buildvars']['mkl']=int(env['mkl'])
308
309 ######## UMFPACK
310 umfpack_inc_path=''
311 umfpack_lib_path=''
312 if env['umfpack']:
313 umfpack_inc_path,umfpack_lib_path=findLibWithHeader(env, env['umfpack_libs'], 'umfpack.h', env['umfpack_prefix'], lang='c++')
314 env.AppendUnique(CPPPATH = [umfpack_inc_path])
315 env.AppendUnique(LIBPATH = [umfpack_lib_path])
316 env.AppendUnique(LIBS = env['umfpack_libs'])
317 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], umfpack_lib_path)
318 env.Append(CPPDEFINES = ['USE_UMFPACK'])
319 env['buildvars']['umfpack_inc_path']=umfpack_inc_path
320 env['buildvars']['umfpack_lib_path']=umfpack_lib_path
321 env['buildvars']['umfpack']=int(env['umfpack'])
322
323 ######## LAPACK
324 if env['lapack']=='mkl' and not env['mkl']:
325 print("mkl_lapack requires MKL!")
326 env.Exit(1)
327
328 env['uselapack'] = env['lapack']!='none'
329 lapack_inc_path=''
330 lapack_lib_path=''
331 if env['uselapack']:
332 header='clapack.h'
333 if env['lapack']=='mkl':
334 env.AppendUnique(CPPDEFINES = ['MKL_LAPACK'])
335 header='mkl_lapack.h'
336 lapack_inc_path,lapack_lib_path=findLibWithHeader(env, env['lapack_libs'], header, env['lapack_prefix'], lang='c++')
337 env.AppendUnique(CPPPATH = [lapack_inc_path])
338 env.AppendUnique(LIBPATH = [lapack_lib_path])
339 env.AppendUnique(LIBS = env['lapack_libs'])
340 env.Append(CPPDEFINES = ['USE_LAPACK'])
341 env['buildvars']['lapack_inc_path']=lapack_inc_path
342 env['buildvars']['lapack_lib_path']=lapack_lib_path
343 env['buildvars']['lapack']=env['lapack']
344
345 ######## Silo
346 silo_inc_path=''
347 silo_lib_path=''
348 if env['silo']:
349 silo_inc_path,silo_lib_path=findLibWithHeader(env, env['silo_libs'], 'silo.h', env['silo_prefix'], lang='c++')
350 env.AppendUnique(CPPPATH = [silo_inc_path])
351 env.AppendUnique(LIBPATH = [silo_lib_path])
352 # Note that we do not add the libs since they are only needed for the
353 # weipa library and tools.
354 #env.AppendUnique(LIBS = [env['silo_libs']])
355 env['buildvars']['silo_inc_path']=silo_inc_path
356 env['buildvars']['silo_lib_path']=silo_lib_path
357 env['buildvars']['silo']=int(env['silo'])
358
359 ######## VisIt
360 visit_inc_path=''
361 visit_lib_path=''
362 if env['visit']:
363 visit_inc_path,visit_lib_path=findLibWithHeader(env, env['visit_libs'], 'VisItControlInterface_V2.h', env['visit_prefix'], lang='c++')
364 env.AppendUnique(CPPPATH = [visit_inc_path])
365 env.AppendUnique(LIBPATH = [visit_lib_path])
366 env['buildvars']['visit_inc_path']=visit_inc_path
367 env['buildvars']['visit_lib_path']=visit_lib_path
368 env['buildvars']['visit']=int(env['visit'])
369
370 ######## MPI
371 if env['mpi']=='no':
372 env['mpi']='none'
373
374 env['usempi'] = env['mpi']!='none'
375 mpi_inc_path=''
376 mpi_lib_path=''
377 if env['usempi']:
378 mpi_inc_path,mpi_lib_path=findLibWithHeader(env, env['mpi_libs'], 'mpi.h', env['mpi_prefix'], lang='c++')
379 env.AppendUnique(CPPPATH = [mpi_inc_path])
380 env.AppendUnique(LIBPATH = [mpi_lib_path])
381 env.AppendUnique(LIBS = env['mpi_libs'])
382 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], mpi_lib_path)
383 env.Append(CPPDEFINES = ['ESYS_MPI', 'MPI_NO_CPPBIND', 'MPICH_IGNORE_CXX_SEEK'])
384 # NetCDF 4.1 defines MPI_Comm et al. if MPI_INCLUDED is not defined!
385 # On the other hand MPT and OpenMPI don't define the latter so we have
386 # to do that here
387 if env['netcdf'] and env['mpi'] in ['MPT','OPENMPI']:
388 env.Append(CPPDEFINES = ['MPI_INCLUDED'])
389 env['buildvars']['mpi_inc_path']=mpi_inc_path
390 env['buildvars']['mpi_lib_path']=mpi_lib_path
391 env['buildvars']['mpi']=env['mpi']
392
393 ######## BOOMERAMG
394 if env['mpi'] == 'none': env['boomeramg'] = False
395 boomeramg_inc_path=''
396 boomeramg_lib_path=''
397 if env['boomeramg']:
398 boomeramg_inc_path,boomeramg_lib_path=findLibWithHeader(env, env['boomeramg_libs'], 'HYPRE.h', env['boomeramg_prefix'], lang='c++')
399 env.AppendUnique(CPPPATH = [boomeramg_inc_path])
400 env.AppendUnique(LIBPATH = [boomeramg_lib_path])
401 env.AppendUnique(LIBS = env['boomeramg_libs'])
402 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], boomeramg_lib_path)
403 env.Append(CPPDEFINES = ['BOOMERAMG'])
404 env['buildvars']['boomeramg_inc_path']=boomeramg_inc_path
405 env['buildvars']['boomeramg_lib_path']=boomeramg_lib_path
406 env['buildvars']['boomeramg']=int(env['boomeramg'])
407
408 ######## ParMETIS
409 if not env['usempi']: env['parmetis'] = False
410 parmetis_inc_path=''
411 parmetis_lib_path=''
412 if env['parmetis']:
413 parmetis_inc_path,parmetis_lib_path=findLibWithHeader(env, env['parmetis_libs'], 'parmetis.h', env['parmetis_prefix'], lang='c++')
414 env.AppendUnique(CPPPATH = [parmetis_inc_path])
415 env.AppendUnique(LIBPATH = [parmetis_lib_path])
416 env.AppendUnique(LIBS = env['parmetis_libs'])
417 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], parmetis_lib_path)
418 env.Append(CPPDEFINES = ['USE_PARMETIS'])
419 env['buildvars']['parmetis_inc_path']=parmetis_inc_path
420 env['buildvars']['parmetis_lib_path']=parmetis_lib_path
421 env['buildvars']['parmetis']=int(env['parmetis'])
422
423 ######## gmsh (for tests)
424 env['gmsh'] = False
425 if env['IS_WINDOWS']:
426 try:
427 p=Popen(['gmsh', '-info'], stderr=PIPE)
428 _,e=p.communicate()
429 if e.split().count("MPI"):
430 env['gmsh']='m'
431 else:
432 env['gmsh']='s'
433 p.wait()
434 except OSError:
435 pass
436 else:
437 which = Popen(['which', 'gmsh'], stdout=PIPE)
438 path,_ = which.communicate()
439 if which.wait() == 0:
440 cmd = ['ldd', path[:-1]]
441 if env['IS_OSX']:
442 cmd = ['otool','-L', path[:-1]]
443 try:
444 p=Popen(cmd, stdout=PIPE)
445 gmshlibs,_ = p.communicate()
446 ret = p.wait()
447 if ret == 0 and 'libmpi' in gmshlibs:
448 env['gmsh'] = 'm'
449 else:
450 env['gmsh'] = 's'
451 except OSError:
452 pass
453
454 ######## boost::iostreams
455 if env['compressed_files']:
456 try:
457 boost_inc_path, boost_lib_path = findLibWithHeader(env, env['compression_libs'], 'boost/iostreams/filter/gzip.hpp', env['boost_prefix'], lang='c++')
458 env.Append(CPPDEFINES = ['USE_BOOSTIO'])
459 env.AppendUnique(LIBS = env['compression_libs'])
460 except RuntimeError as e:
461 env['compressed_files'] = False
462 env['buildvars']['compressed_files']=int(env['compressed_files'])
463
464 return env
465
466 def checkPDFLatex(env):
467 if 'PDF' in dir(env) and '.tex' in env.PDF.builder.src_suffixes(env):
468 env['pdflatex']=True
469 else:
470 env['pdflatex']=False
471 return env
472
473

  ViewVC Help
Powered by ViewVC 1.1.26