title: How to run sanitizers on whole project
body: <p>I'm trying to get familiar with sanitizers as ASAN, LSAN etc and got a lot of useful information already from here: <a href="https://developers.redhat.com/blog/2021/05/05/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind" rel="nofollow noreferrer">https://developers.redhat.com/blog/2021/05/05/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind</a></p>
  <p>I am able to run all sort of sanitizers on specific files, as shown on the site, like this:</p>
  <pre><code>clang -g -fsanitize=address -fno-omit-frame-pointer -g ../TestFiles/ASAN_TestFile.c
  ASAN_SYMBOLIZER_PATH=/usr/local/bin/llvm-symbolizer ./a.out &gt;../Logs/ASAN_C.log 2&gt;&amp;1
  </code></pre>
  <p>which generates a log with found issue. Now I would like to extend this to run upon building the project with cmake. This is the command to build it at the moment:</p>
  <pre><code>cmake -S . -B build
  cd build
  make
  </code></pre>
  <p>Is there any way I can use this script with adding the sanitizers, without having to alter the cmakelist.txt file??</p>
  <p>For instance something like this:</p>
  <pre><code>cmake -S . -B build
  cd build
  make -fsanitize=address
  ./a.out &gt;../Logs/ASAN_C.log 2&gt;&amp;1
  </code></pre>
  <p>The reason is that I want to be able to build the project multiple times with different sanitizers (since they cannot be used together) and have a log created without altering the cmakelist.txt file (just want to be able to quickly test the whole project for memory issues instead of doing it for each file created).</p>