Valgrind Memcheck
valgrind
This module defines functions to help use the valgrind tools.
enable_memcheck() enables rumtime leak detection.
Loading this file creates a run_memcheck target.
- enable_memcheck
Automatically add memory leak detection with valgrind’s memcheck for target.
enable_memcheck(TARGET targetName [TARGET_ARGS args...] [MEMCHECK_ARGS args...] [EXCLUDE_FROM ALL] )
enable_memcheckcreates a new targetrun_memcheck_<targetName>to trigger analysis.The options are:
TARGET targetNameSpecifies the target to be analysed, which must be a known CMake executable target.
TARGET_ARGS args...Specifies additional arguments to be forwarded to the target called. This allows for instance to define a language folder, data directories, etc.
MEMCHECK_ARGS args...Specifies additional arguments to be appended to the memcheck call. This allows for instance to increase the stack trace size for some binaries.
EXCLUDE_FROM_ALLNormally, the function creates a dependency between the
run_memchecktarget and the currentrun_memcheck_<targetName>target, allowing the first one to trigger the other one. If this behaviour is not desired (as may be the case when some resource is required but not always available), this option can be used to prevent the dependency from beeing added.
For each registered target, a result file is created in
${data_base_path}/valgrind-reports, the actual file name is<targetName>.memcheck-results.log.If not set, ${data_base_path} will be set as ${CMAKE_BINARY_DIR}
- run_memcheck
Automatically call memcheck to run and analyse all registered
run_memcheck_<target_name>targets (except those marked withEXCLUDE_FROM_ALL).
Usage example:
set (CMAKE_EXPORT_COMPILE_COMMANDS ON) include(valgrind) add_library(FooLib FooLib.cc) add_executable(FooExe FooExe.cc) add_executable(FooTest FooTest.cc) enable_memcheck(TARGET FooTest TARGET_ARGS -lang "${CURRENT_SOURCE_DIR}/lang")