how to use cppcheck for static code analysis

510 views
Skip to first unread message

Bruno Kuhn

unread,
Feb 17, 2017, 9:35:19 AM2/17/17
to The Meson Build System
 Hi all

I found a example in the internet how to use clang for code analysis with ninja scan-build. Is there a way to use cppcheck instead?

Kind Regards
Bruno

Jussi Pakkanen

unread,
Feb 17, 2017, 10:20:18 AM2/17/17
to Bruno Kuhn, The Meson Build System
On Fri, Feb 17, 2017 at 4:35 PM, Bruno Kuhn <bruno....@gmail.com> wrote:

> I found a example in the internet how to use clang for code analysis with
> ninja scan-build. Is there a way to use cppcheck instead?

There is no builtin support but it is easy to do your own. It is
mostly a matter of deciding your arguments and then doing something
like this:

run_target('cppcheck', command : ['cppcheck', meson.source_root(),
<extra args>])

If you want to scan only a subdirectory rather than everything you can
build a path to your chose dir with join_paths(meson.source_root(),
'src') or equivalent.

Bruno Kuhn

unread,
Feb 20, 2017, 5:29:09 AM2/20/17
to The Meson Build System, bruno....@gmail.com

I would like to cppcheck file after file with the same defines and include pathes as meson/ninja passes to the compiler (I would "inherit" the include pathes and defines from the meson.build files).
I think with the run_target example above this is not easy possible.

Jussi Pakkanen

unread,
Feb 20, 2017, 6:31:28 AM2/20/17
to Bruno Kuhn, The Meson Build System
On Mon, Feb 20, 2017 at 12:29 PM, Bruno Kuhn <bruno....@gmail.com> wrote:

> I would like to cppcheck file after file with the same defines and include
> pathes as meson/ninja passes to the compiler (I would "inherit" the include
> pathes and defines from the meson.build files).
> I think with the run_target example above this is not easy possible.

Cppcheck supports the compilation database format which we generate by
default. Thus something like this should work:

run_target('cppcheck', command : ['cppcheck', '--project=' +
join_paths(meson.build_root(), 'compile_commands.json')])
Reply all
Reply to author
Forward
0 new messages