summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorYuval Lifshitz <yuvalif@yahoo.com>2019-11-11 11:19:34 +0100
committerYuval Lifshitz <yuvalif@yahoo.com>2019-11-18 18:43:14 +0100
commitc876a0d81707d4344d95631b63b2826c266cf83e (patch)
tree87310b89fea53a3eb75ae5d5f89ef6ca38d4bb11 /cmake
parentMerge pull request #31571 from rhcs-dashboard/42775-fix-typo (diff)
downloadceph-c876a0d81707d4344d95631b63b2826c266cf83e.tar.xz
ceph-c876a0d81707d4344d95631b63b2826c266cf83e.zip
cmake: add cppcheck and iwyu static analysis targets
Signed-off-by: Yuval Lifshitz <yuvalif@yahoo.com>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/modules/FindCppCheck.cmake30
-rw-r--r--cmake/modules/FindIWYU.cmake27
2 files changed, 57 insertions, 0 deletions
diff --git a/cmake/modules/FindCppCheck.cmake b/cmake/modules/FindCppCheck.cmake
new file mode 100644
index 00000000000..5dabfa66aad
--- /dev/null
+++ b/cmake/modules/FindCppCheck.cmake
@@ -0,0 +1,30 @@
+unset(CPPCHECK_BIN CACHE)
+find_program(CPPCHECK_BIN cppcheck)
+
+if(CPPCHECK_BIN)
+ find_file(PROJECT_FILE compile_commands.json PATH .)
+ if(NOT PROJECT_FILE)
+ message(STATUS "Found cppcheck, but no \"compile_commands.json\" file. To enable cppcheck, set CMAKE_EXPORT_COMPILE_COMMANDS to \"ON\" and build again.")
+ return()
+ endif()
+
+ include(ProcessorCount)
+ ProcessorCount(N)
+
+ execute_process(COMMAND cppcheck --version OUTPUT_VARIABLE CPPCHECK_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
+ separate_arguments(CPPCHECK_VERSION)
+ list(GET CPPCHECK_VERSION 1 VERSION_NUMBER)
+ if(VERSION_NUMBER VERSION_GREATER_EQUAL 1.88)
+ set(CPP_STD_VERSION "c++17")
+ else()
+ set(CPP_STD_VERSION "c++14")
+ endif()
+
+ add_custom_target(cppcheck
+ COMMAND ${CPPCHECK_BIN} --verbose -j${N} --std=${CPP_STD_VERSION} --inline-suppr --project=${PROJECT_FILE} 2> cppcheck.txt | grep done
+ )
+
+ message(STATUS "Found cppcheck. To perform static analysis using cppcheck, use: \"make cppcheck\". Results will be stored in \"cppcheck.txt\".")
+else()
+ message(STATUS "Could not find cppcheck. To perform static analysis using cppcheck install the tool (e.g. \"yum install cppcheck\").")
+endif()
diff --git a/cmake/modules/FindIWYU.cmake b/cmake/modules/FindIWYU.cmake
new file mode 100644
index 00000000000..adbdbb25a95
--- /dev/null
+++ b/cmake/modules/FindIWYU.cmake
@@ -0,0 +1,27 @@
+unset(IWYU_BIN CACHE)
+find_program(IWYU_BIN iwyu_tool.py)
+
+if(IWYU_BIN)
+ find_file(PROJECT_FILE compile_commands.json PATH .)
+ if(NOT PROJECT_FILE)
+ message(STATUS "Found IWYU, but no \"compile_commands.json\" file. To enable IWYU, set CMAKE_EXPORT_COMPILE_COMMANDS to \"ON\" and build again.")
+ return()
+ endif()
+
+ if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+ message(STATUS "Found IWYU, but clang++ is not used used. To enable IWYU, set CMAKE_C_COMPILER to \"clang\" and CMAKE_CXX_COMPILER to \"clang++\" and build again.")
+ return()
+ endif()
+
+ include(ProcessorCount)
+ ProcessorCount(N)
+
+ add_custom_target(iwyu
+ COMMAND echo "IWYU is analyzing includes - this may take a while..."
+ COMMAND ${IWYU_BIN} -j${N} -p . > iwyu.txt
+ )
+
+ message(STATUS "Found IWYU. To perform header analysis using IWYU, use: \"make iwyu\". Results will be stored in \"iwyu.txt\".")
+else()
+ message(STATUS "Could not find IWYU. To perform header analysis using IWYU install the tool (e.g. \"yum install iwyu\").")
+endif()