blob: 299493aeb1483c36144450c2f6a12874142faab1 [file] [log] [blame]
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -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
21 ]
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']
33 if not areCustomCxxflagsPresent:
34 conf.add_supported_cxxflags(cxxflags=defaultFlags)
35
36@Configure.conf
37def add_supported_cxxflags(self, cxxflags):
38 """
39 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
40 """
41 self.start_msg('Checking allowed flags for c++ compiler')
42
43 supportedFlags = []
44 for flag in cxxflags:
45 if self.check_cxx(cxxflags=[flag], mandatory=False):
46 supportedFlags += [flag]
47
48 self.end_msg(' '.join (supportedFlags))
49 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS