Menu

Exclude Third-party Source files ftom CppCheck when built via CMake

MarkP
2024-02-22
2024-02-25
  • MarkP

    MarkP - 2024-02-22

    I am working on a large codebase consisting of Modern C++, Legacy C++ (30+ years old MFC) and a number of third-party libraries (Boost, RangeV3, Catch2 etc.).

    The code is built using CMake and targeted to Windows and Linux (x86 & ARM). For the modern code I am using CppCheck for static analysis. Unfortunately when I build with CppCheck enabled a lot of time is spent running CppCheck over the third-party source (cpp) files, the worst one being Catch2

    The thirdparty sources are included via the CMake FecthContent syntax, e.g.

    Include(FetchContent)
    FetchContent_Declare(
      Catch2
      GIT_REPOSITORY https://github.com/catchorg/Catch2.git
      GIT_TAG        v3.0.1
      SYSTEM
    )
    FetchContent_MakeAvailable(Catch2)
    

    CppCheck is enabled via:

    set(CMAKE_CXX_CPPCHECK
                           --suppress=missingInclude
                           --suppress=missingIncludeSystem
                           --suppress=unusedFunction
                           --suppress=unmatchedSuppression
                           --suppress=functionStatic
                           --suppress=funcArgNamesDifferent
                           --suppress=*:*_deps/*
                           --enable=all
                           --inline-suppr
                           --inconclusive
                           --force
                           -i ${CMAKE_SOURCE_DIR}/imgui/lib
                           )
    

    The _deps directory is the location where thirdparty sources are fetched and built and the line
    --suppress=*:*_deps/*

    • disables CppCheck for the headers but does not prevent it from running when each thirdparty library is built.

    How can I prevent CppCheck from being run over the thirdparty libraries?

    Is there something I can add to the CMake section which pulls in the library to disable it? Such as clearing CMAKE_CXX_CPPCHECK before the call to FetchContent_Declare and setting it again after the call FetchContent_MakeAvailable

     
  • tbeu

    tbeu - 2024-02-25

    The idea is to use the -i flag for file to directory paths to be ignored.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.