From 3261b4108ab690516a49396d1e1722ae2eb4aae9 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 20 Jul 2016 18:43:41 -0400 Subject: [PATCH] [SCons] Link Fortran sample programs to the correct standard library --- SConstruct | 5 +++++ platform/posix/Cantera.mak.in | 2 +- platform/posix/SConscript | 7 +++++++ samples/f77/SConscript | 11 +++++++++-- samples/f90/SConscript | 11 +++++++++-- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/SConstruct b/SConstruct index 7a5515617..6ea9daf6e 100644 --- a/SConstruct +++ b/SConstruct @@ -828,6 +828,11 @@ def get_expression_value(includes, expression): env['HAS_TIMES_H'] = conf.CheckCHeader('sys/times.h', '""') env['HAS_UNISTD_H'] = conf.CheckCHeader('unistd.h', '""') +# Determine which standard library to link to when using Fortran to +# compile code that links to Cantera +env['HAS_GLIBCXX'] = conf.CheckDeclaration('__GLIBCXX__', '#include ', 'C++') +env['HAS_LIBCPP'] = conf.CheckDeclaration('_LIBCPP_VERSION', '#include ', 'C++') + boost_version_source = get_expression_value([''], 'BOOST_LIB_VERSION') retcode, boost_lib_version = conf.TryRun(boost_version_source, '.cpp') env['BOOST_LIB_VERSION'] = boost_lib_version.strip() diff --git a/platform/posix/Cantera.mak.in b/platform/posix/Cantera.mak.in index ce16e75af..f404dbf6c 100644 --- a/platform/posix/Cantera.mak.in +++ b/platform/posix/Cantera.mak.in @@ -42,7 +42,7 @@ CANTERA_CORE_FTN=-L@ct_libdir@ -lcantera_fortran @mak_corelibs@ CANTERA_FORTRAN_MODS=$(CANTERA_INSTALL_ROOT)/include/cantera -CANTERA_FORTRAN_SYSLIBS=@mak_fort_threadflags@ -lstdc++ +CANTERA_FORTRAN_SYSLIBS=@mak_fort_threadflags@ @mak_stdlib@ ############################################################################### # BOOST diff --git a/platform/posix/SConscript b/platform/posix/SConscript index ad796c664..6a8cda142 100644 --- a/platform/posix/SConscript +++ b/platform/posix/SConscript @@ -42,6 +42,13 @@ pc_incdirs.extend(localenv['extra_inc_dirs']) localenv['mak_extra_libdirs'] = ' '.join('-L%s' % s for s in localenv['extra_lib_dirs']) pc_libdirs.extend(localenv['extra_lib_dirs']) +if env['HAS_GLIBCXX']: + localenv['mak_stdlib'] = '-lstdc++' +elif env['HAS_LIBCPP']: + localenv['mak_stdlib'] = '-lc++' +else: + localenv['mak_stdlib'] = '' + if localenv['system_sundials']: # Add links to the sundials environment localenv['mak_sundials_libs'] = ' '.join('-l%s' % s diff --git a/samples/f77/SConscript b/samples/f77/SConscript index 02bf6cfd8..14b481e84 100644 --- a/samples/f77/SConscript +++ b/samples/f77/SConscript @@ -3,6 +3,13 @@ from buildutils import * Import('env', 'install', 'buildSample') localenv = env.Clone() +if env['HAS_GLIBCXX']: + stdlib = ['stdc++'] +elif env['HAS_LIBCPP']: + stdlib = ['c++'] +else: + stdlib = [] + # (program name, [source files]) samples = [('ctlib', ['ctlib.f']), ('isentropic', ['isentropic.f'])] @@ -13,14 +20,14 @@ for program_name, fortran_sources in samples: buildSample(localenv.Program, program_name, fortran_sources + ftn_demo, CPPPATH=['#build/src/fortran', '#include'], - LIBS=env['cantera_libs']+['cantera_fortran']+['stdc++'], + LIBS=env['cantera_libs']+['cantera_fortran']+stdlib, LIBPATH=[env['sundials_libdir'], '#build/lib'], LINK='$F77') # Generate SConstruct file to be installed incdirs = (localenv['ct_incroot'], localenv['sundials_include'], localenv['boost_inc_dir']) + tuple(localenv['extra_inc_dirs']) -libs = ['cantera_fortran'] + localenv['cantera_libs'] + ['stdc++'] +libs = ['cantera_fortran'] + localenv['cantera_libs'] + stdlib libdirs = ((localenv['ct_libdir'], localenv['sundials_libdir'], localenv['blas_lapack_dir']) + tuple(localenv['extra_lib_dirs'])) linkflags = ('-g', localenv['thread_flags']) diff --git a/samples/f90/SConscript b/samples/f90/SConscript index 7ffee1dea..ce498d88c 100644 --- a/samples/f90/SConscript +++ b/samples/f90/SConscript @@ -3,18 +3,25 @@ from buildutils import * Import('env', 'install', 'buildSample') localenv = env.Clone() +if env['HAS_GLIBCXX']: + stdlib = ['stdc++'] +elif env['HAS_LIBCPP']: + stdlib = ['c++'] +else: + stdlib = [] + # (program name, [source files]) samples = [('demo', ['demo.f90'])] for programName, sources in samples: buildSample(localenv.Program, programName, sources, F90PATH='#build/src/fortran', - LIBS=['cantera_fortran']+env['cantera_libs']+['stdc++'], + LIBS=['cantera_fortran']+env['cantera_libs']+stdlib, LIBPATH=[env['sundials_libdir'], '#build/lib']) # Generate SConstruct files to be installed incdirs = [pjoin(localenv['ct_incroot'], 'cantera')] + localenv['extra_inc_dirs'] - libs = ['cantera_fortran'] + localenv['cantera_libs'] + ['stdc++'] + libs = ['cantera_fortran'] + localenv['cantera_libs'] + stdlib libdirs = ((localenv['ct_libdir'], localenv['sundials_libdir'], localenv['blas_lapack_dir']) + tuple(localenv['extra_lib_dirs'])) linkflags = ('-g', localenv['thread_flags'])