I want to write a CMakeLists.txt so that I can run my tests normally or with valgrind. I have seen much on integrating ctest with valgrind but all with the assumption that you w
You can generate a minimal 'DartConfiguration.tcl' configuration file using add_custom_target()
. Then you can add a valgrind
custom target that calls ctest
with the appropriate args. This is how I usually do it:
find_program(VALGRIND "valgrind")
if (VALGRIND)
set(DART_CONFIG DartConfiguration.tcl)
add_custom_target(${DART_CONFIG}
COMMAND echo "MemoryCheckCommand: ${VALGRIND}" >> ${DART_CONFIG}
COMMENT "Generating ${DART_CONFIG}"
)
set(VALGRIND_ARGS
--leak-check=full
--error-exitcode=255
)
set(LOGFILE memcheck.log)
add_custom_target(valgrind
COMMAND ctest -O ${LOGFILE} -D ExperimentalMemCheck --overwrite MemoryCheckCommandOptions="${VALGRIND_ARGS}"
COMMAND tail -n1 ${LOGFILE} | grep 'Memory checking results:' > /dev/null
COMMAND rm -f ${LOGFILE}
DEPENDS ${DART_CONFIG}
)
endif()
Hope this helps! :-)
Credit: https://github.com/ARMmbed/mbedtls/blob/development/CMakeLists.txt#L237