Skip to content

Commit

Permalink
Add argument to cppcheck to be able to enable additional checks
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Rousseau <vincent.rousseau@sabi-agri.com>
  • Loading branch information
Vincent Rousseau committed Sep 5, 2022
1 parent 96d9ca4 commit 5f29a97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ament_cmake_cppcheck/cmake/ament_cppcheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# @public
#
function(ament_cppcheck)
cmake_parse_arguments(ARG "" "LANGUAGE;TESTNAME" "EXCLUDE;LIBRARIES;INCLUDE_DIRS" ${ARGN})
cmake_parse_arguments(ARG "" "ENABLE_EXTRA_CHECKS;LANGUAGE;TESTNAME" "EXCLUDE;LIBRARIES;INCLUDE_DIRS" ${ARGN})
if(NOT ARG_TESTNAME)
set(ARG_TESTNAME "cppcheck")
endif()
Expand All @@ -61,6 +61,10 @@ function(ament_cppcheck)
if(ARG_INCLUDE_DIRS)
list(APPEND cmd "--include_dirs" "${ARG_INCLUDE_DIRS}")
endif()
if(ARG_ENABLE_EXTRA_CHECKS)
string(TOLOWER ${ARG_ENABLE_EXTRA_CHECKS} ARG_ENABLE_EXTRA_CHECKS)
list(APPEND cmd "--enable-extra-checks" "${ARG_ENABLE_EXTRA_CHECKS}")
endif()

file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/ament_cppcheck")
ament_add_test(
Expand Down
6 changes: 6 additions & 0 deletions ament_cppcheck/ament_cppcheck/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ def main(argv=sys.argv[1:]):
'--cppcheck-version',
action='store_true',
help='Get the cppcheck version, print it, and then exit.')
parser.add_argument(
'--enable-extra-checks',
help="Passed to cppcheck as '--enable=<extra_checks>', and add extra checks to cppcheck "
"as the given extra_checks (e.g. 'all', 'warning', 'style').")
args = parser.parse_args(argv)

cppcheck_bin = find_cppcheck_executable()
Expand Down Expand Up @@ -161,6 +165,8 @@ def main(argv=sys.argv[1:]):
cmd.extend(['--suppress=*:' + exclude])
if jobs:
cmd.extend(['-j', '%d' % jobs])
if args.enable_extra_checks:
cmd.extend(['--enable={0}'.format(args.enable_extra_checks)])
cmd.extend(files)
try:
p = subprocess.Popen(cmd, stderr=subprocess.PIPE)
Expand Down

0 comments on commit 5f29a97

Please sign in to comment.