##// END OF EJS Templates
Ajout de cppcheck
perrinel -
r3:a8b5bae69326
parent child
Show More
@@ -0,0 +1,167
1 # - try to find cppcheck tool
2 #
3 # Cache Variables:
4 # CPPCHECK_EXECUTABLE
5 #
6 # Non-cache variables you might use in your CMakeLists.txt:
7 # CPPCHECK_FOUND
8 # CPPCHECK_POSSIBLEERROR_ARG
9 # CPPCHECK_UNUSEDFUNC_ARG
10 # CPPCHECK_STYLE_ARG
11 # CPPCHECK_QUIET_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.
17 #
18 # Requires these CMake modules:
19 # FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
20 #
21 # Original Author:
22 # 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
23 # http://academic.cleardefinition.com
24 # Iowa State University HCI Graduate Program/VRAC
25 #
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)
30
31 file(TO_CMAKE_PATH "${CPPCHECK_ROOT_DIR}" CPPCHECK_ROOT_DIR)
32 set(CPPCHECK_ROOT_DIR
33 "${CPPCHECK_ROOT_DIR}"
34 CACHE
35 PATH
36 "Path to search for cppcheck")
37
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)
41
42 if(CPPCHECK_EXECUTABLE AND NOT EXISTS "${CPPCHECK_EXECUTABLE}")
43 set(CPPCHECK_EXECUTABLE "notfound" CACHE PATH FORCE "")
44 endif()
45
46 # If we have a custom path, look there first.
47 if(CPPCHECK_ROOT_DIR)
48 find_program(CPPCHECK_EXECUTABLE
49 NAMES
50 cppcheck
51 cli
52 PATHS
53 "${CPPCHECK_ROOT_DIR}"
54 PATH_SUFFIXES
55 cli
56 NO_DEFAULT_PATH)
57 endif()
58
59 find_program(CPPCHECK_EXECUTABLE NAMES cppcheck)
60
61 # Restore original setting for appbundle finding
62 set(CMAKE_FIND_APPBUNDLE ${_oldappbundlesetting})
63
64 # Find out where our test file is
65 get_filename_component(_cppcheckmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
66 set(_cppcheckdummyfile "${_cppcheckmoddir}/Findcppcheck.cpp")
67 if(NOT EXISTS "${_cppcheckdummyfile}")
68 message(FATAL_ERROR
69 "Missing file ${_cppcheckdummyfile} - should be alongside Findcppcheck.cmake, can be found at https://github.com/rpavlik/cmake-modules")
70 endif()
71
72 function(_cppcheck_test_arg _resultvar _arg)
73 if(NOT CPPCHECK_EXECUTABLE)
74 set(${_resultvar} NO)
75 return()
76 endif()
77 execute_process(COMMAND
78 "${CPPCHECK_EXECUTABLE}"
79 "${_arg}"
80 "--quiet"
81 "${_cppcheckdummyfile}"
82 RESULT_VARIABLE
83 _cppcheck_result
84 OUTPUT_QUIET
85 ERROR_QUIET)
86 if("${_cppcheck_result}" EQUAL 0)
87 set(${_resultvar} YES PARENT_SCOPE)
88 else()
89 set(${_resultvar} NO PARENT_SCOPE)
90 endif()
91 endfunction()
92
93 function(_cppcheck_set_arg_var _argvar _arg)
94 if("${${_argvar}}" STREQUAL "")
95 _cppcheck_test_arg(_cppcheck_arg "${_arg}")
96 if(_cppcheck_arg)
97 set(${_argvar} "${_arg}" PARENT_SCOPE)
98 endif()
99 endif()
100 endfunction()
101
102 if(CPPCHECK_EXECUTABLE)
103
104 # Check for the two types of command line arguments by just trying them
105 _cppcheck_set_arg_var(CPPCHECK_STYLE_ARG "--enable=style")
106 _cppcheck_set_arg_var(CPPCHECK_STYLE_ARG "--style")
107 if("${CPPCHECK_STYLE_ARG}" STREQUAL "--enable=style")
108
109 _cppcheck_set_arg_var(CPPCHECK_UNUSEDFUNC_ARG
110 "--enable=unusedFunction")
111 _cppcheck_set_arg_var(CPPCHECK_INFORMATION_ARG "--enable=information")
112 _cppcheck_set_arg_var(CPPCHECK_MISSINGINCLUDE_ARG
113 "--enable=missingInclude")
114 _cppcheck_set_arg_var(CPPCHECK_POSIX_ARG "--enable=posix")
115 _cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG
116 "--enable=possibleError")
117 _cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG "--enable=all")
118
119 if(MSVC)
120 set(CPPCHECK_TEMPLATE_ARG --template vs)
121 set(CPPCHECK_FAIL_REGULAR_EXPRESSION "[(]error[)]")
122 set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]")
123 elseif(CMAKE_COMPILER_IS_GNUCXX)
124 set(CPPCHECK_TEMPLATE_ARG --template gcc)
125 set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ")
126 set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ")
127 else()
128 set(CPPCHECK_TEMPLATE_ARG --template gcc)
129 set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ")
130 set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ")
131 endif()
132 elseif("${CPPCHECK_STYLE_ARG}" STREQUAL "--style")
133 # Old arguments
134 _cppcheck_set_arg_var(CPPCHECK_UNUSEDFUNC_ARG "--unused-functions")
135 _cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG "--all")
136 set(CPPCHECK_FAIL_REGULAR_EXPRESSION "error:")
137 set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]")
138 else()
139 # No idea - some other issue must be getting in the way
140 message(STATUS
141 "WARNING: Can't detect whether CPPCHECK wants new or old-style arguments!")
142 endif()
143
144 set(CPPCHECK_QUIET_ARG "--quiet")
145 set(CPPCHECK_INCLUDEPATH_ARG "-I")
146
147 endif()
148
149 set(CPPCHECK_ALL
150 "${CPPCHECK_EXECUTABLE} ${CPPCHECK_POSSIBLEERROR_ARG} ${CPPCHECK_UNUSEDFUNC_ARG} ${CPPCHECK_STYLE_ARG} ${CPPCHECK_QUIET_ARG} ${CPPCHECK_INCLUDEPATH_ARG} some/include/path")
151
152 include(FindPackageHandleStandardArgs)
153 find_package_handle_standard_args(cppcheck
154 DEFAULT_MSG
155 CPPCHECK_ALL
156 CPPCHECK_EXECUTABLE
157 CPPCHECK_POSSIBLEERROR_ARG
158 CPPCHECK_UNUSEDFUNC_ARG
159 CPPCHECK_STYLE_ARG
160 CPPCHECK_INCLUDEPATH_ARG
161 CPPCHECK_QUIET_ARG)
162
163 if(CPPCHECK_FOUND OR CPPCHECK_MARK_AS_ADVANCED)
164 mark_as_advanced(CPPCHECK_ROOT_DIR)
165 endif()
166
167 mark_as_advanced(CPPCHECK_EXECUTABLE)
@@ -0,0 +1,16
1 /**
2 * \file Findcppcheck.cpp
3 * \brief Dummy C++ source file used by CMake module Findcppcheck.cmake
4 *
5 * \author
6 * Ryan Pavlik, 2009-2010
7 * <rpavlik@iastate.edu>
8 * http://academic.cleardefinition.com/
9 *
10 */
11
12
13
14 int main(int argc, char* argv[]) {
15 return 0;
16 }
General Comments 0
You need to be logged in to leave comments. Login now