Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meson needs -Dbuildtype=custom to change the optimisation & debug values #10487

Open
aidan-gallagher opened this issue Jun 13, 2022 · 1 comment · May be fixed by #12699
Open

Meson needs -Dbuildtype=custom to change the optimisation & debug values #10487

aidan-gallagher opened this issue Jun 13, 2022 · 1 comment · May be fixed by #12699

Comments

@aidan-gallagher
Copy link

aidan-gallagher commented Jun 13, 2022

Overview

According to the documentation you should be able to independently set the optimisation and debug levels by passing -Debug and -Doptimization. However you actually have to pass -Dbuildtype=custom as well.

From the docs:
"For setting optimization levels and toggling debug, you can either set the buildtype option, or you can set the optimization and debug options which give finer control over the same. Whichever you decide to use, the other will be deduced from it. For example, -Dbuildtype=debugoptimized is the same as -Ddebug=true -Doptimization=2 and vice-versa."

"All other combinations of debug and optimization set buildtype to 'custom'"

Steps

Given debug set to true and optimisation set 1

$ meson setup -Ddebug=true -Doptimization=1 build

When I check the values

$ cd build
$ meson configure
...
  Core options        Current Value        Possible Values                                               Description
  ------------        -------------        ---------------                                               -----------
...
  buildtype           release              [plain, debug, debugoptimized, release, minsize, custom]      Build type to use
  debug               false                [true, false]                                                 Debug
...
  optimization        3                    [0, g, 1, 2, 3, s]                                            Optimization level
...

Then I expect buildtype=custom, debug=true, optimisation=1

Environment

$ meson --version
0.53.2
@albfan
Copy link
Contributor

albfan commented Oct 15, 2022

I can confirm in

$ meson --version
0.62.2

this is still true.

I'm testing with a vala project. If buildtype has debug true, valac uses -g and add line directives to generated source code.

$ mkdir example
$ cd example
$ meson init -l vala
$ meson -Ddebug=false -Doptimization=0 build
$ meson introspect --buildoptions build | jq '.[] | select(.name == "buildtype").value'
"debug"
$ ninja -C build
$ grep -qR "#line" build && echo YES line directives
YES line directives

Doing again with buildtype=custom works but there's a funny warning:

$ rm -rf build
$ meson -Ddebug=false -Doptimization=0 --buildtype=custom build

WARNING: Recommend using either -Dbuildtype or -Doptimization + -Ddebug. Using both is redundant since they override each other. See: https://mesonbuild.com/Builtin-options.html#build-type-options
The Meson build system
Version: 0.62.2
....
$ meson introspect --buildoptions build | jq '.[] | select(.name == "buildtype").value'
"custom"
$ ninja -C build
$ grep -qR "#line" build || echo NO line directives
NO line directives

I'm trying to setup this with an option but looks I need to set two which is annoying:

meson.build:

if get_option('plain_debug')
  if get_option('buildtype') != 'plain'
    error('set buildtype=plain to use option plain_debug')
  endif
  add_global_arguments('-g', language:'c')
endif

I'm looking for something like:

if get_option('plain_debug')
  set_option('debug', false)
  set_option('optimization', 0)
  add_global_arguments('-g', language:'c')
endif

this try to avoid valac to add #line directives but make c to compile with debug so debug a vala complied code show the real c code.

but reading @jpakkane commens on other issues, I think meson cannot change options in meson.build files

bruchar1 added a commit to bruchar1/meson that referenced this issue Dec 1, 2023
bruchar1 added a commit to bruchar1/meson that referenced this issue Dec 2, 2023
bruchar1 added a commit to bruchar1/meson that referenced this issue Dec 5, 2023
jpakkane pushed a commit that referenced this issue Dec 23, 2023
This is a first step to make `buildtype` a true alias of `debug` and
`optimization` options.

See #10808.

Relates to:
- #11645
- #12096
- #5920
- #5814
- #8220
- #8493
- #9540
- #10487
- #12265
- #8308
- #8214
- #7194
- #11732
@bruchar1 bruchar1 linked a pull request Jan 5, 2024 that will close this issue
gerioldman pushed a commit to gerioldman/meson that referenced this issue Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants