@@ -13,12 +13,16 @@ environment variables <env_vars>`:
1313Zephyr will then include the toolchain cmake files located in the
1414:file: `TOOLCHAIN_ROOT ` directory:
1515
16- - :file: `cmake/toolchain/generic.cmake `: configures the toolchain for "generic"
17- use, which mostly means running the C preprocessor on :ref: `devicetree
18- input files <dt-input-files>`.
19- - :file: `cmake/toolchain/target.cmake `: configures the toolchain for "target"
20- use, i.e. building Zephyr and your application's source code.
16+ - :file: `cmake/toolchain/<toolchain name>/generic.cmake `: configures the
17+ toolchain for "generic" use, which mostly means running the C preprocessor
18+ on the generated
19+ :ref: `devicetree ` file.
20+ - :file: `cmake/toolchain/<toolchain name>/target.cmake `: configures the
21+ toolchain for "target" use, i.e. building Zephyr and your application's
22+ source code.
2123
24+ Here <toolchain name> is the same as the name provided in
25+ :envvar: `ZEPHYR_TOOLCHAIN_VARIANT `
2226See the zephyr files :zephyr_file: `cmake/generic_toolchain.cmake ` and
2327:zephyr_file: `cmake/target_toolchain.cmake ` for more details on what your
2428:file: `generic.cmake ` and :file: `target.cmake ` files should contain.
@@ -39,5 +43,30 @@ your :makevar:`ZEPHYR_TOOLCHAIN_VARIANT`, :makevar:`TOOLCHAIN_ROOT`, and other
3943settings in a file named :file: `my-toolchain.cmake `, you can then invoke cmake
4044as ``cmake -C my-toolchain.cmake ... `` to save typing.
4145
46+ Zephyr includes :file: `include/toolchain.h ` which again includes a toolchain
47+ specific header based on the compiler identifier, such as ``__llvm__ `` or
48+ ``__GNUC__ ``.
49+ Some custom compilers identify themselves as the compiler on which they are
50+ based, for example ``llvm `` which then gets the :file: `toolchain/llvm.h ` included.
51+ This included file may though not be right for the custom toolchain. In order
52+ to solve this, and thus to get the :file: `include/other.h ` included instead,
53+ add the set(TOOLCHAIN_USE_CUSTOM 1) cmake line to the generic.cmake and/or
54+ target.cmake files located under
55+ :file: `<TOOLCHAIN_ROOT>/cmake/toolchain/<toolchain name>/ `.
56+
57+ When :makevar: `TOOLCHAIN_USE_CUSTOM ` is set, the :file: `other.h ` must be
58+ available out-of-tree and it must include the correct header for the custom
59+ toolchain.
60+ A good location for the :file: `other.h ` header file, would be a
61+ directory under the directory specified in :envvar: `TOOLCHAIN_ROOT ` as
62+ :file: `include/toolchain `.
63+ To get the toolchain header included in zephyr's build, the
64+ :makevar: `USERINCLUDE ` can be set to point to the include directory, as shown
65+ here:
66+
67+ .. code-block :: console
68+
69+ west build -- -DZEPHYR_TOOLCHAIN_VARIANT=... -DTOOLCHAIN_ROOT=... -DUSERINCLUDE=...
70+
4271 .. _cmake option :
4372 https://cmake.org/cmake/help/latest/manual/cmake.1.html#options
0 commit comments