How to ignore 3rd-party sources from static analysis

I’ve been using project options as a way to get some solid defaults for my projects without too much trouble.

One problem I’ve been running into though is the CMAKE_$LANG_CPPCHECK defaults and how they apply to 3rd party dependencies.

It seems like when this option is set, 3rd party libraries (in my case, Catch2) are also subject to these globals. Static analysis (e.g. cppcheck) is performed on them and fails, when it is not my intention to run it on these 3rd-party libs. If it matters, I’m using CPM to download Catch2.

Is there a preferred way to globally ignore 3rd party libraries globally from static analysis like cppcheck?

My current approach is to do set_target_properties(my_target PROPERTIES CXX_CPPCHECK ${some_good_options}), where some_good_options are the ones set by project_options. I clear these CMAKE_$LANG_CPPCHECK properties right after calling into project_options for it to set them up.

1 Like

These CMAKE_ variables just initialize target properties when the target is defined. You can do something like:

block (SCOPE_FOR VARIABLES)
  unset(CMAKE_CXX_CPPCHECK)
  add_subdirectory(Catch2)
endblock ()

to clear these initializations for your 3p projects.

1 Like