Q:

How to use Valgrind with Meson?

project('testproject', 'cpp')

src = ['a.cpp', 'b.cpp']

executable('test', src)

What is the simplest way to build my executable with Valgrind using Meson build system?

A:

Just for completeness, wanted to note that valgrind can be used as wrapper in meson command line, for example
$ meson test --wrap='valgrind --leak-check=full --error-exitcode=1' testname

or
$ meson test --wrap='valgrind --tool=helgrind -v --error-exitcode=1' testname

which can be combined with other test options, e.g.
$ meson test --wrap='valgrind --leak-check=full --error-exitcode=1' testname --repeat=100

Check this page of reference manual.

A:

valgrind is a dynamic analysis tool, there is no need to recompile it specially for valgrind.
For example, you can do:

valgrind ls

and valgrind will run and analyse the ls command.
Note that it is however recommended to compile with debugging information, as otherwise the error reports of valgrind will not be very understandable.
An introduction on how to use valgrind is available in http://www.valgrind.org/docs/manual/QuickStart.html

