cantera/src/matlab/SConscript
Ray Speth c092bbaede Fixed the order of include and library directories when compiling
Include directories in the Cantera source tree should be listed first so that
they take precedence over headers from other installed copies of Cantera that
might end up on the include search path. This was potentially a problem when
Cantera was installed in the same location (e.g. /usr/local) as one of its
dependencies (e.g. Sundials).

The same logic applies to directories on the library link path.
2012-08-10 21:03:06 +00:00

95 lines
3.4 KiB
Python

from buildutils import *
Import('env', 'build', 'install')
localenv = env.Clone()
linkflags = []
matlab_include = pjoin(localenv['matlab_path'], 'extern', 'include')
if localenv['OS'] == 'Windows':
linklibs = list(env['cantera_shared_libs'])
linklibs += ['libmx', 'libmex', 'libmat']
if localenv['OS_BITS'] == 32:
matlab_libs = pjoin(localenv['matlab_path'], 'extern',
'lib' ,'win32', 'microsoft')
mexSuffix = '.mexw32'
else:
matlab_libs = pjoin(localenv['matlab_path'], 'extern',
'lib' ,'win64', 'microsoft')
mexSuffix = '.mexw64'
if localenv['CC'] == 'cl':
linkflags.append('/export:mexFunction')
machtype = 'X64' if localenv['OS_BITS'] == 64 else 'X86'
linkflags.append('/MACHINE:' + machtype)
elif localenv['CC'] == 'gcc':
linkflags.append('-Wl,--export-all-symbols')
linkflags.extend(['-static-libgcc', '-static-libstdc++'])
elif localenv['OS'] == 'Darwin':
linklibs = list(env['cantera_libs'])
linklibs += ['mx', 'mex', 'mat'] + env['LIBM']
linkflags.extend(['-Wl,-exported_symbol,_mexFunction'])
if localenv['OS_BITS'] == 64:
matlab_libs = pjoin(localenv['matlab_path'], 'bin', 'maci64')
mexSuffix = '.mexmaci64'
else:
matlab_libs = pjoin(localenv['matlab_path'], 'bin', 'macx86')
mexSuffix = '.mexmaci'
elif os.name == 'posix':
linklibs = list(env['cantera_libs'])
linklibs += ['mx', 'mex', 'mat'] + env['LIBM']
if localenv['OS_BITS'] == 64:
matlab_libs = pjoin(localenv['matlab_path'], 'bin', 'glnxa64')
mexSuffix = '.mexa64'
else:
matlab_libs = pjoin(localenv['matlab_path'], 'bin', 'glnx86')
mexSuffix = '.mexglx'
linkflags.extend(['-Wl,--no-undefined',
'-Wl,--version-script,src/matlab/mexFunction.map'])
localenv.Prepend(CPPPATH=['#include', '#src', matlab_include])
localenv.Append(CPPDEFINES=['MATLAB_MEX_FILE'],
LIBPATH=[matlab_libs],
LINKFLAGS=linkflags)
linklibs += localenv['sundials_libs']
linklibs += localenv['blas_lapack_libs']
ctmethods = build(localenv.SharedLibrary('#interfaces/matlab/toolbox/ctmethods',
mglob(localenv, '.', 'cpp'),
LIBPREFIX='',
SHLIBPREFIX='',
SHLIBSUFFIX=mexSuffix,
LIBS=linklibs))
if localenv['OS'] in ('Windows', 'Darwin'):
localenv.Depends(ctmethods, localenv['cantera_shlib'])
else:
localenv.Depends(ctmethods, localenv['cantera_staticlib'])
env['matlab_extension'] = ctmethods
### Install the Matlab toolbox ###
# 'ctpath.m'
target = build(localenv.SubstFile('#interfaces/matlab/ctpath.m',
'#interfaces/matlab/ctpath.m.in'))
install('$inst_matlab_dir', target)
# 'cantera_demos.m'
install('$inst_matlab_dir', '#samples/matlab/cantera_demos.m')
install(localenv.RecursiveInstall, '$inst_matlab_dir',
'#interfaces/matlab/toolbox',
exclude=['dll$', 'exp$', 'lib$', 'ilk$', 'manifest$'])
install(localenv.RecursiveInstall, pjoin('$inst_sampledir', 'matlab'), '#samples/matlab')
if os.name == 'nt':
shlib = [f for f in localenv['cantera_shlib']
if f.name.endswith('dll')]
install('$inst_matlab_dir', shlib)