Skip to content

How to integrate CHIP with CMake based build system

ATmobica edited this page Jan 28, 2021 · 6 revisions

Brief

The CHIP project is based on the GN build system. More information about GN you can find here: GN build system

However, it is possible to integrate the CHIP connectivity protocol with CMake-based projects. A good example of that solution is nrfconnect platform implementation inside the CHIP project. NRFconnect platform uses the Zephyr as an OS engine of which building system is based on CMake (Zephyr build).

Integration approach

The main assumption of this integration is to build a static library of CHIP connectivity protocol and link it to the main target.

In nrfconnect platform, the CHIP is defined as an extra Zephyr module that builds a static library linked to examples application (see: connectedhomeip/config/nrfconnect/app/app.cmake).

The nrfconnect config directory also includes:

  • chip-module - cmake configuration files to create an environment for build CHIP library with GN
  • chip-gn - GN configuration file to build CHIP library for nrfconnect platform

In this case, the chip-module is a layer connecting two different building systems. In the CMakeList.txt file we can find the following integration steps:

  1. Declare configuration variables and define constants
  2. Prepare CHIP configuration based on the application configuration
  3. Generate a configuration for CHIP GN build system (args.gn file as result)
  4. Define target that builds CHIP library(ies) with GN build system (CMake ExternalProject is used)
  5. Define target that exposes CHIP headers & libraries to the application

As a result of the chip-module's operation, a chip-module is created inside the application build directory (build/modules/chip-module).

The chip-gn is a building CHIP libraries layer. It contains GN building configuration files and the main BUILD.gn. The default build arguments are set to ARM CPU, Zephyr OS and nrfconnect platform(.gn and args.gni). In addition, depending on the application being built, other dependencies are added to the platform group(BUILD.gn). Also, the toolchain for this platform is defined in a toolchain/BUILD.gn file. As a result of the chip-gn's operation, a chip library is created inside the application build directory (build/modules/chip-module/lib/libCHIP.a).

List of parameters that should be defined before building CHIP library:

  • chip_device_platform - [platform] - definition of platform for CHIP project
  • chip_project_config_include - [project] - path to custom project CHIP configuration
  • chip_system_project_config_include - [project] - path to custom system project CHIP configuration
  • chip_ble_project_config_include - [project] - path to custom BLE project CHIP configuration
  • chip_build_tests - [project] - definition of using test dependency for project
  • chip_enable_openthread - [project] - definition of using openthread dependency for project
  • chip_inet_config_enable_ipv4 - [platform] - definition of enabling IPv4 for platform
  • custom_toolchain - [platform] - definition of custom toolchain dependency for platform
  • mbedtls_target - [platform] - definition of mbedtls dependency for platform
  • target_cpu - [project] - definition of target CPU for CHIP project
  • target_os - [project] - definition of target OS for CHIP project
  • is_debug - [project] - definition of debug mode for project

NOTE: Perhaps that these are not all parameters that should be defined to configure the mbed project. Depending on the dependency between the CHIP and the Mbed some functionalities should be turned on and some turned of.

Summary

This example shows how can we integrate the CHIP connectivity protocol with CMake-based projects. It is a complex but ready-to-use solution.

In this approach, the most important point of integration with the Cmake application are:

  1. Create a CHIP library GN building project for your platform (remember about platform-specific settings: toolchain, target CPU, target OS)
  2. Setup GN building environment (declare configuration variables, create configuration files)
  3. Add external project to run GN building for CHIP library
  4. Link CHIP library with your application