1
# - try to find cppcheck tool
6
# Non-cache variables you might use in your CMakeLists.txt:
8
# CPPCHECK_POSSIBLEERROR_ARG
9
# CPPCHECK_UNUSEDFUNC_ARG
12
# CPPCHECK_INCLUDEPATH_ARG
13
# CPPCHECK_FAIL_REGULAR_EXPRESSION
14
# CPPCHECK_WARN_REGULAR_EXPRESSION
15
# CPPCHECK_MARK_AS_ADVANCED - whether to mark our vars as advanced even
16
# if we don't find this program.
18
# Requires these CMake modules:
19
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
22
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
23
# http://academic.cleardefinition.com
24
# Iowa State University HCI Graduate Program/VRAC
26
# Copyright Iowa State University 2009-2010.
27
# Distributed under the Boost Software License, Version 1.0.
28
# (See accompanying file LICENSE_1_0.txt or copy at
29
# http://www.boost.org/LICENSE_1_0.txt)
31
file(TO_CMAKE_PATH "${CPPCHECK_ROOT_DIR}" CPPCHECK_ROOT_DIR)
33
"${CPPCHECK_ROOT_DIR}"
36
"Path to search for cppcheck")
38
# cppcheck app bundles on Mac OS X are GUI, we want command line only
39
set(_oldappbundlesetting ${CMAKE_FIND_APPBUNDLE})
40
set(CMAKE_FIND_APPBUNDLE NEVER)
42
# If we have a custom path, look there first.
44
find_program(CPPCHECK_EXECUTABLE
49
"${CPPCHECK_ROOT_DIR}"
55
find_program(CPPCHECK_EXECUTABLE NAMES cppcheck)
57
# Restore original setting for appbundle finding
58
set(CMAKE_FIND_APPBUNDLE ${_oldappbundlesetting})
60
if(CPPCHECK_EXECUTABLE)
61
# Find out where our test file is
62
get_filename_component(_cppcheckmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
63
set(_cppcheckdummyfile "${_cppcheckmoddir}/Findcppcheck.cpp")
65
# Check for the two types of command line arguments by just trying them
66
execute_process(COMMAND
67
"${CPPCHECK_EXECUTABLE}"
70
"${_cppcheckdummyfile}"
75
execute_process(COMMAND
76
"${CPPCHECK_EXECUTABLE}"
79
"${_cppcheckdummyfile}"
84
if("${_cppcheck_new_result}" EQUAL 0)
86
set(CPPCHECK_UNUSEDFUNC_ARG "--enable=unusedFunctions")
87
set(CPPCHECK_POSSIBLEERROR_ARG "--enable=possibleError")
88
set(CPPCHECK_STYLE_ARG "--enable=style")
89
set(CPPCHECK_QUIET_ARG "--quiet")
90
set(CPPCHECK_INCLUDEPATH_ARG "-I")
92
set(CPPCHECK_TEMPLATE_ARG --template vs)
93
set(CPPCHECK_FAIL_REGULAR_EXPRESSION "[(]error[)]")
94
set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]")
95
elseif(CMAKE_COMPILER_IS_GNUCXX)
96
set(CPPCHECK_TEMPLATE_ARG --template gcc)
97
set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ")
98
set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ")
101
"Warning: FindCppcheck doesn't know how to format error messages for your compiler!")
102
set(CPPCHECK_TEMPLATE_ARG --template gcc)
103
set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ")
104
set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ")
106
elseif("${_cppcheck_old_result}" EQUAL 0)
108
set(CPPCHECK_UNUSEDFUNC_ARG "--unused-functions")
109
set(CPPCHECK_POSSIBLEERROR_ARG "--all")
110
set(CPPCHECK_STYLE_ARG "--style")
111
set(CPPCHECK_QUIET_ARG "--quiet")
112
set(CPPCHECK_INCLUDEPATH_ARG "-I")
113
set(CPPCHECK_FAIL_REGULAR_EXPRESSION "error:")
114
set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]")
116
# No idea - some other issue must be getting in the way
118
"WARNING: Can't detect whether CPPCHECK wants new or old-style arguments!")
125
"${CPPCHECK_EXECUTABLE} ${CPPCHECK_POSSIBLEERROR_ARG} ${CPPCHECK_UNUSEDFUNC_ARG} ${CPPCHECK_STYLE_ARG} ${CPPCHECK_QUIET_ARG} ${CPPCHECK_INCLUDEPATH_ARG} some/include/path")
127
include(FindPackageHandleStandardArgs)
128
find_package_handle_standard_args(cppcheck
132
CPPCHECK_POSSIBLEERROR_ARG
133
CPPCHECK_UNUSEDFUNC_ARG
135
CPPCHECK_INCLUDEPATH_ARG
138
if(CPPCHECK_FOUND OR CPPCHECK_MARK_AS_ADVANCED)
139
mark_as_advanced(CPPCHECK_ROOT_DIR)
142
mark_as_advanced(CPPCHECK_EXECUTABLE)