Obaid | 2ea377f | 2014-02-27 19:45:15 -0600 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
Alexander Afanasyev | 80f06a5 | 2014-03-27 14:40:00 -0700 | [diff] [blame^] | 3 | from waflib import Logs, Configure |
Obaid | 2ea377f | 2014-02-27 19:45:15 -0600 | [diff] [blame] | 4 | |
| 5 | def configure(conf): |
Alexander Afanasyev | 80f06a5 | 2014-03-27 14:40:00 -0700 | [diff] [blame^] | 6 | areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0) |
Obaid | 2ea377f | 2014-02-27 19:45:15 -0600 | [diff] [blame] | 7 | if conf.options.debug: |
Alexander Afanasyev | 80f06a5 | 2014-03-27 14:40:00 -0700 | [diff] [blame^] | 8 | conf.define('_DEBUG', 1) |
| 9 | defaultFlags = ['-O0', '-g3', |
| 10 | '-Werror', |
| 11 | '-Wall', |
| 12 | '-fcolor-diagnostics', # only clang supports |
Obaid | 2ea377f | 2014-02-27 19:45:15 -0600 | [diff] [blame] | 13 | |
Alexander Afanasyev | 80f06a5 | 2014-03-27 14:40:00 -0700 | [diff] [blame^] | 14 | # # to disable known warnings |
| 15 | # '-Wno-unused-variable', # cryptopp |
| 16 | # '-Wno-unused-function', |
| 17 | # '-Wno-deprecated-declarations', |
| 18 | ] |
Obaid | 2ea377f | 2014-02-27 19:45:15 -0600 | [diff] [blame] | 19 | |
Alexander Afanasyev | 80f06a5 | 2014-03-27 14:40:00 -0700 | [diff] [blame^] | 20 | if areCustomCxxflagsPresent: |
| 21 | missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS] |
| 22 | if len(missingFlags) > 0: |
| 23 | Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'" |
| 24 | % " ".join(conf.env.CXXFLAGS)) |
| 25 | Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags)) |
| 26 | else: |
| 27 | conf.add_supported_cxxflags(cxxflags=defaultFlags) |
Obaid | 2ea377f | 2014-02-27 19:45:15 -0600 | [diff] [blame] | 28 | else: |
Alexander Afanasyev | 80f06a5 | 2014-03-27 14:40:00 -0700 | [diff] [blame^] | 29 | defaultFlags = ['-O2', '-g', '-Wall', |
| 30 | |
| 31 | # # to disable known warnings |
| 32 | # '-Wno-unused-variable', # cryptopp |
| 33 | # '-Wno-unused-function', |
| 34 | # '-Wno-deprecated-declarations', |
| 35 | ] |
| 36 | if not areCustomCxxflagsPresent: |
| 37 | conf.add_supported_cxxflags(cxxflags=defaultFlags) |
Obaid | 2ea377f | 2014-02-27 19:45:15 -0600 | [diff] [blame] | 38 | |
| 39 | @Configure.conf |
| 40 | def add_supported_cxxflags(self, cxxflags): |
| 41 | """ |
| 42 | Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable |
| 43 | """ |
| 44 | self.start_msg('Checking allowed flags for c++ compiler') |
| 45 | |
| 46 | supportedFlags = [] |
| 47 | for flag in cxxflags: |
| 48 | if self.check_cxx (cxxflags=[flag], mandatory=False): |
| 49 | supportedFlags += [flag] |
| 50 | |
| 51 | self.end_msg (' '.join (supportedFlags)) |
| 52 | self.env.CXXFLAGS += supportedFlags |