cmake: fix detection of library functions when -Werror is enabled. (Reference issue: https://github.com/libsdl-org/SDL/issues/7011)