1

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.

alfC
  • 14,261
  • 4
  • 67
  • 118
  • It seems that I have to "overwrite" the `ctest` options, not the `cmake` options: https://stackoverflow.com/a/56116311/225186. Although I couldn't replace `set(MEMORYCHECK_SUPPRESSIONS_FILE "${PROJECT_SOURCE_DIR}/.valgrind-suppressions")` because I can't specify a relative directory. – alfC Dec 25 '21 at 07:40

0 Answers0