diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2018-10-25 17:18:37 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2018-10-25 17:44:42 +0200 |
commit | 8ababa51319753c5c697374c722bb01e845e3e68 (patch) | |
tree | c8f89bffc129d3004da232c327eb81b9a1459e77 /build2/cc/guess.hxx | |
parent | 59dec666d17fdd7c5394c3c081cf21381a8af07d (diff) |
Redesign cc::compiler_id to make variant customizable
Diffstat (limited to 'build2/cc/guess.hxx')
-rw-r--r-- | build2/cc/guess.hxx | 70 |
1 files changed, 39 insertions, 31 deletions
diff --git a/build2/cc/guess.hxx b/build2/cc/guess.hxx index 6e0281c..8b10b29 100644 --- a/build2/cc/guess.hxx +++ b/build2/cc/guess.hxx @@ -26,45 +26,53 @@ namespace build2 // msvc Microsoft cl.exe // icc Intel icc/icpc // - struct compiler_id + // Note that the user can provide a custom id with one of the predefined + // types and a custom variant (say 'gcc-tasking'). + // + enum class compiler_type { - std::string type; - std::string variant; + gcc = 1, // 0 value represents invalid type. + clang, + msvc, + icc + // Update compiler_id(string) and to_string() if adding a new type. + }; - bool - empty () const {return type.empty ();} + const compiler_type invalid_compiler_type = static_cast<compiler_type> (0); - std::string - string () const {return variant.empty () ? type : type + "-" + variant;} - - enum value_type - { - gcc, - clang, - clang_apple, - msvc, - icc - }; - - value_type - value () const; - - compiler_id () = default; - compiler_id (value_type); - compiler_id (std::string t, std::string v) - : type (move (t)), variant (move (v)) {} - }; + string + to_string (compiler_type); inline ostream& - operator<< (ostream& os, const compiler_id& id) + operator<< (ostream& o, const compiler_type& t) { - return os << id.string (); + return o << to_string (t); } + struct compiler_id + { + compiler_type type = invalid_compiler_type; + std::string variant; + + bool + empty () const {return type == invalid_compiler_type;} + + std::string + string () const; + + compiler_id () + : type (invalid_compiler_type) {} + + compiler_id (compiler_type t, std::string v) + : type (t), variant (move (v)) {} + + //compiler_id (const std::string& type, std::string variant); + }; + inline ostream& - operator<< (ostream& os, const compiler_id::value_type& v) + operator<< (ostream& o, const compiler_id& id) { - return os << compiler_id (v); + return o << id.string (); } // Compiler class describes a set of compilers that follow more or less @@ -87,9 +95,9 @@ namespace build2 to_string (compiler_class); inline ostream& - operator<< (ostream& os, compiler_class cl) + operator<< (ostream& o, compiler_class c) { - return os << to_string (cl); + return o << to_string (c); } // Compiler version. Here we map the various compiler version formats to |