Add new CPPCHECK build system module for static code analysis of projects.

pull/1469/head
Dean Camera 13 years ago
parent 8f8f347891
commit 41b4c5b645

File diff suppressed because one or more lines are too long

@ -0,0 +1,84 @@
#
# LUFA Library
# Copyright (C) Dean Camera, 2012.
#
# dean [at] fourwalledcubicle [dot] com
# www.lufa-lib.org
#
LUFA_BUILD_MODULES += CPPCHECK
LUFA_BUILD_TARGETS += cppcheck cppcheck-config
LUFA_BUILD_MANDATORY_VARS +=
LUFA_BUILD_OPTIONAL_VARS += CPPCHECK_PATH CPPCHECK_INCLUDES CPPCHECK_EXCLUDES CPPCHECK_MSG_TEMPLATE \
CPPCHECK_ENABLE CPPCHECK_SUPPRESS CPPCHECK_FAIL_ON_WARNING CPPCHECK_QUIET
# -----------------------------------------------------------------------------
# LUFA CPPCheck Buildsystem Makefile Module.
# -----------------------------------------------------------------------------
# DESCRIPTION:
# Provides a set of targets to scan a project with the free "cppcheck" static
# analysis tool, to check for code errors at runtime (see http://cppcheck.sourceforge.net).
# -----------------------------------------------------------------------------
# TARGETS:
#
# cppcheck - Scan the project with CPPCheck
# cppcheck-config - Use CPPCheck to look for missing include files
#
# MANDATORY PARAMETERS:
#
# (None)
#
# OPTIONAL PARAMETERS:
#
# CPPCHECK_PATH - Path of the files to statically analyze
# CPPCHECK_INCLUDES - Extra include paths to search for missing
# header files
# CPPCHECK_EXCLUDES - Source file paths to exclude checking (can be
# a path fragment if desired)
# CPPCHECK_MSG_TEMPLATE - Template for cppcheck error and warning output
# CPPCHECK_ENABLE - General cppcheck category checks to enable
# CPPCHECK_SUPPRESS - Specific cppcheck warnings to disable by ID
# CPPCHECK_FAIL_ON_WARNING - Set to Y to fail the build on cppcheck
# warnings, N to continue even if warnings occur
# CPPCHECK_QUIET - Enable cppcheck verbose or quiet output mode
#
# -----------------------------------------------------------------------------
# Default values of optionally user-supplied variables
CPPCHECK_PATH ?= .
CPPCHECK_INCLUDES ?=
CPPCHECK_EXCLUDES ?=
CPPCHECK_MSG_TEMPLATE ?= {file}:{line}: {severity} ({id}): {message}
CPPCHECK_ENABLE ?= all
CPPCHECK_SUPPRESS ?= variableScope missingInclude
CPPCHECK_FAIL_ON_WARNING ?= Y
CPPCHECK_QUIET ?= Y
# Build a default argument list for cppcheck
CPPCHECK_OPTIONS := --template="$(CPPCHECK_MSG_TEMPLATE)" $(CPPCHECK_INCLUDES:%=-I%) $(CPPCHECK_EXCLUDES:%=-i%) --inline-suppr --force --std=c99
# Sanity check parameters and construct additional command line arguments to cppcheck
ifeq ($(CPPCHECK_PATH),)
$(error Makefile CPPCHECK_PATH option cannot be blank)
endif
ifeq ($(CPPCHECK_FAIL_ON_WARNING), Y)
CPPCHECK_OPTIONS += --error-exitcode=1
else ifneq ($(CPPCHECK_FAIL_ON_WARNING), N)
$(error CPPCHECK_FAIL_ON_WARNING must be Y or N)
endif
ifeq ($(CPPCHECK_QUIET), Y)
CPPCHECK_OPTIONS += --quiet
else ifneq ($(CPPCHECK_QUIET), N)
$(error CPPCHECK_QUIET must be Y or N)
endif
# Output Messages
MSG_CPPCHECK_CMD := ' [CPPCHECK]:'
cppcheck-config:
@echo $(MSG_CPPCHECK_CMD) Checking cppcheck configuration for path \"$(CPPCHECK_PATH)\"
cppcheck $(CPPCHECK_OPTIONS) --check-config $(CPPCHECK_PATH)
cppcheck:
@echo $(MSG_CPPCHECK_CMD) Performing cppcheck analysis on path \"$(CPPCHECK_PATH)\"
cppcheck $(CPPCHECK_OPTIONS) --enable=$(CPPCHECK_ENABLE) $(CPPCHECK_SUPPRESS:%=--suppress=%) $(CPPCHECK_PATH)
Loading…
Cancel
Save