Skip to content

Commit

Permalink
[SCons] Fix Makefiles generated for C++ examples
Browse files Browse the repository at this point in the history
- Use CXXFLAGS to pass flags to C++ compiler (not CCFLAGS)
- Set CXXFLAGS based on flags that Cantera was compiled with (which will include
  things like -pthread and -std=c++0x as necessary
- Remove incorrect / unused target for the target binary
- Add the generated binary to things remove by 'make clean'
  • Loading branch information
speth committed Jul 22, 2016
1 parent 3261b41 commit bc609ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
11 changes: 4 additions & 7 deletions samples/cxx/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@ include @make_Cantera_dot_mak@
CC=@CC@
CXX=@CXX@
RM=rm -f
CCFLAGS=-g
CXXFLAGS=@mak_compiler_flags@
CPPFLAGS=$(CANTERA_INCLUDES)
LDFLAGS=
LDLIBS=$(CANTERA_LIBS)

SRCS=@make_sourcefile@
SRCS=@tmpl_sourcename@
OBJS=$(subst .cpp,.o,$(SRCS))

all: @make_target@

@make_target@: $(OBJS)
$(CXX) $(LDFLAGS) -o @make_target@ $(OBJS) $(LDLIBS)
all: @tmpl_progname@

clean:
$(RM) $(OBJS)
$(RM) $(OBJS) @tmpl_progname@

dist-clean: clean
$(RM) *~
29 changes: 14 additions & 15 deletions samples/cxx/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,6 @@ for subdir, name, extensions in samples:
# Note: These Makefiles and SConstruct files are automatically installed
# by the "RecursiveInstall" that grabs everything in the cxx directory.

## Generate Makefiles to be installed
localenv['make_sourcefile'] = '%s.cpp' % name
localenv['make_target'] = name

mak_path = pjoin(localenv['ct_incroot'], 'cantera', 'Cantera.mak')
if ' ' in mak_path:
# There is no reasonable way to handle spaces in Makefile 'include'
# statement, so we fall back to using the relative path instead
mak_path = os.path.relpath(mak_path, pjoin(localenv['ct_sampledir'], 'cxx', subdir))
localenv['make_Cantera_dot_mak'] = mak_path

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'],
localenv['boost_inc_dir']) + tuple(localenv['extra_inc_dirs'])
libdirs = ((localenv['ct_libdir'], localenv['sundials_libdir'],
Expand All @@ -50,6 +35,8 @@ for subdir, name, extensions in samples:
localenv['tmpl_progname'] = name
localenv['tmpl_sourcename'] = name + '.cpp'
env_args = []

## Generate SConstruct files to be installed
if localenv['TARGET_ARCH'] is not None:
env_args.append('TARGET_ARCH={0!r}'.format(localenv['TARGET_ARCH']))
if 'MSVC_VERSION' in localenv:
Expand All @@ -58,3 +45,15 @@ for subdir, name, extensions in samples:

sconstruct = localenv.SubstFile(pjoin(subdir, 'SConstruct'), 'SConstruct.in')
install(pjoin('$inst_sampledir', 'cxx', subdir), sconstruct)

## Generate Makefiles to be installed
mak_path = pjoin(localenv['ct_incroot'], 'cantera', 'Cantera.mak')
localenv['mak_compiler_flags'] = ' '.join(localenv['CCFLAGS'] + localenv['CXXFLAGS'])
if ' ' in mak_path:
# There is no reasonable way to handle spaces in Makefile 'include'
# statement, so we fall back to using the relative path instead
mak_path = os.path.relpath(mak_path, pjoin(localenv['ct_sampledir'], 'cxx', subdir))
localenv['make_Cantera_dot_mak'] = mak_path

makefile = build(localenv.SubstFile(pjoin(subdir, 'Makefile'), 'Makefile.in'))
install(pjoin('$inst_sampledir', 'cxx', subdir), makefile)

0 comments on commit bc609ce

Please sign in to comment.