title: How to "hook" into Cmake command add_executable or add_library to run something extra?
body: <p>We build with CMake and normal Unix makefiles. There are some static analysis checks, e.g. <a href="http://cppcheck.sourceforge.net/" rel="nofollow noreferrer">Cppcheck</a>, we run at every C/C++ file in the project to catch errors at compile time.</p>
  
  <p>I have created a custom target for cppcheck and attached it into "all" target. This checks all the *.c and *.cpp files in the project.</p>
  
  <p>We want to run a check every time a file is changed and recompiled and <strong>only on that file</strong>. The check should be run automatically and without the user having to add extra commands in CMake. Essentially, the check should be "attached/hooked" to normal CMake commands <code>add_library()</code> and <code>add_executable()</code>. Is there any way to do this in CMake?</p>