6

It seems something obvious to me, but I couldn't find any solution. Suppose I want to add or change a compiler flag/option which applies to all yocto recipes. It is possible to add a global flag somewhere, without changing the recipes ?

Waldorf
  • 833
  • 2
  • 13
  • 24

2 Answers2

5

You can add it to the machine configuration file.

The machine configuration file is in the board support layer, under conf/machine. It is named $MACHINE.conf, where MACHINE is defined in your local.conf.

Here are the ones in poky 1.4. Yours might be in a layer outside of poky.

> ls -1 meta-yocto-bsp/conf/machine/
atom-pc.conf
beagleboard.conf
mpc8315e-rdb.conf
routerstationpro.conf
> ls -1 meta/conf/machine/
include
qemuarm.conf
qemumips.conf
qemuppc.conf
qemux86-64.conf
qemux86.conf

Once you identify your board configuration file, add a line to the end to add to your C Flags:

TARGET_CFLAGS += " <my flags> "
pinta
  • 51
  • 1
  • 1
4

You can add global compiler options for Yocto builds in poky/meta/conf/bitbake.conf. After adding options, check the bitbake environment using the command bitbake -e

cat poky/meta/conf/bitbake.conf

...
...
##################################################################
# Build flags and options.
##################################################################

export BUILD_CPPFLAGS = "-isystem${STAGING_INCDIR_NATIVE}"
BUILDSDK_CPPFLAGS = "-isystem${STAGING_INCDIR}"
export CPPFLAGS = "${TARGET_CPPFLAGS}"

export BUILD_CFLAGS = "${BUILD_CPPFLAGS} ${BUILD_OPTIMIZATION}"
BUILDSDK_CFLAGS = "${BUILDSDK_CPPFLAGS} ${BUILD_OPTIMIZATION}"
export CFLAGS = "${TARGET_CFLAGS}"
export TARGET_CFLAGS = "${TARGET_CPPFLAGS} ${SELECTED_OPTIMIZATION}"

export BUILD_CXXFLAGS = "${BUILD_CFLAGS}"
export CXXFLAGS = "${TARGET_CXXFLAGS}"
export TARGET_CXXFLAGS = "${TARGET_CFLAGS}"
Ashok Vairavan
  • 1,862
  • 1
  • 15
  • 21
  • 2
    It is **not** advisable to modify any files under `poky/...` because in case of an update of your poky layer, all your modifications get lost. Use an own layer instead. – hellow Nov 24 '21 at 14:34