I have old big code base, and since I only need a small subset of the functionality in my main Im looking for a way to automatically detect needed .cpps (asuming they are in the same folder and have matching name as .h files).  

Unfortunately I still need a lot of code so going through code by hand is out of the question. 
Is there tool that would go from my "main.cpp" and recursively figure out all the .h files needed, so that I can just do simple string replace (.h -> .cpp) and give it to compiler.