blob: f0f04824af8a636c0d1867d72cee405df24bb65e [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
21
22 # to disable known warnings
23 '-Wno-unused-variable', # cryptopp
24 '-Wno-unused-function',
25 '-Wno-deprecated-declarations',
26 ]
27
28 if areCustomCxxflagsPresent:
29 missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
30 if len(missingFlags) > 0:
31 Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
32 % " ".join(conf.env.CXXFLAGS))
33 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
34 else:
35 conf.add_supported_cxxflags(cxxflags = defaultFlags)
36 else:
37 defaultFlags = ['-O2', '-g', '-Wall',
38
39 # to disable known warnings
40 '-Wno-unused-variable', # cryptopp
41 '-Wno-unused-function',
42 '-Wno-deprecated-declarations',
43 ]
44 if not areCustomCxxflagsPresent:
45 conf.add_supported_cxxflags(cxxflags = defaultFlags)
46
47@Configure.conf
48def add_supported_cxxflags(self, cxxflags):
49 """
50 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
51 """
52 self.start_msg('Checking allowed flags for c++ compiler')
53
54 supportedFlags = []
55 for flag in cxxflags:
56 if self.check_cxx(cxxflags=[flag], mandatory=False):
57 supportedFlags += [flag]
58
59 self.end_msg(' '.join (supportedFlags))
60 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS