From bb811b27cffbeb4c24d9d3f2e739f99eab8299ec Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 23 Feb 2012 10:47:16 +0200 Subject: Add --std option that allows selecting between C++98 and C++11 --- odb/odb.cxx | 56 +++++++++++++++++++++++++++++++++++++++------------- odb/option-types.cxx | 35 ++++++++++++++++++++++++++++++++ odb/option-types.hxx | 23 +++++++++++++++++++++ odb/options.cli | 11 +++++++++++ 4 files changed, 111 insertions(+), 14 deletions(-) diff --git a/odb/odb.cxx b/odb/odb.cxx index b17369a..38d7a50 100644 --- a/odb/odb.cxx +++ b/odb/odb.cxx @@ -325,6 +325,7 @@ main (int argc, char* argv[]) // args.push_back ("-x"); args.push_back ("c++"); + args.push_back (""); // Reserve space for -std=c++XX. args.push_back ("-S"); args.push_back ("-Wunknown-pragmas"); args.push_back ("-fplugin=" + plugin.string ()); @@ -459,21 +460,8 @@ main (int argc, char* argv[]) // args.insert (args.end (), def_inc_dirs.begin (), def_inc_dirs.end ()); - // Obtain profile (-I) search paths. - // - paths prof_paths (profile_paths (args, argv[0])); - - if (v) - { - e << "Profile search paths:" << endl; - - for (paths::const_iterator i (prof_paths.begin ()); - i != prof_paths.end (); ++i) - e << " " << *i << endl; - } - // Parse plugin options. We have to do it twice to get the target - // database which is need while loading profiles. + // database which is needed while loading profiles. // vector av; av.push_back (argv[0]); @@ -537,8 +525,39 @@ main (int argc, char* argv[]) } db = ops.database (); + + // Translate some ODB options to GCC options. + // + switch (ops.std ()) + { + case cxx_version::cxx98: + { + args[3] = "-std=c++98"; + break; + } + case cxx_version::cxx11: + { + args[3] = "-std=c++0x"; // c++11 was only added in GCC 4.7.0. + break; + } + } } + // Obtain profile (-I) search paths. + // + paths prof_paths (profile_paths (args, argv[0])); + + if (v) + { + e << "Profile search paths:" << endl; + + for (paths::const_iterator i (prof_paths.begin ()); + i != prof_paths.end (); ++i) + e << " " << *i << endl; + } + + // Second parse. + // profile_data pd (prof_paths, db, argv[0]); oi[1].search_func = &profile_search; oi[2].search_func = &profile_search; @@ -576,12 +595,21 @@ main (int argc, char* argv[]) string k, v; string a (plugin_args[i]); + // Ignore certain options. + // if (a == "--") { // Ignore the option seperator since GCC doesn't understand it. // continue; } + else if (a == "--std") + { + // Translated to GCC -std=. + // + ++i; + continue; + } cli::options::const_iterator it (desc.find (a)); diff --git a/odb/option-types.cxx b/odb/option-types.cxx index cfe1f06..3bbe72e 100644 --- a/odb/option-types.cxx +++ b/odb/option-types.cxx @@ -12,6 +12,41 @@ using namespace std; // +// cxx_version +// + +static const char* cxx_version_[] = +{ + "c++98", + "c++11" +}; + +const char* cxx_version:: +string () const +{ + return cxx_version_[v_]; +} + +istream& +operator>> (istream& is, cxx_version& v) +{ + string s; + is >> s; + + if (!is.fail ()) + { + if (s == "c++98") + v = cxx_version::cxx98; + else if (s == "c++11") + v = cxx_version::cxx11; + else + is.setstate (istream::failbit); + } + + return is; +} + +// // database // diff --git a/odb/option-types.hxx b/odb/option-types.hxx index 7da346f..de3bdb7 100644 --- a/odb/option-types.hxx +++ b/odb/option-types.hxx @@ -11,6 +11,29 @@ using semantics::relational::qname; +struct cxx_version +{ + enum value + { + cxx98, + cxx11 + }; + + cxx_version (value v = value (0)) : v_ (v) {} + operator value () const {return v_;} + + const char* + string () const; + +private: + value v_; +}; + +std::istream& +operator>> (std::istream&, cxx_version&); + +// +// struct database { enum value diff --git a/odb/options.cli b/odb/options.cli index 8f2bc56..f501315 100644 --- a/odb/options.cli +++ b/odb/options.cli @@ -164,6 +164,17 @@ class options then you should include it into the prefix value." }; + // Language. + // + cxx_version --std = cxx_version::cxx98 + { + "", + "Specify the C++ standard that should be used during compilation. + Valid values are \cb{c++98} (default) and \cb{c++11}." + }; + + // Output. + // std::string --output-dir | -o { "", -- cgit v1.1