I know it's about cmake but you should use modern C++, not fprintf etc. Indentation seems off too.
https://cmake.org/cmake-tutorial/