28

I call cppcheck on our own files in our source base. However, some source files include header files from third party libraries, say from ./lib/some_library/. These are automatically parsed by cppcheck as well.

I don't want this, since I don't want to see warnings on third party code. Is there a way to get around this?

The difference with how can i tell cppcheck to skip a header file is that this post explicitly asks for skipping an entire directory, not just an individual header file.

Community
  • 1
  • 1
chtenb
  • 14,924
  • 14
  • 78
  • 116
  • 1
    `-i ` Give path to ignore. Give several -i parameters to ignore several paths. Give directory name or filename with path as parameter. Directory name is matched to all parts of the path. – Gluttton Jun 03 '16 at 09:31
  • For me it says: `-i ` Give a source file or source file directory to exclude from the check. **This applies only to source files so header files included by source files are not matched.** Directory name is matched to all parts of the path. – chtenb Jun 03 '16 at 10:23
  • see https://stackoverflow.com/a/38335737/792456 – arved Jul 15 '16 at 15:54
  • 1
    Possible duplicate of [how can i tell cppcheck to skip a header file](http://stackoverflow.com/questions/13591696/how-can-i-tell-cppcheck-to-skip-a-header-file) – arved Jul 15 '16 at 15:55
  • 1
    Same issue here. I am seeing issues from header files under directories which are explicitly excluded with `-i`. This is not desirable. – simon.watts Jul 10 '17 at 16:09

3 Answers3

14

Another possibility would be to use suppressions via a file (see manual chapter 7 "Listing suppressions in a file") or via commandline.

Your suppressions.txt could be

*:/path/to/your/thirdpartylibs/*

Which would exclude all errors from that path. The syntax is

[error id]:[filename]:[line]

with wildcard support for * (multiple characters) and ? (single character).

The call to cppcheck would then be

cppcheck --suppressions-list=suppressions.txt .
BNT
  • 936
  • 10
  • 27
8

As per cppcheck manual:

Excluding a file or folder from checking To exclude a file or folder, there are two options. The first option is to only provide the paths and files you want to check.

cppcheck src/a src/b

All files under src/a and src/b are then checked.

The second option is to use -i, with it you specify files/paths to ignore. With this command no files in src/c are checked:

cppcheck -isrc/c src

This option does not currently work with the --project option and is only valid when supplying an input directory.

To ignore multiple directories supply the -i multiple times. The following command ignores both the src/b and src/c directories.

cppcheck -isrc/b -isrc/c
Vaillancourt
  • 1,380
  • 1
  • 11
  • 42
8

I had a similar need to exclude reporting on a dedicated third party directory. To do so, I've used the --suppress option directly on the cli:

"C:\Program Files\Cppcheck\cppcheck" --suppress=*:*3rdparty\* --language=c++ --enable=all --xml --xml-version=2 . 2> cppcheck-result.xml

The interesting thing with cppcheck is that it will still show on the stdout that it's going through the 'suppressed' directory but in the result file, there won't be any files from the excluded directory in there. Looks like it could be further optimised.

fduff
  • 3,671
  • 2
  • 30
  • 39