cmake part

The best way is to separate the reusable code into a .cmake module file and put a copy of this file in each project.

However, CMake already has a FindDoxygen module, which may already do what you want.