0

Context

I'm currently working on yocto on a build for raspberrypi 4 (not really relevant). I would like to create two recipes for two different images:

  1. An image with the bare minimum to run fast. Mostly for production phase
  2. An image with a lot of extra tools and debug options

Basically the core idea is pretty easy to sort out, I just create two image files, the first one requires the basic recipes for my image, the second one requires the first file and requires a few additional modules (such as apt, valgrind, gdb, etc...).

Question

Now here is the issue: Most of my recipes are built with cmake. I would like to add extra flags (especially -g) when building for the debug image.

What is the best way or most common way to do that? Is there a good practice?

To me this is a little tricky due to the fact that bitbake does not supports the if statement.

My solution

For now here is the solution I found: In the image recipe for the dev file add a variable to define the debug mode:

DEBUG_MODE = "1"

Then in every file that compiles a module with cmake conditionally add the flag (-g for example):

TARGET_CXXFLAGS += "${@'-g' if d.getVar('DEBUG_MODE') == '1' else ''}"

However I'm not sure how this apply to dependencies, and I'm not sure if it is the best way to do it. It seems like a lot of duplicate code and tedious to maintain. Is there anything easier to manage?

LNiederha
  • 911
  • 4
  • 18

1 Answers1

1

Currently you set

DEBUG_MODE = "1"

but then check for DEV_MODE in your if condition, so this approach should not work at all.

Suggestion: Set -g globally

One step could be to define TARGET_CPPFLAGS in a *.conf for your debug-image to include -g.

TARGET_CPPFLAGS +=  "-g"

That way there should be no need to add it on recipe base, but can be done globally. Also when it is added in a conf only used for your debug image, there is no need for any if/else.

I would also use TARGET_CPPFLAGS, as those are then used for c and c++. But bear in min that some recipes might unset the compiler flags again.

Sunme
  • 26
  • 3
  • Hey! Thanks for your answer! First off, the `DEV_MODE`/`DEBUG_MODE` mismatch was a typo from my part... edited that but I think you got the gist of it, thanks for pointing it out. Then both my image recipes are in the same layer, if I'm not mistaken have to manually change the layer.conf each time I'd like to set/unset "-g"... could I set TARGET_CPPFLAGE in the image-debug.bb instead? Or is setting a variable in a *.conf file the only way to set a variable globally? And thanks for the tip on `TARGET_CPPFLAGS` – LNiederha Sep 10 '21 at 10:09
  • Well [this](https://www.yoctoproject.org/pipermail/yocto/2012-February/004557.html) answers the question on setting a global variable in a recipes. It is impossible due to the parse order in yocto. For now my tow recipes (debug and dev) are in the same layer. Does creating a new layer for the debug recipe with its own config seem like a good idea? – LNiederha Sep 10 '21 at 11:21
  • I am not sure which way is best for you, but I could imagine the following options: 1) pass the information to bitbake https://www.yoctoproject.org/docs/1.6/bitbake-user-manual/bitbake-user-manual.html#passing-information-into-the-build-task-environment 2) create some debug distro that sets appropriate flags in a distro.conf – Sunme Sep 10 '21 at 14:58