The setup I am running is for a microcontroller with particular memory constraints, which means that I cannot compile an entire image with no/low optimization - it will simply be too large. But performing on-target single-step debugging is a vital tool in our development, since there are some bugs that are simply too hard to notice without this.
We have done this in make for other projects, and I believe this is also possible in CMake with something like this:
SET_SOURCE_FILES_PROPERTIES( foo.cpp PROPERTIES COMPILE_FLAGS -O0)
I have seen this open issue on the meson project, where the suggestion is to make an external library for the files that need different compiler flags. This is not applicable to my situation, since if I have to debug only foo.cpp
, the library will then have to include all the other objects needed by foo.cpp
in the library, and that will different for each source file.
I have also tried using the meson generator, where the executable was simply my compiler:
debug_srcs = [
'foo.cpp'
]
cpp_debug_args = [
'-O0'
...
]
cpp_arm_compiler = find_program('arm-none-eabi-g++')
cpp_debug_gen = generator(cpp_arm_compiler,
output: '@BASENAME@.o',
arguments: [ cpp_debug_args, '@INPUT@', '@OUTPUT@'])
debug_objs = cpp_debug_gen.process(debug_srcs)
exe = executable('image',
...
objects: debug_objs,
)
But here, meson actually tells me that this is not allowed:
ERROR: Generated files are not allowed in the 'objects' kwarg for target 'image'.
It is meant only for pre-built object files that are shipped with the
source tree. Try adding it in the list of sources.
The only other option I can think of, is to make some tool outside meson to generate the files and create a .txt file with a list of all the .o files. This can be read in meson:
fs = import('fs')
debug_objs = fs.read('list.txt').strip().split('\n')
exe = executable('image',
...
objects: debug_objs,
)
This has the potential to be not pretty and make the build system more convoluted than what it needs to be, since things will have to be moved outside meson. Is there a better way?