Skip to content

add_languages doesn't honor default values if it's called for the first time from a reconfigure #10664

@dcbaker

Description

@dcbaker

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.

Metadata

Metadata

Assignees

Labels

bugoptionsMeson configuration options

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions