From d4ddabc76c2bdfd54d61f76de6bfe477912325eb Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 5 Jul 2016 13:56:33 -0400 Subject: [PATCH] Use system-installed version of fmt library if available Resolves #348. --- SConstruct | 48 ++++++++++++++----- ext/SConscript | 11 ++--- include/cantera/base/config.h.in | 1 + include/cantera/base/ctexceptions.h | 3 +- include/cantera/base/fmt.h | 10 ++++ include/cantera/base/global.h | 2 +- include/cantera/base/stringUtils.h | 2 +- src/SConscript | 2 + .../surfSolverTest/surfaceSolver.cpp | 2 +- .../surfSolverTest/surfaceSolver2.cpp | 2 +- 10 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 include/cantera/base/fmt.h diff --git a/SConstruct b/SConstruct index 0a3292ecd..31c0eaee0 100644 --- a/SConstruct +++ b/SConstruct @@ -412,6 +412,12 @@ config_options = [ """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_fmt', + """Select whether to use the fmt library 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 @@ -730,19 +736,32 @@ if not conf.CheckCXXHeader('cmath', '<>'): config_error('The C++ compiler is not correctly configured.') # Check for fmt library and checkout submodule if needed -if not os.path.exists('ext/fmt/fmt/format.h'): - if not os.path.exists('.git'): - config_error('fmt is missing. Install source in ext/fmt.') +# Test for 'ostream.h' to ensure that version >= 3.0.0 is available +if env['system_fmt'] in ('y', 'default'): + if conf.CheckCXXHeader('fmt/ostream.h', '""'): + env['system_fmt'] = True + print """INFO: Using system installation of fmt library.""" - try: - code = subprocess.call(['git','submodule','update','--init', - '--recursive','ext/fmt']) - except Exception: - code = -1 - if code: - config_error('fmt submodule checkout failed.\n' - 'Try manually checking out the submodule with:\n\n' - ' git submodule update --init --recursive ext/fmt\n') + elif env['system_fmt'] == 'y': + config_error('Expected system installation of fmt library, but it ' + 'could not be found.') + +if env['system_fmt'] in ('n', 'default'): + env['system_fmt'] = False + print """INFO: Using private installation of fmt library.""" + if not os.path.exists('ext/fmt/fmt/format.h'): + if not os.path.exists('.git'): + config_error('fmt is missing. Install source in ext/fmt.') + + try: + code = subprocess.call(['git','submodule','update','--init', + '--recursive','ext/fmt']) + except Exception: + code = -1 + if code: + config_error('fmt submodule checkout failed.\n' + 'Try manually checking out the submodule with:\n\n' + ' git submodule update --init --recursive ext/fmt\n') # Check for googletest and checkout submodule if needed if env['system_googletest'] in ('y', 'default'): @@ -1242,6 +1261,7 @@ cdefine('FTN_TRAILING_UNDERSCORE', 'lapack_ftn_trailing_underscore') cdefine('LAPACK_NAMES_LOWERCASE', 'lapack_names', 'lower') cdefine('CT_USE_LAPACK', 'use_lapack') cdefine('CT_USE_SYSTEM_EIGEN', env['system_eigen']) +cdefine('CT_USE_SYSTEM_FMT', 'system_fmt') config_h = env.Command('include/cantera/base/config.h', 'include/cantera/base/config.h.in', @@ -1335,6 +1355,10 @@ if env['blas_lapack_libs']: linkLibs.extend(env['blas_lapack_libs']) linkSharedLibs.extend(env['blas_lapack_libs']) +if env['system_fmt']: + linkLibs.append('fmt') + linkSharedLibs.append('fmt') + # Store the list of needed static link libraries in the environment env['cantera_libs'] = linkLibs env['cantera_shared_libs'] = linkSharedLibs diff --git a/ext/SConscript b/ext/SConscript index 7d0738c2a..37a930b7d 100644 --- a/ext/SConscript +++ b/ext/SConscript @@ -26,12 +26,11 @@ def prep_gtest(env): def prep_fmt(env): localenv = prep_default(env) license_files.append(('fmtlib', 'fmt/LICENSE.rst')) - build(localenv.Command("#include/cantera/ext/fmt/format.h", - "#ext/fmt/fmt/format.h", - Copy('$TARGET', '$SOURCE'))) - build(localenv.Command("#include/cantera/ext/fmt/ostream.h", - "#ext/fmt/fmt/ostream.h", - Copy('$TARGET', '$SOURCE'))) + if not env['system_fmt']: + for name in ('format.h', 'ostream.h'): + build(localenv.Command("#include/cantera/ext/fmt/" + name, + "#ext/fmt/fmt/" + name, + Copy('$TARGET', '$SOURCE'))) return localenv # each element of libs is: (subdir, (file extensions), prepfunction) diff --git a/include/cantera/base/config.h.in b/include/cantera/base/config.h.in index cd8d40c16..18b850b9d 100644 --- a/include/cantera/base/config.h.in +++ b/include/cantera/base/config.h.in @@ -43,6 +43,7 @@ typedef int ftnlen; // Fortran hidden string length type %(CT_USE_LAPACK)s %(CT_USE_SYSTEM_EIGEN)s +%(CT_USE_SYSTEM_FMT)s //--------- operating system -------------------------------------- diff --git a/include/cantera/base/ctexceptions.h b/include/cantera/base/ctexceptions.h index ef6ea6be1..3c6ef9143 100644 --- a/include/cantera/base/ctexceptions.h +++ b/include/cantera/base/ctexceptions.h @@ -9,9 +9,8 @@ #ifndef CT_CTEXCEPTIONS_H #define CT_CTEXCEPTIONS_H +#include "cantera/base/fmt.h" #include -#include -#include "cantera/ext/fmt/format.h" namespace Cantera { diff --git a/include/cantera/base/fmt.h b/include/cantera/base/fmt.h new file mode 100644 index 000000000..d11f64172 --- /dev/null +++ b/include/cantera/base/fmt.h @@ -0,0 +1,10 @@ +//! @file fmt.h Wrapper for either system-installed or local headers for fmt +#include "ct_defs.h" + +#if CT_USE_SYSTEM_FMT + #include "fmt/format.h" + #include "fmt/ostream.h" +#else + #include "cantera/ext/fmt/format.h" + #include "cantera/ext/fmt/ostream.h" +#endif diff --git a/include/cantera/base/global.h b/include/cantera/base/global.h index 7d12d14f0..1c0a06ee6 100644 --- a/include/cantera/base/global.h +++ b/include/cantera/base/global.h @@ -18,7 +18,7 @@ #define CT_GLOBAL_H #include "ct_defs.h" -#include "cantera/ext/fmt/format.h" +#include "cantera/base/fmt.h" namespace Cantera { diff --git a/include/cantera/base/stringUtils.h b/include/cantera/base/stringUtils.h index 5df4806a8..8ecd622cd 100644 --- a/include/cantera/base/stringUtils.h +++ b/include/cantera/base/stringUtils.h @@ -8,7 +8,7 @@ #define CT_STRINGUTILS_H #include "ct_defs.h" -#include "cantera/ext/fmt/format.h" +#include "cantera/base/fmt.h" #include diff --git a/src/SConscript b/src/SConscript index 14a1cef66..d033f880b 100644 --- a/src/SConscript +++ b/src/SConscript @@ -49,6 +49,8 @@ if localenv['OS'] in ('Darwin', 'Windows', 'Cygwin'): if localenv['blas_lapack_libs']: localenv.Append(LIBS=localenv['blas_lapack_libs'], LIBPATH=localenv['blas_lapack_dir']) + if localenv['system_fmt']: + localenv.Append(LIBS='fmt') # Build the Cantera shared library if localenv['layout'] != 'debian': diff --git a/test_problems/surfSolverTest/surfaceSolver.cpp b/test_problems/surfSolverTest/surfaceSolver.cpp index 09906d3cd..09ed96471 100644 --- a/test_problems/surfSolverTest/surfaceSolver.cpp +++ b/test_problems/surfSolverTest/surfaceSolver.cpp @@ -18,7 +18,7 @@ #include "cantera/kinetics.h" #include "cantera/kinetics/ImplicitSurfChem.h" #include "cantera/kinetics/solveSP.h" -#include "cantera/ext/fmt/ostream.h" +#include "cantera/base/fmt.h" #include #include diff --git a/test_problems/surfSolverTest/surfaceSolver2.cpp b/test_problems/surfSolverTest/surfaceSolver2.cpp index 28f07332c..a2adf6a70 100644 --- a/test_problems/surfSolverTest/surfaceSolver2.cpp +++ b/test_problems/surfSolverTest/surfaceSolver2.cpp @@ -27,7 +27,7 @@ static void printUsage() #include "cantera/kinetics.h" #include "cantera/kinetics/ImplicitSurfChem.h" #include "cantera/kinetics/solveSP.h" -#include "cantera/ext/fmt/ostream.h" +#include "cantera/base/fmt.h" #include #include