1.. _sca: 2 3Static Code Analysis (SCA) 4########################## 5 6Support for static code analysis tools in Zephyr is possible through CMake. 7 8The build setting :makevar:`ZEPHYR_SCA_VARIANT` can be used to specify the SCA 9tool to use. :envvar:`ZEPHYR_SCA_VARIANT` is also supported as 10:ref:`environment variable <env_vars>`. 11 12Use ``-DZEPHYR_SCA_VARIANT=<tool>``, for example ``-DZEPHYR_SCA_VARIANT=sparse`` 13to enable the static analysis tool ``sparse``. 14 15.. _sca_infrastructure: 16 17SCA Tool infrastructure 18*********************** 19 20Support for an SCA tool is implemented in a file:`sca.cmake` file. 21The file:`sca.cmake` must be placed under file:`<SCA_ROOT>/cmake/sca/<tool>/sca.cmake`. 22Zephyr itself is always added as an :makevar:`SCA_ROOT` but the build system offers the 23possibility to add additional folders to the :makevar:`SCA_ROOT` setting. 24 25You can provide support for out of tree SCA tools by creating the following 26structure: 27 28.. code-block:: none 29 30 <sca_root>/ # Custom SCA root 31 └── cmake/ 32 └── sca/ 33 └── <tool>/ # Name of SCA tool, this is the value given to ZEPHYR_SCA_VARIANT 34 └── sca.cmake # CMake code that configures the tool to be used with Zephyr 35 36To add ``foo`` under ``/path/to/my_tools/cmake/sca`` create the following structure: 37 38.. code-block:: none 39 40 /path/to/my_tools 41 └── cmake/ 42 └── sca/ 43 └── foo/ 44 └── sca.cmake 45 46To use ``foo`` as SCA tool you must then specify ``-DZEPHYR_SCA_VARIANT=foo``. 47 48Remember to add ``/path/to/my_tools`` to :makevar:`SCA_ROOT`. 49 50:makevar:`SCA_TOOL` can be set as a regular CMake setting using 51``-DSCA_ROOT=<sca_root>``, or added by a Zephyr module in its :file:`module.yml` 52file, see :ref:`Zephyr Modules - Build settings <modules_build_settings>` 53 54.. _sca_native_tools: 55 56Native SCA Tool support 57*********************** 58 59The following is a list of SCA tools natively supported by Zephyr build system. 60 61.. toctree:: 62 :maxdepth: 1 63 64 codechecker 65 sparse 66 gcc 67 cpptest 68