Cantera now produces a single library for linking C++ applications

This commit is contained in:
Ray Speth
2012-02-13 17:24:34 +00:00
parent 52e0e30c61
commit 99d951ceb8
9 changed files with 78 additions and 84 deletions

View File

@@ -476,9 +476,6 @@ opts.AddVariables(
stripped-down version of 'dot'. If 'dot' is on your path,
make sure it is not the Matlab version!""",
'', PathVariable.PathAccept),
('ct_shared_lib',
'',
'clib'),
('rpfont',
"""The font to use in reaction path diagrams. This must be a font
name recognized by the 'dot' program. On linux systems, this
@@ -680,7 +677,7 @@ elif env['use_sundials'] == 'y' and env['sundials_version'] not in ('2.2','2.3',
if env['blas_lapack_libs'] == '':
# External BLAS/LAPACK were not given, so we need to compile them
env['BUILD_BLAS_LAPACK'] = True
env['blas_lapack_libs'] = ['ctlapack', 'ctblas']
env['blas_lapack_libs'] = [] # built into libcantera
else:
env['blas_lapack_libs'] = env['blas_lapack_libs'].split(',')
env['BUILD_BLAS_LAPACK'] = False
@@ -826,6 +823,7 @@ env['config_h_target'] = config_h
buildDir = 'build'
buildTargets = []
libraryTargets = [] # objects that go in the Cantera library
installTargets = []
demoTargets = []
@@ -849,27 +847,23 @@ inst = env.RecursiveInstall(pjoin('$inst_sampledir', 'cxx'),
installTargets.extend(inst)
### List of libraries needed to link to Cantera ###
linkLibs = ['oneD','zeroD','equil','kinetics','transport',
'thermo','ctnumerics','ctmath','tpx',
'ctspectra','converters','ctbase']
linkLibs = ['cantera']
if env['use_sundials'] == 'y':
linkLibs.extend(('sundials_cvodes','sundials_nvecserial'))
else:
linkLibs.append('cvode')
linkLibs.extend(env['blas_lapack_libs'])
if env['build_with_f2c']:
linkLibs.append('ctf2c')
else:
if not env['build_with_f2c']:
linkLibs.append('gfortran')
env['cantera_libs'] = linkLibs
# Add targets from the SConscript files in the various subdirectories
Export('env', 'buildDir', 'buildTargets', 'installTargets', 'demoTargets')
Export('env', 'buildDir', 'buildTargets', 'libraryTargets',
'installTargets', 'demoTargets')
# ext needs to come before src so that libraryTargets is fully populated
VariantDir('build/ext', 'ext', duplicate=0)
SConscript('build/ext/SConscript')

View File

@@ -1,6 +1,6 @@
from buildutils import *
Import('env', 'buildDir', 'buildTargets', 'installTargets')
Import('env', 'buildDir', 'buildTargets', 'installTargets', 'libraryTargets')
localenv = env.Clone()
def prep_default(env):
@@ -41,11 +41,11 @@ def prep_gtest(env):
CPPDEFINES={'GTEST_HAS_PTHREAD': 0})
return localenv
# (subdir, library name, (file extensions), prepfunction)
libs = [('gtest/src','gtest',['^gtest-all.cc'], prep_gtest)]
# (subdir, (file extensions), prepfunction)
libs = []
if env['build_with_f2c']:
libs.append(('f2c_math', 'ctmath', ['cpp','c'], prep_f2c))
libs.append(('f2c_math', ['cpp','c'], prep_f2c))
# Create arith.h using the arithchk program
if not os.path.exists('arith.h'):
@@ -66,27 +66,33 @@ if env['build_with_f2c']:
headerenv.Command('#ext/f2c_libs/sysdep1.h', 'f2c_libs/sysdep1.h0',
Copy('$TARGET', '$SOURCE'))
libs.append(('f2c_libs', 'ctf2c', 'c', prep_f2c))
libs.append(('f2c_libs', 'c', prep_f2c))
if env['BUILD_BLAS_LAPACK']:
libs.append(('f2c_blas', 'ctblas', ['c'], prep_f2c))
libs.append(('f2c_lapack', 'ctlapack', ['c'], prep_f2c))
libs.append(('f2c_blas', ['c'], prep_f2c))
libs.append(('f2c_lapack', ['c'], prep_f2c))
else:
libs.append(('math', 'ctmath', ['cpp','c','f'], prep_default))
libs.append(('math', ['cpp','c','f'], prep_default))
if env['BUILD_BLAS_LAPACK']:
libs.append(('blas', 'ctblas', ['f'], prep_default))
libs.append(('lapack', 'ctlapack', ['f'], prep_default))
libs.append(('blas', ['f'], prep_default))
libs.append(('lapack', ['f'], prep_default))
if env['use_sundials'] == 'n':
libs.append(('cvode/source', 'cvode', ['c'], prep_sundials))
libs.append(('cvode/source', ['c'], prep_sundials))
for subdir, libname, extensions, prepFunction in libs:
for subdir, extensions, prepFunction in libs:
localenv = prepFunction(env)
lib = localenv.Library(pjoin('../lib', libname),
source=mglob(localenv, subdir, *extensions))
inst = localenv.Install('$inst_libdir', lib)
buildTargets.extend(lib)
installTargets.extend(inst)
objects = localenv.SharedObject(mglob(localenv, subdir, *extensions))
libraryTargets.extend(objects)
# Google Teset
localenv = env.Clone()
localenv.Append(CPPPATH=[Dir('#ext/gtest'),
Dir('#ext/gtest/include')],
CPPDEFINES={'GTEST_HAS_PTHREAD': 0})
lib = localenv.Library(pjoin('../lib', 'gtest'),
source=['gtest/src/gtest-all.cc'])
buildTargets.extend(lib)

View File

@@ -4,7 +4,7 @@ import os
dataFiles = ['_cantera%s' % get_config_var('SO')]
if os.name == 'nt':
dataFiles.append('clib.dll')
dataFiles.append('cantera_shared.dll')
if '@python_package@' == 'full':
setup(name="Cantera",

View File

@@ -1,6 +1,6 @@
from buildutils import *
Import('env','buildTargets','installTargets')
Import('env', 'buildTargets', 'installTargets', 'libraryTargets')
def defaultSetup(env, subdir, extensions):
return mglob(env, subdir, *extensions)
@@ -22,46 +22,42 @@ def numericsSetup(env, subdir, extensions):
return [s for s in mglob(env, subdir, *extensions)
if s.name != remove]
# (subdir, library name, (file extensions), (extra setup(env)))
libs = [('base', 'ctbase', ['cpp'], baseSetup),
('thermo', 'thermo', ['cpp'], defaultSetup),
('tpx', 'tpx', ['cpp'], defaultSetup),
('equil', 'equil', ['cpp','c'], equilSetup),
('converters', 'converters', ['cpp'], defaultSetup),
('numerics', 'ctnumerics', ['cpp'], numericsSetup),
('kinetics', 'kinetics', ['cpp'], defaultSetup),
('transport', 'transport', ['cpp'], defaultSetup),
('spectra', 'ctspectra', ['cpp'], defaultSetup),
('oneD', 'oneD', ['cpp'], defaultSetup),
('zeroD', 'zeroD', ['cpp'], defaultSetup),
# (subdir, (file extensions), (extra setup(env)))
libs = [('base', ['cpp'], baseSetup),
('thermo', ['cpp'], defaultSetup),
('tpx', ['cpp'], defaultSetup),
('equil', ['cpp','c'], equilSetup),
('converters', ['cpp'], defaultSetup),
('numerics', ['cpp'], numericsSetup),
('kinetics', ['cpp'], defaultSetup),
('transport', ['cpp'], defaultSetup),
('spectra', ['cpp'], defaultSetup),
('oneD', ['cpp'], defaultSetup),
('zeroD', ['cpp'], defaultSetup),
('clib', ['cpp'], defaultSetup),
]
for subdir, libname, extensions, setup in libs:
for subdir, extensions, setup in libs:
localenv = env.Clone()
localenv.Append(CPPPATH=Dir('#include'))
localenv.Append(CPPPATH=Dir('#src')) # todo: remove when not needed
source = setup(localenv, subdir, extensions)
objects = localenv.SharedObject(source)
localenv.Depends(objects, localenv['config_h_target'])
libraryTargets.extend(objects)
lib = localenv.Library(pjoin('../lib', libname), source=source)
localenv.Depends(lib, localenv['config_h_target'])
inst = localenv.Install('$inst_libdir', lib)
buildTargets.extend(lib)
installTargets.extend(inst)
# clib is a bit different
# build the Cantera static library
localenv = env.Clone()
source = defaultSetup(localenv, 'clib', ['cpp'])
localenv.Append(CPPPATH=[Dir('#include'), Dir('#src')])
if env['OS'] == 'Windows':
lib = localenv.SharedLibrary(pjoin('../lib', 'clib'),
source=source,
LIBS=localenv['cantera_libs'])
env['clib_shared'] = lib
else:
lib = localenv.Library(pjoin('../lib', 'clib'),
source=source)
lib = localenv.StaticLibrary('../lib/cantera', libraryTargets)
localenv.Depends(lib, localenv['config_h_target'])
inst = localenv.Install('$inst_libdir', lib)
buildTargets.extend(lib)
installTargets.extend(inst)
# Build the Cantera shared library
lib = localenv.SharedLibrary('../lib/cantera_shared', libraryTargets)
env['cantera_shlib'] = lib
localenv.Depends(lib, localenv['config_h_target'])
inst = localenv.Install('$inst_libdir', lib)
buildTargets.extend(lib)

View File

@@ -3,15 +3,15 @@ from buildutils import *
Import('env', 'buildTargets', 'installTargets')
localenv = env.Clone()
programs = [('cti2ctml', ['cti2ctml.cpp'], ['ctbase']),
('ck2cti', ['ck2cti.cpp'], ['converters','ctbase','tpx'])]
programs = [('cti2ctml', ['cti2ctml.cpp']),
('ck2cti', ['ck2cti.cpp'])]
localenv.Append(CPPPATH=['#src', '#include'])
for name, src, libs in programs:
for name, src in programs:
prog = localenv.Program(target=pjoin('#build/bin', name),
source=src,
LIBS=libs)
LIBS=['cantera'])
inst = localenv.Install('$inst_bindir', prog)
buildTargets.extend(prog)
installTargets.extend(inst)

View File

@@ -22,6 +22,7 @@ class MatlabBuilder(object):
"%(includes)s %(libdir)s "
"%(libs)s %(sourcestr)s\n"
"disp('done.');\n"
"pause(2)\n"
"exit\n") % locals()
with open(str(target[0]), 'w') as f:
@@ -31,13 +32,10 @@ class MatlabBuilder(object):
localenv = env.Clone()
localenv.Append(CPPPATH=['#include', '#src'])
libs = ['clib']
if localenv['OS'] != 'Windows':
libs.extend(env['cantera_libs'])
cantera_libname = 'cantera_shared' if os.name=='nt' else 'cantera'
localenv.Command('build_cantera.m',
mglob(localenv, '.', 'cpp'),
MatlabBuilder(libs))
MatlabBuilder([cantera_libname]))
localenv['ENV']['PATH'] = os.environ['PATH']
if 'TEMP' in os.environ:
@@ -45,22 +43,24 @@ if 'TEMP' in os.environ:
build_cmd = 'cd ${SOURCE.dir} && "%(matlab_cmd)s" -nojvm -nosplash -r build_cantera'
if os.name == 'posix':
mexFile = 'cantera/ctmethods.mexa%i' % localenv['OS_BITS']
mexPlatform = 'a'
elif os.name == 'nt':
mexFile = 'cantera/ctmethods.mexw%i' % localenv['OS_BITS']
mexPlatform = 'w'
if localenv['OS_BITS'] == 64:
localenv['ENV']['PROCESSOR_ARCHITECTURE'] = "AMD64"
else:
localenv['ENV']['PROCESSOR_ARCHITECTURE'] = "x86"
mexFile = ('#interfaces/matlab/toolbox/ctmethods.mex%s%i' %
(mexPlatform, localenv['OS_BITS']))
target = localenv.Command(mexFile,
'build_cantera.m',
build_cmd % localenv)
localenv.Depends(target, localenv['cantera_shlib'])
buildTargets.extend(target)
### Install the Matlab toolbox ###
# 'ctpath.m'
@@ -80,5 +80,5 @@ inst = localenv.RecursiveInstall(pjoin('$inst_sampledir', 'matlab'), '#samples/m
installTargets.extend(inst)
if os.name == 'nt':
inst = localenv.Install('$inst_matlab_dir', localenv['clib_shared'])
inst = localenv.Install('$inst_matlab_dir', localenv['cantera_shlib'])
installTargets.extend(inst)

View File

@@ -23,20 +23,18 @@ make_setup = localenv.SubstFile('#interfaces/python/setup.py',
'#interfaces/python/setup.py.in')
if localenv['python_package'] == 'full':
libs = ['clib']
if localenv['OS'] != 'Windows':
libs.extend(env['cantera_libs'])
localenv.Append(CPPPATH=['#src', '#include'])
cantera_libname = 'cantera_shared' if os.name=='nt' else 'cantera'
pymodule = localenv.SharedLibrary('#interfaces/python/Cantera/_cantera',
['pycantera.cpp'],
LIBS=libs,
LIBS=[cantera_libname],
SHLIBPREFIX='',
SHLIBSUFFIX=gcv('SO'))
buildTargets.extend(pymodule)
localenv.Depends(pymodule, make_setup)
if localenv['OS'] == 'Windows':
for file in localenv['clib_shared']:
for file in localenv['cantera_shlib']:
dest = pjoin('interfaces', 'python', 'Cantera', file.name)
localenv.AddPreAction(pymodule,Copy(dest, file))

View File

@@ -4,7 +4,7 @@ import subprocess
Import('env','buildTargets','installTargets')
localenv = env.Clone()
localenv.Append(CPPPATH='#ext/gtest/include',
localenv.Append(CPPPATH=['#ext/gtest/include', '#include'],
LIBPATH='#build/lib',
LIBS=['gtest'] + localenv['cantera_libs'])

View File

@@ -96,7 +96,7 @@ class CompileAndTest(Test):
def run(self, env):
prog = env.Program(pjoin(self.subdir, self.programName),
mglob(env, self.subdir, *self.extensions),
LIBS=env['cantera_libs'])
LIBS=env['cantera_libs'])
source = [prog]
return Test.run(self, env, *source)