Skip to content

Commit

Permalink
core: Add compiler flag checking
Browse files Browse the repository at this point in the history
  • Loading branch information
cawka committed Jan 9, 2015
1 parent 70cc04f commit fc42a8a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
41 changes: 36 additions & 5 deletions waf-tools/cflags.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from waflib import Logs, Options, Utils
from waflib import Logs, Options, Utils, Configure


class CompilerTraits(object):
def get_compiler_flags(self):
"""get_compiler_flags() -> list of cflags"""
raise NotImplementedError

def get_warnings_flags(self, level):
"""get_warnings_flags(level) -> list of cflags"""
raise NotImplementedError
Expand All @@ -19,7 +23,11 @@ class GccTraits(CompilerTraits):
def __init__(self):
super(GccTraits, self).__init__()
# cumulative list of warnings per level
self.warnings_flags = [['-Wall', '-std=c++11']]
self.warnings_flags = [['-Wall', '-Wno-error=deprecated-declarations',
'-fstrict-aliasing', '-Wstrict-aliasing']]

def get_compiler_flags(self):
return ['-std=c++0x', '-std=c++11']

def get_warnings_flags(self, level):
warnings = []
Expand Down Expand Up @@ -56,6 +64,9 @@ def __init__(self):
# icc is _very_ verbose with -Wall, -Werror is barely achievable
self.warnings_flags = [[], [], ['-Wall']]

def get_compiler_flags(self):
return ['/Qstd=c++11']

def get_warnings_flags(self, level):
warnings = []
for l in range(level):
Expand Down Expand Up @@ -84,13 +95,15 @@ def get_debug_flags(self, level):
return (['-ggdb', '-g3'], ['_DEBUG'])



class MsvcTraits(CompilerTraits):
def __init__(self):
super(MsvcTraits, self).__init__()
# cumulative list of warnings per level
self.warnings_flags = [['/W2'], ['/WX'], ['/Wall']]

def get_compiler_flags(self):
return []

def get_warnings_flags(self, level):
warnings = []
for l in range(level):
Expand Down Expand Up @@ -174,17 +187,35 @@ def configure(conf):

opt_level, warn_level, dbg_level = profiles[Options.options.build_profile]

optimizations = compiler.get_optimization_flags(opt_level)
compilerFlags = conf.get_supported_cxxflags(compiler.get_compiler_flags(), msg="compiler ")
optimizations = conf.get_supported_cxxflags(compiler.get_optimization_flags(opt_level), msg="optimizations ")
debug, debug_defs = compiler.get_debug_flags(dbg_level)
warnings = compiler.get_warnings_flags(warn_level)
debug = conf.get_supported_cxxflags(debug, msg="debug ")
warnings = conf.get_supported_cxxflags(compiler.get_warnings_flags(warn_level), msg="warnings ")

if cc and not conf.env['CCFLAGS']:
conf.env.append_value('CCFLAGS', optimizations)
conf.env.append_value('CCFLAGS', debug)
conf.env.append_value('CCFLAGS', warnings)
conf.env.append_value('CCDEFINES', debug_defs)
if cxx and not conf.env['CXXFLAGS']:
conf.env.append_value('CXXFLAGS', compilerFlags)
conf.env.append_value('CXXFLAGS', optimizations)
conf.env.append_value('CXXFLAGS', debug)
conf.env.append_value('CXXFLAGS', warnings)
conf.env.append_value('CXXDEFINES', debug_defs)

@Configure.conf
def get_supported_cxxflags(self, cxxflags, msg=""):
"""
Check which cxxflags are supported by the compiler
"""
self.start_msg('Checking supported %sCXXFLAGS' % msg)

supportedFlags = []
for flag in cxxflags:
if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False):
supportedFlags += [flag]

self.end_msg(' '.join(supportedFlags))
return supportedFlags
12 changes: 0 additions & 12 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -503,18 +503,6 @@ def configure(conf):
# for compiling C code, copy over the CXX* flags
conf.env.append_value('CCFLAGS', conf.env['CXXFLAGS'])

def add_gcc_flag(flag):
if env['COMPILER_CXX'] == 'g++' and 'CXXFLAGS' not in os.environ:
if conf.check_compilation_flag(flag, mode='cxx'):
env.append_value('CXXFLAGS', flag)
if env['COMPILER_CC'] == 'gcc' and 'CCFLAGS' not in os.environ:
if conf.check_compilation_flag(flag, mode='cc'):
env.append_value('CCFLAGS', flag)

add_gcc_flag('-Wno-error=deprecated-declarations')
add_gcc_flag('-fstrict-aliasing')
add_gcc_flag('-Wstrict-aliasing')

try:
conf.find_program('doxygen', var='DOXYGEN')
except WafError:
Expand Down

0 comments on commit fc42a8a

Please sign in to comment.