[SCons] Modify build system to exclude unused Fortran and f2c code

Cantera no longer requires BLAS / LAPACK (but can use them if available), so it
is never necessary to compile any of the external Fortran or f2c-converted code.
This commit is contained in:
Ray Speth 2016-04-13 18:24:49 -04:00
parent efb068e319
commit df43a474cd
7 changed files with 23 additions and 120 deletions

View file

@ -61,7 +61,6 @@ if 'clean' in COMMAND_LINE_TARGETS:
removeFile('.sconsign.dblite') removeFile('.sconsign.dblite')
removeFile('include/cantera/base/config.h') removeFile('include/cantera/base/config.h')
removeDirectory('include/cantera/ext') removeDirectory('include/cantera/ext')
removeFile('ext/f2c_libs/arith.h')
removeFile('interfaces/cython/cantera/_cantera.cpp') removeFile('interfaces/cython/cantera/_cantera.cpp')
removeFile('interfaces/cython/setup2.py') removeFile('interfaces/cython/setup2.py')
removeFile('interfaces/cython/setup3.py') removeFile('interfaces/cython/setup3.py')
@ -385,7 +384,8 @@ config_options = [
PathVariable( PathVariable(
'FORTRAN', 'FORTRAN',
"""The Fortran (90) compiler. If unspecified, the builder will look for """The Fortran (90) compiler. If unspecified, the builder will look for
a compatible compiler (gfortran, ifort, g95) in the $PATH.""", a compatible compiler (gfortran, ifort, g95) in the $PATH. Used only
for compiling the Fortran 90 interface.""",
'', PathVariable.PathAccept), '', PathVariable.PathAccept),
('FORTRANFLAGS', ('FORTRANFLAGS',
'Compilation options for the Fortran (90) compiler.', 'Compilation options for the Fortran (90) compiler.',
@ -433,12 +433,12 @@ config_options = [
e.g. /usr/lib.""", e.g. /usr/lib.""",
'', PathVariable.PathAccept), '', PathVariable.PathAccept),
('blas_lapack_libs', ('blas_lapack_libs',
"""Cantera comes with Fortran (or C) versions of those parts of BLAS and """Cantera can use BLAS and LAPACK libraries available on your system if
LAPACK it requires. But performance may be better if you use a version you have optimized versions available (e.g. Intel MKL). Otherwise,
of these libraries optimized for your machine hardware. If you want to Cantera will use Eigen for linear algebra support. To use BLAS
use your own libraries, set blas_lapack_libs to the the list of and LAPACK, set blas_lapack_libs to the the list of libraries
libraries that should be passed to the linker, separated by commas, that should be passed to the linker, separated by commas, e.g.
e.g. "lapack,blas" or "lapack,f77blas,cblas,atlas".""", "lapack,blas" or "lapack,f77blas,cblas,atlas".""",
''), ''),
PathVariable('blas_lapack_dir', PathVariable('blas_lapack_dir',
"""Directory containing the libraries specified by 'blas_lapack_libs'.""", """Directory containing the libraries specified by 'blas_lapack_libs'.""",
@ -516,13 +516,6 @@ config_options = [
'boost_inc_dir', 'boost_inc_dir',
'Location of the Boost header files.', 'Location of the Boost header files.',
defaults.boostIncDir, PathVariable.PathAccept), defaults.boostIncDir, PathVariable.PathAccept),
BoolVariable(
'build_with_f2c',
"""For external procedures written in Fortran 77, both the
original F77 source code and C source code generated by the
'f2c' program are included. Set this to "n" if you want to
build Cantera using the F77 sources in the ext directory.""",
True),
PathVariable( PathVariable(
'stage_dir', 'stage_dir',
""" Directory relative to the Cantera source directory to be """ Directory relative to the Cantera source directory to be
@ -661,15 +654,14 @@ if env['system_sundials'] in ('y','default'):
# BLAS / LAPACK configuration # BLAS / LAPACK configuration
if env['blas_lapack_libs'] != '': if env['blas_lapack_libs'] != '':
env['blas_lapack_libs'] = env['blas_lapack_libs'].split(',') env['blas_lapack_libs'] = env['blas_lapack_libs'].split(',')
env['BUILD_BLAS_LAPACK'] = False env['use_lapack'] = True
elif env['OS'] == 'Darwin': elif env['OS'] == 'Darwin':
env['blas_lapack_libs'] = [] env['blas_lapack_libs'] = []
env['BUILD_BLAS_LAPACK'] = False env['use_lapack'] = True
env.Append(FRAMEWORKS=['Accelerate']) env.Append(FRAMEWORKS=['Accelerate'])
else: else:
# External BLAS/LAPACK were not given, so we need to compile them env['blas_lapack_libs'] = []
env['BUILD_BLAS_LAPACK'] = True env['use_lapack'] = False
env['blas_lapack_libs'] = [] # built into libcantera
# ************************************ # ************************************
# *** Compiler Configuration Tests *** # *** Compiler Configuration Tests ***
@ -895,17 +887,16 @@ if env['system_sundials'] == 'y':
# In the case where a user is trying to link Cantera to an external BLAS/LAPACK # In the case where a user is trying to link Cantera to an external BLAS/LAPACK
# library, but Sundials was configured without this support, print a Warning. # library, but Sundials was configured without this support, print a Warning.
if not env['has_sundials_lapack'] and not env['BUILD_BLAS_LAPACK']: if not env['has_sundials_lapack'] and env['use_lapack']:
print ('WARNING: External BLAS/LAPACK has been specified for Cantera ' print ('WARNING: External BLAS/LAPACK has been specified for Cantera '
'but Sundials was built without this support.') 'but Sundials was built without this support.')
else: # env['system_sundials'] == 'n' else: # env['system_sundials'] == 'n'
print """INFO: Using private installation of Sundials version 2.6.""" print """INFO: Using private installation of Sundials version 2.6."""
env['sundials_version'] = '2.6' env['sundials_version'] = '2.6'
env['has_sundials_lapack'] = int(not env['BUILD_BLAS_LAPACK']) env['has_sundials_lapack'] = int(env['use_lapack'])
# Try to find a working Fortran compiler: # Try to find a working Fortran compiler:
env['FORTRANSYSLIBS'] = []
fortran_libs = {'gfortran':'gfortran', 'g95':'f95'} fortran_libs = {'gfortran':'gfortran', 'g95':'f95'}
def check_fortran(compiler, expected=False): def check_fortran(compiler, expected=False):
if which(compiler) is not None: if which(compiler) is not None:
@ -913,7 +904,6 @@ def check_fortran(compiler, expected=False):
if lib: if lib:
have_lib = conf.CheckLib(lib) have_lib = conf.CheckLib(lib)
if have_lib: if have_lib:
env.Append(FORTRANSYSLIBS=lib)
env['FORTRAN'] = compiler env['FORTRAN'] = compiler
return True return True
else: else:
@ -1241,7 +1231,7 @@ else:
configh['SUNDIALS_VERSION'] = env['sundials_version'].replace('.','') configh['SUNDIALS_VERSION'] = env['sundials_version'].replace('.','')
if env.get('has_sundials_lapack') and not env['BUILD_BLAS_LAPACK']: if env.get('has_sundials_lapack') and env['use_lapack']:
configh['SUNDIALS_USE_LAPACK'] = 1 configh['SUNDIALS_USE_LAPACK'] = 1
else: else:
configh['SUNDIALS_USE_LAPACK'] = 0 configh['SUNDIALS_USE_LAPACK'] = 0
@ -1250,7 +1240,7 @@ cdefine('LAPACK_FTN_STRING_LEN_AT_END', 'lapack_ftn_string_len_at_end')
cdefine('LAPACK_FTN_TRAILING_UNDERSCORE', 'lapack_ftn_trailing_underscore') cdefine('LAPACK_FTN_TRAILING_UNDERSCORE', 'lapack_ftn_trailing_underscore')
cdefine('FTN_TRAILING_UNDERSCORE', 'lapack_ftn_trailing_underscore') cdefine('FTN_TRAILING_UNDERSCORE', 'lapack_ftn_trailing_underscore')
cdefine('LAPACK_NAMES_LOWERCASE', 'lapack_names', 'lower') cdefine('LAPACK_NAMES_LOWERCASE', 'lapack_names', 'lower')
configh['CT_USE_LAPACK'] = 0 if env['BUILD_BLAS_LAPACK'] else 1 cdefine('CT_USE_LAPACK', 'use_lapack')
cdefine('CT_USE_SYSTEM_EIGEN', env['system_eigen']) cdefine('CT_USE_SYSTEM_EIGEN', env['system_eigen'])
config_h = env.Command('include/cantera/base/config.h', config_h = env.Command('include/cantera/base/config.h',
@ -1345,10 +1335,6 @@ if env['blas_lapack_libs']:
linkLibs.extend(env['blas_lapack_libs']) linkLibs.extend(env['blas_lapack_libs'])
linkSharedLibs.extend(env['blas_lapack_libs']) linkSharedLibs.extend(env['blas_lapack_libs'])
if not env['build_with_f2c']:
linkLibs.extend(env['FORTRANSYSLIBS'])
linkSharedLibs.append(env['FORTRANSYSLIBS'])
# Store the list of needed static link libraries in the environment # Store the list of needed static link libraries in the environment
env['cantera_libs'] = linkLibs env['cantera_libs'] = linkLibs
env['cantera_shared_libs'] = linkSharedLibs env['cantera_shared_libs'] = linkSharedLibs

View file

@ -390,24 +390,6 @@ Building Documentation
scons build doxygen_docs=y sphinx_docs=y scons build doxygen_docs=y sphinx_docs=y
MinGW Compilation problems
--------------------------
* If you get a compiler error while compiling some of the "f2c" code, then your
version of MinGW has a problem with the order of its internal include paths,
such that it sees the GCC float.h before its own special version. To fix this
problem edit the GCC float.h located at (roughly)::
c:\MinGW\lib\gcc\mingw32\4.6.1\include\float.h
and add the following just before the end (before the final #endif)
.. code-block:: c++
#ifndef _MINGW_FLOAT_H_
#include_next <float.h>
#endif
.. _sec-dependencies: .. _sec-dependencies:
Software used by Cantera Software used by Cantera

View file

@ -272,13 +272,6 @@ running 'scons build'. The format of this file is:
Location of the Boost header files. Location of the Boost header files.
- default: '' - default: ''
* build_with_f2c: [ yes | no ]
For external procedures written in Fortran 77, both the original F77
source code and C source code generated by the 'f2c' program are
included. Set this to "n" if you want to build Cantera using the F77
sources in the ext directory.
- default: 'yes'
* F77: [ string ] * F77: [ string ]
Compiler used to build the external Fortran 77 procedures from the Compiler used to build the external Fortran 77 procedures from the
Fortran source code. Fortran source code.

View file

@ -13,27 +13,6 @@ def prep_default(env):
return localenv return localenv
def prep_fortran(env):
localenv = prep_default(env)
localenv.Prepend(CPPPATH='#include/cantera/base') # for config.h
return localenv
def prep_f2c(env):
localenv = prep_default(env)
localenv.Prepend(CPPPATH=Dir('#ext/f2c_libs'))
if not localenv['HAS_TIMES_H']:
localenv.Append(CPPDEFINES=['USE_CLOCK'])
if not localenv['HAS_UNISTD_H']:
localenv.Append(CPPDEFINES=['MSDOS'])
if env['VERBOSE']:
print "INFO 2: prep_f2c: adding MSDOS to CPPDEFINES"
print "INFO 2: CPPDEFINES ", localenv['CPPDEFINES']
return localenv
def prep_gtest(env): def prep_gtest(env):
localenv = prep_default(env) localenv = prep_default(env)
localenv.Prepend(CPPPATH=[Dir('#ext/googletest'), localenv.Prepend(CPPPATH=[Dir('#ext/googletest'),
@ -52,33 +31,6 @@ def prep_fmt(env):
libs = [('libexecstream', ['cpp'], prep_default), libs = [('libexecstream', ['cpp'], prep_default),
('fmt/fmt', ['cc'], prep_fmt)] ('fmt/fmt', ['cc'], prep_fmt)]
if env['build_with_f2c']:
libs.append(('f2c_math', ['cpp','c'], prep_f2c))
# Create arith.h using the arithchk program
if not os.path.exists('arith.h'):
arithenv = prep_f2c(env)
# TODO: make link flag more general
arithenv.Append(CPPFLAGS='-DNO_FPINIT')
arithenv.Program('f2c_libs/arithchk/arithchk', source='f2c_libs/arithchk/arithchk.c',
LIBS=env['LIBM'])
arithenv.Command('#ext/f2c_libs/arith.h', 'f2c_libs/arithchk/arithchk$PROGSUFFIX',
'$SOURCE > $TARGET')
libs.append(('f2c_libs', 'c', prep_f2c))
if env['BUILD_BLAS_LAPACK']:
libs.append(('f2c_blas', ['c'], prep_f2c))
libs.append(('f2c_lapack', ['c'], prep_f2c))
else:
libs.append(('math', ['cpp','c','f'], prep_fortran))
if env['BUILD_BLAS_LAPACK']:
libs.append(('blas', ['f'], prep_default))
libs.append(('lapack', ['f'], prep_default))
for subdir, extensions, prepFunction in libs: for subdir, extensions, prepFunction in libs:
localenv = prepFunction(env) localenv = prepFunction(env)
objects = localenv.SharedObject(mglob(localenv, subdir, *extensions)) objects = localenv.SharedObject(mglob(localenv, subdir, *extensions))
@ -92,7 +44,7 @@ if env['system_sundials'] == 'n':
sundials_configh = {} sundials_configh = {}
if env['OS'] != 'Windows': if env['OS'] != 'Windows':
sundials_configh['SUNDIALS_USE_GENERIC_MATH'] = 1 sundials_configh['SUNDIALS_USE_GENERIC_MATH'] = 1
if not env['BUILD_BLAS_LAPACK']: if env['use_lapack']:
sundials_configh['SUNDIALS_BLAS_LAPACK'] = 1 sundials_configh['SUNDIALS_BLAS_LAPACK'] = 1
localenv.AlwaysBuild(env.Command('#include/cantera/ext/sundials/sundials_config.h', localenv.AlwaysBuild(env.Command('#include/cantera/ext/sundials/sundials_config.h',
'sundials_config.h.in', 'sundials_config.h.in',
@ -106,10 +58,13 @@ if env['system_sundials'] == 'n':
Copy('$TARGET', '$SOURCE'))) Copy('$TARGET', '$SOURCE')))
# Compile Sundials source files # Compile Sundials source files
exclude = ['_klu', '_superlumt']
if not env['use_lapack']:
exclude.append('_lapack')
for subdir in ('sundials', 'nvec_ser', 'cvodes', 'ida'): for subdir in ('sundials', 'nvec_ser', 'cvodes', 'ida'):
libraryTargets.extend(localenv.SharedObject( libraryTargets.extend(localenv.SharedObject(
[f for f in mglob(localenv, 'sundials/src/'+subdir, 'c') [f for f in mglob(localenv, 'sundials/src/'+subdir, 'c')
if '_klu' not in f.name and '_superlumt' not in f.name])) if not any(pattern in f.name for pattern in exclude)]))
if not env['system_eigen']: if not env['system_eigen']:
build(localenv.Command('#include/cantera/ext/Eigen', '#ext/eigen/Eigen', build(localenv.Command('#include/cantera/ext/Eigen', '#ext/eigen/Eigen',

View file

@ -44,8 +44,6 @@ CANTERA_FORTRAN_MODS=$(CANTERA_INSTALL_ROOT)/include/cantera
CANTERA_FORTRAN_SYSLIBS=@mak_fort_threadflags@ -lstdc++ CANTERA_FORTRAN_SYSLIBS=@mak_fort_threadflags@ -lstdc++
CANTERA_SYSLIBS=@mak_syslibs@
############################################################################### ###############################################################################
# BOOST # BOOST
############################################################################### ###############################################################################
@ -79,7 +77,7 @@ CANTERA_DEFINES = -DCANTERA_VERSION=@cantera_version@
CANTERA_LIBS=$(CANTERA_CORE_LIBS) \ CANTERA_LIBS=$(CANTERA_CORE_LIBS) \
$(CANTERA_EXTRA_LIBDIRS) $(CANTERA_SUNDIALS_LIBS) \ $(CANTERA_EXTRA_LIBDIRS) $(CANTERA_SUNDIALS_LIBS) \
$(CANTERA_BLAS_LAPACK_LIBS) $(CANTERA_SYSLIBS) $(CANTERA_BLAS_LAPACK_LIBS)
CANTERA_TOTAL_LIBS=$(CANTERA_LIBS) CANTERA_TOTAL_LIBS=$(CANTERA_LIBS)

View file

@ -84,12 +84,6 @@ if '-pthread' in localenv['thread_flags']:
else: else:
localenv['mak_fort_threadflags'] = '' localenv['mak_fort_threadflags'] = ''
if not localenv['build_with_f2c']:
localenv['mak_syslibs'] = ' '.join('-l%s' % s for s in localenv['FORTRANSYSLIBS'])
pc_libs.extend(localenv['FORTRANSYSLIBS'])
else:
localenv['mak_syslibs'] = ''
mak = build(localenv.SubstFile('Cantera.mak', 'Cantera.mak.in')) mak = build(localenv.SubstFile('Cantera.mak', 'Cantera.mak.in'))
install('$inst_incdir', mak) install('$inst_incdir', mak)

View file

@ -10,15 +10,11 @@ def baseSetup(env, subdir, extensions):
env.Append(CPPDEFINES={'CANTERA_DATA': escaped_datadir}) env.Append(CPPDEFINES={'CANTERA_DATA': escaped_datadir})
return defaultSetup(env, subdir, extensions) return defaultSetup(env, subdir, extensions)
def equilSetup(env, subdir, extensions):
env.Append(CPPPATH=['#ext/f2c_libs'])
return defaultSetup(env, subdir, extensions)
# (subdir, (file extensions), (extra setup(env))) # (subdir, (file extensions), (extra setup(env)))
libs = [('base', ['cpp'], baseSetup), libs = [('base', ['cpp'], baseSetup),
('thermo', ['cpp'], defaultSetup), ('thermo', ['cpp'], defaultSetup),
('tpx', ['cpp'], defaultSetup), ('tpx', ['cpp'], defaultSetup),
('equil', ['cpp','c'], equilSetup), ('equil', ['cpp','c'], defaultSetup),
('numerics', ['cpp'], defaultSetup), ('numerics', ['cpp'], defaultSetup),
('kinetics', ['cpp'], defaultSetup), ('kinetics', ['cpp'], defaultSetup),
('transport', ['cpp'], defaultSetup), ('transport', ['cpp'], defaultSetup),
@ -47,7 +43,6 @@ env['cantera_staticlib'] = lib
# Windows and OS X require shared libraries at link time # Windows and OS X require shared libraries at link time
if localenv['OS'] in ('Darwin', 'Windows', 'Cygwin'): if localenv['OS'] in ('Darwin', 'Windows', 'Cygwin'):
localenv.Append(LIBS=localenv['FORTRANSYSLIBS'])
if (localenv['system_sundials'] == 'y'): if (localenv['system_sundials'] == 'y'):
localenv.Append(LIBS=localenv['sundials_libs'], localenv.Append(LIBS=localenv['sundials_libs'],
LIBPATH=localenv['sundials_libdir']) LIBPATH=localenv['sundials_libdir'])