3 CHIP supports configuring the build with [GN](https://gn.googlesource.com/gn/),
4 a fast and scalable meta-build system that generates inputs to
5 [ninja](https://ninja-build.org/).
13 Build system features:
15 - Very fast and small footprint
16 - Cross-platform handling: (Linux, Darwin, embedded arm, etc.)
17 - Multiple toolchains & cross toolchain dependencies
18 - Integrates automated testing framework: `ninja check`
19 - Introspection: `gn desc`
20 - Automatic formatting: `gn format`
22 ### Checking out the Code
24 To check out the CHIP repostiory:
27 git clone --recurse-submodules git@github.com:project-chip/connectedhomeip.git
30 If you already have a checkout, run the following command to sync submodules:
33 git submodule update --init
38 Before building, you'll need to install a few OS specific dependencies.
40 #### How to install prerequisites on Linux
42 On Debian-based Linux distributions such as Ubuntu, these dependencies can be
43 satisfied with the following:
46 sudo apt-get install git gcc g++ python pkg-config libssl-dev libdbus-1-dev libglib2.0-dev libavahi-client-dev ninja-build python3-venv python3-dev unzip
49 #### How to install prerequisites on macOS
51 On macOS, first install Xcode from the Mac App Store. The remaining dependencies
52 can be installed and satisfied using [Brew](https://brew.sh/):
55 brew install openssl pkg-config
58 However, that does not expose the package to `pkg-config`. To fix that, one
59 needs to run something like the following:
62 cd /usr/local/lib/pkgconfig
63 ln -s ../../Cellar/openssl@1.1/1.1.1g/lib/pkgconfig/* .
66 where `openssl@1.1/1.1.1g` may need to be replaced with the actual version of
67 OpenSSL installed by Brew.
69 Note: If using MacPorts, `port install openssl` is sufficient to satisfy this
72 #### How to install prerequisites on Raspberry Pi 4
74 Using `rpi-imager`, install the Ubuntu _20.10_ LTS 64-bit _server_ OS for arm64
75 architectures on a micro SD card. This release will have bluez 5.55 which is
76 required for BLE functionality.
78 Boot the SD card, login with the default user account "ubuntu" and password
79 "ubuntu", then proceed with "How to install prerequisites on Linux".
81 Finally, install some Raspberry Pi specific dependencies:
84 sudo apt-get install pi-bluetooth
87 You need to reboot your RPi after install `pi-bluetooth`.
91 Before running any other build command, the `scripts/activate.sh` environment
92 setup script should be sourced at the top level. This script takes care of
93 downloading GN, ninja, and setting up a Python environment with libraries used
97 source scripts/activate.sh
100 If this script says the environment is out of date, it can be updated by
104 source scripts/bootstrap.sh
107 The `scripts/bootstrap.sh` script re-creates the environment from scratch, which
108 is expensive, so avoid running it unless the environment is out of date.
110 ### Build for the Host OS (Linux or macOS)
112 This will build all sources, libraries, and tests for the host platform:
115 source scripts/activate.sh
122 This generates a configuration suitable for debugging. To configure an optimized
123 build, specify `is_debug=false`:
126 gn gen out/host --args='is_debug=false'
131 The directory name `out/host` can be any directory, although it's conventional
132 to build within the `out` directory. This example uses `host` to emphasize that
133 we're building for the host system. Different build directories can be used for
134 different configurations, or a single directory can be used and reconfigured as
135 necessary via `gn args`.
137 To run all tests, run:
140 ninja -C out/host check
143 To run only the tests in src/inet/tests, you can run:
146 ninja -C out/host src/inet/tests:tests_run
149 Note that the build system caches passing tests, so if you see
155 that means that the tests passed in a previous build.
157 ### Build Custom configuration
159 The build is configured by setting build arguments. These are set by passing the
160 `--args` option to `gn gen`, by running `gn args` on the output directory, or by
161 hand editing `args.gn` in the output directory. To configure a new build or edit
162 the arguments to existing build, run:
165 source scripts/activate.sh
172 Two key builtin build arguments are `target_os` and `target_cpu`, which control
173 the OS & CPU of the build.
175 To see help for all available build arguments:
179 gn args --list out/custom
184 Examples can be built in two ways, as separate projects that add CHIP in the
185 third_party directory, or in the top level CHIP project.
187 To build the `chip-shell` example as a separate project:
195 To build it at the top level, see below under "Unified Builds".
199 To build a unified configuration that approximates the set of continuous builds:
202 source scripts/activate.sh
204 gn gen out/unified --args='is_debug=true target_os="all"'
206 ninja -C out/unified all
209 This can be used prior to change submission to configure, build, and test the
210 gcc, clang, mbedtls, & examples configurations all together in one parallel
211 build. Each configuration has a separate subdirectory in the output dir.
213 This unified build can be used for day to day development, although it's more
214 expensive to build everything for every edit. To save time, you can name the
215 configuration to build:
218 ninja -C out/unified host_gcc
219 ninja -C out/unified check_host_gcc
222 Replace `host_gcc` with the name of the configuration, which is found in the
225 You can also fine tune the configurations generated via arguments such as:
228 gn gen out/unified --args='is_debug=true target_os="all" enable_host_clang_build=false'
231 For a full list, see the root `BUILD.gn`.
233 Note that in the unified build, targets have multiple instances and need to be
234 disambiguated by adding a `(toolchain)` suffix. Use `gn ls out/debug` to list
235 all of the target instances. For example:
238 gn desc out/unified '//src/controller(//build/toolchain/host:linux_x64_clang)'
241 Note: Some platforms that can be build as part of the unified build require
242 downloading additional SDKs. To add these to the build, the location of the SDK
243 installation must be provided as a build argument. For example, to add the
244 Simplelink cc13x2_26x2 examples to the unified build, install the
245 [SDK](https://ti.com/chip_sdk) and add the following build arguments:
248 gn gen out/unified --args="target_os=\"all\" enable_ti_simplelink_builds=true ti_simplelink_sdk_root=\"/path/to/sdk\" ti_sysconfig_root=\"/path/to/sysconfig\""
253 GN has builtin help via
268 [quick start guide](https://gn.googlesource.com/gn/+/master/docs/quick_start.md).
272 GN has various introspection tools to help examine the build configuration.
274 To show all of the targets in an output directory:
280 To show all of the files that will be built:
283 gn outputs out/host '*'
286 To show the GN representation of a configured target:
289 gn desc out/host //src/inet --all
292 To dump the GN representation of the entire build as JSON:
295 gn desc out/host/ '*' --all --format=json
298 To show the dependency tree:
301 gn desc out/host //:all deps --tree --all
304 To find dependency paths:
307 gn path out/host //src/transport/tests:tests //src/system
310 To list useful information for linking against libCHIP:
313 gn desc out/host //src/lib include_dirs
314 gn desc out/host //src/lib defines
315 gn desc out/host //src/lib outputs
318 gn desc out/host //src/lib --format=json
323 If you make any change to the GN build system, the next build will regenerate
324 the ninja files automatically. No need to do anything.