Add Ceedling task for analyzing code with Cppcheck.
Clone this into Ceedling's plugin folder of your current project.
$ cd <your-project>/vendor/ceedling/plugins
$ git clone https://github.com/deltalejo/cppcheck-ceedling-plugin.git cppcheck
Add the plugins path to your project.yml
if you have not done it yet.
Then add cppcheck
plugin to the enabled plugins list:
:plugins:
:load_paths:
- vendor/ceedling/plugins
:enabled:
- cppcheck
Add cppcheck
section to your project.yml
specifying configuration options.
e.g:
:cppcheck:
:reports:
- html
:addons:
- misra
Three types of reports are available:
- text
- xml
- html
They can be enabled by listing them on the :reports
list:
:cppcheck:
:reports:
- text
- html
Artifact file and output format can be configured:
:cppcheck:
:text_artifact_filename: CppcheckResults.txt
:template: gcc
:template
can be any of the ones included with Cppcheck or custom format string.
Artifact file can be configured:
:cppcheck:
:xml_artifact_filename: CppcheckResults.xml
HTML title can be configured:
:cppcheck:
:html_title: Awesome Project
Notes:
- This report requires the
cppcheck-htmlreport
tool to be available. - This report implies the
xml
report.
You can import some project files and build configurations into Cppcheck. Some of compatible files are:
- Cppcheck GUI project (*.cppcheck)
- Compile Commands (compile_commands.json)
- Visual Studio projects (*.vcxproj, *.sln)
:cppcheck:
:project: path/to/compile_commands.json
Note: If configured, Cppcheck won't look for sources and includes paths from Ceedling configuration files.
:cppcheck:
:defines:
- A
- B
- C=1
:cppcheck:
:undefines:
- A
- B
- C
Note: By default TEST
is undefined so the analysis is performed against production code.
Force inclusion of files before checked files.
:cppcheck:
:includes:
- file1.h
- file2.h
Exclude files from the analysis.
:cppcheck:
:excludes:
- file1.c
- file2.c
Specify platform to use for the analysis, can be any of the ones included with Cppcheck, e.g.: unix64, or the path of the platform XML file.
:cppcheck:
:platform: unix64
Specify C/C++ language standard.
:cppcheck:
:standard: c99
Specify the check level to be used.
- normal
- exhaustive
:cppcheck:
:check_level: exhaustive
Addons to be run.
:cppcheck:
:addons:
- misra
- path/to/addon.py
Locate your rules text file or copy it to your project.
e.g.: <your-project>/misra.txt
and create the addon file misra.json
inside
your project:
{
"script": "misra",
"args": ["--rule-texts=misra.txt"]
}
Enable the addon:
:cppcheck:
:addons:
- misra.json
Enable additional checks. Default is style.
:cppcheck:
:enable_checks:
- performance
- portability
Note: These are only used for single file analysis. Whole project analysis always enable all checks.
Disable individual checks:
:cppcheck:
:disable_checks:
- style
- information
Inline suppressions are disabled by default, they can be enabled with:
:cppcheck:
:inline_suppressions: true
Suppressions files can be used by giving the search paths and/or files in the
:paths
and :files
sections of your project.yml
respectively.
e.g.:
:paths:
:cppcheck:
- suppressions/
- source/*/suppressions/
:files:
:cppcheck:
- suppressions.xml
Both XML and text files are supported, and for the latter, the file extension
can be configured. The default is .txt
.
e.g.:
:extension:
:cppcheck: .txt
The files that will ultimately be used can be verified with:
$ ceedling files:cppcheck
Command line suppressions can also be added:
:cppcheck:
:suppressions:
- memleak:src/file1.cpp
- exceptNew:src/file1.cpp
Add library configuration files:
:cppcheck:
:libraries:
- lib1.cfg
- lib2.cfg
Regular expression rules:
:cppcheck:
:rules:
- if \( p \) { free \( p \) ; }
For things not covered above, add extra command line options:
:cppcheck:
:options:
- --max-configs=<limit>
- --suppressions-list=<file>
Run analysis for all project sources:
$ ceedling cppcheck:all
Note: Analysis is run with all checks enabled.
Run analysis for single source file:
$ ceedling cppcheck:<filename>
Note: Analysis will run with the checks in :enable_checks
list enabled.