title: Makefile for Unit Tests in C++
body: <p>I'm struggling to write Makefiles that properly build my unit tests. As an example, suppose the file structure looks like this</p>
  
  <pre><code>src/foo.cpp
  src/foo.hpp
  src/main.cpp
  tests/test_foo.cpp
  tests/test_all.cpp
  </code></pre>
  
  <p>So, to build the executable test_all, I'd need to build test_foo.o which in turn depends on test_foo.cpp but also on src/foo.o. </p>
  
  <p>What is the best practice in this case? One Makefile in the parent folder? One Makefile per folder? If so, how do I manage the dependencies across folders? </p>