-
Romain Thomas committed 7 years ago
Showing first 76 files as there are too many
-
-
-
1 + Authors: 2 + 3 + Romain Thomas <[email protected]> 4 + -
-
-
-
1 + # - Run cppcheck on c++ source files as a custom target and a test 2 + # 3 + # include(CppcheckTargets) 4 + # add_cppcheck(<target-name> [UNUSED_FUNCTIONS] [STYLE] [POSSIBLE_ERROR] [FORCE] [FAIL_ON_WARNINGS]) - 5 + # Create a target to check a target's sources with cppcheck and the indicated options 6 + # add_cppcheck_sources(<target-name> [UNUSED_FUNCTIONS] [STYLE] [POSSIBLE_ERROR] [FORCE] [FAIL_ON_WARNINGS]) - 7 + # Create a target to check standalone sources with cppcheck and the indicated options 8 + # 9 + # Requires these CMake modules: 10 + # Findcppcheck 11 + # 12 + # Requires CMake 2.6 or newer (uses the 'function' command) 13 + # 14 + # Original Author: 15 + # 2009-2010 Ryan Pavlik <[email protected]> <[email protected]> 16 + # http://academic.cleardefinition.com 17 + # Iowa State University HCI Graduate Program/VRAC 18 + # 19 + # Copyright Iowa State University 2009-2010. 20 + # Distributed under the Boost Software License, Version 1.0. 21 + # (See accompanying file LICENSE_1_0.txt or copy at 22 + # http://www.boost.org/LICENSE_1_0.txt) 23 + 24 + if(__add_cppcheck) 25 + return() 26 + endif() 27 + set(__add_cppcheck YES) 28 + 29 + if(NOT CPPCHECK_FOUND) 30 + find_package(cppcheck QUIET) 31 + endif() 32 + 33 + if(CPPCHECK_FOUND) 34 + if(NOT TARGET all_cppcheck) 35 + add_custom_target(all_cppcheck) 36 + set_target_properties(all_cppcheck PROPERTIES EXCLUDE_FROM_ALL TRUE) 37 + endif() 38 + endif() 39 + 40 + function(add_cppcheck_sources _targetname) 41 + if(CPPCHECK_FOUND) 42 + set(_cppcheck_args) 43 + set(_input ${ARGN}) 44 + list(FIND _input UNUSED_FUNCTIONS _unused_func) 45 + if("${_unused_func}" GREATER "-1") 46 + list(APPEND _cppcheck_args ${CPPCHECK_UNUSEDFUNC_ARG}) 47 + list(REMOVE_AT _input ${_unused_func}) 48 + endif() 49 + 50 + list(FIND _input STYLE _style) 51 + if("${_style}" GREATER "-1") 52 + list(APPEND _cppcheck_args ${CPPCHECK_STYLE_ARG}) 53 + list(REMOVE_AT _input ${_style}) 54 + endif() 55 + 56 + list(FIND _input POSSIBLE_ERROR _poss_err) 57 + if("${_poss_err}" GREATER "-1") 58 + list(APPEND _cppcheck_args ${CPPCHECK_POSSIBLEERROR_ARG}) 59 + list(REMOVE_AT _input ${_poss_err}) 60 + endif() 61 + 62 + list(FIND _input FORCE _force) 63 + if("${_force}" GREATER "-1") 64 + list(APPEND _cppcheck_args "--force") 65 + list(REMOVE_AT _input ${_force}) 66 + endif() 67 + 68 + list(FIND _input FAIL_ON_WARNINGS _fail_on_warn) 69 + if("${_fail_on_warn}" GREATER "-1") 70 + list(APPEND 71 + CPPCHECK_FAIL_REGULAR_EXPRESSION 72 + ${CPPCHECK_WARN_REGULAR_EXPRESSION}) 73 + list(REMOVE_AT _input ${_fail_on_warn}) 74 + endif() 75 + 76 + set(_files) 77 + foreach(_source ${_input}) 78 + get_source_file_property(_cppcheck_loc "${_source}" LOCATION) 79 + if(_cppcheck_loc) 80 + # This file has a source file property, carry on. 81 + get_source_file_property(_cppcheck_lang "${_source}" LANGUAGE) 82 + if("${_cppcheck_lang}" MATCHES "CXX") 83 + list(APPEND _files "${_cppcheck_loc}") 84 + endif() 85 + else() 86 + # This file doesn't have source file properties - figure it out. 87 + get_filename_component(_cppcheck_loc "${_source}" ABSOLUTE) 88 + if(EXISTS "${_cppcheck_loc}") 89 + list(APPEND _files "${_cppcheck_loc}") 90 + else() 91 + message(FATAL_ERROR 92 + "Adding CPPCHECK for file target ${_targetname}: " 93 + "File ${_source} does not exist or needs a corrected path location " 94 + "since we think its absolute path is ${_cppcheck_loc}") 95 + endif() 96 + endif() 97 + endforeach() 98 + 99 + if("1.${CMAKE_VERSION}" VERSION_LESS "1.2.8.0") 100 + # Older than CMake 2.8.0 101 + add_test(${_targetname}_cppcheck_test 102 + "${CPPCHECK_EXECUTABLE}" 103 + ${CPPCHECK_TEMPLATE_ARG} 104 + ${_cppcheck_args} "--inline-suppr" 105 + ${_files}) 106 + else() 107 + # CMake 2.8.0 and newer 108 + add_test(NAME 109 + ${_targetname}_cppcheck_test 110 + COMMAND 111 + "${CPPCHECK_EXECUTABLE}" 112 + ${CPPCHECK_TEMPLATE_ARG} 113 + ${_cppcheck_args} "--inline-suppr" 114 + ${_files}) 115 + endif() 116 + 117 + set_tests_properties(${_targetname}_cppcheck_test 118 + PROPERTIES 119 + FAIL_REGULAR_EXPRESSION 120 + "${CPPCHECK_FAIL_REGULAR_EXPRESSION}") 121 + 122 + add_custom_command(TARGET 123 + all_cppcheck 124 + PRE_BUILD 125 + COMMAND 126 + ${CPPCHECK_EXECUTABLE} 127 + ${CPPCHECK_QUIET_ARG} 128 + ${CPPCHECK_TEMPLATE_ARG} 129 + ${_cppcheck_args} "--inline-suppr" 130 + ${_files} 131 + WORKING_DIRECTORY 132 + "${CMAKE_CURRENT_SOURCE_DIR}" 133 + COMMENT 134 + "${_targetname}_cppcheck: Running cppcheck on target ${_targetname}..." 135 + VERBATIM) 136 + endif() 137 + endfunction() 138 + 139 + function(add_cppcheck _name) 140 + if(NOT TARGET ${_name}) 141 + message(FATAL_ERROR 142 + "add_cppcheck given a target name that does not exist: '${_name}' !") 143 + endif() 144 + if(CPPCHECK_FOUND) 145 + set(_cppcheck_args CACHE STRING "${_cppcheck_args} ") 146 + #set(_cppcheck_args "${_cppcheck_args} ") 147 + list(FIND ARGN UNUSED_FUNCTIONS _unused_func) 148 + if("${_unused_func}" GREATER "-1") 149 + list(APPEND _cppcheck_args ${CPPCHECK_UNUSEDFUNC_ARG}) 150 + endif() 151 + 152 + list(FIND ARGN STYLE _style) 153 + if("${_style}" GREATER "-1") 154 + list(APPEND _cppcheck_args ${CPPCHECK_STYLE_ARG}) 155 + endif() 156 + 157 + list(FIND ARGN POSSIBLE_ERROR _poss_err) 158 + if("${_poss_err}" GREATER "-1") 159 + list(APPEND _cppcheck_args ${CPPCHECK_POSSIBLEERROR_ARG}) 160 + endif() 161 + 162 + list(FIND ARGN FORCE _force) 163 + if("${_force}" GREATER "-1") 164 + list(APPEND _cppcheck_args "--force") 165 + endif() 166 + 167 + list(FIND _input FAIL_ON_WARNINGS _fail_on_warn) 168 + if("${_fail_on_warn}" GREATER "-1") 169 + list(APPEND 170 + CPPCHECK_FAIL_REGULAR_EXPRESSION 171 + ${CPPCHECK_WARN_REGULAR_EXPRESSION}) 172 + list(REMOVE_AT _input ${_unused_func}) 173 + endif() 174 + 175 + get_target_property(_cppcheck_includes "${_name}" INCLUDE_DIRECTORIES) 176 + set(_includes) 177 + foreach(_include ${_cppcheck_includes}) 178 + list(APPEND _includes "-I${_include}") 179 + endforeach() 180 + 181 + get_target_property(_cppcheck_sources "${_name}" SOURCES) 182 + set(_files) 183 + foreach(_source ${_cppcheck_sources}) 184 + get_source_file_property(_cppcheck_lang "${_source}" LANGUAGE) 185 + get_source_file_property(_cppcheck_loc "${_source}" LOCATION) 186 + if("${_cppcheck_lang}" MATCHES "CXX") 187 + list(APPEND _files "${_cppcheck_loc}") 188 + endif() 189 + endforeach() 190 + 191 + if("1.${CMAKE_VERSION}" VERSION_LESS "1.2.8.0") 192 + # Older than CMake 2.8.0 193 + add_test(${_name}_cppcheck_test 194 + "${CPPCHECK_EXECUTABLE}" 195 + ${CPPCHECK_TEMPLATE_ARG} 196 + ${_cppcheck_args} "--inline-suppr" 197 + ${_files}) 198 + else() 199 + # CMake 2.8.0 and newer 200 + add_test(NAME 201 + ${_name}_cppcheck_test 202 + COMMAND 203 + "${CPPCHECK_EXECUTABLE}" 204 + ${CPPCHECK_TEMPLATE_ARG} 205 + ${_cppcheck_args} "--inline-suppr" 206 + ${_files}) 207 + endif() 208 + 209 + set_tests_properties(${_name}_cppcheck_test 210 + PROPERTIES 211 + FAIL_REGULAR_EXPRESSION 212 + "${CPPCHECK_FAIL_REGULAR_EXPRESSION}") 213 + MESSAGE(STATUS "CPPCHECKargs: ${_cppcheck_args}") 214 + add_custom_command(TARGET 215 + all_cppcheck 216 + PRE_BUILD 217 + COMMAND 218 + ${CPPCHECK_EXECUTABLE} 219 + ${CPPCHECK_QUIET_ARG} 220 + ${CPPCHECK_TEMPLATE_ARG} 221 + ${_cppcheck_args} "--inline-suppr" 222 + ${_includes} 223 + ${_files} 224 + WORKING_DIRECTORY 225 + "${CMAKE_CURRENT_SOURCE_DIR}" 226 + COMMENT 227 + "${_name}_cppcheck: Running cppcheck on target ${_name}..." 228 + VERBATIM) 229 + endif() 230 + 231 + endfunction() 232 + -
-
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 <[email protected]> <[email protected]> 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) 168 + -
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 + * <[email protected]> 8 + * http://academic.cleardefinition.com/ 9 + * 10 + */ 11 + 12 + 13 + 14 + int main(int argc, char* argv[]) { 15 + return 0; 16 + } 17 + -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-