waifulib: cxx11: refactor

This commit is contained in:
Alibek Omarov 2019-10-18 02:21:34 +03:00
parent 4526b9bb8a
commit 0670625c80

View File

@ -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
def check_cxx11(ctx, msg): modern_cpp_flags = {
try: 'msvc': [],
# not best way, but this check 'default': ['-std=c++11']
# was written for exactly mainui_cpp, }
# where lambdas are mandatory
ctx.check_cxx( @Configure.conf
fragment='int main( void ){ auto pfnLambda = [](){}; return 0;}', def check_cxx11(ctx, *k, **kw):
msg = msg) if not 'msg' in kw:
except ctx.errors.ConfigurationError: kw['msg'] = 'Checking if \'%s\' supports C++11' % ctx.env.COMPILER_CXX
return False
return True if not 'mandatory' in kw:
kw['mandatory'] = False
# not best way, but this check
# was written for exactly mainui_cpp,
# where lambdas are mandatory
return ctx.check_cxx(fragment='int main( void ){ auto pfnLambda = [](){}; return 0;}', *k, **kw)
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): else:
conf.env.HAVE_CXX11 = False conf.env.HAVE_CXX11 = False
else:
env_stash = conf.env if conf.env.CXX11_MANDATORY:
conf.env.append_unique('CXXFLAGS', flags) conf.fatal('C++11 support not available!')
if not check_cxx11(conf, '...trying with additional flags'):
conf.env.HAVE_CXX11 = False
conf.env = env_stash
if getattr(conf.env, 'CXX11_MANDATORY'):
conf.fatal('C++11 support not available!')