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

Contents of /trunk/site_scons/dependencies.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4419 - (show annotations)
Mon May 20 05:03:35 2013 UTC (5 years, 1 month ago) by caltinay
File MIME type: text/x-python
File size: 17469 byte(s)
Fixed a typo.

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 # Now we know whether we are using python3 or not
103 p=Popen([env['pythoncmd'], '-c', initstring+'print(sysconfig.get_python_inc())'], stdout=PIPE)
104 python_inc_path=p.stdout.readline()
105 if env['usepython3']:
106 python_inc_path=python_inc_path.encode()
107 p.wait()
108 python_inc_path=python_inc_path.strip()
109 if env['IS_WINDOWS']:
110 cmd="import os;os.path.join(sysconfig.get_config_var('prefix'), 'libs')"
111 elif env['PLATFORM']=='darwin':
112 cmd="sysconfig.get_config_var(\"LIBPL\")"
113 else:
114 cmd="sysconfig.get_config_var(\"LIBDIR\")"
115
116 p=Popen([env['pythoncmd'], '-c', initstring+'print('+cmd+')'], stdout=PIPE)
117 python_lib_path=p.stdout.readline()
118 if env['usepython3']:
119 python_lib_path=python_lib_path.decode()
120 p.wait()
121 python_lib_path=python_lib_path.strip()
122
123 env['buildvars']['python']=env['pythoncmd']
124 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)
125 verstring=p.stdout.readline().strip()
126 p.wait()
127 env['buildvars']['python_version']=verstring
128
129 # Check for an override from the config file.
130 # Ideally, this should be automatic but we need to deal with the case
131 # where python is not in its INSTALL directory
132 if env['pythonlibpath']!='':
133 python_lib_path=env['pythonlibpath']
134
135 if env['pythonincpath']!='':
136 python_inc_path=env['pythonincpath']
137
138 conf = Configure(env.Clone())
139
140 if env['sysheaderopt'] == '':
141 conf.env.AppendUnique(CPPPATH = [python_inc_path])
142 else:
143 conf.env.Append(CCFLAGS = [env['sysheaderopt'], python_inc_path])
144
145 conf.env.AppendUnique(LIBPATH = [python_lib_path])
146 conf.env.AppendUnique(LIBS = python_libs)
147 # The wrapper script needs to find the libs
148 conf.env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], python_lib_path)
149
150 if not conf.CheckCHeader('Python.h'):
151 print("Cannot find python include files (tried 'Python.h' in directory %s)" % (python_inc_path))
152 env.Exit(1)
153 if not conf.CheckFunc('Py_Exit'):
154 print("Cannot find python library method Py_Main (tried %s in directory %s)" % (python_libs, python_lib_path))
155 env.Exit(1)
156
157 return conf.Finish()
158
159 def checkBoost(env):
160 boost_inc_path,boost_lib_path=findLibWithHeader(env, env['boost_libs'], 'boost/python.hpp', env['boost_prefix'], lang='c++')
161 if env['sysheaderopt'] == '':
162 env.AppendUnique(CPPPATH = [boost_inc_path])
163 else:
164 # This is required because we can't -isystem /usr/include since it
165 # breaks std includes
166 if os.path.normpath(boost_inc_path) == '/usr/include':
167 env.Append(CCFLAGS=[env['sysheaderopt'], os.path.join(boost_inc_path,'boost')])
168 else:
169 env.Append(CCFLAGS=[env['sysheaderopt'], boost_inc_path])
170
171 env.AppendUnique(LIBPATH = [boost_lib_path])
172 env.AppendUnique(LIBS = env['boost_libs'])
173 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], boost_lib_path)
174
175 # Try to extract the boost version from version.hpp
176 boosthpp=open(os.path.join(boost_inc_path, 'boost', 'version.hpp'))
177 boostversion='unknown'
178 try:
179 for line in boosthpp:
180 ver=re.match(r'#define BOOST_VERSION (\d+)',line)
181 if ver:
182 boostversion=ver.group(1)
183 except StopIteration:
184 pass
185 boosthpp.close()
186 env['buildvars']['boost_inc_path']=boost_inc_path
187 env['buildvars']['boost_lib_path']=boost_lib_path
188 env['buildvars']['boostversion']=boostversion
189 return env
190
191 def checkNumpy(env):
192 if not detectModule(env, 'numpy'):
193 print("Cannot import numpy. If it is installed try setting your PYTHONPATH and probably %s"%env['LD_LIBRARY_PATH_KEY'])
194 env.Exit(1)
195
196 ## check for numpy header (optional)
197 conf = Configure(env.Clone())
198 if env['usepython3']:
199 # FIXME: This is until we can work out how to make the checks in python 3
200 conf.env['numpy_h']=False
201 else:
202 if conf.CheckCXXHeader(['Python.h','numpy/ndarrayobject.h']):
203 conf.env.Append(CPPDEFINES = ['HAVE_NUMPY_H'])
204 conf.env['numpy_h']=True
205 else:
206 conf.env['numpy_h']=False
207
208 return conf.Finish()
209
210 def checkCppUnit(env):
211 try:
212 cppunit_inc_path,cppunit_lib_path=findLibWithHeader(env, env['cppunit_libs'], 'cppunit/TestFixture.h', env['cppunit_prefix'], lang='c++')
213 env.AppendUnique(CPPPATH = [cppunit_inc_path])
214 env.AppendUnique(LIBPATH = [cppunit_lib_path])
215 env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], cppunit_lib_path)
216 env['cppunit']=True
217 except:
218 env['cppunit']=False
219 return env
220
221 def checkOptionalModules(env):
222 ######## scipy
223 if not detectModule(env, 'scipy'):
224 env['warnings'].append("Cannot import scipy. NetCDF sources will not be available for inversions.")
225
226 ######## sympy
227 if not detectModule(env, 'sympy'):
228 env['warnings'].append("Cannot import sympy. Symbolic toolbox and nonlinear PDEs will not be available.")
229
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 = ['BLOCKPAPI'])
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 return env
409
410 def checkPDFLatex(env):
411 if 'PDF' in dir(env) and '.tex' in env.PDF.builder.src_suffixes(env):
412 env['pdflatex']=True
413 else:
414 env['pdflatex']=False
415 return env
416
417

  ViewVC Help
Powered by ViewVC 1.1.26