From ed24198e633203e9f59ccfb40479cf5eef165e85 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 11 Jan 2018 21:42:25 -0500 Subject: [PATCH] Add option to compile yaml-cpp or use system library --- SConstruct | 36 ++++++++++++++++++++++++++++++++ ext/SConscript | 18 ++++++++++++++++ include/cantera/base/config.h.in | 1 + include/cantera/base/yaml.h | 6 ++++++ src/kinetics/importKinetics.cpp | 1 + 5 files changed, 62 insertions(+) create mode 100644 include/cantera/base/yaml.h diff --git a/SConstruct b/SConstruct index 769c80554..e1f56514b 100644 --- a/SConstruct +++ b/SConstruct @@ -440,6 +440,14 @@ config_options = [ ('y'), from a Git submodule ('n'), or to decide automatically ('default').""", 'default', ('default', 'y', 'n')), + EnumVariable( + 'system_yamlcpp', + """Select whether to use the yaml-cpp library from a system installation + ('y'), from a Git submodule ('n'), or to decide automatically + ('default'). If yaml-cpp is not installed directly into system + include and library directories, then you will need to add those + directories to 'extra_inc_dirs' and 'extra_lib_dirs'.""", + 'default', ('default', 'y', 'n')), EnumVariable( 'system_sundials', """Select whether to use SUNDIALS from a system installation ('y'), from @@ -908,6 +916,33 @@ elif env['system_googletest'] == 'y': elif env['system_googletest'] == 'n': env['googletest'] = 'submodule' +# Check for yaml-cpp library and checkout submodule if needed +if env['system_yamlcpp'] in ('y', 'default'): + if conf.CheckCXXHeader('yaml-cpp/yaml.h', '""'): + env['system_yamlcpp'] = True + print("""INFO: Using system installation of yaml-cpp library.""") + + elif env['system_yamlcpp'] == 'y': + config_error('Expected system installation of yaml-cpp library, but it ' + 'could not be found.') + +if env['system_yamlcpp'] in ('n', 'default'): + env['system_yamlcpp'] = False + print("""INFO: Using private installation of yaml-cpp library.""") + if not os.path.exists('ext/yaml-cpp/include/yaml-cpp/yaml.h'): + if not os.path.exists('.git'): + config_error('yaml-cpp is missing. Install source in ext/yaml-cpp.') + + try: + code = subprocess.call(['git', 'submodule', 'update', '--init', + '--recursive', 'ext/yaml-cpp']) + except Exception: + code = -1 + if code: + config_error('yaml-cpp submodule checkout failed.\n' + 'Try manually checking out the submodule with:\n\n' + ' git submodule update --init --recursive ext/yaml-cpp\n') + # Check for googletest and checkout submodule if needed if env['googletest'] in ('system', 'default'): has_gtest = conf.CheckCXXHeader('gtest/gtest.h', '""') @@ -1444,6 +1479,7 @@ cdefine('LAPACK_NAMES_LOWERCASE', 'lapack_names', 'lower') cdefine('CT_USE_LAPACK', 'use_lapack') cdefine('CT_USE_SYSTEM_EIGEN', 'system_eigen') cdefine('CT_USE_SYSTEM_FMT', 'system_fmt') +cdefine('CT_USE_SYSTEM_YAMLCPP', 'system_yamlcpp') config_h_build = env.Command('build/src/config.h.build', 'include/cantera/base/config.h.in', diff --git a/ext/SConscript b/ext/SConscript index e4cfd9d87..912bd6f0d 100644 --- a/ext/SConscript +++ b/ext/SConscript @@ -82,6 +82,24 @@ if env['system_sundials'] == 'n': libraryTargets.extend(localenv.SharedObject( [f for f in mglob(localenv, 'sundials/src/'+subdir, 'c')])) +if not env['system_yamlcpp']: + localenv = prep_default(env) + localenv.Prepend(CPPPATH=Dir('#include/cantera/ext')) + license_files.append(('YAML-CPP', 'yaml-cpp/LICENSE')) + + # Copy header files into common include directory + for subdir in ('', 'contrib', 'node', 'node/detail'): + for header in mglob(env, 'yaml-cpp/include/yaml-cpp/'+subdir, 'h'): + h = build(localenv.Command('#include/cantera/ext/yaml-cpp/{}/{}'.format(subdir, header.name), + '#ext/yaml-cpp/include/yaml-cpp/{}/{}'.format(subdir, header.name), + Copy('$TARGET', '$SOURCE'))) + + # Compile yaml-cpp source files + for subdir in ('', 'contrib'): + libraryTargets.extend(localenv.SharedObject( + [f for f in mglob(localenv, 'yaml-cpp/src/'+subdir, 'cpp')])) + + if not env['system_eigen']: license_files.append(('Eigen', 'eigen/COPYING.MPL2')) h = build(copyenv.Command('#include/cantera/ext/Eigen', '#ext/eigen/Eigen', diff --git a/include/cantera/base/config.h.in b/include/cantera/base/config.h.in index 15e25c845..75cf23227 100644 --- a/include/cantera/base/config.h.in +++ b/include/cantera/base/config.h.in @@ -44,6 +44,7 @@ typedef int ftnlen; // Fortran hidden string length type %(CT_USE_SYSTEM_EIGEN)s %(CT_USE_SYSTEM_FMT)s +%(CT_USE_SYSTEM_YAMLCPP)s //--------- operating system -------------------------------------- diff --git a/include/cantera/base/yaml.h b/include/cantera/base/yaml.h new file mode 100644 index 000000000..638d0d79a --- /dev/null +++ b/include/cantera/base/yaml.h @@ -0,0 +1,6 @@ +#include "cantera/base/ct_defs.h" +#if CT_USE_SYSTEM_YAMLCPP +#include "yaml-cpp/yaml.h" +#else +#include "cantera/ext/yaml-cpp/yaml.h" +#endif diff --git a/src/kinetics/importKinetics.cpp b/src/kinetics/importKinetics.cpp index cb02ea76f..2f1458d78 100644 --- a/src/kinetics/importKinetics.cpp +++ b/src/kinetics/importKinetics.cpp @@ -18,6 +18,7 @@ #include "cantera/kinetics/Reaction.h" #include "cantera/base/stringUtils.h" #include "cantera/base/ctml.h" +#include "cantera/base/yaml.h" #include