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 thirdparty sources are included via the CMake FethContent 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
That's the best way to do it to prevent cmake from running Cppcheck on sources you don't want it to.
Try this: