From e2ba7fa123213fcc5673119b8d993d7967a1fb24 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 7 Sep 2017 18:09:44 +0200 Subject: Implement {c,cxx}.guess modules These can be loaded before {c,cxx} to guess the compiler. Based on this information we can then choose the standard, experimental features, etc. For example: using cxx.guess if ($cxx.id == 'clang') cxx.features.modules = false cxx.std = experimental using cxx --- build2/cxx/init.cxx | 61 +++++++++++++++++++++++++++++++++++++++-------------- build2/cxx/init.hxx | 9 ++++++++ 2 files changed, 54 insertions(+), 16 deletions(-) (limited to 'build2/cxx') diff --git a/build2/cxx/init.cxx b/build2/cxx/init.cxx index 5bd14ee..4a72c90 100644 --- a/build2/cxx/init.cxx +++ b/build2/cxx/init.cxx @@ -30,7 +30,7 @@ namespace build2 config_module (config_data&& d) : config_data (move (d)), cc::config_module (move (d)) {} - strings + virtual strings translate_std (const compiler_info&, scope&, const string*) const override; @@ -285,22 +285,24 @@ namespace build2 return r; } + // See cc::module for details on guess_init vs config_init. + // bool - config_init (scope& rs, - scope& bs, - const location& loc, - unique_ptr& mod, - bool, - bool, - const variable_map& hints) + guess_init (scope& rs, + scope& bs, + const location& loc, + unique_ptr& mod, + bool, + bool, + const variable_map& hints) { - tracer trace ("cxx::config_init"); + tracer trace ("cxx::guess_init"); l5 ([&]{trace << "for " << bs.out_path ();}); // We only support root loading (which means there can only be one). // if (&rs != &bs) - fail (loc) << "cxx.config module must be loaded in project root"; + fail (loc) << "cxx.guess module must be loaded in project root"; // Load cc.core.vars so that we can cache all the cc.* variables. // @@ -396,7 +398,34 @@ namespace build2 assert (mod == nullptr); config_module* m (new config_module (move (d))); mod.reset (m); - m->init (rs, loc, hints); + m->guess (rs, loc, hints); + return true; + } + + bool + config_init (scope& rs, + scope& bs, + const location& loc, + unique_ptr&, + bool, + bool, + const variable_map& hints) + { + tracer trace ("cxx::config_init"); + l5 ([&]{trace << "for " << bs.out_path ();}); + + // We only support root loading (which means there can only be one). + // + if (&rs != &bs) + fail (loc) << "cxx.config module must be loaded in project root"; + + // Load cxx.guess. + // + if (!cast_false (rs["cxx.guess.loaded"])) + load_module (rs, rs, "cxx.guess", loc, false, hints); + + config_module& cm (*rs.modules.lookup ("cxx.guess")); + cm.init (rs, loc, hints); return true; } @@ -444,7 +473,7 @@ namespace build2 if (!cast_false (rs["cxx.config.loaded"])) load_module (rs, rs, "cxx.config", loc, false, hints); - config_module& cm (*rs.modules.lookup ("cxx.config")); + config_module& cm (*rs.modules.lookup ("cxx.guess")); auto& vp (var_pool.rw (rs)); @@ -467,10 +496,10 @@ namespace build2 "cxx.install", "cxx.uninstall", - cm.cid, - cast (rs[cm.x_id_variant]), - cast (rs[cm.x_version_major]), - cast (rs[cm.x_version_minor]), + cm.ci.id.value (), + cm.ci.id.variant, + cm.ci.version.major, + cm.ci.version.minor, cast (rs[cm.x_path]), cast (rs[cm.x_target]), diff --git a/build2/cxx/init.hxx b/build2/cxx/init.hxx index 5ba4041..a952bf8 100644 --- a/build2/cxx/init.hxx +++ b/build2/cxx/init.hxx @@ -15,6 +15,15 @@ namespace build2 namespace cxx { bool + guess_init (scope&, + scope&, + const location&, + unique_ptr&, + bool, + bool, + const variable_map&); + + bool config_init (scope&, scope&, const location&, -- cgit v1.1