cb690ec56e
Static code analyser (SCA) tools are important in software development. CMake offers built-in support for some tools, such as cppcheck and clang-tidy. Other tools, such as sparse, are not directly supported. This commit provides a uniform way for users to specify a supported SCA using `ZEPHYR_SCA_VARIANT=<tool>` which is consistent with how toolchains are specified. ZEPHYR_SCA_VARIANT can be set using `-D` or in environment. Support for an SCA tool is done in `cmake/sca/<tool>/sca.cmake`. SCA_ROOT can be used to specify additional search paths when looking up implementation for a tool. SCA_ROOT can also be specified in `zephyr/module.yml` as setting. This makes it possible to provide SCA tool implementation as part of a Zephyr module. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
32 lines
979 B
CMake
32 lines
979 B
CMake
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# Copyright (c) 2022, Nordic Semiconductor ASA
|
|
|
|
# 'SCA_ROOT' is a prioritized list of directories where SCA tools may
|
|
# be found. It always includes ${ZEPHYR_BASE} at the lowest priority.
|
|
list(APPEND SCA_ROOT ${ZEPHYR_BASE})
|
|
|
|
zephyr_get(ZEPHYR_SCA_VARIANT)
|
|
|
|
if(ScaTools_FIND_REQUIRED AND NOT DEFINED ZEPHYR_SCA_VARIANT)
|
|
message(FATAL_ERROR "ScaTools required but 'ZEPHYR_SCA_VARIANT' is not set. "
|
|
"Please set 'ZEPHYR_SCA_VARIANT' to desired tool."
|
|
)
|
|
endif()
|
|
|
|
if(NOT DEFINED ZEPHYR_SCA_VARIANT)
|
|
return()
|
|
endif()
|
|
|
|
foreach(root ${SCA_ROOT})
|
|
if(EXISTS ${root}/cmake/sca/${ZEPHYR_SCA_VARIANT}/sca.cmake)
|
|
include(${root}/cmake/sca/${ZEPHYR_SCA_VARIANT}/sca.cmake)
|
|
return()
|
|
endif()
|
|
endforeach()
|
|
|
|
message(FATAL_ERROR "ZEPHYR_SCA_VARIANT set to '${ZEPHYR_SCA_VARIANT}' but no "
|
|
"implementation for '${ZEPHYR_SCA_VARIANT}' found. "
|
|
"SCA_ROOTs searched: ${SCA_ROOT}"
|
|
)
|