blob: b2702437ff997ccb2bd13559eb6b0ce0cba2ef12 [file] [log] [blame]
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -07002
3from waflib import Logs, Configure
4
5def options(opt):
6 opt.add_option('--debug', '--with-debug', action='store_true', default=False, dest='debug',
7 help='''Compile in debugging mode without all optimizations (-O0)''')
Alexander Afanasyev766cea72014-04-24 19:16:42 -07008 opt.add_option('--with-c++11', action='store_true', default=False, dest='use_cxx11',
9 help='''Use C++ 11 features if available in the compiler''')
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070010
11def configure(conf):
12 areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070013 defaultFlags = []
14
15 if conf.options.use_cxx11:
16 defaultFlags += ['-std=c++0x', '-std=c++11']
17 else:
18 defaultFlags += ['-std=c++03']
19
20 defaultFlags += ['-pedantic', '-Wall', '-Wno-long-long']
21
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070022 if conf.options.debug:
23 conf.define('_DEBUG', 1)
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070024 defaultFlags += ['-O0',
25 '-Og', # gcc >= 4.8
26 '-g3',
27 '-fcolor-diagnostics', # clang
28 '-fdiagnostics-color', # gcc >= 4.9
29 '-Werror'
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070030 ]
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070031 if areCustomCxxflagsPresent:
32 missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
33 if len(missingFlags) > 0:
34 Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070035 % " ".join(conf.env.CXXFLAGS))
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070036 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
37 else:
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070038 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070039 else:
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070040 defaultFlags += ['-O2', '-g']
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070041 if not areCustomCxxflagsPresent:
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070042 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070043
44@Configure.conf
45def add_supported_cxxflags(self, cxxflags):
46 """
47 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
48 """
49 self.start_msg('Checking allowed flags for c++ compiler')
50
51 supportedFlags = []
52 for flag in cxxflags:
53 if self.check_cxx(cxxflags=[flag], mandatory=False):
54 supportedFlags += [flag]
55
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070056 self.end_msg(' '.join(supportedFlags))
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070057 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS