1

I'm editing a meson build file. a line that currently exists the the file is working perfectly.

if cc.has_argument('-Wno-format-truncation')                                                                                                                                                                                           
default_cflags += '-Wno-format-truncation'
endif

I've added a line because I want debug information:

default_cflags += '-ggdb -O0'

However, this is being interpreted with the single quotes, and breaking the make command.

-Wno-missing-field-initializers -D_GNU_SOURCE -march=native '-ggdb -O0' -DALLOW_EXPERIMENTAL_API -MD -MQ

Obviously, cc doesn't like this and is throwing an error. What is causing meson to interpret this output with the single quotes? I've tried double quotes and no quotes, but that throws other errors altogether.

Edit

This is a dpdk build file, so the compiler call is:

            executable('dpdk-' + name, sources,
                    include_directories: includes,
                    link_whole: link_whole_libs,
                    link_args: ldflags,
                    c_args: default_cflags,
                    dependencies: dep_objs)
Brydon Gibson
  • 1,179
  • 3
  • 11
  • 22
  • How are you passing `default_cflags` to your target?? – droptop Sep 28 '21 at 11:14
  • 1
    @BrydonGibson is your goal to build the binary with `-O0 -g` for debugging with meson? If yes, there is much easier way than modifying or editing the meson file. Please let me know. – Vipin Varghese Sep 28 '21 at 13:27
  • @VipinVarghese Exactly. The accepted answer provides a way to do that. I am new to meson so I'm generally used to adding my own targets and such to makefiles – Brydon Gibson Sep 28 '21 at 16:46
  • @BrydonGibson thanks for confirming I have only modified pmod answer to reflect your intention. Happy to hear your problem is resolved. – Vipin Varghese Sep 28 '21 at 17:23
  • @VipinVarghese thank you for updates – pmod Sep 28 '21 at 21:21

1 Answers1

2

The += syntax is used by meson to add elements to arrays (append). Thus, when array is later flattened and space is detected - then quotes are used, I guess. So append one by one:

default_cflags += '-ggdb'
default_cflags += '-O0'

or update as array:

default_cflags += ['-ggdb, '-O0']

As for the debug information, check meson's core options: buildtype and optimization. You can configure your build without including related flags into meson.build (if it suffices to your needs).

The option to use is --buildtype=debug for non optimized binary and --buildtype=debugoptimized for binary built with -g -O2.

The recommended way to pass these CFLAGS arguments as list objects. Such for shared_library, static_library, executable with the custom c_args : default_cflags where default_cflags is declared as

default_cflags = []
...
...
...
if is_debug
  default_cflags += ['-ggdb', '-O0']
endif
...
...
pmod
  • 10,450
  • 1
  • 37
  • 50