PlatformIO Community

Cppcheck - how to exclude Includes?

I have a project with platform files (like CMSIS, etc) being part of the project - for various reasons!
Those files are included as instructed by build_flags = -I src/CMSIS.
When I use cppcheck with misra I am getting hundreds of warnings originating from the CMSIS and others that are not user code.
When I run pio check -v, I can see all the Includes being listed. I don’t want any of them - per the manual: image

How can I remove arbitrary or all the includes? I can only add new ones using check_flags. It would be best if that check_flags = cppcheck: --I xxxxx command was replacing the Includes, instead of adding to them.

Per Cppcheck — PlatformIO latest documentation and Cppcheck: how to skip a directory of third party header files? - Stack Overflow, could you use something like

check_flags =
  cppcheck: --suppress=*:src/CMSIS/*


I tried a few different versions of it, but I cannot make it work. This also probably would have to be an absolute path judging by the rest of the arguments cppcheck.exe is getting.

check_flags =
  cppcheck:--addon=misra.json --std=c99 --language=c --suppress=*:C:\Users\dzidm\Repos\firmware\src\CMSIS\core_cm3.h:*

I think suppression may not work with misra plugin - based on issues online…

Besides, Cppcheck would run much much faster if it didn’t have go through all the includes.

Indeed, --suppress=*:*/src/CMSIS/* should be used as the flag so that the path in front of it doesn’t matter.

This does work, I have personally tested this with the project.

Without the suppress, found defects:

Component     HIGH    MEDIUM    LOW
-----------  ------  --------  -----
src            0        0        6
src\CMSIS      0        0      1304
src\Device     0        0       40

Total          0        0      1350

With the flag:

Component     HIGH    MEDIUM    LOW
-----------  ------  --------  -----
src            0        0        6
src\Device     0        0       40

Total          0        0       46

Since I don’t see an option in PlatformIO to do this, you would have to file a feature request at Issues · platformio/platformio-core · GitHub.

Ah - that extra * in front did the job. Thank you for the example. :heart:

Any idea how would you suppress multiple directories? - src/CMSIS and src/Device from your example.

I have created a feature request as suggested:

Adding multiple --suppress flags is allowed.

check_flags =
  cppcheck:--addon=misra.json --std=c99 --language=c  --suppress=*:*/src/CMSIS/* --suppress=*:*/src/Device/*

gives only

Component     HIGH    MEDIUM    LOW
-----------  ------  --------  -----
src            0        0        6

Total          0        0        6
1 Like

And of course that worked!

Interesting that --addon=misra gives less results than --addon=misra.json:

Checking genericSTM32F103C8 > cppcheck (platform: ststm32; board: genericSTM32F103C8)
src\main.c:4: [low:style] misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-8.2]
src\main.c:8: [low:style] misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-10.1]
src\main.c:5: [low:style] misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-11.4]
src\main.c:6: [low:style] misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-11.4]
============================================================================================================== [PASSED] Took 4.27 seconds ==============================================================================================================

Component     HIGH    MEDIUM    LOW
-----------  ------  --------  -----
src            0        0        4

Total          0        0        4

Environment         Tool      Status    Duration
------------------  --------  --------  ------------
genericSTM32F103C8  cppcheck  PASSED    00:00:04.267

Perhaps related to: