summaryrefslogtreecommitdiffstats
path: root/cmake/modules/FindCppcheck.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/modules/FindCppcheck.cmake')
-rw-r--r--cmake/modules/FindCppcheck.cmake32
1 files changed, 32 insertions, 0 deletions
diff --git a/cmake/modules/FindCppcheck.cmake b/cmake/modules/FindCppcheck.cmake
new file mode 100644
index 0000000..d3b6e84
--- /dev/null
+++ b/cmake/modules/FindCppcheck.cmake
@@ -0,0 +1,32 @@
1#.rst:
2# FindCppcheck
3# ------------
4# Finds cppcheck and sets it up to run along with the compiler for C and CXX.
5
6find_program(CPPCHECK_EXECUTABLE cppcheck)
7
8if(CPPCHECK_EXECUTABLE)
9 execute_process(COMMAND "${CPPCHECK_EXECUTABLE}" --version
10 OUTPUT_VARIABLE CPPCHECK_VERSION
11 OUTPUT_STRIP_TRAILING_WHITESPACE)
12 string(REGEX REPLACE "Cppcheck (.*)" "\\1" CPPCHECK_VERSION "${CPPCHECK_VERSION}")
13endif()
14
15include(FindPackageHandleStandardArgs)
16find_package_handle_standard_args(Cppcheck REQUIRED_VARS CPPCHECK_EXECUTABLE
17 VERSION_VAR CPPCHECK_VERSION)
18
19if(CPPCHECK_FOUND)
20 # CMake < 3.16 treats Objective-C (OBJC) files as C files and Objective-C++ (OBJCXX) files as C++ files,
21 # but cppcheck doesn't support Objective-C and Objective-C++.
22 # CMake >= 3.16 added support for Objective-C and Objective-C++ language,
23 # but doesn't support OBJC and OBJCXX for <LANG>_CLANG_TIDY.
24 file(WRITE "${CMAKE_BINARY_DIR}/cppcheck" "case \"$@\" in *.m|*.mm) exit 0; esac\nexec \"${CPPCHECK_EXECUTABLE}\" --quiet --relative-paths=\"${CMAKE_SOURCE_DIR}\" \"$@\"\n")
25 execute_process(COMMAND chmod +x "${CMAKE_BINARY_DIR}/cppcheck")
26
27 # Supports Unix Makefiles and Ninja
28 set(CMAKE_C_CPPCHECK "${CMAKE_BINARY_DIR}/cppcheck" PARENT_SCOPE)
29 set(CMAKE_CXX_CPPCHECK "${CMAKE_BINARY_DIR}/cppcheck" PARENT_SCOPE)
30endif()
31
32mark_as_advanced(CPPCHECK_EXECUTABLE)