feat(tools): add support for clang-tidy
This patch integrates clang-tidy into the project. Custom targets for
clang-tidy are added, which run clang-tidy on either the codebase or
pending commits.
A selection of checks has been enabled, some have their warnings
promoted to errors. The enabled checks, and the checks which have
warnings promoted to errors, are configured in the .clang-tidy file.
Signed-off-by: Chuyue Luo <Chuyue.Luo@arm.com>
Change-Id: Idba6d6b3e4438f524ac68307b1e463b9aec958e3
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 40e887a..905db56 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -191,3 +191,28 @@
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
COMMAND ${CMAKE_COMMAND} -DCHECKINCLUDES_PATCH=1 -P ${CMAKE_SOURCE_DIR}/tools/checkincludes/CheckIncludes.cmake
)
+
+#
+# Rules for running clang-tidy checks
+#
+# Pass through the value of RMM_TOOLCHAIN as this must be verified before
+# clang-tidy can be run.
+#
+# Also pass through the build directory as this cannot be accessed when the
+# clang-tidy target is built.
+#
+add_custom_target(clang-tidy-codebase
+ WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
+ COMMAND ${CMAKE_COMMAND} -DCLANG-TIDY_CODEBASE=1
+ -DRMM_TOOLCHAIN=${RMM_TOOLCHAIN}
+ -DBUILD_DIR=${CMAKE_BINARY_DIR}
+ -P ${CMAKE_SOURCE_DIR}/tools/clang-tidy/clang-tidy.cmake
+ )
+
+add_custom_target(clang-tidy-patch
+ WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
+ COMMAND ${CMAKE_COMMAND} -DCLANG-TIDY_PATCH=1
+ -DRMM_TOOLCHAIN=${RMM_TOOLCHAIN}
+ -DBUILD_DIR=${CMAKE_BINARY_DIR}
+ -P ${CMAKE_SOURCE_DIR}/tools/clang-tidy/clang-tidy.cmake
+ )