Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cpp_std option for Visual Studio C++ compiler #2836

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/markdown/Release-notes-for-0.46.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ Added the function `subdir_done()`. Its invocation exits the current script at
the point of invocation. All previously invoked build targets and commands are
build/executed. All following ones are ignored. If the current script was
invoked via `subdir()` the parent script continues normally.

## 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`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be added into the docs/markdown/snippets directory.

3 changes: 2 additions & 1 deletion mesonbuild/backend/vs2010backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,12 +727,13 @@ def gen_vcxproj(self, target, ofname, guid):
file_args = dict((lang, CompilerArgs(comp)) for lang, comp in target.compilers.items())
file_defines = dict((lang, []) for lang in target.compilers)
file_inc_dirs = dict((lang, []) for lang in target.compilers)

# The order in which these compile args are added must match
# generate_single_compile() and generate_basic_compiler_args()
for l, comp in target.compilers.items():
if l in file_args:
file_args[l] += compilers.get_base_compile_args(self.get_base_options_for_target(target), comp)
file_args[l] += comp.get_option_compile_args(self.environment.coredata.compiler_options)
file_args[l] += comp.get_option_compile_args(self.get_compiler_options_for_target(target))
# Add compile args added using add_project_arguments()
for l, args in self.build.projects_args.get(target.subproject, {}).items():
if l in file_args:
Expand Down
13 changes: 13 additions & 0 deletions mesonbuild/compilers/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,20 @@ def __init__(self, exelist, version, is_cross, exe_wrap, is_64):
self.base_options = ['b_pch'] # FIXME add lto, pgo and the like

def get_options(self):
c_stds = ['none', 'c++11']
# Visual Studio 2015 Update 3 and later
if version_compare(self.version, '>=19.10.25017'):
c_stds += ['c++14', 'c++latest']
# Visual Studio 2017 and later
if version_compare(self.version, '>=19.11'):
c_stds += ['c++17']
return {'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',
c_stds,
'none'),
'cpp_winlibs': coredata.UserArrayOption('cpp_winlibs',
'Windows libs to link against.',
msvc_winlibs)
Expand All @@ -221,6 +231,9 @@ def get_option_compile_args(self, options):
std = options['cpp_eh']
if std.value != 'none':
args.append('/EH' + std.value)
std = options['cpp_std']
if std.value not in ['none', 'c++11']:
args.append('/std:' + std.value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this value added for c++11? Please add a comment about that.

Also, why aren't we warning when cpp_std: on an MSVC compiler that does not support the /std: argument?

return args

def get_option_link_args(self, options):
Expand Down
7 changes: 7 additions & 0 deletions test cases/windows/14 vs c++17/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[[nodiscard]] int foo() {
return 0;
}

int main() {
return foo();
}
8 changes: 8 additions & 0 deletions test cases/windows/14 vs c++17/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
project('wincpp', 'cpp')

if meson.get_compiler('cpp').version().version_compare('<19.11')
error('MESON_SKIP_TEST Visual Studio 2017 (version 15.3) or later is required for C++17 support')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you skipping the test here? Also where's the cpp_std: option set for this test?

endif

exe = executable('prog', 'main.cpp', override_options: ['cpp_std=c++17'])
test('wincpp', exe)