Skip to content

Commit

Permalink
Use system-installed version of fmt library if available
Browse files Browse the repository at this point in the history
Resolves #348.
  • Loading branch information
speth committed Jul 5, 2016
1 parent 4e23793 commit d4ddabc
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 24 deletions.
48 changes: 36 additions & 12 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""

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')
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'):
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions ext/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions include/cantera/base/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------------------------------------

Expand Down
3 changes: 1 addition & 2 deletions include/cantera/base/ctexceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
#ifndef CT_CTEXCEPTIONS_H
#define CT_CTEXCEPTIONS_H

#include "cantera/base/fmt.h"
#include <exception>
#include <string>
#include "cantera/ext/fmt/format.h"

namespace Cantera
{
Expand Down
10 changes: 10 additions & 0 deletions include/cantera/base/fmt.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion include/cantera/base/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/base/stringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define CT_STRINGUTILS_H

#include "ct_defs.h"
#include "cantera/ext/fmt/format.h"
#include "cantera/base/fmt.h"

#include <string>

Expand Down
2 changes: 2 additions & 0 deletions src/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
2 changes: 1 addition & 1 deletion test_problems/surfSolverTest/surfaceSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstdio>
#include <fstream>

Expand Down
2 changes: 1 addition & 1 deletion test_problems/surfSolverTest/surfaceSolver2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstdio>
#include <fstream>

Expand Down

0 comments on commit d4ddabc

Please sign in to comment.