Custom CMake Toolchains¶
To use a custom toolchain defined in an external CMake file, set these environment variables:
ZEPHYR_TOOLCHAIN_VARIANTto your toolchain’s name
TOOLCHAIN_ROOTto the path to the directory containing your toolchain’s CMake configuration files.
Zephyr will then include the toolchain cmake files located in the
cmake/toolchain/generic.cmake: configures the toolchain for “generic” use, which mostly means running the C preprocessor on the generated Devicetree file.
cmake/toolchain/target.cmake: configures the toolchain for “target” use, i.e. building Zephyr and your application’s source code.
You can also set
TOOLCHAIN_ROOT as CMake
variables when generating a build system for a Zephyr application, like so:
west build ... -- -DZEPHYR_TOOLCHAIN_VARIANT=... -DTOOLCHAIN_ROOT=...
cmake -DZEPHYR_TOOLCHAIN_VARIANT=... -DTOOLCHAIN_ROOT=...
If you do this,
-C <initial-cache> cmake option may useful. If you save
your ZEPHYR_TOOLCHAIN_VARIANT, TOOLCHAIN_ROOT, and other
settings in a file named
my-toolchain.cmake, you can then invoke cmake
cmake -C my-toolchain.cmake ... to save typing.