Skip to content

Commit 7eca256

Browse files
mbolivar-nordicnashif
authored andcommitted
doc: additional clarifications on west
Add a missing reference to how west is used to set ZEPHYR_MODULES in without-west.rst, augmenting the application development guide a bit to include this in the list of important variables, cleaning that up a bit while we are here and adding some more west details. Add a big fat warning in the getting started guide that using Zephyr without west is not for the faint of heart. Signed-off-by: Marti Bolivar <[email protected]>
1 parent b991962 commit 7eca256

File tree

5 files changed

+218
-101
lines changed

5 files changed

+218
-101
lines changed

doc/application/index.rst

Lines changed: 121 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,16 @@ section describes the most important ones that every Zephyr developer
253253
should know about.
254254

255255
.. note::
256-
All variables listed in this section can be supplied to the build system
257-
in 3 ways (in order of precedence):
256+
257+
The variables :makevar:`BOARD`, :makevar:`CONF_FILE`, and
258+
:makevar:`DTC_OVERLAY_FILE` can be supplied to the build system in
259+
3 ways (in order of precedence):
258260

259261
* As a parameter to the ``cmake`` invocation via the ``-D`` command-line
260262
switch
261263
* As an environment variables (``export`` on Linux/macOS and ``set`` on
262264
Windows)
263-
* As a ``set(<VARIABLE>, <VALUE>)`` statement in your :file:`CMakeLists.txt`
264-
265-
The exception is :makevar:`ZEPHYR_BASE`, which **must** be exported as an
266-
environment variable.
265+
* As a ``set(<VARIABLE> <VALUE>)`` statement in your :file:`CMakeLists.txt`
267266

268267
* :makevar:`ZEPHYR_BASE`: Sets the path to the directory containing Zephyr,
269268
which is needed by the build system's boilerplate file. This is an
@@ -273,24 +272,24 @@ should know about.
273272
:makevar:`ZEPHYR_BASE` explicitly, but then you won't get the other features
274273
provided by those scripts.
275274

276-
* :makevar:`BOARD`: Selects the board that the application's build will use for
277-
the default configuration. This can be defined in the environment, in your
278-
application's :file:`CMakeLists.txt` file, or in the ``cmake`` command line.
279-
See :ref:`boards` for built-in boards, and :ref:`board_porting_guide` for
280-
information on adding board support.
275+
* :makevar:`BOARD`: Selects the board that the application's build
276+
will use for the default configuration. See :ref:`boards` for
277+
built-in boards, and :ref:`board_porting_guide` for information on
278+
adding board support.
281279

282280
* :makevar:`CONF_FILE`: Indicates the name of one or more configuration
283-
fragment files. Multiple filenames can either be separated by a single space
284-
or a single semicolon. Each file includes Kconfig configuration values that
285-
override the default configuration values. Like :makevar:`BOARD`, this can
286-
also be defined in the environment, in your application's
287-
:file:`CMakeLists.txt` file, or in the ``cmake`` command line.
281+
fragment files. Multiple filenames can be separated with either spaces or
282+
semicolons. Each file includes Kconfig configuration values that override
283+
the default configuration values.
288284

289285
* :makevar:`DTC_OVERLAY_FILE`: Indicates the name of one or more Device Tree
290-
overlay files. Each file includes Device Tree values that
291-
override the default DT values. Like :makevar:`CONF_FILE`, this
292-
can also be defined in the environment, in your application's
293-
:file:`CMakeLists.txt` file, or in the ``cmake`` command line.
286+
overlay files. Multiple filenames can be separated with either spaces or
287+
semicolons. Each file includes Device Tree values that override the default
288+
DT values.
289+
290+
* :makevar:`ZEPHYR_MODULES`: A CMake list containing absolute paths of
291+
additional directories with source code, Kconfig, etc. that should be used in
292+
the application build. See :ref:`ext-projs` below for details.
294293

295294
.. _build_an_application:
296295

@@ -653,73 +652,125 @@ Modules (External projects)
653652
Zephyr relies on the source code of several externally maintained projects in
654653
order to avoid reinventing the wheel and to reuse as much well-established,
655654
mature code as possible when it makes sense. In the context of Zephyr's build
656-
system those are called *modules*.
655+
system those are called *modules*. These modules must be integrated with the
656+
Zephyr build system, which is described in more detail in other sections on
657+
this page.
658+
657659
There are several categories of external projects that Zephyr depends on,
658660
including:
659661

660662
- Debugger integration
661-
- Silicon Vendor Hardware Abstraction Layers (HALs)
663+
- Silicon vendor Hardware Abstraction Layers (HALs)
662664
- Cryptography libraries
663665
- Filesystems
664-
- Inter-Process Communication (IPC)
666+
- Inter-Process Communication (IPC) libraries
665667

666-
These modules (external projects) must be integrated with the Zephyr
667-
build system, which is based around Kconfig and CMake (see
668-
:ref:`application` for more information about Zephyr's build system).
668+
The build system variable :makevar:`ZEPHYR_MODULES` is a `CMake list`_ of
669+
absolute paths to the directories containing Zephyr modules. These modules
670+
contain :file:`CMakeLists.txt` and :file:`Kconfig` files describing how to
671+
build and configure them, respectively. Module :file:`CMakeLists.txt` files are
672+
added to the build using CMake's `add_subdirectory()`_ command, and the
673+
:file:`Kconfig` files are included in the build's Kconfig menu tree.
669674

670-
The way that the build system discovers and includes external projects when
671-
building an application is based around the :ref:`west` tool's ``west list``
672-
command. The main CMake script in Zephyr (the :file:`CMakeLists.txt` located
673-
in the zephyr repository root folder) invokes ``west list`` to obtain a list of
674-
projects managed by west. For each project then, the CMake scripts will verify
675-
if the project contains the metadata required in a module. If the project is
676-
identified to be a module then CMake will include it in the build.
675+
If you have :ref:`west <west>` installed, you don't need to worry about how
676+
this variable is defined unless you are adding a new module. The build system
677+
knows how to use west to set :makevar:`ZEPHYR_MODULES`. You can add additional
678+
modules to this list by setting the :makevar:`ZEPHYR_EXTRA_MODULES` CMake
679+
variable. This can be useful if you want to keep the list of modules found with
680+
west and also add your own.
677681

678-
.. note::
679-
Although the build system normally uses :ref:`west` to list the available
680-
external projects for potential inclusion in the build, it is perfectly
681-
possible to use any other script or tool. By calling cmake as
682-
``cmake --DZEPHYR_MODULES=<oot-path-to-module>[;<additional-oot-module(s)>]``
683-
, it will search in those paths instead of invoking ``west list``
682+
Finally, you can also specify the list of modules yourself in various ways, or
683+
not use modules at all if your application doesn't need them.
684684

685-
The code in :file:`CMakeLists.txt` retrieves the following information for
686-
each project using ``west list``:
685+
Module Initialization Using West
686+
================================
687687

688-
- name: The name of the project as specified in the manifest file
689-
- path: The path of the project within the west installation
688+
If west is installed and :makevar:`ZEPHYR_MODULES` is not already set, the
689+
build system finds all the modules in your :term:`west installation` and uses
690+
those. It does this by running :ref:`west list <west-multi-repo-misc>` to get
691+
the paths of all the projects in the installation, then filters the results to
692+
just those projects which have the necessary module metadata files.
690693

691-
Once it has collected the list, the CMake script performs the following
692-
operations on each project to determine if it is a module to be included in
693-
the build:
694+
Each project in the ``west list`` output is tested like this:
694695

695-
- If a matching (see below) :file:`CMakeLists.txt` is located, it will process
696-
it directly by using the CMake ``add_subdirectory`` command
697-
- If a matching (see below) :file:`Kconfig` is located, it will instruct
698-
Kconfig to source it (i.e. process it)
696+
- If the project contains a file named :file:`zephyr/module.yml`, then
697+
its contents should look like this:
699698

700-
The way that the script determines if a matching :file:`CMakeLists.txt` and
701-
:file:`Kconfig` are present is the following (in order of precedence):
699+
.. code-block:: yaml
702700
703-
- If the project contains a file named :file:`<path>/zephyr/module.yml` then
704-
its contents are parsed:
701+
build:
702+
cmake: <cmake-directory>
703+
kconfig: <directory>/Kconfig
705704
706-
- If a ``cmake: <folder>`` field is present then the build system will match
707-
the :file:`CMakeLists.txt` in ``<folder>``
708-
- If a ``kconfig: <folder>/<kconfig-file>`` field is present then the build
709-
system will match the setting.
710-
- If the project contains a file named exactly
711-
:file:`<path>/zephyr/CMakeLists.txt` the build system will match it
712-
- If the project contains a file named :file:`<path>/zephyr/Kconfig` the build
713-
system will match it
705+
The ``cmake: <cmake-directory>`` part specifies that
706+
:file:`<cmake-directory>` contains the :file:`CMakeLists.txt` to use. The
707+
``kconfig: <directory>/Kconfig`` part specifies the Kconfig file to use.
708+
Neither is required: ``cmake`` defaults to ``zephyr``, and ``kconfig``
709+
defaults to ``zephyr/Kconfig``.
714710

715-
Example of a :file:`<path>/zephyr/module.yml` file referring to
716-
:file:`CMakeLists.txt` and :file:`Kconfig` files at the root of the module:
711+
Here is an example :file:`module.yml` file referring to
712+
:file:`CMakeLists.txt` and :file:`Kconfig` files in the root directory of the
713+
module:
717714

718-
.. code-block:: console
715+
.. code-block:: yaml
716+
717+
build:
718+
cmake: .
719+
kconfig: Kconfig
720+
721+
- Otherwise (i.e. if the project has no :file:`zephyr/module.yml`), then the
722+
build system looks for :file:`zephyr/CMakeLists.txt` and
723+
:file:`zephyr/Kconfig` files in the project. If both are present, the project
724+
is considered a module, and those files will be added to the build.
725+
726+
- If neither of those checks succeed, the project is not considered a module,
727+
and is not added to :makevar:`ZEPHYR_MODULES`.
728+
729+
Module Initialization Without West
730+
==================================
731+
732+
If you don't have west installed or don't want the build system to use it to
733+
find Zephyr modules, you can set :makevar:`ZEPHYR_MODULES` yourself using one
734+
of the following options. Each of the directories in the list must contain
735+
either a :file:`zephyr/module.yml` file or the files
736+
:file:`zephyr/CMakeLists.txt` and :file:`Kconfig`, as described in the previous
737+
section.
738+
739+
#. At the CMake command line, like this:
740+
741+
.. code-block:: console
719742
720-
build:
721-
cmake: .
722-
kconfig: Kconfig
743+
cmake -DZEPHYR_MODULES=<path-to-module1>[;<path-to-module2>[...]] ...
744+
745+
#. At the top of your application's top level :file:`CMakeLists.txt`, like this:
746+
747+
.. code-block:: cmake
748+
749+
set(ZEPHYR_MODULES <path-to-module1> <path-to-module2> [...])
750+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
751+
752+
If you choose this option, make sure to set the variable **before** including
753+
the boilerplate file, as shown above.
754+
755+
#. In a separate CMake script which is pre-loaded to populate the CMake cache,
756+
like this:
757+
758+
.. code-block:: cmake
759+
760+
# Put this in a file with a name like "zephyr-modules.cmake"
761+
set(ZEPHYR_MODULES <path-to-module1> <path-to-module2>
762+
CACHE STRING "pre-cached modules")
763+
764+
You can tell the build system to use this file by adding ``-C
765+
zephyr-modules.cmake`` to your CMake command line.
766+
767+
Not Using Modules
768+
=================
769+
770+
If you don't have west installed and don't specify :makevar:`ZEPHYR_MODULES`
771+
yourself, then no additional modules are added to the build. You will still be
772+
able to build any applications that don't require code or Kconfig options
773+
defined in an external repository.
723774

724775
Application Debugging
725776
*********************
@@ -1489,4 +1540,5 @@ project that demonstrates some of these features.
14891540
.. _Eclipse IDE for C/C++ Developers: https://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/oxygen2
14901541
.. _GNU MCU Eclipse plug-ins: https://gnu-mcu-eclipse.github.io/plugins/install/
14911542
.. _pyOCD v0.11.0: https://github.com/mbedmicro/pyOCD/releases/tag/v0.11.0
1492-
1543+
.. _CMake list: https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#lists
1544+
.. _add_subdirectory(): https://cmake.org/cmake/help/latest/command/add_subdirectory.html

doc/getting_started/index.rst

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,15 @@ Zephyr's multi-purpose :ref:`west` tool lets you easily get the Zephyr project
2929
source code, instead of manually cloning the Zephyr repos along with west
3030
itself.
3131

32-
.. note::
33-
If you prefer to manage the repositories manually or with another tool
34-
instead of using ``west``, you can still opt to do so. The documentation
35-
section :ref:`no-west` describes how to work with Zephyr without using
36-
west to manage its source code.
32+
.. warning::
33+
34+
It's possible to use Zephyr without installing west, but you have
35+
to **really** know :ref:`what you are doing <no-west>`.
3736

3837
Bootstrap west
3938
==============
4039

41-
Install the bootstrapper for Zephyr's command-line tool, :ref:`west <west>` in a
42-
shell or ``cmd.exe`` prompt:
40+
First, install the ``west`` binary and bootstrapper:
4341

4442
.. code-block:: console
4543
@@ -53,9 +51,6 @@ shell or ``cmd.exe`` prompt:
5351
See :ref:`gs_python_deps` for additional clarfication on using the
5452
``--user`` switch.
5553

56-
Additional information about west's structure can be found
57-
:ref:`in the relevant west documentation section <west-struct>`.
58-
5954
Clone the Zephyr Repositories
6055
=============================
6156

@@ -71,7 +66,8 @@ Clone the Zephyr Repositories
7166

7267
You should see ``West bootstrapper version: v0.5.0`` (or higher).
7368

74-
Clone the Zephyr source code repositories from GitHub using the ``west`` tool:
69+
Next, clone the Zephyr source code repositories from GitHub using the
70+
``west`` tool you just installed:
7571

7672
.. code-block:: console
7773

doc/guides/west/index.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ sub-command::
1111

1212
west [common-opts] <command> [opts] <args>
1313

14-
West's built-in commands provide a multiple repository management system with
15-
features inspired by Google's Repo tool and Git submodules. West is also
16-
pluggable: you can write your own west "extension commands" which add
17-
additional features to west. Zephyr provides extension commands for building
18-
applications, debugging them, and more.
14+
West's built-in commands provide a multiple repository management
15+
system with features inspired by Google's Repo tool and Git
16+
submodules. West simplifies configuration and is also pluggable: you
17+
can write your own west "extension commands" which add additional
18+
features to west. Zephyr uses this feature to provide conveniences
19+
for building applications, flashing and debugging them, and more.
20+
21+
It is possible not to use west for Zephyr development if you do not
22+
require these features, prefer to use your own tools, or want to
23+
eliminate the extra layer of indirection. However, this implies extra
24+
effort and expert knowledge.
1925

2026
You can run ``west --help`` (or ``west -h`` for short) to get top-level help
2127
for available west commands, and ``west <command> -h`` for detailed help on

doc/guides/west/repo-tool.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ important to understand.
226226
By default, ``west update`` also updates the west repository in the
227227
installation. To prevent this, use ``--exclude-west``.
228228

229+
.. _west-multi-repo-misc:
230+
229231
Miscellaneous Commands
230232
======================
231233

0 commit comments

Comments
 (0)