Hi Dan,
thanks for taking the time to answer!
On Fri, 15 Jan 2021 at 23:13, Daniele Nicolodi <
dan...@grinta.net> wrote:
>
> On 15/01/2021 23:01, Joachim Kuebart wrote:
> > Hi,
> >
> > I'm new to Meson and I've read a fair bit of the user guide and have
> > looked around a bit, but haven't been able to figure out how to do this:
> >
> > I have a project that needs to be compiled with -std=c++2a on clang/gcc
> > and /std:c++latest on msvc.
> >
> > If I add cpp_std=c++2a to the default_options, »meson setup« fails on
> > msvc because of the invalid value, and vice versa for c++latest.
> >
> > I was surprised that even overriding the value using
> >
> > meson setup -Dcpp_std=c++latest build
> >
> > doesn't work and still fails because of c++2a in default_options.
>
> Accordingly to the documentation "c++latest" is not a valid choice for
> cpp_std, "vc++latest" is. Maybe this is the reason why this did not
> work. However, you should have received an error about this.
I did indeed get an error and didn't paste it because it was on the
»other« computer and I was being lazy. It also mentions »c++latest«
which was what I picked:
The Meson build system
Version: 0.56.2
Source dir: D:\Users\joki\src\wa2html
Build dir: D:\Users\joki\src\wa2html\build
Build type: native build
Project name: wa2html
Project version: 0.1
C++ compiler for the host machine: cl (msvc 19.28.29336 "Microsoft (R)
C/C++ Optimizing Compiler Version 19.28.29336 for x86")
C++ linker for the host machine: link link 14.28.29336.0
Host machine cpu family: x86
Host machine cpu: x86
Did not find pkg-config by name 'pkg-config'
Found Pkg-config: NO
Found CMake: C:\Program Files (x86)\Microsoft Visual
Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.EXE
(3.18.20081302)
Build targets in project: 7
wa2html 0.1
ERROR: Validation failed for option cpp_std: Value "c++2a" (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".
A full log can be found at
D:\Users\joki\src\wa2html\build\meson-logs\meson-log.txt
> IIRC, there is not a default for cpp_std, thus you can threat it like
> any other compiler option. I haven't tested it, but something like:
>
> cpp = meson.get_compiler('cpp')
> if cpp.get_id() == 'msvc'
> add_project_argument('-std=c++latest', language : 'cpp')
> else
> add_project_argument('-std=c++2a', language : 'cpp')
>
> should work.
I did the following
cpp = meson.get_compiler('cpp')
add_project_arguments(
cpp.get_supported_arguments('/std:c++latest', '-std=c++2a'),
language: 'cpp'
)
This does work, but gives me
Compiler for C++ supports arguments /std:c++latest: YES
Compiler for C++ supports arguments -std=c++2a: NO
meson.build:14: WARNING: Consider using the built-in option for
language standard version instead of using "/std:c++latest".
which was why I thought there might be a more elegant way.
But it is fully automatic, so maybe I'll just stick with this and live
with the warning until all of clang, gcc and msvc support
"cpp_std=c++20".
Thanks!
Joachim