cmake: do not detect _GNU_SOURCE/__GNU_LIBRARY__ if it is cached (cherry picked from commit 3ed93997387296e374d8a2dd770e43ddfa3328e9)