build: update default CXXFLAGS.
* Add -std=c++03 and -pedantic, and fix the resulting warnings. The
long-long-int warning is explicitly suppressed because it's not
trivial to workaround in a platform-independent and ISO-conformant
way without using C++11.
* Initial support for building with -std=c++11 (experimental).
* Prefer -Og optimization level in debug builds if supported by the
compiler.
Change-Id: I744a25c8b52842dc3ea3a733d6ab2fa66171e6f8
diff --git a/.waf-tools/boost.py b/.waf-tools/boost.py
index e54f513..305945a 100644
--- a/.waf-tools/boost.py
+++ b/.waf-tools/boost.py
@@ -61,6 +61,14 @@
#include <boost/version.hpp>
int main() { std::cout << BOOST_LIB_VERSION << ":" << BOOST_VERSION << std::endl; }
'''
+BOOST_SYSTEM_CODE = '''
+#include <boost/system/error_code.hpp>
+int main() { boost::system::error_code c; }
+'''
+BOOST_THREAD_CODE = '''
+#include <boost/thread.hpp>
+int main() { boost::thread t; }
+'''
# toolsets from {boost_dir}/tools/build/v2/tools/common.jam
PLATFORM = Utils.unversioned_sys_platform()
@@ -96,10 +104,10 @@
opt.add_option('--boost-includes', type='string',
default='', dest='boost_includes',
- help='''path to the directory where the boost includes are, e.g., /path/to/boost_1_47_0/stage/include''')
+ help='''path to the directory where the boost includes are, e.g., /path/to/boost_1_55_0/stage/include''')
opt.add_option('--boost-libs', type='string',
default='', dest='boost_libs',
- help='''path to the directory where the boost libs are, e.g., /path/to/boost_1_47_0/stage/lib''')
+ help='''path to the directory where the boost libs are, e.g., /path/to/boost_1_55_0/stage/lib''')
opt.add_option('--boost-static', action='store_true',
default=False, dest='boost_static',
help='link with static boost libraries (.lib/.a)')
@@ -136,10 +144,10 @@
except (OSError, IOError):
Logs.error("Could not read the file %r" % node.abspath())
else:
- re_but1 = re.compile('^#define\\s+BOOST_LIB_VERSION\\s+"(.*)"', re.M)
+ re_but1 = re.compile('^#define\\s+BOOST_LIB_VERSION\\s+"(.+)"', re.M)
m1 = re_but1.search(txt)
- re_but2 = re.compile('^#define\\s+BOOST_VERSION\\s+"(.*)"', re.M)
+ re_but2 = re.compile('^#define\\s+BOOST_VERSION\\s+(\\d+)', re.M)
m2 = re_but2.search(txt)
if m1 and m2:
@@ -310,19 +318,13 @@
def try_link():
if 'system' in params['lib']:
self.check_cxx(
- fragment="\n".join([
- '#include <boost/system/error_code.hpp>',
- 'int main() { boost::system::error_code c; }',
- ]),
+ fragment=BOOST_SYSTEM_CODE,
use=var,
execute=False,
)
if 'thread' in params['lib']:
self.check_cxx(
- fragment="\n".join([
- '#include <boost/thread.hpp>',
- 'int main() { boost::thread t; }',
- ]),
+ fragment=BOOST_THREAD_CODE,
use=var,
execute=False,
)
diff --git a/.waf-tools/default-compiler-flags.py b/.waf-tools/default-compiler-flags.py
index 299493a..9f7843e 100644
--- a/.waf-tools/default-compiler-flags.py
+++ b/.waf-tools/default-compiler-flags.py
@@ -12,14 +12,24 @@
def configure(conf):
areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
+ defaultFlags = []
+
+ if conf.options.use_cxx11:
+ defaultFlags += ['-std=c++0x', '-std=c++11']
+ else:
+ defaultFlags += ['-std=c++03']
+
+ defaultFlags += ['-pedantic', '-Wall', '-Wno-long-long']
+
if conf.options.debug:
conf.define('_DEBUG', 1)
- defaultFlags = ['-O0', '-g3',
- '-Werror',
- '-Wall',
- '-fcolor-diagnostics', # only clang supports
+ defaultFlags += ['-O0',
+ '-Og', # gcc >= 4.8
+ '-g3',
+ '-fcolor-diagnostics', # clang
+ '-fdiagnostics-color', # gcc >= 4.9
+ '-Werror'
]
-
if areCustomCxxflagsPresent:
missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
if len(missingFlags) > 0:
@@ -27,11 +37,11 @@
% " ".join(conf.env.CXXFLAGS))
Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
else:
- conf.add_supported_cxxflags(cxxflags=defaultFlags)
+ conf.add_supported_cxxflags(defaultFlags)
else:
- defaultFlags = ['-O2', '-g', '-Wall']
+ defaultFlags += ['-O2', '-g']
if not areCustomCxxflagsPresent:
- conf.add_supported_cxxflags(cxxflags=defaultFlags)
+ conf.add_supported_cxxflags(defaultFlags)
@Configure.conf
def add_supported_cxxflags(self, cxxflags):
@@ -45,5 +55,5 @@
if self.check_cxx(cxxflags=[flag], mandatory=False):
supportedFlags += [flag]
- self.end_msg(' '.join (supportedFlags))
+ self.end_msg(' '.join(supportedFlags))
self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS