@@ -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 | } |
@@ -0,0 +1,116 | |||
|
1 | # - Run cppcheck on c++ source files as a custom target and a test | |
|
2 | # | |
|
3 | # add_test_cppcheck(<target-name> [UNUSED_FUNCTIONS] [STYLE] [POSSIBLE_ERROR] [FAIL_ON_WARNINGS]) - | |
|
4 | # Create a target to check a target's sources with cppcheck and the indicated options | |
|
5 | # | |
|
6 | # Requires these CMake modules: | |
|
7 | # Findcppcheck | |
|
8 | # | |
|
9 | # Requires CMake 2.8 or newer | |
|
10 | # | |
|
11 | # Original Author: | |
|
12 | # 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> | |
|
13 | # http://academic.cleardefinition.com | |
|
14 | # Iowa State University HCI Graduate Program/VRAC | |
|
15 | # | |
|
16 | # Copyright Iowa State University 2009-2010. | |
|
17 | # Distributed under the Boost Software License, Version 1.0. | |
|
18 | # (See accompanying file LICENSE_1_0.txt or copy at | |
|
19 | # http://www.boost.org/LICENSE_1_0.txt) | |
|
20 | ||
|
21 | IF(__add_cppcheck) | |
|
22 | RETURN() | |
|
23 | ENDIF() | |
|
24 | SET(__add_cppcheck YES) | |
|
25 | ||
|
26 | FIND_PACKAGE(cppcheck) | |
|
27 | ||
|
28 | ||
|
29 | ||
|
30 | IF(NOT TARGET all_cppcheck) | |
|
31 | ADD_CUSTOM_TARGET(all_cppcheck) | |
|
32 | ENDIF() | |
|
33 | ||
|
34 | FUNCTION(add_test_cppcheck _target_name) | |
|
35 | IF(NOT TARGET ${_target_name}) | |
|
36 | MESSAGE(FATAL_ERROR "add_test_cppcheck given a target name that does not exist: '${_target_name}' !") | |
|
37 | ENDIF() | |
|
38 | ||
|
39 | ||
|
40 | SET(cppcheck_args) | |
|
41 | ||
|
42 | LIST(FIND ARGN UNUSED_FUNCTIONS index) | |
|
43 | IF("${index}" GREATER "-1") | |
|
44 | LIST(APPEND cppcheck_args ${CPPCHECK_UNUSEDFUNC_ARG}) | |
|
45 | ENDIF() | |
|
46 | ||
|
47 | LIST(FIND ARGN STYLE index) | |
|
48 | IF("${index}" GREATER "-1") | |
|
49 | LIST(APPEND cppcheck_args ${CPPCHECK_STYLE_ARG}) | |
|
50 | ENDIF() | |
|
51 | ||
|
52 | LIST(FIND ARGN POSSIBLE_ERROR index) | |
|
53 | IF("${index}" GREATER "-1") | |
|
54 | LIST(APPEND cppcheck_args ${CPPCHECK_POSSIBLEERROR_ARG}) | |
|
55 | ENDIF() | |
|
56 | ||
|
57 | LIST(FIND ARGN MISSING_INCLUDE index) | |
|
58 | IF("${index}" GREATER "-1") | |
|
59 | LIST(APPEND cppcheck_args ${CPPCHECK_MISSINGINCLUDE_ARG}) | |
|
60 | ENDIF() | |
|
61 | ||
|
62 | LIST(FIND _input FAIL_ON_WARNINGS index) | |
|
63 | IF("${index}" GREATER "-1") | |
|
64 | LIST(APPEND CPPCHECK_FAIL_REGULAR_EXPRESSION ${CPPCHECK_WARN_REGULAR_EXPRESSION}) | |
|
65 | LIST(REMOVE_AT _input ${_unused_func}) | |
|
66 | ENDIF() | |
|
67 | ||
|
68 | GET_TARGET_PROPERTY(target_sources "${_target_name}" SOURCES) | |
|
69 | SET(cppcheck_sources) | |
|
70 | FOREACH(source ${target_sources}) | |
|
71 | GET_SOURCE_FILE_PROPERTY(path "${source}" LOCATION) | |
|
72 | GET_SOURCE_FILE_PROPERTY(lang "${source}" LANGUAGE) | |
|
73 | IF("${lang}" MATCHES "CXX") | |
|
74 | LIST(APPEND cppcheck_sources "${path}") | |
|
75 | ENDIF() | |
|
76 | IF("${lang}" MATCHES "C") | |
|
77 | LIST(APPEND cppcheck_sources "${path}") | |
|
78 | ENDIF() | |
|
79 | ENDFOREACH() | |
|
80 | ||
|
81 | GET_TARGET_PROPERTY(target_definitions "${_target_name}" SOURCES) | |
|
82 | GET_TARGET_PROPERTY(target_source_location "${_target_name}" SOURCES) | |
|
83 | ||
|
84 | SET(test_target_name "${_target_name}_cppcheck_test") | |
|
85 | ||
|
86 | GET_TARGET_PROPERTY(include_folders "${_target_name}" INCLUDE_DIRECTORIES) | |
|
87 | ||
|
88 | SET(include_args) | |
|
89 | FOREACH(folder ${include_folders}) | |
|
90 | LIST(APPEND include_args "-I${folder}") | |
|
91 | ENDFOREACH() | |
|
92 | ||
|
93 | ADD_TEST(NAME "${test_target_name}" | |
|
94 | COMMAND "${CPPCHECK_EXECUTABLE}" | |
|
95 | ${CPPCHECK_TEMPLATE_ARG} | |
|
96 | ${cppcheck_args} | |
|
97 | ${include_args} | |
|
98 | ${cppcheck_sources}) | |
|
99 | ||
|
100 | SET_TESTS_PROPERTIES("${test_target_name}" | |
|
101 | PROPERTIES | |
|
102 | FAIL_REGULAR_EXPRESSION "${CPPCHECK_FAIL_REGULAR_EXPRESSION}") | |
|
103 | ||
|
104 | ADD_CUSTOM_COMMAND(TARGET all_cppcheck | |
|
105 | PRE_BUILD | |
|
106 | COMMAND "${CPPCHECK_EXECUTABLE}" | |
|
107 | ${CPPCHECK_QUIET_ARG} | |
|
108 | ${CPPCHECK_TEMPLATE_ARG} | |
|
109 | ${cppcheck_args} | |
|
110 | ${include_args} | |
|
111 | ${cppcheck_sources} | |
|
112 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | |
|
113 | COMMENT "${test_target_name}: Running cppcheck on target ${_target_name}..." | |
|
114 | VERBATIM) | |
|
115 | ||
|
116 | ENDFUNCTION() |
@@ -8,7 +8,7 endif(NOT CMAKE_BUILD_TYPE) | |||
|
8 | 8 | |
|
9 | 9 | set(LFR_BP_SRC ${CMAKE_CURRENT_SOURCE_DIR}/LFR_basic-parameters/basic_parameters.c) |
|
10 | 10 | |
|
11 |
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_ |
|
|
11 | SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/sparc") | |
|
12 | 12 | |
|
13 | 13 | add_subdirectory(src) |
|
14 | 14 | add_subdirectory(timegen) |
@@ -2,6 +2,7 cmake_minimum_required (VERSION 2.6) | |||
|
2 | 2 | project (FSW) |
|
3 | 3 | |
|
4 | 4 | include(sparc-rtems) |
|
5 | include(cppcheck) | |
|
5 | 6 | |
|
6 | 7 | include_directories("../header" |
|
7 | 8 | "../header/lfr_common_headers" |
@@ -103,3 +104,5 add_definitions(-DSW_VERSION_N3=${SW_VER | |||
|
103 | 104 | add_definitions(-DSW_VERSION_N4=${SW_VERSION_N4}) |
|
104 | 105 | |
|
105 | 106 | add_executable(FSW ${SOURCES}) |
|
107 | ||
|
108 | add_test_cppcheck(FSW STYLE UNUSED_FUNCTIONS POSSIBLE_ERROR MISSING_INCLUDE) |
General Comments 0
You need to be logged in to leave comments.
Login now