waifulib: cxx11: refactor
This commit is contained in:
parent
4526b9bb8a
commit
0670625c80
@ -13,40 +13,42 @@
|
|||||||
|
|
||||||
try: from fwgslib import get_flags_by_compiler
|
try: from fwgslib import get_flags_by_compiler
|
||||||
except: from waflib.extras.fwgslib import get_flags_by_compiler
|
except: from waflib.extras.fwgslib import get_flags_by_compiler
|
||||||
|
from waflib import Configure
|
||||||
|
|
||||||
# Input:
|
# Input:
|
||||||
# CXX11_MANDATORY(optional) -- fail if C++11 not available
|
# CXX11_MANDATORY(optional) -- fail if C++11 not available
|
||||||
# Output:
|
# Output:
|
||||||
# HAVE_CXX11 -- true if C++11 available, otherwise else
|
# HAVE_CXX11 -- true if C++11 available, otherwise false
|
||||||
|
|
||||||
|
modern_cpp_flags = {
|
||||||
|
'msvc': [],
|
||||||
|
'default': ['-std=c++11']
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configure.conf
|
||||||
|
def check_cxx11(ctx, *k, **kw):
|
||||||
|
if not 'msg' in kw:
|
||||||
|
kw['msg'] = 'Checking if \'%s\' supports C++11' % ctx.env.COMPILER_CXX
|
||||||
|
|
||||||
|
if not 'mandatory' in kw:
|
||||||
|
kw['mandatory'] = False
|
||||||
|
|
||||||
def check_cxx11(ctx, msg):
|
|
||||||
try:
|
|
||||||
# not best way, but this check
|
# not best way, but this check
|
||||||
# was written for exactly mainui_cpp,
|
# was written for exactly mainui_cpp,
|
||||||
# where lambdas are mandatory
|
# where lambdas are mandatory
|
||||||
ctx.check_cxx(
|
return ctx.check_cxx(fragment='int main( void ){ auto pfnLambda = [](){}; return 0;}', *k, **kw)
|
||||||
fragment='int main( void ){ auto pfnLambda = [](){}; return 0;}',
|
|
||||||
msg = msg)
|
|
||||||
except ctx.errors.ConfigurationError:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def configure(conf):
|
def configure(conf):
|
||||||
conf.env.HAVE_CXX11 = True # predict state
|
flags = get_flags_by_compiler(modern_cpp_flags, conf.env.COMPILER_CXX)
|
||||||
if not check_cxx11(conf, 'Checking if \'{0}\' supports C++11'.format(conf.env.COMPILER_CC)):
|
|
||||||
modern_cpp_flags = {
|
if conf.check_cxx11():
|
||||||
'msvc': [],
|
conf.env.HAVE_CXX11 = True
|
||||||
'default': ['-std=c++11']
|
elif len(flags) != 0 and conf.check_cxx11(msg='...trying with additional flags', cxxflags = flags):
|
||||||
}
|
conf.env.HAVE_CXX11 = True
|
||||||
flags = get_flags_by_compiler(modern_cpp_flags, conf.env.COMPILER_CC)
|
conf.env.CXXFLAGS += flags
|
||||||
if(len(flags) == 0):
|
|
||||||
conf.env.HAVE_CXX11 = False
|
|
||||||
else:
|
else:
|
||||||
env_stash = conf.env
|
|
||||||
conf.env.append_unique('CXXFLAGS', flags)
|
|
||||||
if not check_cxx11(conf, '...trying with additional flags'):
|
|
||||||
conf.env.HAVE_CXX11 = False
|
conf.env.HAVE_CXX11 = False
|
||||||
conf.env = env_stash
|
|
||||||
if getattr(conf.env, 'CXX11_MANDATORY'):
|
if conf.env.CXX11_MANDATORY:
|
||||||
conf.fatal('C++11 support not available!')
|
conf.fatal('C++11 support not available!')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user