From 45fe098d5105a3e409beb7421de4d9d852b450db Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 1 Mar 2012 00:44:56 +0000 Subject: [PATCH] Added example Makefiles to install with C++ sample programs --- SConstruct | 19 ++++++--- platform/posix/Cantera.mak.in | 72 +++++++++++++++++++++++++++++++++++ platform/posix/SConscript | 27 +++++++++++++ samples/cxx/Makefile.in | 23 +++++++++++ samples/cxx/SConscript | 25 ++++++++---- 5 files changed, 153 insertions(+), 13 deletions(-) create mode 100644 platform/posix/Cantera.mak.in create mode 100644 samples/cxx/Makefile.in diff --git a/SConstruct b/SConstruct index fe8253c1a..33bb3282d 100644 --- a/SConstruct +++ b/SConstruct @@ -918,6 +918,13 @@ config_h = env.Command('include/cantera/base/config.h', env.AlwaysBuild(config_h) env['config_h_target'] = config_h +if env['build_thread_safe']: + env['use_boost_libs'] = True + env['boost_libs'] = env['boost_thread_lib'] +else: + env['use_boost_libs'] = False + env['boost_libs'] = [] + # ********************* # *** Build Cantera *** # ********************* @@ -977,11 +984,6 @@ if env['addInstallTargets']: pjoin(headerdir, name, filename), cmd) installTargets.extend(inst) - # Install C++ samples - inst = env.RecursiveInstall(pjoin('$inst_sampledir', 'cxx'), - 'samples/cxx') - installTargets.extend(inst) - # Data files inst = env.Install('$inst_datadir', mglob(env, pjoin('data','inputs'), 'cti', 'xml')) installTargets.extend(inst) @@ -1040,11 +1042,16 @@ if env['OS'] != 'Windows': if env['build_docs']: SConscript('doc/SConscript') -if 'samples' in COMMAND_LINE_TARGETS: +if 'samples' in COMMAND_LINE_TARGETS or 'install' in COMMAND_LINE_TARGETS: SConscript('samples/cxx/SConscript') if env['f90_interface'] == 'y': SConscript('samples/f77/SConscript') + # Install C++ samples + inst = env.RecursiveInstall(pjoin('$inst_sampledir', 'cxx'), + 'samples/cxx') + installTargets.extend(inst) + ### Meta-targets ### build_samples = Alias('samples', sampleTargets) diff --git a/platform/posix/Cantera.mak.in b/platform/posix/Cantera.mak.in new file mode 100644 index 000000000..d549cabac --- /dev/null +++ b/platform/posix/Cantera.mak.in @@ -0,0 +1,72 @@ +############################################################################### +# Include Snippet for Makefiles +# +# To create Cantera C++ applications from the install environment +# include this file into your Makefile environment by putting +# the line "include Cantera.mak" in your Makefile. +# +# Main Variables: +# +# CANTERA_INCLUDES = Variable containing the include path +# +# CANTERA_LIBS = List of libraries to include on the link line +# + +CANTERA_VERSION=@cantera_version@ + +############################################################################### +# CANTERA CORE +############################################################################### + +# The directory where Cantera include files may be found. +# Include files in application programs should start with: +# #include "cantera/thermo.h" +# #include "cantera/kernel/HMWSoln.h" + +CANTERA_CORE_INCLUDES=-I@ct_incroot@ + +# Required Cantera libraries +CANTERA_CORE_LIBS=-L@ct_libdir@ -lcantera + +############################################################################### +# BOOST +############################################################################### + +CANTERA_BOOST_INCLUDES=@mak_boost_include@ +CANTERA_BOOST_LIBS=@mak_boost_libdir@ @mak_boost_libs@ + +############################################################################### +# CVODE/SUNDIALS LINKAGE +############################################################################### + +CANTERA_SUNDIALS_INCLUDE=@mak_sundials_include@ +CANTERA_SUNDIALS_LIBS=@mak_sundials_libdir@ @mak_sundials_libs@ + +############################################################################### +# BLAS LAPACK LINKAGE +############################################################################### + +CANTERA_have_blas_lapack_dir=@mak_have_blas_lapack_dir@ + +ifeq ($(CANTERA_have_blas_lapack_dir), 1) +CANTERA_BLAS_LAPACK_LIBS=-L@blas_lapack_dir@ +else +CANTERA_BLAS_LAPACK_LIBS=@mak_blas_lapack_libs@ +endif + +############################################################################### +# COMBINATIONS OF INCLUDES AND LIBS +############################################################################### + +CANTERA_INCLUDES=$(CANTERA_CORE_INCLUDES) $(CANTERA_SUNDIALS_INCLUDE) \ + $(CANTERA_BOOST_INCLUDES) + +# Add this into the compilation environment to identify the version number +CANTERA_DEFINES = -DCANTERA_VERSION=@cantera_version@ + +CANTERA_LIBS=$(CANTERA_CORE_LIBS) $(CANTERA_SUNDIALS_LIBS) \ + $(CANTERA_BLAS_LAPACK_LIBS) $(CANTERA_BOOST_LIBS) + +############################################################################### +# END +############################################################################### diff --git a/platform/posix/SConscript b/platform/posix/SConscript index 6bd3def4d..80077703b 100644 --- a/platform/posix/SConscript +++ b/platform/posix/SConscript @@ -26,3 +26,30 @@ if env['python_package'] == 'full': inst = localenv.Install('$inst_bindir', 'mixmaster') localenv.AddPostAction(inst, Chmod('$TARGET', 0755)) installTargets.extend(inst) + +# Cantera.mak include file for Makefile projects +localenv['mak_sundials_libs'] = ' '.join('-l%s' % s + for s in localenv['sundials_libs']) +localenv['mak_sundials_libdir'] = ('-L' + localenv['sundials_libdir'] + if localenv['sundials_libdir'] else '') +localenv['mak_sundials_include'] = ('-I' + localenv['sundials_include'] + if localenv['sundials_include'] else '') + +localenv['mak_boost_include'] = ('-I' + localenv['boost_inc_dir'] + if localenv['boost_inc_dir'] else '') +localenv['mak_boost_libdir'] = ('-L' + localenv['boost_lib_dir'] + if localenv['boost_inc_dir'] and + localenv['use_boost_libs'] else '') +localenv['mak_boost_libs'] = ' '.join('-l%s' % s + for s in localenv['boost_libs']) + +localenv['mak_have_blas_lapack_dir'] = '1' if localenv['blas_lapack_dir'] else '0' +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) diff --git a/samples/cxx/Makefile.in b/samples/cxx/Makefile.in new file mode 100644 index 000000000..3de181c1d --- /dev/null +++ b/samples/cxx/Makefile.in @@ -0,0 +1,23 @@ +include ../../Cantera.mak + +CC=@CC@ +CXX=@CXX@ +RM=rm -f +CCFLAGS=-g +CPPFLAGS=$(CANTERA_INCLUDES) +LDFLAGS= +LDLIBS=$(CANTERA_LIBS) + +SRCS=@make_sourcefile@ +OBJS=$(subst .cpp,.o,$(SRCS)) + +all: @make_target@ + +@make_target@: $(OBJS) + $(CXX) $(LDFLAGS) -o @make_target@ $(OBJS) $(LDLIBS) + +clean: + $(RM) $(OBJS) + +dist-clean: clean + $(RM) *~ diff --git a/samples/cxx/SConscript b/samples/cxx/SConscript index 13d14a7c7..3db29f950 100644 --- a/samples/cxx/SConscript +++ b/samples/cxx/SConscript @@ -2,8 +2,6 @@ from buildutils import * Import('env', 'buildTargets', 'installTargets', 'sampleTargets') -localenv = env.Clone() - # (subdir, program name, [source extensions]) samples = [('combustor', 'combustor', ['cpp']), ('flamespeed', 'flamespeed', ['cpp']), @@ -12,8 +10,21 @@ samples = [('combustor', 'combustor', ['cpp']), ('rankine', 'rankine', ['cpp'])] for subdir, name, extensions in samples: - prog = localenv.Program(pjoin(subdir, name), - mglob(localenv, subdir, *extensions), - CPPPATH=['#include'], - LIBS=env['cantera_libs']) - sampleTargets.extend(prog) + 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) + + ## 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) + + # Note: These Makefiles are automatically installed by the + # "RecursiveInstall" that grabs everything in the cxx directory + + ## Generate SConstruct files to be installed