Part 1
요약·해설
TOOLCHAIN_ROOT 구조, generic.cmake와 target.cmake 역할, CMake 변수·initial cache 전달, TOOLCHAIN_USE_CUSTOM과 USERINCLUDE 설정을 설명합니다.
TOOLCHAIN_ROOT
generic · target
other.h · USERINCLUDE
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
162A80D9B2B9393AD61479517152D77030B885DCEFC3ACE10ECDC31267086C08
.. _custom_cmake_toolchains:
Custom CMake Toolchains
#######################
To use a custom toolchain defined in an external CMake file, :ref:`set these
environment variables <env_vars>`:
- Set :envvar:`ZEPHYR_TOOLCHAIN_VARIANT` to your toolchain's name
- Set ``TOOLCHAIN_ROOT`` to the path to the directory containing your
toolchain's CMake configuration files.
Zephyr will then include the toolchain cmake files located in the
:file:`TOOLCHAIN_ROOT` directory:
- :file:`cmake/toolchain/<toolchain name>/generic.cmake`: configures the
toolchain for "generic" use, which mostly means running the C preprocessor
on the generated
:ref:`devicetree` file.
- :file:`cmake/toolchain/<toolchain name>/target.cmake`: configures the
toolchain for "target" use, i.e. building Zephyr and your application's
source code.
Here <toolchain name> is the same as the name provided in
:envvar:`ZEPHYR_TOOLCHAIN_VARIANT`
See the zephyr files :zephyr_file:`cmake/modules/FindHostTools.cmake` and
:zephyr_file:`cmake/modules/FindTargetTools.cmake` for more details on what your
:file:`generic.cmake` and :file:`target.cmake` files should contain.
You can also set ``ZEPHYR_TOOLCHAIN_VARIANT`` and ``TOOLCHAIN_ROOT`` as CMake
variables when generating a build system for a Zephyr application, like so:
.. code-block:: console
west build ... -- -DZEPHYR_TOOLCHAIN_VARIANT=... -DTOOLCHAIN_ROOT=...
.. code-block:: console
cmake -DZEPHYR_TOOLCHAIN_VARIANT=... -DTOOLCHAIN_ROOT=...
If you do this, ``-C <initial-cache>`` `cmake option`_ may useful. If you save
your :makevar:`ZEPHYR_TOOLCHAIN_VARIANT`, :makevar:`TOOLCHAIN_ROOT`, and other
settings in a file named :file:`my-toolchain.cmake`, you can then invoke cmake
as ``cmake -C my-toolchain.cmake ...`` to save typing.
Zephyr includes :file:`include/toolchain.h` which again includes a toolchain
specific header based on the compiler identifier, such as ``__llvm__`` or
``__GNUC__``.
Some custom compilers identify themselves as the compiler on which they are
based, for example ``llvm`` which then gets the :file:`toolchain/llvm.h` included.
This included file may though not be right for the custom toolchain. In order
to solve this, and thus to get the :file:`include/other.h` included instead,
add the set(TOOLCHAIN_USE_CUSTOM 1) cmake line to the generic.cmake and/or
target.cmake files located under
:file:`<TOOLCHAIN_ROOT>/cmake/toolchain/<toolchain name>/`.
When :makevar:`TOOLCHAIN_USE_CUSTOM` is set, the :file:`other.h` must be
available out-of-tree and it must include the correct header for the custom
toolchain.
A good location for the :file:`other.h` header file, would be a
directory under the directory specified in ``TOOLCHAIN_ROOT`` as
:file:`include/toolchain`.
To get the toolchain header included in zephyr's build, the
:makevar:`USERINCLUDE` can be set to point to the include directory, as shown
here:
.. code-block:: console
west build -- -DZEPHYR_TOOLCHAIN_VARIANT=... -DTOOLCHAIN_ROOT=... -DUSERINCLUDE=...
.. _cmake option:
https://cmake.org/cmake/help/latest/manual/cmake.1.html#options
Part 3
한국어 전문 번역
외부 CMake file로 custom toolchain 정의
외부 CMake file에 정의한 custom toolchain을 쓰려면 환경 변수 설정 안내에 따라 ZEPHYR_TOOLCHAIN_VARIANT를 toolchain 이름으로, TOOLCHAIN_ROOT를 toolchain CMake configuration directory로 설정합니다.
Zephyr는 TOOLCHAIN_ROOT 아래의 다음 file을 포함합니다.
cmake/toolchain/<toolchain name>/generic.cmake: generated Devicetree에 C preprocessor를 실행하는 등 generic 용도의 host toolchain 동작을 설정합니다.cmake/toolchain/<toolchain name>/target.cmake: Zephyr와 application source code를 build하는 target toolchain 동작을 설정합니다.
<toolchain name>은 ZEPHYR_TOOLCHAIN_VARIANT 값과 같습니다. 필요한 정의는 FindHostTools.cmake와 FindTargetTools.cmake에서 확인할 수 있습니다.
환경 변수 대신 CMake 변수로 전달
Build system을 생성할 때 두 값을 CMake 변수로 직접 넘길 수도 있습니다.
west build ... -- -DZEPHYR_TOOLCHAIN_VARIANT=... -DTOOLCHAIN_ROOT=...cmake -DZEPHYR_TOOLCHAIN_VARIANT=... -DTOOLCHAIN_ROOT=...CMake -C option을 사용하면 반복 입력을 줄일 수 있습니다. 예를 들어 ZEPHYR_TOOLCHAIN_VARIANT, TOOLCHAIN_ROOT와 기타 값을 my-toolchain.cmake에 저장한 뒤 cmake -C my-toolchain.cmake ...로 불러옵니다.
Custom compiler header 선택
include/toolchain.h은 __llvm__ 또는 __GNUC__ 같은 compiler identifier에 따라 toolchain 전용 header를 포함합니다. 기반 compiler와 같은 identifier를 쓰는 custom compiler는 실제로 맞지 않는 toolchain/llvm.h 같은 header를 선택할 수 있습니다.
generic.cmake 또는 target.cmake에 set(TOOLCHAIN_USE_CUSTOM 1)을 추가하면 Zephyr가 대신 include/other.h를 사용합니다. 이때 out-of-tree other.h가 실제 custom toolchain header를 포함해야 합니다.
other.h는 TOOLCHAIN_ROOT/include/toolchain 같은 directory에 두고, USERINCLUDE가 그 include directory를 가리키게 설정합니다.
west build -- -DZEPHYR_TOOLCHAIN_VARIANT=... -DTOOLCHAIN_ROOT=... -DUSERINCLUDE=...
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.