0

I am using cppcheck with cmake. Which works as expected but I would like to exclude some files or folders from the check. I tried some different things with --supress and --supress-list andi -i but I did not get any solution right now.

lets say i have this folder structure:

source
test
   unity
   lib
      mylib.c
   source
   CMakeLists.txt

So how can i exclude unity and mylib.c from the check? This is a snippet from the CMakeLists.txt ...

find_program(CMAKE_C_CPPCHECK NAMES cppcheck)
if (CMAKE_C_CPPCHECK)
    message("-- CppCheck found : ${CMAKE_C_CPPCHECK}")
    message("-- current source dir : ${CMAKE_CURRENT_SOURCE_DIR}")
    message("-- source dir : ${CMAKE_SOURCE_DIR}")
    list(
        APPEND CMAKE_C_CPPCHECK 
            "--enable=warning,style,performance,portability,information,missingInclude"
            "--force"    
            "-i${CMAKE_CURRENT_SOURCE_DIR}/unity/"
            "-i${CMAKE_CURRENT_SOURCE_DIR}/lib/mylib.c"
            #"--suppress=*:${CMAKE_CURRENT_SOURCE_DIR}/unity/*" # also tried this for the folder
    )
endif()

So nothing works right now. What am I doing wrong here.

thx

mgiaco
  • 319
  • 1
  • 5
  • 17
  • I think there is no ways to ignore the files (but I am not sure) and I would share that I ended up by generating `compile_commands.json` and then running `cppcheck` with `--project` and then `--ignore` works as intended. The downside is, it is running `cppcheck` on all files each time. – KamilCuk Sep 29 '20 at 08:11
  • I disagree with KamilCuk. I've successfully used the --suppress option to disable analysis of specific .h files, and to disable specific warnings when analyzing a .cpp file. I've never tried to use a single --suppress to suppress all files in a folder though. If I can find the time, I'll experiment and post an answer... – Eric Backus Sep 29 '20 at 16:19

0 Answers0