Currently to do test with memchecker and CMake, I put these lines in the CMakeLists.txt
:
find_program(MEMORYCHECK_COMMAND valgrind)
set(VALGRIND_COMMAND_OPTIONS "-q --tool=memcheck --leak-check=yes --num-callers=51 --trace-children=yes --leak-check=full --track-origins=yes --gen-suppressions=all")
set(MEMORYCHECK_COMMAND_OPTIONS "-q --tool=memcheck --leak-check=yes --num-callers=52 --trace-children=yes --leak-check=full --track-origins=yes --gen-suppressions=all") # must go before `include(CTest)`
set(MEMORYCHECK_SUPPRESSIONS_FILE "${PROJECT_SOURCE_DIR}/.valgrind-suppressions") # must go before `include(CTest)`
then I run ctest -T memcheck ... etc
.
I don't want to polute the CMake file with all these options.
Is there a way to replace these options with an option in the cmake or ctest command?
...in a similar way one adds static analysis by just adding -DCMAKE_CXX_CLANG_TIDY="clang-tidy;clangoptions1;clangoptions2"
to the cmake command line.