compiler flags: add cxx98 standard support (#7601)
The following improvements are made to cxx standard support (e.g. compiler.cxxNN_flag functions) in compilers: * Add cxx98_flag property * Add support for throwing an exception when a flag is not supported (previously if a flag was not supported the application was terminated with tty.die) * The name of the flag associated with e.g. c++14 standard support changes for different compiler versions (e.g. c++1y vs c++14). This makes a few corrections on what flag to return for which version. * Added tests to confirm that versions report expected flags for various c++ standards (or raise an exception for versions that don't provide a given cxx standard) Note that if a given cxx standard is the default, the associated flag property will return ""; cxx98 is assumed to be the default standard so this is the behavior for the associated property in the base compiler class. Package changes: * Improvements to the boost spec to take advantage of the improved standard flag facility. * Update the clingo spec to catch the new exception rather than look for an empty flag to indicate non-support (which is not part of the compiler flag API)
This commit is contained in:
@@ -126,6 +126,11 @@ class Boost(Package):
|
||||
variant(lib, default=(lib not in default_noinstall_libs),
|
||||
description="Compile with {0} library".format(lib))
|
||||
|
||||
variant('cxxstd',
|
||||
default='default',
|
||||
values=('default', '98', '11', '14', '17'),
|
||||
multi=False,
|
||||
description='Use the specified C++ standard when building.')
|
||||
variant('debug', default=False,
|
||||
description='Switch to the debug version of Boost')
|
||||
variant('shared', default=True,
|
||||
@@ -250,6 +255,26 @@ def determine_bootstrap_options(self, spec, withLibs, options):
|
||||
if '+python' in spec:
|
||||
f.write(self.bjam_python_line(spec))
|
||||
|
||||
def cxxstd_to_flag(self, std):
|
||||
flag = ''
|
||||
if self.spec.variants['cxxstd'].value == '98':
|
||||
flag = self.compiler.cxx98_flag
|
||||
elif self.spec.variants['cxxstd'].value == '11':
|
||||
flag = self.compiler.cxx11_flag
|
||||
elif self.spec.variants['cxxstd'].value == '14':
|
||||
flag = self.compiler.cxx14_flag
|
||||
elif self.spec.variants['cxxstd'].value == '17':
|
||||
flag = self.compiler.cxx17_flag
|
||||
elif self.spec.variants['cxxstd'].value == 'default':
|
||||
# Let the compiler do what it usually does.
|
||||
pass
|
||||
else:
|
||||
# The user has selected a (new?) legal value that we've
|
||||
# forgotten to deal with here.
|
||||
tty.die("INTERNAL ERROR: cannot accommodate unexpected variant ",
|
||||
"cxxstd={0}".format(spec.variants['cxxstd'].value))
|
||||
return flag
|
||||
|
||||
def determine_b2_options(self, spec, options):
|
||||
if '+debug' in spec:
|
||||
options.append('variant=debug')
|
||||
@@ -299,6 +324,17 @@ def determine_b2_options(self, spec, options):
|
||||
'toolset=%s' % self.determine_toolset(spec)
|
||||
])
|
||||
|
||||
# Other C++ flags.
|
||||
cxxflags = []
|
||||
|
||||
# Deal with C++ standard.
|
||||
if spec.satisfies('@1.66:'):
|
||||
options.append('cxxstd={0}'.format(spec.variants['cxxstd'].value))
|
||||
else: # Add to cxxflags for older Boost.
|
||||
flag = self.cxxstd_to_flag(spec.variants['cxxstd'].value)
|
||||
if flag:
|
||||
cxxflags.append(flag)
|
||||
|
||||
# clang is not officially supported for pre-compiled headers
|
||||
# and at least in clang 3.9 still fails to build
|
||||
# http://www.boost.org/build/doc/html/bbv2/reference/precompiled_headers.html
|
||||
@@ -306,10 +342,13 @@ def determine_b2_options(self, spec, options):
|
||||
if spec.satisfies('%clang'):
|
||||
options.extend(['pch=off'])
|
||||
if '+clanglibcpp' in spec:
|
||||
cxxflags.append('-stdlib=libc++')
|
||||
options.extend(['toolset=clang',
|
||||
'cxxflags="-stdlib=libc++"',
|
||||
'linkflags="-stdlib=libc++"'])
|
||||
|
||||
if cxxflags:
|
||||
options.append('cxxflags="{0}"'.format(' '.join(cxxflags)))
|
||||
|
||||
return threadingOpts
|
||||
|
||||
def add_buildopt_symlinks(self, prefix):
|
||||
|
@@ -44,7 +44,9 @@ class Clingo(CMakePackage):
|
||||
depends_on('python')
|
||||
|
||||
def cmake_args(self):
|
||||
if not self.compiler.cxx14_flag:
|
||||
try:
|
||||
self.compiler.cxx14_flag
|
||||
except UnsupportedCompilerFlag:
|
||||
InstallError('clingo requires a C++14-compliant C++ compiler')
|
||||
|
||||
args = ['-DCLINGO_BUILD_WITH_PYTHON=ON',
|
||||
|
Reference in New Issue
Block a user