aboutsummaryrefslogtreecommitdiff
path: root/build2/cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-09-07 18:09:44 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-09-07 18:09:44 +0200
commite2ba7fa123213fcc5673119b8d993d7967a1fb24 (patch)
tree22b545150af90ec2831a2665afbac9b19828e65f /build2/cxx
parentd01c30fa81a849ea7545b8235656eb1dcbba877b (diff)
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
Diffstat (limited to 'build2/cxx')
-rw-r--r--build2/cxx/init.cxx61
-rw-r--r--build2/cxx/init.hxx9
2 files changed, 54 insertions, 16 deletions
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<module_base>& mod,
- bool,
- bool,
- const variable_map& hints)
+ guess_init (scope& rs,
+ scope& bs,
+ const location& loc,
+ unique_ptr<module_base>& 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<module_base>&,
+ 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<bool> (rs["cxx.guess.loaded"]))
+ load_module (rs, rs, "cxx.guess", loc, false, hints);
+
+ config_module& cm (*rs.modules.lookup<config_module> ("cxx.guess"));
+ cm.init (rs, loc, hints);
return true;
}
@@ -444,7 +473,7 @@ namespace build2
if (!cast_false<bool> (rs["cxx.config.loaded"]))
load_module (rs, rs, "cxx.config", loc, false, hints);
- config_module& cm (*rs.modules.lookup<config_module> ("cxx.config"));
+ config_module& cm (*rs.modules.lookup<config_module> ("cxx.guess"));
auto& vp (var_pool.rw (rs));
@@ -467,10 +496,10 @@ namespace build2
"cxx.install",
"cxx.uninstall",
- cm.cid,
- cast<string> (rs[cm.x_id_variant]),
- cast<uint64_t> (rs[cm.x_version_major]),
- cast<uint64_t> (rs[cm.x_version_minor]),
+ cm.ci.id.value (),
+ cm.ci.id.variant,
+ cm.ci.version.major,
+ cm.ci.version.minor,
cast<process_path> (rs[cm.x_path]),
cast<target_triplet> (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<module_base>&,
+ bool,
+ bool,
+ const variable_map&);
+
+ bool
config_init (scope&,
scope&,
const location&,