how to set debug and optimization flag with meson

Viewed 2684

I use meson 0.53.2 on ubuntu 20.04.
I would like to have a maximally optimized executable (-Ofast) but contain all debug symbols (-g3)

  • If I use --buildtype=release it optimizes -O2 and the executable contains no debug symbol.
  • If I use --buildtype=debug it does not optimize at all and uses -g.
  • If I use --buildtype=debugoptimized it optimizes -O2 and uses -g.

I tried to use --debug which seems not to work, because the executable does not contain any debug symbol. Instead if I use -Ddebug=true the debug symbols are there but with the flag -g.

So how do I get gcc to compile with -Ofast -g3 flags in the least dirty way possible?

1 Answers

From the commandline, you can switch higher level of optimization with option optimization=3. It gives you -O3 instead -O2.

By editing meson script, you can set any flags.

if get_option('buildtype') == 'custom'
  add_project_arguments('-Ofast', '-g3',  language : 'cpp')
endif

And in case you cannot modify meson script, you may alter environment variables

CXXFLAGS="-Ofast -g3" meson --buildtype=custom build_c

And --reconfigure seems to not see environment variables.

Related