blob: 29955f856f10e9a402c618d16b30d342ce1b7f27 [file] [log] [blame]
Marti Bolivar0d811b92018-10-14 23:20:24 -06001.. _custom_cmake_toolchains:
2
3Custom CMake Toolchains
4#######################
5
Marti Bolivar5edb6d52019-05-06 23:36:30 -06006To use a custom toolchain defined in an external CMake file, :ref:`set these
7environment variables <env_vars>`:
Marti Bolivar0d811b92018-10-14 23:20:24 -06008
Marti Bolivar5edb6d52019-05-06 23:36:30 -06009- Set :envvar:`ZEPHYR_TOOLCHAIN_VARIANT` to your toolchain's name
10- Set :envvar:`TOOLCHAIN_ROOT` to the path to the directory containing your
11 toolchain's CMake configuration files.
Marti Bolivar0d811b92018-10-14 23:20:24 -060012
Marti Bolivar5edb6d52019-05-06 23:36:30 -060013Zephyr will then include the toolchain cmake files located in the
14:file:`TOOLCHAIN_ROOT` directory:
Marti Bolivar0d811b92018-10-14 23:20:24 -060015
Marti Bolivar5edb6d52019-05-06 23:36:30 -060016- :file:`cmake/toolchain/generic.cmake`: configures the toolchain for "generic"
Martí Bolívar6e57b422020-03-10 18:16:25 -070017 use, which mostly means running the C preprocessor on :ref:`devicetree
18 input files <dt-input-files>`.
Marti Bolivarc98acc22019-06-06 16:33:07 -060019- :file:`cmake/toolchain/target.cmake`: configures the toolchain for "target"
20 use, i.e. building Zephyr and your application's source code.
Marti Bolivar0d811b92018-10-14 23:20:24 -060021
Marti Bolivar5edb6d52019-05-06 23:36:30 -060022See the zephyr files :zephyr_file:`cmake/generic_toolchain.cmake` and
23:zephyr_file:`cmake/target_toolchain.cmake` for more details on what your
24:file:`generic.cmake` and :file:`target.cmake` files should contain.
25
26You can also set ``ZEPHYR_TOOLCHAIN_VARIANT`` and ``TOOLCHAIN_ROOT`` as CMake
27variables when generating a build system for a Zephyr application, like so:
Marti Bolivar0d811b92018-10-14 23:20:24 -060028
29.. code-block:: console
30
Carles Cufib4766432019-06-13 21:59:12 +020031 west build ... -- -DZEPHYR_TOOLCHAIN_VARIANT=... -DTOOLCHAIN_ROOT=...
32
33.. code-block:: console
34
Marti Bolivar0d811b92018-10-14 23:20:24 -060035 cmake -DZEPHYR_TOOLCHAIN_VARIANT=... -DTOOLCHAIN_ROOT=...
Marti Bolivarc98acc22019-06-06 16:33:07 -060036
37If you do this, ``-C <initial-cache>`` `cmake option`_ may useful. If you save
38your :makevar:`ZEPHYR_TOOLCHAIN_VARIANT`, :makevar:`TOOLCHAIN_ROOT`, and other
39settings in a file named :file:`my-toolchain.cmake`, you can then invoke cmake
40as ``cmake -C my-toolchain.cmake ...`` to save typing.
41
42.. _cmake option:
43 https://cmake.org/cmake/help/latest/manual/cmake.1.html#options