/[escript]/branches/doubleplusgood/site_scons/dependencies.py
ViewVC logotype

Contents of /branches/doubleplusgood/site_scons/dependencies.py

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26