diff --git a/SConstruct b/SConstruct index 6d6ff9104..ce40e1831 100644 --- a/SConstruct +++ b/SConstruct @@ -881,7 +881,7 @@ if env['system_fmt'] in ('y', 'default'): 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/ostream.h'): + if not os.path.exists('ext/fmt/include/fmt/ostream.h'): if not os.path.exists('.git'): config_error('fmt is missing. Install source in ext/fmt.') @@ -895,6 +895,18 @@ if env['system_fmt'] in ('n', 'default'): 'Try manually checking out the submodule with:\n\n' ' git submodule update --init --recursive ext/fmt\n') +fmt_include = '' if env['system_fmt'] else '"../ext/fmt/include/fmt/format.h"' +fmt_version_source = get_expression_value([fmt_include], 'FMT_VERSION') +retcode, fmt_lib_version = conf.TryRun(fmt_version_source, '.cpp') +try: + fmt_lib_version = divmod(float(fmt_lib_version.strip()), 10000) + (fmt_maj, (fmt_min, fmt_pat)) = fmt_lib_version[0], divmod(fmt_lib_version[1], 100) + env['FMT_VERSION'] = '{major:.0f}.{minor:.0f}.{patch:.0f}'.format(major=fmt_maj, minor=fmt_min, patch=fmt_pat) + print('INFO: Found fmt version {}'.format(env['FMT_VERSION'])) +except ValueError: + env['FMT_VERSION'] = '0.0.0' + print('INFO: Could not find version of fmt') + # Check for googletest and checkout submodule if needed if env['system_googletest'] in ('y', 'default'): has_gtest = conf.CheckCXXHeader('gtest/gtest.h', '""') diff --git a/ext/SConscript b/ext/SConscript index 0a143509f..3b9c89c03 100644 --- a/ext/SConscript +++ b/ext/SConscript @@ -37,16 +37,23 @@ def prep_gmock(env): def prep_fmt(env): localenv = prep_default(env) if not env['system_fmt']: + localenv.Prepend(CPPPATH=Dir('#include/cantera/ext')) license_files.append(('fmtlib', 'fmt/LICENSE.rst')) - for name in ('format.h', 'ostream.h'): + for name in ('format.h', 'ostream.h', 'printf.h', 'core.h', 'format-inl.h', 'posix.h'): build(copyenv.Command("#include/cantera/ext/fmt/" + name, - "#ext/fmt/fmt/" + name, + "#ext/fmt/include/fmt/" + name, Copy('$TARGET', '$SOURCE'))) return localenv # each element of libs is: (subdir, (file extensions), prepfunction) -libs = [('libexecstream', ['cpp'], prep_default), - ('fmt/fmt', ['cc'], prep_fmt)] +libs = [('libexecstream', ['cpp'], prep_default)] + +# fmtlib versions less than 5.0.0 had the source files for the library in a different folder. +# Also, we expect system-installed versions of fmtlib >= 5.0.0 to have a library already compiled +if LooseVersion(env['FMT_VERSION']) < LooseVersion('5.0.0'): + libs.append(('fmt/fmt', ['cc'], prep_fmt)) +elif not env['system_fmt']: + libs.append(('fmt/src', ['cc'], prep_fmt)) for subdir, extensions, prepFunction in libs: localenv = prepFunction(env) diff --git a/ext/fmt b/ext/fmt index 7fa8f8fa4..5386f1df2 160000 --- a/ext/fmt +++ b/ext/fmt @@ -1 +1 @@ -Subproject commit 7fa8f8fa48b0903deab5bb42e6760477173ac485 +Subproject commit 5386f1df20392a08844f5034e8436c6ec7ce0b03