~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to cmake/modules/Findcppcheck.cmake

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2013-12-20 11:30:16 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131220113016-wre5g9bteeheq6he
Tags: 1.11.1-3
* remove version number from libbost development package names;
* ensure that AUTHORS is correctly shipped in all packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 we have a custom path, look there first.
 
43
if(CPPCHECK_ROOT_DIR)
 
44
        find_program(CPPCHECK_EXECUTABLE
 
45
                NAMES
 
46
                cppcheck
 
47
                cli
 
48
                PATHS
 
49
                "${CPPCHECK_ROOT_DIR}"
 
50
                PATH_SUFFIXES
 
51
                cli
 
52
                NO_DEFAULT_PATH)
 
53
endif()
 
54
 
 
55
find_program(CPPCHECK_EXECUTABLE NAMES cppcheck)
 
56
 
 
57
# Restore original setting for appbundle finding
 
58
set(CMAKE_FIND_APPBUNDLE ${_oldappbundlesetting})
 
59
 
 
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")
 
64
 
 
65
        # Check for the two types of command line arguments by just trying them
 
66
        execute_process(COMMAND
 
67
                "${CPPCHECK_EXECUTABLE}"
 
68
                "--enable=style"
 
69
                "--quiet"
 
70
                "${_cppcheckdummyfile}"
 
71
                RESULT_VARIABLE
 
72
                _cppcheck_new_result
 
73
                OUTPUT_QUIET
 
74
                ERROR_QUIET)
 
75
        execute_process(COMMAND
 
76
                "${CPPCHECK_EXECUTABLE}"
 
77
                "--style"
 
78
                "--quiet"
 
79
                "${_cppcheckdummyfile}"
 
80
                RESULT_VARIABLE
 
81
                _cppcheck_old_result
 
82
                OUTPUT_QUIET
 
83
                ERROR_QUIET)
 
84
        if("${_cppcheck_new_result}" EQUAL 0)
 
85
                # New arguments
 
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")
 
91
                if(MSVC)
 
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: ")
 
99
                else()
 
100
                        message(STATUS
 
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: ")
 
105
                endif()
 
106
        elseif("${_cppcheck_old_result}" EQUAL 0)
 
107
                # Old arguments
 
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[)]")
 
115
        else()
 
116
                # No idea - some other issue must be getting in the way
 
117
                message(STATUS
 
118
                        "WARNING: Can't detect whether CPPCHECK wants new or old-style arguments!")
 
119
        endif()
 
120
 
 
121
 
 
122
endif()
 
123
 
 
124
set(CPPCHECK_ALL
 
125
        "${CPPCHECK_EXECUTABLE} ${CPPCHECK_POSSIBLEERROR_ARG} ${CPPCHECK_UNUSEDFUNC_ARG} ${CPPCHECK_STYLE_ARG} ${CPPCHECK_QUIET_ARG} ${CPPCHECK_INCLUDEPATH_ARG} some/include/path")
 
126
 
 
127
include(FindPackageHandleStandardArgs)
 
128
find_package_handle_standard_args(cppcheck
 
129
        DEFAULT_MSG
 
130
        CPPCHECK_ALL
 
131
        CPPCHECK_EXECUTABLE
 
132
        CPPCHECK_POSSIBLEERROR_ARG
 
133
        CPPCHECK_UNUSEDFUNC_ARG
 
134
        CPPCHECK_STYLE_ARG
 
135
        CPPCHECK_INCLUDEPATH_ARG
 
136
        CPPCHECK_QUIET_ARG)
 
137
 
 
138
if(CPPCHECK_FOUND OR CPPCHECK_MARK_AS_ADVANCED)
 
139
        mark_as_advanced(CPPCHECK_ROOT_DIR)
 
140
endif()
 
141
 
 
142
mark_as_advanced(CPPCHECK_EXECUTABLE)