aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicole Mazzuca <npmazzuca@gmail.com>2018-10-19 12:41:05 -0700
committerJussi Pakkanen <jpakkane@gmail.com>2018-10-22 19:14:00 +0300
commitf1546e289c00d69d16cb6e036154918225118dae (patch)
tree5de80ab328d12d92e6d6ada1fcad55770dedbde6
parent1309b47cbbd75565ea647ba6a570f8db6f8a3c2a (diff)
downloadmeson-f1546e289c00d69d16cb6e036154918225118dae.zip
meson-f1546e289c00d69d16cb6e036154918225118dae.tar.gz
meson-f1546e289c00d69d16cb6e036154918225118dae.tar.bz2
add cpp_std support for MSVC
-rw-r--r--docs/markdown/snippets/add_release_note_snippets_here3
-rw-r--r--mesonbuild/compilers/cpp.py37
-rw-r--r--test cases/windows/17 cpp17/main.cpp7
-rw-r--r--test cases/windows/17 cpp17/meson.build9
4 files changed, 53 insertions, 3 deletions
diff --git a/docs/markdown/snippets/add_release_note_snippets_here b/docs/markdown/snippets/add_release_note_snippets_here
index e69de29..bc4039c 100644
--- a/docs/markdown/snippets/add_release_note_snippets_here
+++ b/docs/markdown/snippets/add_release_note_snippets_here
@@ -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`.
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
index dd0b27f..66ae0e5 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -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):
diff --git a/test cases/windows/17 cpp17/main.cpp b/test cases/windows/17 cpp17/main.cpp
new file mode 100644
index 0000000..36e4156
--- /dev/null
+++ b/test cases/windows/17 cpp17/main.cpp
@@ -0,0 +1,7 @@
+[[nodiscard]] int foo() {
+ return 0;
+}
+
+int main() {
+ return foo();
+}
diff --git a/test cases/windows/17 cpp17/meson.build b/test cases/windows/17 cpp17/meson.build
new file mode 100644
index 0000000..367bfd8
--- /dev/null
+++ b/test cases/windows/17 cpp17/meson.build
@@ -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)