Some recent develoment using cmake resulted in a cutover to invoke cppcheck via the in-built CMAKE_CPPCHECK support.
Having recently gone through a similar process for clang-tidy, making use of compile_commands.json, I blindly added this file via --project. However, cmake invokes cppcheck for every source file (as part of its co-compile process), passing each for a single file analysis.
The version of cppcheck I was using (2.3) ignores the source file if a project file has been specified. The outcome was that a full cppcheck project analysis was invoked for every source file invocation 😅
I see in the latest version that specifying a file and project now generates an error - presumably I'm not the first.
Naturally, the answer is: do not specify the project file.
However, given that the project file provides the compilation settings, etc., it would be useful if cppcheck could behave in the same way as clang-tidy does here; i.e. if an explicit source file is provided on the command-line, then look it up in the project file and perform a single file analysis with the settings found for it (or a switch to activate that behaviour).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Some recent develoment using cmake resulted in a cutover to invoke cppcheck via the in-built
CMAKE_CPPCHECK
support.Having recently gone through a similar process for clang-tidy, making use of compile_commands.json, I blindly added this file via
--project
. However, cmake invokes cppcheck for every source file (as part of its co-compile process), passing each for a single file analysis.The version of cppcheck I was using (2.3) ignores the source file if a project file has been specified. The outcome was that a full cppcheck project analysis was invoked for every source file invocation 😅
I see in the latest version that specifying a file and project now generates an error - presumably I'm not the first.
Naturally, the answer is: do not specify the project file.
However, given that the project file provides the compilation settings, etc., it would be useful if cppcheck could behave in the same way as clang-tidy does here; i.e. if an explicit source file is provided on the command-line, then look it up in the project file and perform a single file analysis with the settings found for it (or a switch to activate that behaviour).
Looks like I didn't pick the correct search terms...just found this old thread:
https://sourceforge.net/p/cppcheck/discussion/general/thread/08b0400c/
I think you need to use
--project=
with--file-filter=
to get the expected result.That is actually a nice trick we should document (in case it works as expected).