meson: Subproject default_options are ignored

Describe the bug

The ‘default_options’ argument to ‘subproject()’ seems to be ignored.

To Reproduce

Main meson.build:

...
libfoo = subproject('libfoo', default_options: [ 'BUILD_TESTS=false' ])
...

Libfoo meson.build:

...
if get_option('BUILD_TESTS')
    message('Building unit tests')
    subdir('tests')
endif
...

Libfoo meson_options.txt:

option('BUILD_TESTS', type: 'boolean', value: true)

Then:

rm -rf ./build
meson ./build

Tests are built, the default_options setting is ignored. meson configure shows ‘libfoo:BUILD_TESTS = true’.

To achieve desired behaviour, the option has to be specified from the command line:

rm -rf ./build
meson ./build -D libfoo:BUILD_TESTS=false

Expected behavior

Don’t ignore subproject() default_options.

system parameters

  • Plain native build
  • Oracle Linux 7.7
  • Python version: 3.7.4
  • Meson version: 0.53.1
  • Ninja version: 1.9.0

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 1
  • Comments: 15 (9 by maintainers)

Commits related to this issue

Most upvoted comments

This seems to be a long-standing issue. As a workaround you can put all default options for your subprojects in the superproject’s project() statement, like so:

project('taisei', 'c',
    license : 'MIT',
    version : 'v1.4-dev',
    meson_version : '>=0.48.0',
    default_options : [
        # Should really be c11, but gnu11 is a safer default because everything is terrible.
        'c_std=gnu11',

        'default_library=static',

        'libzip:enable_crypto=false',
        'libzip:enable_bzip2=false',

        'sdl2:use_haptic=disabled',
        'sdl2:use_power=disabled',
        'sdl2:use_render=disabled',
        'sdl2:use_sensor=disabled',

        # You may want to change these for a debug build dir
        'buildtype=release',
        'strip=true',
        'b_lto=true',
        'b_ndebug=if-release',
    ]
)