From bf67cce25fb0d5a777a7c8b4931d39b82e34f275 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sat, 9 Apr 2016 22:31:40 -0400 Subject: [PATCH] [SCons] Make Eigen available to Cantera Check for a system copy of Eigen, and if that is not found, install Eigen's headers with the Cantera headers. Add the header 'eigen_dense.h' to provide a single header to include from other locations. --- SConstruct | 30 ++++++++++++++++++++++++++ ext/SConscript | 4 ++++ include/cantera/base/config.h.in | 2 ++ include/cantera/numerics/eigen_dense.h | 6 ++++++ 4 files changed, 42 insertions(+) create mode 100644 include/cantera/numerics/eigen_dense.h diff --git a/SConstruct b/SConstruct index e240ae031..f0b674d2a 100644 --- a/SConstruct +++ b/SConstruct @@ -407,6 +407,11 @@ config_options = [ 'sphinx_cmd', """Command to use for building the Sphinx documentation.""", 'sphinx-build', PathVariable.PathAccept), + EnumVariable( + 'system_eigen', + """Select whether to use Eigen from a system installation ('y'), from + a git submodule ('n'), or to decide automatically ('default').""", + 'default', ('default', 'y', 'n')), EnumVariable( 'system_sundials', """Select whether to use Sundials from a system installation ('y'), from @@ -771,6 +776,30 @@ if env['system_googletest'] in ('n', 'default'): 'Try manually checking out the submodule with:\n\n' ' git submodule update --init --recursive ext/googletest\n') +# Check for Eigen and checkout submodule if needed +if env['system_eigen'] in ('y', 'default'): + if conf.CheckCXXHeader('Eigen/Dense', '<>'): + env['system_eigen'] = True + elif env['system_eigen'] == 'y': + config_error('Expected system installation of Eigen, but it ' + 'could not be found.') + +if env['system_eigen'] in ('n', 'default'): + env['system_eigen'] = False + if not os.path.exists('ext/eigen/Eigen/Dense'): + if not os.path.exists('.git'): + config_error('Eigen is missing. Install Eigen in ext/eigen.') + + try: + code = subprocess.call(['git','submodule','update','--init', + '--recursive','ext/eigen']) + except Exception: + code = -1 + if code: + config_error('Eigen not found and submodule checkout failed.\n' + 'Try manually checking out the submodule with:\n\n' + ' git submodule update --init --recursive ext/eigen\n') + def get_expression_value(includes, expression): s = ['#include ' + i for i in includes] @@ -1222,6 +1251,7 @@ cdefine('LAPACK_FTN_TRAILING_UNDERSCORE', 'lapack_ftn_trailing_underscore') cdefine('FTN_TRAILING_UNDERSCORE', 'lapack_ftn_trailing_underscore') cdefine('LAPACK_NAMES_LOWERCASE', 'lapack_names', 'lower') configh['CT_USE_LAPACK'] = 0 if env['BUILD_BLAS_LAPACK'] else 1 +cdefine('CT_USE_SYSTEM_EIGEN', env['system_eigen']) config_h = env.Command('include/cantera/base/config.h', 'include/cantera/base/config.h.in', diff --git a/ext/SConscript b/ext/SConscript index 1354fa501..66ec22ed4 100644 --- a/ext/SConscript +++ b/ext/SConscript @@ -111,6 +111,10 @@ if env['system_sundials'] == 'n': [f for f in mglob(localenv, 'sundials/src/'+subdir, 'c') if '_klu' not in f.name and '_superlumt' not in f.name])) +if not env['system_eigen']: + build(localenv.Command('#include/cantera/ext/Eigen', '#ext/eigen/Eigen', + Copy('$TARGET', '$SOURCE'))) + # Google Test: Used internally for Cantera unit tests. if not env['system_googletest']: localenv = prep_gtest(env) diff --git a/include/cantera/base/config.h.in b/include/cantera/base/config.h.in index 948668f36..cd8d40c16 100644 --- a/include/cantera/base/config.h.in +++ b/include/cantera/base/config.h.in @@ -42,6 +42,8 @@ typedef int ftnlen; // Fortran hidden string length type %(LAPACK_FTN_TRAILING_UNDERSCORE)s %(CT_USE_LAPACK)s +%(CT_USE_SYSTEM_EIGEN)s + //--------- operating system -------------------------------------- // The configure script defines this if the operating system is Mac diff --git a/include/cantera/numerics/eigen_dense.h b/include/cantera/numerics/eigen_dense.h new file mode 100644 index 000000000..b64e6b8ca --- /dev/null +++ b/include/cantera/numerics/eigen_dense.h @@ -0,0 +1,6 @@ +#include "cantera/base/ct_defs.h" +#if CT_USE_SYSTEM_EIGEN +#include +#else +#include "cantera/ext/Eigen/Dense" +#endif