aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-02-23 10:47:16 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-02-23 10:47:16 +0200
commitbb811b27cffbeb4c24d9d3f2e739f99eab8299ec (patch)
tree28aec7f2dd521cca2ed34ddacf344cf0aa89c474
parent3a1eed21d4d5d0e7f6a9f400420fdc28d7be9b61 (diff)
Add --std option that allows selecting between C++98 and C++11
-rw-r--r--odb/odb.cxx56
-rw-r--r--odb/option-types.cxx35
-rw-r--r--odb/option-types.hxx23
-rw-r--r--odb/options.cli11
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<char*> 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
+ {
+ "<version>",
+ "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
{
"<dir>",