blob: 265259e2804f78e958e3eae88a18071e054bb671 [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)
15 if conf.options.debug:
16 conf.define('_DEBUG', 1)
17 defaultFlags = ['-O0', '-g3',
18 '-Werror',
19 '-Wall',
20 '-fcolor-diagnostics', # only clang supports
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070021 ]
22
23 if areCustomCxxflagsPresent:
24 missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
25 if len(missingFlags) > 0:
26 Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
27 % " ".join(conf.env.CXXFLAGS))
28 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
29 else:
30 conf.add_supported_cxxflags(cxxflags = defaultFlags)
31 else:
32 defaultFlags = ['-O2', '-g', '-Wall',
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070033 ]
34 if not areCustomCxxflagsPresent:
35 conf.add_supported_cxxflags(cxxflags = defaultFlags)
36
37@Configure.conf
38def add_supported_cxxflags(self, cxxflags):
39 """
40 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
41 """
42 self.start_msg('Checking allowed flags for c++ compiler')
43
44 supportedFlags = []
45 for flag in cxxflags:
46 if self.check_cxx(cxxflags=[flag], mandatory=False):
47 supportedFlags += [flag]
48
49 self.end_msg(' '.join (supportedFlags))
50 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS