diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2023-07-27 12:58:59 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2023-07-27 12:58:59 +0200 |
commit | a021dcbcabb4898f65110bd6f08fa767f8f5a2f8 (patch) | |
tree | 8a3a1e972b220c9cef3314be4979909a3c0e9da6 /libbuild2/c | |
parent | 0f265841e3d3a9a2b63f6f1a3cfa46b9ddc72b89 (diff) |
Recognize cNN/c++NN in addition to NN in c.std/cxx.std
Also recognize 23 in addition to 2x for C23.
Diffstat (limited to 'libbuild2/c')
-rw-r--r-- | libbuild2/c/init.cxx | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/libbuild2/c/init.cxx b/libbuild2/c/init.cxx index 42ade68..c3d8174 100644 --- a/libbuild2/c/init.cxx +++ b/libbuild2/c/init.cxx @@ -54,6 +54,26 @@ namespace build2 strings& mode, const string* v) const { + // The standard is `NN` but can also be `gnuNN`. + + // This helper helps recognize both NN and [cC]NN to avoid an endless + // stream of user questions. It can also be used to recognize Nx in + // addition to NN (e.g., "23" and "2x"). + // + auto stdcmp = [v] (const char* nn, const char* nx = nullptr) + { + if (v != nullptr) + { + const char* s (v->c_str ()); + if (s[0] == 'c' || s[0] == 'C') + s += 1; + + return strcmp (s, nn) == 0 || (nx != nullptr && strcmp (s, nx) == 0); + } + + return false; + }; + switch (ci.class_) { case compiler_class::msvc: @@ -92,17 +112,17 @@ namespace build2 // if (v == nullptr) ; - else if (*v != "90") + else if (!stdcmp ("90")) { uint64_t cver (ci.version.major); - if ((*v == "99" && cver < 16) || // Since VS2010/10.0. - ((*v == "11" || - *v == "17" || - *v == "18") && cver < 18) || - (*v == "2x" )) + if ((stdcmp ("99") && cver < 16) || // Since VS2010/10.0. + ((stdcmp ("11") || + stdcmp ("17") || + stdcmp ("18")) && cver < 18) || // Since VS????/11.0. + (stdcmp ("23", "2x") )) { - fail << "C" << *v << " is not supported by " << ci.signature << + fail << "C " << *v << " is not supported by " << ci.signature << info << "required by " << project (rs) << '@' << rs; } } @@ -119,12 +139,12 @@ namespace build2 { string o ("-std="); - if (*v == "2x") o += "c2x"; // GCC 9, Clang 9 (8?). - else if (*v == "17" || - *v == "18") o += "c17"; // GCC 8, Clang 6. - else if (*v == "11") o += "c1x"; - else if (*v == "99") o += "c9x"; - else if (*v == "90") o += "c90"; + if (stdcmp ("23", "2x")) o += "c2x"; // GCC 9, Clang 9 (8?). + else if (stdcmp ("17") || + stdcmp ("18")) o += "c17"; // GCC 8, Clang 6. + else if (stdcmp ("11")) o += "c1x"; + else if (stdcmp ("99")) o += "c9x"; + else if (stdcmp ("90")) o += "c90"; else o += *v; // In case the user specifies `gnuNN` or some such. mode.insert (mode.begin (), move (o)); |