Changing a project's meson options depending on buildtype #14217
-
Hello, beetroot_opts = ['buildtype=release', 'warning_level=3', 'c_std=c23']
beetroot_version = '0.4.0'
compiler = meson.get_compiler('c')
if get_option('buildtype') == 'debug'
# Note how I change beetroot_opts depending on buildtype
beetroot_opts += '-b_sanitize=address,undefined'
beetroot_opts += '-b_sanitize=leak'
if compiler.has_argument('-fsanitize=bounds')
add_global_arguments('-fsanitize=bounds')
add_global_link_arguments('-fsanitize=bounds')
endif
if compiler.has_argument('-fsanitize=integer')
add_global_arguments('-fsanitize=integer')
add_global_link_arguments('-fsanitize=integer')
endif
endif
project('beetroot', 'c',
version: beetroot_version,
include_directores = 'xmem',
default_options: beetroot_opts)
crypt = dependency('crypt', required: true)
beetroot_src = [
'src/main.c',
'src/password.c',
'src/security.c',
'xmem/internal/xalloc.c',
'xmem/internal/xexit.c',
'xmem/internal/xmemdup.c',
'xmem/internal/xmemset.c',
'xmem/internal/xstrdup.c',
]
beetroot_include = [
include_directories('src'),
include_directories('xmem'),
]
executable('beetroot',
beetroot_src,
dependencies: crypt,
include_directories: beetroot_include,
install: true) as you can see, i want a way to add meson options depending on if the buildtype is debug. however, this requires me to have an array of meson options. is there a different way that I could do the dynamic options part? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Sorry I should've clarified as to why this doesn't work: $ meson setup build
The Meson build system
Version: 1.7.0
Source dir: /home/capy/Documents/beetroot
Build dir: /home/capy/Documents/beetroot/build
Build type: native build
ERROR: Invalid source tree: first statement must be a call to project() |
Beta Was this translation helpful? Give feedback.
-
You might be able to use override_options to change your options based on buildtype So... yes, you must have |
Beta Was this translation helpful? Give feedback.
You might be able to use override_options to change your options based on buildtype
So... yes, you must have
project()
first, but later you can change any default options by using overrides later.