blob: 9f7843eb4802a38ca8ec8b3a1a3e4b4f7349e489 [file] [log] [blame]
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2#
3# Copyright (c) 2014, Regents of the University of California
4#
5# GPL 3.0 license, see the COPYING.md file for more information
6
7from waflib import Logs, Configure
8
9def options(opt):
10 opt.add_option('--debug', '--with-debug', action='store_true', default=False, dest='debug',
11 help='''Compile in debugging mode without all optimizations (-O0)''')
12
13def configure(conf):
14 areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070015 defaultFlags = []
16
17 if conf.options.use_cxx11:
18 defaultFlags += ['-std=c++0x', '-std=c++11']
19 else:
20 defaultFlags += ['-std=c++03']
21
22 defaultFlags += ['-pedantic', '-Wall', '-Wno-long-long']
23
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070024 if conf.options.debug:
25 conf.define('_DEBUG', 1)
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070026 defaultFlags += ['-O0',
27 '-Og', # gcc >= 4.8
28 '-g3',
29 '-fcolor-diagnostics', # clang
30 '-fdiagnostics-color', # gcc >= 4.9
31 '-Werror'
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070032 ]
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070033 if areCustomCxxflagsPresent:
34 missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
35 if len(missingFlags) > 0:
36 Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070037 % " ".join(conf.env.CXXFLAGS))
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070038 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
39 else:
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070040 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070041 else:
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070042 defaultFlags += ['-O2', '-g']
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070043 if not areCustomCxxflagsPresent:
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070044 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070045
46@Configure.conf
47def add_supported_cxxflags(self, cxxflags):
48 """
49 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
50 """
51 self.start_msg('Checking allowed flags for c++ compiler')
52
53 supportedFlags = []
54 for flag in cxxflags:
55 if self.check_cxx(cxxflags=[flag], mandatory=False):
56 supportedFlags += [flag]
57
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070058 self.end_msg(' '.join(supportedFlags))
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070059 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS