Given a meson.build such as
project('foo', default_options : ['cpp_std=c++14'])
if get_option('with-cpp')
add_languages(['cpp'])
executable('exe', 'main.cpp')
endif
if you run meson as
meson setup builddir -Dwith-cpp=true then things work as expected and main.cpp is compiled with -std=c++14 (or equivalent)
However, if it's run as
meson setup builddir -Dwith-cpp=false`
meson configure builddir -Dwith-cpp=true`
Then meson will fail to honor the default cpp options, and will instead compile with whatever the default is (this is true of all cpp args, cpp_args, cpp_link_args, cpp_eh, etc)
This happens because the initial values are read into the transient Environment, and only copied into the presistant coredata when the compiler is initialized. We do this so that we can validate that the given compiler options are valid for the current compiler (both the argument itself, and the value of the argument), but this has the drawback that unused options do not persist.
I haven't checked, but I believe that this would be the same for values set in a machine file.
Given a meson.build such as
if you run meson as
meson setup builddir -Dwith-cpp=truethen things work as expected and main.cpp is compiled with-std=c++14(or equivalent)However, if it's run as
Then meson will fail to honor the default cpp options, and will instead compile with whatever the default is (this is true of all cpp args,
cpp_args,cpp_link_args,cpp_eh, etc)This happens because the initial values are read into the transient Environment, and only copied into the presistant coredata when the compiler is initialized. We do this so that we can validate that the given compiler options are valid for the current compiler (both the argument itself, and the value of the argument), but this has the drawback that unused options do not persist.
I haven't checked, but I believe that this would be the same for values set in a machine file.