1.. _using-snippets:
2
3Using Snippets
4##############
5
6.. tip::
7
8   See :ref:`built-in-snippets` for a list of snippets that are provided by
9   Zephyr.
10
11Snippets have names. You use snippets by giving their names to the build
12system.
13
14With west build
15***************
16
17To use a snippet named ``foo`` when building an application ``app``:
18
19.. code-block:: console
20
21   west build -S foo app
22
23To use multiple snippets:
24
25.. code-block:: console
26
27   west build -S snippet1 -S snippet2 [...] app
28
29With cmake
30**********
31
32If you are running CMake directly instead of using ``west build``, use the
33``SNIPPET`` variable. This is a whitespace- or semicolon-separated list of
34snippet names you want to use. For example:
35
36.. code-block:: console
37
38   cmake -Sapp -Bbuild -DSNIPPET="snippet1;snippet2" [...]
39   cmake --build build
40
41Application required snippets
42*****************************
43
44If an application should always be compiled with a given snippet, it
45can be added to that application's ``CMakeLists.txt`` file. For example:
46
47.. code-block:: cmake
48
49   if(NOT snippet1 IN_LIST SNIPPET)
50     set(SNIPPET snippet1 ${SNIPPET} CACHE STRING "" FORCE)
51   endif()
52
53   find_package(Zephyr ....)
54