Marti Bolivar | 0d811b9 | 2018-10-14 23:20:24 -0600 | [diff] [blame] | 1 | .. _custom_cmake_toolchains: |
| 2 | |
| 3 | Custom CMake Toolchains |
| 4 | ####################### |
| 5 | |
Marti Bolivar | 5edb6d5 | 2019-05-06 23:36:30 -0600 | [diff] [blame] | 6 | To use a custom toolchain defined in an external CMake file, :ref:`set these |
| 7 | environment variables <env_vars>`: |
Marti Bolivar | 0d811b9 | 2018-10-14 23:20:24 -0600 | [diff] [blame] | 8 | |
Marti Bolivar | 5edb6d5 | 2019-05-06 23:36:30 -0600 | [diff] [blame] | 9 | - 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 Bolivar | 0d811b9 | 2018-10-14 23:20:24 -0600 | [diff] [blame] | 12 | |
Marti Bolivar | 5edb6d5 | 2019-05-06 23:36:30 -0600 | [diff] [blame] | 13 | Zephyr will then include the toolchain cmake files located in the |
| 14 | :file:`TOOLCHAIN_ROOT` directory: |
Marti Bolivar | 0d811b9 | 2018-10-14 23:20:24 -0600 | [diff] [blame] | 15 | |
Marti Bolivar | 5edb6d5 | 2019-05-06 23:36:30 -0600 | [diff] [blame] | 16 | - :file:`cmake/toolchain/generic.cmake`: configures the toolchain for "generic" |
Martí Bolívar | 6e57b42 | 2020-03-10 18:16:25 -0700 | [diff] [blame] | 17 | use, which mostly means running the C preprocessor on :ref:`devicetree |
| 18 | input files <dt-input-files>`. |
Marti Bolivar | c98acc2 | 2019-06-06 16:33:07 -0600 | [diff] [blame] | 19 | - :file:`cmake/toolchain/target.cmake`: configures the toolchain for "target" |
| 20 | use, i.e. building Zephyr and your application's source code. |
Marti Bolivar | 0d811b9 | 2018-10-14 23:20:24 -0600 | [diff] [blame] | 21 | |
Marti Bolivar | 5edb6d5 | 2019-05-06 23:36:30 -0600 | [diff] [blame] | 22 | See 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 | |
| 26 | You can also set ``ZEPHYR_TOOLCHAIN_VARIANT`` and ``TOOLCHAIN_ROOT`` as CMake |
| 27 | variables when generating a build system for a Zephyr application, like so: |
Marti Bolivar | 0d811b9 | 2018-10-14 23:20:24 -0600 | [diff] [blame] | 28 | |
| 29 | .. code-block:: console |
| 30 | |
Carles Cufi | b476643 | 2019-06-13 21:59:12 +0200 | [diff] [blame] | 31 | west build ... -- -DZEPHYR_TOOLCHAIN_VARIANT=... -DTOOLCHAIN_ROOT=... |
| 32 | |
| 33 | .. code-block:: console |
| 34 | |
Marti Bolivar | 0d811b9 | 2018-10-14 23:20:24 -0600 | [diff] [blame] | 35 | cmake -DZEPHYR_TOOLCHAIN_VARIANT=... -DTOOLCHAIN_ROOT=... |
Marti Bolivar | c98acc2 | 2019-06-06 16:33:07 -0600 | [diff] [blame] | 36 | |
| 37 | If you do this, ``-C <initial-cache>`` `cmake option`_ may useful. If you save |
| 38 | your :makevar:`ZEPHYR_TOOLCHAIN_VARIANT`, :makevar:`TOOLCHAIN_ROOT`, and other |
| 39 | settings in a file named :file:`my-toolchain.cmake`, you can then invoke cmake |
| 40 | as ``cmake -C my-toolchain.cmake ...`` to save typing. |
| 41 | |
| 42 | .. _cmake option: |
| 43 | https://cmake.org/cmake/help/latest/manual/cmake.1.html#options |