add cpp_std support for MSVC

pull/4404/head
Nicole Mazzuca 6 years ago committed by Jussi Pakkanen
parent 1309b47cbb
commit f1546e289c
  1. 3
      docs/markdown/snippets/add_release_note_snippets_here
  2. 37
      mesonbuild/compilers/cpp.py
  3. 7
      test cases/windows/17 cpp17/main.cpp
  4. 9
      test cases/windows/17 cpp17/meson.build

@ -0,0 +1,3 @@
## Added `cpp_std` option for the Visual Studio C++ compiler
Allows the use of C++17 features and experimental not-yet-standardized
features. Valid options are `c++11`, `c++14`, `c++17`, and `c++latest`.

@ -309,11 +309,23 @@ class VisualStudioCPPCompiler(VisualStudioCCompiler, CPPCompiler):
self.base_options = ['b_pch', 'b_vscrt'] # FIXME add lto, pgo and the like
def get_options(self):
cpp_stds = ['none', 'c++11']
# Visual Studio 2015 Update 3 and later
if version_compare(self.version, '>=19'):
cpp_stds.extend(['c++14', 'c++latest'])
# Visual Studio 2017 and later
if version_compare(self.version, '>=19.11'):
cpp_stds.append('c++17')
opts = CPPCompiler.get_options(self)
opts.update({'cpp_eh': coredata.UserComboOption('cpp_eh',
'C++ exception handling type.',
['none', 'a', 's', 'sc'],
'sc'),
'cpp_std': coredata.UserComboOption('cpp_std',
'C++ language standard to use',
cpp_stds,
'none'),
'cpp_winlibs': coredata.UserArrayOption('cpp_winlibs',
'Windows libs to link against.',
msvc_winlibs)})
@ -321,9 +333,28 @@ class VisualStudioCPPCompiler(VisualStudioCCompiler, CPPCompiler):
def get_option_compile_args(self, options):
args = []
std = options['cpp_eh']
if std.value != 'none':
args.append('/EH' + std.value)
eh = options['cpp_eh']
if eh.value != 'none':
args.append('/EH' + eh.value)
std = options['cpp_std']
if std.value == 'none':
pass
elif std.value == 'c++11':
# Note: there is no explicit flag for supporting C++11; we attempt to do the best we can
# which means setting the C++ standard version to C++14, in compilers that support it
# (i.e., after VS2015U3)
# if one is using anything before that point, one cannot set the standard.
if version_compare(self.version, '>=19.00.24210'):
mlog.warning('MSVC does not support C++11; '
'attempting best effort; setting the standard to C++14')
args.append('/std:c++14')
else:
mlog.warning('This version of MSVC does not support cpp_std arguments')
else:
args.append('/std:' + std.value)
return args
def get_option_link_args(self, options):

@ -0,0 +1,7 @@
[[nodiscard]] int foo() {
return 0;
}
int main() {
return foo();
}

@ -0,0 +1,9 @@
project('msvc_cpp17', 'cpp', default_options: ['cpp_std=c++17'])
compiler = meson.get_compiler('cpp')
if compiler.get_id() != 'msvc' or compiler.version().version_compare('<19.11')
error('MESON_SKIP_TEST Visual Studio 2017 (version 15.3) or later is required for C++17 support')
endif
exe = executable('msvc_cpp17', 'main.cpp')
test('msvc_cpp17', exe)
Loading…
Cancel
Save