Improved CMake scripts that detect libraries