mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.63k stars 1.63k forks source link

Can't define cpp_std to latest version with multi-platform support #8140

Open jmoguillansky-gpsw opened 3 years ago

jmoguillansky-gpsw commented 3 years ago

Describe the bug Try to set cpp_std to c++latest. The problem is that msvc toolchain recognizes "c++latest" while gcc toolchain recognizes "c++2a". Also, can't define project default_options using conditional logic.
Meson complains that the first statement needs to be project statement.

To Reproduce cpp_std = '' host_system = host_machine.system() cpp = meson.get_compiler('cpp') if cpp.get_id() == 'msvc' cpp_std = 'c++latest' else cpp_std = 'c++2a' endif

project( 'testproj', [ 'c', 'cpp' ], default_options: 'cpp_std='+cpp_std ... )

Expected behavior Meson should support defining cpp_std to latest version in a way that's platform agnostic.
Also, meson should support setting cpp_std using conditional logic.

system parameters Cross build : Windows + MSVC, Linux + GCC

willwray commented 3 years ago

Still an issue on v0.59.1 - there should be a portable way to select c++20 for a project, in 2021...

I hit it a month ago, independently came up with the same conditional platform-specific hack, and visited the meson IRC to raise it there too.

HolyWu commented 3 years ago

According to https://devblogs.microsoft.com/cppblog/msvc-cpp20-and-the-std-cpp20-switch/, MSVC has added the /std:c++20 switch in 16.11. Currently I still get the following error using Meson v0.59.1.

meson.build:1:0: ERROR: Value "c++20" (of type "string") for combo option "C++ language standard to use" is not one of the choices. Possible choices are (as string): "none", "c++11", "vc++11", "c++14", "c++latest", "vc++latest", "vc++14", "c++17", "vc++17".

Looking at https://github.com/mesonbuild/meson/blob/173a40be330c1aedec9f7f99ebca67a5edd25c3d/mesonbuild/compilers/cpp.py#L566 and https://github.com/mesonbuild/meson/blob/173a40be330c1aedec9f7f99ebca67a5edd25c3d/mesonbuild/compilers/cpp.py#L668, the code is not updated to support c++20 for MSVC yet.