Simplified adding SCons build and install targets

This commit is contained in:
Ray Speth
2012-03-05 20:45:20 +00:00
parent a3b1946871
commit 8150f49c2c
14 changed files with 118 additions and 172 deletions

View File

@@ -933,33 +933,49 @@ else:
env.SetOption('max_drift', 2)
env.SetOption('implicit_cache', True)
env['addInstallTargets'] = 'install' in COMMAND_LINE_TARGETS
buildDir = 'build'
buildTargets = []
libraryTargets = [] # objects that go in the Cantera library
installTargets = []
sampleTargets = []
def build(targets):
""" Wrapper to add target to list of build targets """
buildTargets.extend(targets)
return targets
def buildSample(*args, **kwargs):
""" Wrapper to add target to list of samples """
targets = args[0](*args[1:], **kwargs)
sampleTargets.extend(targets)
return targets
def install(*args, **kwargs):
""" Wrapper to add target to list of install targets """
if 'install' not in COMMAND_LINE_TARGETS:
return
if len(args) == 2:
inst = env.Install(*args, **kwargs)
else:
inst = args[0](*args[1:], **kwargs)
installTargets.extend(inst)
return inst
env.SConsignFile()
env.Append(CPPPATH=[],
LIBPATH=[Dir('build/lib')])
if env['addInstallTargets']:
if 'install' in COMMAND_LINE_TARGETS:
# Put headers in place
headerBase = 'include/cantera'
inst = env.RecursiveInstall('$inst_incdir', 'include/cantera')
installTargets.extend(inst)
install(env.RecursiveInstall, '$inst_incdir', 'include/cantera')
# Make symlinks to replicate old header directory structure
if env['legacy_headers']:
inst = env.Command(pjoin('$inst_incdir', 'kernel'), [],
Mkdir("$TARGET"))
installTargets.extend(inst)
inst = env.Install('$inst_incdir', 'platform/legacy/Cantera.h')
installTargets.extend(inst)
install(env.Command, pjoin('$inst_incdir', 'kernel'), [], Mkdir("$TARGET"))
install('$inst_incdir', 'platform/legacy/Cantera.h')
if env['OS'] == 'Windows':
cmd = Copy("$TARGET", "$SOURCE")
@@ -983,13 +999,11 @@ if env['addInstallTargets']:
if not filename.endswith('.h'):
continue
headerdir = pjoin(instRoot, 'include', 'cantera')
inst = env.Command(pjoin(headerdir, 'kernel', filename),
pjoin(headerdir, name, filename), cmd)
installTargets.extend(inst)
install(env.Command, pjoin(headerdir, 'kernel', filename),
pjoin(headerdir, name, filename), cmd)
# Data files
inst = env.Install('$inst_datadir', mglob(env, pjoin('data','inputs'), 'cti', 'xml'))
installTargets.extend(inst)
install('$inst_datadir', mglob(env, pjoin('data','inputs'), 'cti', 'xml'))
### List of libraries needed to link to Cantera ###
linkLibs = ['cantera']
@@ -1008,8 +1022,7 @@ if not env['build_with_f2c']:
env['cantera_libs'] = linkLibs
# Add targets from the SConscript files in the various subdirectories
Export('env', 'buildDir', 'buildTargets', 'libraryTargets',
'installTargets', 'sampleTargets')
Export('env', 'build', 'libraryTargets', 'install', 'buildSample')
# ext needs to come before src so that libraryTargets is fully populated
VariantDir('build/ext', 'ext', duplicate=0)
@@ -1045,23 +1058,18 @@ if 'samples' in COMMAND_LINE_TARGETS or 'install' in COMMAND_LINE_TARGETS:
SConscript('build/samples/cxx/SConscript')
# Install C++ samples
inst = env.RecursiveInstall(pjoin('$inst_sampledir', 'cxx'),
'samples/cxx',
exclude=sampledir_excludes)
installTargets.extend(inst)
install(env.RecursiveInstall, pjoin('$inst_sampledir', 'cxx'),
'samples/cxx', exclude=sampledir_excludes)
if env['f90_interface'] == 'y':
SConscript('build/samples/f77/SConscript')
SConscript('build/samples/f90/SConscript')
if env['addInstallTargets'] and env['f90_interface'] == 'y':
# install F90 / F77 samples
inst = env.RecursiveInstall(pjoin('$inst_sampledir', 'f77'),
'samples/f77', sampledir_excludes)
installTargets.extend(inst)
inst = env.RecursiveInstall(pjoin('$inst_sampledir', 'f90'),
'samples/f90', sampledir_excludes)
installTargets.extend(inst)
install(env.RecursiveInstall, pjoin('$inst_sampledir', 'f77'),
'samples/f77', sampledir_excludes)
install(env.RecursiveInstall, pjoin('$inst_sampledir', 'f90'),
'samples/f90', sampledir_excludes)
### Meta-targets ###

View File

@@ -1,15 +1,11 @@
from buildutils import *
Import('env', 'buildTargets', 'installTargets')
Import('env', 'build', 'install')
localenv = env.Clone()
build = localenv.Command('#build/docs/html/index.html',
'doxygen/Doxyfile', 'doxygen $SOURCE')
buildTargets.extend(build)
build(localenv.Command('#build/docs/html/index.html',
'doxygen/Doxyfile', 'doxygen $SOURCE'))
if localenv['addInstallTargets']:
inst = localenv.Install(pjoin('$inst_docdir', 'html'),
mglob(localenv, '#/build/docs/html',
'html', 'svg', 'css', 'png'))
installTargets.extend(inst)
install(pjoin('$inst_docdir', 'html'),
mglob(localenv, '#/build/docs/html', 'html', 'svg', 'css', 'png'))

View File

@@ -1,6 +1,6 @@
from buildutils import *
Import('env', 'buildDir', 'buildTargets', 'installTargets', 'libraryTargets')
Import('env', 'build', 'install', 'libraryTargets')
localenv = env.Clone()
def prep_default(env):
@@ -104,6 +104,5 @@ 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)
build(localenv.Library(pjoin('../lib', 'gtest'),
source=['gtest/src/gtest-all.cc']))

View File

@@ -2,7 +2,7 @@ import sys
from buildutils import *
Import('env', 'buildTargets', 'installTargets')
Import('env', 'build', 'install')
localenv = env.Clone()
### Generate customized scripts ###
@@ -10,22 +10,15 @@ localenv = env.Clone()
# 'setup_cantera'
v = sys.version_info
localenv['python_module_loc'] = pjoin(localenv['prefix'], 'lib', 'python%i.%i' % v[:2], 'site-packages')
target = localenv.SubstFile('setup_cantera', 'setup_cantera.in')
buildTargets.extend(target)
if localenv['addInstallTargets']:
inst = localenv.Install('$inst_bindir','setup_cantera')
installTargets.append(inst)
target = build(localenv.SubstFile('setup_cantera', 'setup_cantera.in'))
install('$inst_bindir', target)
# 'mixmaster'
if env['python_package'] == 'full':
target = localenv.SubstFile('mixmaster', 'mixmaster.in')
buildTargets.extend(target)
target = build(localenv.SubstFile('mixmaster', 'mixmaster.in'))
if localenv['addInstallTargets']:
inst = localenv.Install('$inst_bindir', 'mixmaster')
localenv.AddPostAction(inst, Chmod('$TARGET', 0755))
installTargets.extend(inst)
inst = install('$inst_bindir', target)
install(localenv.AddPostAction, inst, Chmod('$TARGET', 0755))
# Cantera.mak include file for Makefile projects
localenv['mak_sundials_libs'] = ' '.join('-l%s' % s
@@ -47,9 +40,5 @@ localenv['mak_have_blas_lapack_dir'] = '1' if localenv['blas_lapack_dir'] else '
localenv['mak_blas_lapack_libs'] = ' '.join('-l%s' % s
for s in localenv['blas_lapack_libs'])
mak = localenv.SubstFile('Cantera.mak', 'Cantera.mak.in')
buildTargets.extend(mak)
if localenv['addInstallTargets']:
inst = localenv.Install('$inst_sampledir', mak)
installTargets.extend(inst)
mak = build(localenv.SubstFile('Cantera.mak', 'Cantera.mak.in'))
install('$inst_sampledir', mak)

View File

@@ -1,6 +1,6 @@
from buildutils import *
Import('env', 'buildTargets', 'installTargets', 'sampleTargets')
Import('env', 'build', 'install', 'buildSample')
# (subdir, program name, [source extensions])
samples = [('combustor', 'combustor', ['cpp']),
@@ -11,12 +11,10 @@ samples = [('combustor', 'combustor', ['cpp']),
for subdir, name, extensions in samples:
localenv = env.Clone()
if 'samples' in COMMAND_LINE_TARGETS:
prog = localenv.Program(pjoin(subdir, name),
mglob(localenv, subdir, *extensions),
CPPPATH=['#include'],
LIBS=env['cantera_libs'])
sampleTargets.extend(prog)
buildSample(localenv.Program, pjoin(subdir, name),
mglob(localenv, subdir, *extensions),
CPPPATH=['#include'],
LIBS=env['cantera_libs'])
# Note: These Makefiles and SConstruct files are automatically installed
# by the "RecursiveInstall" that grabs everything in the cxx directory.
@@ -24,8 +22,8 @@ for subdir, name, extensions in samples:
## Generate Makefiles to be installed
localenv['make_sourcefile'] = '%s.cpp' % name
localenv['make_target'] = name
makefile = localenv.SubstFile(pjoin(subdir, 'Makefile'), 'Makefile.in')
buildTargets.extend(makefile)
makefile = build(localenv.SubstFile(pjoin(subdir, 'Makefile'), 'Makefile.in'))
install(pjoin('$inst_sampledir', 'cxx', subdir), makefile)
## Generate SConstruct files to be installed
incdirs = (localenv['ct_incroot'], localenv['sundials_include'],
@@ -41,8 +39,4 @@ for subdir, name, extensions in samples:
localenv['tmpl_sourcename'] = name + '.cpp'
sconstruct = localenv.SubstFile(pjoin(subdir, 'SConstruct'), 'SConstruct.in')
if env['addInstallTargets']:
inst = localenv.Install(pjoin('$inst_sampledir', 'cxx', subdir), makefile)
installTargets.extend(inst)
inst = localenv.Install(pjoin('$inst_sampledir', 'cxx', subdir), sconstruct)
installTargets.extend(inst)
install(pjoin('$inst_sampledir', 'cxx', subdir), sconstruct)

View File

@@ -1,6 +1,6 @@
from buildutils import *
Import('env', 'installTargets', 'sampleTargets')
Import('env', 'install', 'buildSample')
localenv = env.Clone()
# (program name, [source files])
@@ -10,13 +10,12 @@ samples = [('ctlib', ['ctlib.f']),
ftn_demo = localenv.Object('demo_ftnlib.cpp',
CPPPATH=['#include'])
for program_name, fortran_sources in samples:
prog = localenv.Program(program_name,
fortran_sources + ftn_demo,
CPPPATH=['#build/src/fortran', '#include'],
LIBS=env['cantera_libs']+['cantera_fortran']+['stdc++'],
LIBPATH=[env['sundials_libdir'], '#build/lib'],
LINK='$F77')
sampleTargets.extend(prog)
buildSample(localenv.Program, program_name,
fortran_sources + ftn_demo,
CPPPATH=['#build/src/fortran', '#include'],
LIBS=env['cantera_libs']+['cantera_fortran']+['stdc++'],
LIBPATH=[env['sundials_libdir'], '#build/lib'],
LINK='$F77')
# Generate SConstruct file to be installed
incdirs = (localenv['ct_incroot'], localenv['sundials_include'],
@@ -34,8 +33,5 @@ sconstruct = localenv.SubstFile('SConstruct', 'SConstruct.in')
# Generate Makefile to be installed
makefile = localenv.SubstFile('Makefile', 'Makefile.in')
if env['addInstallTargets']:
inst = localenv.Install(pjoin('$inst_sampledir', 'f77'), makefile)
installTargets.extend(inst)
inst = localenv.Install(pjoin('$inst_sampledir', 'f77'), sconstruct)
installTargets.extend(inst)
install(pjoin('$inst_sampledir', 'f77'), makefile)
install(pjoin('$inst_sampledir', 'f77'), sconstruct)

View File

@@ -1,18 +1,16 @@
from buildutils import *
Import('env', 'installTargets', 'sampleTargets')
Import('env', 'install', 'buildSample')
localenv = env.Clone()
# (program name, [source files])
samples = [('demo', ['demo.f90'])]
for programName, sources in samples:
if 'samples' in COMMAND_LINE_TARGETS:
prog = localenv.Program(programName, sources,
CPPPATH=['#build/src/fortran', '#include'],
LIBS=env['cantera_libs']+['cantera_fortran']+['stdc++'],
LIBPATH=[env['sundials_libdir'], '#build/lib'])
sampleTargets.extend(prog)
buildSample(localenv.Program, programName, sources,
CPPPATH=['#build/src/fortran', '#include'],
LIBS=env['cantera_libs']+['cantera_fortran']+['stdc++'],
LIBPATH=[env['sundials_libdir'], '#build/lib'])
# Generate SConstruct files to be installed
incdirs = [pjoin(localenv['ct_incroot'], 'cantera')]
@@ -33,8 +31,5 @@ for programName, sources in samples:
localenv['make_sourcefile'] = programName + '.f90'
makefile = localenv.SubstFile('Makefile', 'Makefile.in')
if env['addInstallTargets']:
inst = localenv.Install(pjoin('$inst_sampledir', 'f90'), makefile)
installTargets.extend(inst)
inst = localenv.Install(pjoin('$inst_sampledir', 'f90'), sconstruct)
installTargets.extend(inst)
install(pjoin('$inst_sampledir', 'f90'), makefile)
install(pjoin('$inst_sampledir', 'f90'), sconstruct)

View File

@@ -1,6 +1,6 @@
from buildutils import *
Import('env', 'buildTargets', 'installTargets', 'libraryTargets')
Import('env', 'build', 'install', 'libraryTargets')
def defaultSetup(env, subdir, extensions):
return mglob(env, subdir, *extensions)
@@ -49,14 +49,10 @@ for subdir, extensions, setup in libs:
# build the Cantera static library
localenv = env.Clone()
lib = localenv.StaticLibrary('../lib/cantera', libraryTargets,
SPAWN=getSpawn(localenv))
buildTargets.extend(lib)
lib = build(localenv.StaticLibrary('../lib/cantera', libraryTargets,
SPAWN=getSpawn(localenv)))
localenv.Depends(lib, localenv['config_h_target'])
if localenv['addInstallTargets']:
inst = localenv.Install('$inst_libdir', lib)
installTargets.extend(inst)
install('$inst_libdir', lib)
# OS X requires the shared libraries at link time
if localenv['OS'] == 'Darwin' and localenv['use_sundials'] == 'y':
@@ -64,12 +60,8 @@ if localenv['OS'] == 'Darwin' and localenv['use_sundials'] == 'y':
LIBPATH=localenv['sundials_libdir'])
# Build the Cantera shared library
lib = localenv.SharedLibrary('../lib/cantera_shared', libraryTargets,
SPAWN=getSpawn(localenv))
lib = build(localenv.SharedLibrary('../lib/cantera_shared', libraryTargets,
SPAWN=getSpawn(localenv)))
env['cantera_shlib'] = lib
buildTargets.extend(lib)
localenv.Depends(lib, localenv['config_h_target'])
if localenv['addInstallTargets']:
inst = localenv.Install('$inst_libdir', lib)
installTargets.extend(inst)
install('$inst_libdir', lib)

View File

@@ -1,6 +1,6 @@
from buildutils import *
Import('env', 'buildTargets', 'installTargets')
Import('env', 'build', 'install')
localenv = env.Clone()
programs = [('cti2ctml', ['cti2ctml.cpp']),
@@ -9,16 +9,11 @@ programs = [('cti2ctml', ['cti2ctml.cpp']),
localenv.Append(CPPPATH=['#src', '#include'])
for name, src in programs:
prog = localenv.Program(target=pjoin('#build/bin', name),
source=src,
LIBS=['cantera'])
if localenv['addInstallTargets']:
inst = localenv.Install('$inst_bindir', prog)
buildTargets.extend(prog)
installTargets.extend(inst)
prog = build(localenv.Program(target=pjoin('#build/bin', name),
source=src,
LIBS=['cantera']))
install('$inst_bindir', prog)
# Copy man pages
if localenv['addInstallTargets'] and env['INSTALL_MANPAGES']:
inst = localenv.Install('$inst_mandir', mglob(localenv, 'man', '*'))
installTargets.extend(inst)
if env['INSTALL_MANPAGES']:
install('$inst_mandir', mglob(localenv, 'man', '*'))

View File

@@ -1,6 +1,6 @@
from buildutils import *
Import('env', 'buildTargets', 'installTargets', 'libraryTargets')
Import('env', 'build', 'install')
localenv = env.Clone()
localenv.Append(CPPPATH=['#include', '#src'])
@@ -12,11 +12,8 @@ artifacts = localenv.Object(f90_src,
mods = [o for o in artifacts if o.path.endswith('.mod')]
objects = [o for o in artifacts if not o.path.endswith('.mod')]
lib = localenv.Library(target=pjoin('..','..','lib','cantera_fortran'),
source=objects)
buildTargets.extend(lib)
lib = build(localenv.Library(target=pjoin('..','..','lib','cantera_fortran'),
source=objects))
if localenv['addInstallTargets']:
inst = localenv.Install('$inst_libdir', lib)
installTargets.extend(inst)
installTargets.extend(localenv.Install('$inst_incdir', mods))
install('$inst_libdir', lib)
install('$inst_incdir', mods)

View File

@@ -1,6 +1,6 @@
from buildutils import *
Import('env', 'buildTargets', 'installTargets')
Import('env', 'build', 'install')
class MatlabBuilder(object):
def __init__(self, libs):
@@ -57,32 +57,20 @@ elif os.name == 'nt':
mexFile = ('#interfaces/matlab/toolbox/ctmethods.mex%s%i' %
(mexPlatform, localenv['OS_BITS']))
target = localenv.Command(mexFile,
'build_cantera.m',
build_cmd % localenv)
target = build(localenv.Command(mexFile, 'build_cantera.m',
build_cmd % localenv))
localenv.Depends(target, localenv['cantera_shlib'])
buildTargets.extend(target)
### Install the Matlab toolbox ###
# 'ctpath.m'
target = localenv.SubstFile('ctpath.m', '#interfaces/matlab/ctpath.m.in')
buildTargets.extend(target)
target = build(localenv.SubstFile('ctpath.m', '#interfaces/matlab/ctpath.m.in'))
install('$inst_matlab_dir', target)
if localenv['addInstallTargets']:
inst = localenv.Install('$inst_matlab_dir', target)
installTargets.extend(inst)
# 'cantera_demos.m'
install('$inst_matlab_dir', '#samples/matlab/cantera_demos.m')
install(localenv.RecursiveInstall, '$inst_matlab_dir', '#interfaces/matlab/toolbox')
install(localenv.RecursiveInstall, pjoin('$inst_sampledir', 'matlab'), '#samples/matlab')
# 'cantera_demos.m'
inst = localenv.Install('$inst_matlab_dir', '#samples/matlab/cantera_demos.m')
installTargets.extend(inst)
inst = localenv.RecursiveInstall('$inst_matlab_dir', '#interfaces/matlab/toolbox')
installTargets.extend(inst)
inst = localenv.RecursiveInstall(pjoin('$inst_sampledir', 'matlab'), '#samples/matlab')
installTargets.extend(inst)
if os.name == 'nt':
inst = localenv.Install('$inst_matlab_dir', localenv['cantera_shlib'])
installTargets.extend(inst)
if os.name == 'nt':
install('$inst_matlab_dir', localenv['cantera_shlib'])

View File

@@ -1,7 +1,7 @@
from buildutils import *
import distutils.sysconfig
Import('env', 'buildTargets', 'installTargets')
Import('env', 'build', 'install')
localenv = env.Clone()
@@ -50,7 +50,7 @@ if localenv['python_package'] == 'full':
LIBS=pylinklibs,
SHLIBPREFIX='',
SHLIBSUFFIX=gcv('SO'))
buildTargets.extend(pymodule)
build(pymodule)
localenv.Depends(pymodule, make_setup)
if localenv['OS'] == 'Windows':
for file in localenv['cantera_shlib']:
@@ -78,15 +78,12 @@ if 'MSSdk' in os.environ:
localenv['ENV']['MSSdk'] = os.environ['MSSdk']
if localenv['PYTHON_INSTALLER'] == 'direct':
inst = localenv.Command('dummy', pymodule,
'cd %s && $python_cmd setup.py install %s' % (moddir,extra))
installTargets.extend(inst)
install(localenv.Command, 'dummy', pymodule,
'cd %s && $python_cmd setup.py install %s' % (moddir,extra))
elif localenv['PYTHON_INSTALLER'] == 'binary':
inst = localenv.Command('dummy', pymodule,
'cd %s && $python_cmd setup.py bdist_msi --dist-dir=../..' % moddir)
installTargets.extend(inst)
install(localenv.Command, 'dummy', pymodule,
'cd %s && $python_cmd setup.py bdist_msi --dist-dir=../..' % moddir)
if localenv['python_package'] == 'full':
inst = localenv.RecursiveInstall(pjoin('$inst_sampledir', 'python'),
'#samples/python')
installTargets.extend(inst)
install(localenv.RecursiveInstall, pjoin('$inst_sampledir', 'python'),
'#samples/python')

View File

@@ -1,7 +1,7 @@
from buildutils import *
import subprocess
Import('env','buildTargets','installTargets')
Import('env','build','install')
localenv = env.Clone()
localenv.Append(CPPPATH=['#ext/gtest/include', '#include'],

View File

@@ -1,6 +1,6 @@
from buildutils import *
Import('env','buildTargets','installTargets')
Import('env','build','install')
localenv = env.Clone()
localenv.Append(CPPPATH=['#include', '#src', 'shared'])