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/cc/module.cxx | 75 ++++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 34 deletions(-) (limited to 'build2/cc/module.cxx') diff --git a/build2/cc/module.cxx b/build2/cc/module.cxx index 56b74e9..a18271c 100644 --- a/build2/cc/module.cxx +++ b/build2/cc/module.cxx @@ -25,16 +25,12 @@ namespace build2 namespace cc { void config_module:: - init (scope& rs, const location& loc, const variable_map&) + guess (scope& rs, const location&, const variable_map&) { - tracer trace (x, "config_init"); + tracer trace (x, "guess_init"); bool cc_loaded (cast_false (rs["cc.core.config.loaded"])); - // Configure. - // - compiler_info ci; // For program patterns. - // Adjust module priority (compiler). Also order cc module before us // (we don't want to use priorities for that in case someone manages // to slot in-between). @@ -81,10 +77,10 @@ namespace build2 // Figure out which compiler we are dealing with, its target, etc. // const path& xc (cast (*p.first)); - ci = guess (x_lang, - xc, - cast_null (rs[config_c_coptions]), - cast_null (rs[config_x_coptions])); + ci = cc::guess (x_lang, + xc, + cast_null (rs[config_c_coptions]), + cast_null (rs[config_x_coptions])); // Split/canonicalize the target. First see if the user asked us to // use config.sub. @@ -118,6 +114,39 @@ namespace build2 } } + // Assign value to variables that describe the compile. + // + rs.assign (x_id) = ci.id.string (); + rs.assign (x_id_type) = ci.id.type; + rs.assign (x_id_variant) = ci.id.variant; + + rs.assign (x_version) = ci.version.string; + rs.assign (x_version_major) = ci.version.major; + rs.assign (x_version_minor) = ci.version.minor; + rs.assign (x_version_patch) = ci.version.patch; + rs.assign (x_version_build) = ci.version.build; + + // Also enter as x.target.{cpu,vendor,system,version,class} for + // convenience of access. + // + rs.assign (x_target_cpu) = tt.cpu; + rs.assign (x_target_vendor) = tt.vendor; + rs.assign (x_target_system) = tt.system; + rs.assign (x_target_version) = tt.version; + rs.assign (x_target_class) = tt.class_; + + rs.assign (x_target) = move (tt); + + new_ = p.second; + } + + void config_module:: + init (scope& rs, const location& loc, const variable_map&) + { + tracer trace (x, "config_init"); + + const target_triplet& tt (cast (rs[x_target])); + // Translate x_std value (if any) to the compiler option(s) (if any). // tstd = translate_std (ci, rs, cast_null (rs[x_std])); @@ -154,7 +183,7 @@ namespace build2 // If this is a new value (e.g., we are configuring), then print the // report at verbosity level 2 and up (-v). // - if (verb >= (p.second ? 2 : 3)) + if (verb >= (new_ ? 2 : 3)) { diag_record dr (text); @@ -220,31 +249,9 @@ namespace build2 rs.assign (x_sys_lib_dirs) = move (lib_dirs); rs.assign (x_sys_inc_dirs) = move (inc_dirs); - cid = ci.id.value (); - rs.assign (x_id) = ci.id.string (); - rs.assign (x_id_type) = move (ci.id.type); - rs.assign (x_id_variant) = move (ci.id.variant); - - rs.assign (x_version) = move (ci.version.string); - rs.assign (x_version_major) = ci.version.major; - rs.assign (x_version_minor) = ci.version.minor; - rs.assign (x_version_patch) = ci.version.patch; - rs.assign (x_version_build) = move (ci.version.build); - rs.assign (x_signature) = move (ci.signature); rs.assign (x_checksum) = move (ci.checksum); - // Also enter as x.target.{cpu,vendor,system,version,class} for - // convenience of access. - // - rs.assign (x_target_cpu) = tt.cpu; - rs.assign (x_target_vendor) = tt.vendor; - rs.assign (x_target_system) = tt.system; - rs.assign (x_target_version) = tt.version; - rs.assign (x_target_class) = tt.class_; - - rs.assign (x_target) = move (tt); - // config.x.{p,c,l}options // config.x.libs // @@ -275,7 +282,7 @@ namespace build2 // Load cc.core.config. // - if (!cc_loaded) + if (!cast_false (rs["cc.core.config.loaded"])) { // Prepare configuration hints. // -- cgit v1.1