aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--cmake/scripts/common/StaticAnalysis.cmake41
2 files changed, 43 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 447d08f589..534e8e29f0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -416,6 +416,8 @@ if(CORE_HOST_IS_TARGET AND ENABLE_TESTING)
-DCMAKE_BINARY_DIR=${CMAKE_BINARY_DIR})
set_target_properties(check-commits PROPERTIES FOLDER "Build Utilities")
+ include(${CMAKE_SOURCE_DIR}/cmake/scripts/common/StaticAnalysis.cmake)
+
# code coverage
if(CMAKE_BUILD_TYPE STREQUAL Coverage)
if(EXISTS ${CMAKE_SOURCE_DIR}/cmake/scripts/${CORE_SYSTEM_NAME}/CodeCoverage.cmake)
diff --git a/cmake/scripts/common/StaticAnalysis.cmake b/cmake/scripts/common/StaticAnalysis.cmake
new file mode 100644
index 0000000000..c776961ac8
--- /dev/null
+++ b/cmake/scripts/common/StaticAnalysis.cmake
@@ -0,0 +1,41 @@
+include(ProcessorCount)
+ProcessorCount(CPU_CORES)
+
+find_program(CPPCHECK_EXECUTABLE cppcheck)
+
+if(CPPCHECK_EXECUTABLE)
+ add_custom_target(analyze-cppcheck
+ DEPENDS ${APP_NAME_LC} ${APP_NAME_LC}-test
+ COMMAND ${CPPCHECK_EXECUTABLE}
+ --template="${CMAKE_SOURCE_DIR}/xbmc/\{file\}\(\{line\}\)\: \{severity\} \(\{id\}\): \{message\}"
+ -j${CPU_CORES}
+ --project=${CMAKE_BINARY_DIR}/compile_commands.json
+ --std=c++${CMAKE_CXX_STANDARD}
+ --enable=all
+ --verbose
+ --quiet
+ --xml
+ --xml-version=2
+ --language=c++
+ --output-file=${CMAKE_BINARY_DIR}/cppcheck-result.xml
+ xbmc
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ COMMENT "Static code analysis using cppcheck")
+endif()
+
+find_program(CLANG_TIDY_EXECUTABLE NAMES clang-tidy)
+find_program(RUN_CLANG_TIDY NAMES run-clang-tidy.py run-clang-tidy
+ PATHS /usr/share/clang /usr/bin)
+
+if(RUN_CLANG_TIDY AND CLANG_TIDY_EXECUTABLE)
+ add_custom_target(analyze-clang-tidy
+ DEPENDS ${APP_NAME_LC} ${APP_NAME_LC}-test
+ COMMAND ${RUN_CLANG_TIDY}
+ -j${CPU_CORES}
+ -clang-tidy-binary=${CLANG_TIDY_EXECUTABLE}
+ -p=${CMAKE_BINARY_DIR}
+ -header-filter='${CMAKE_BINARY_DIR}/.*/include/.*'
+ | tee ${CMAKE_BINARY_DIR}/clangtidy-result.xml
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ COMMENT "Static code analysis using clang-tidy")
+endif()