Skip to content

GN arguments definition for Mbed project

ATmobica edited this page Feb 15, 2021 · 2 revisions

Brief

This page describes the approach to defining and passing the GN build arguments for mbed platform.

Every CHIP project for mbed platform build CHIP protocol layer as a static library which is included in the main application. In config/mbed/chip-gn directory we can find the GN project to do this. However, it requires some arguments to build the libraries as expected.

Approach

Build arguments

Build arguments are variables passed in from outside of the build that build files can query to determine how the build works.

First level - default arguments

First, system default arguments are set based on the current system. The built-in arguments are:

  • host_cpu
  • host_os
  • current_cpu
  • current_os
  • target_cpu
  • target_os

These arguments are set automatically.

Second level - platform arguments

Next, platform-specific overrides are applied. These are specified inside the default_args variable of .gn file. Inside the default_args we import the args.gni file which contains all the arguments necessary for the correct CHIP build for the mbed platform.

Third level - project arguments

Arguments file from current build directory is used (this is the file args.gn in the build directory). Args.gn file is autogenerated during cmake building and contains project-specific arguments. These arguments can be modified by changing the config.in file in the project directory. This mechanism allows arguments to be propagated via cmake to GN build. Adding / removing arguments requires the CmakeLists.txt file modification.

Toolchain arguments

Last, for targets being compiled with a non-default toolchain, the toolchain overrides are applied. These are specified in the toolchain_args section of a toolchain definition. In our case, it is a separate target (gcc_toolchain) that should be created for each platform. See config/mbed/chip-gn/toolchain/BUILD.gn

NOTE

Chip components define their own targets which are included as dependencies on others. Each one has its own set of arguments that are usually set to default values. Using platform and project arguments you can easily overwrite them with custom values (i.e chip_device_platform)