cmake: use a different variable for testing with and without libm

CMake seems to cache the result when using the same variable, at least
with some versions, so previously systems requiring libm for log2 may
not have worked as expected.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 082b1d8..0cba0f0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,17 +48,17 @@
 set(LIBM_LIBRARY)
 CHECK_FUNCTION_EXISTS(log2 LOG2_RES)
 if(NOT LOG2_RES)
-  unset(LOG2_RES)
   set(orig_req_libs "${CMAKE_REQUIRED_LIBRARIES}")
   set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};m")
-  CHECK_FUNCTION_EXISTS(log2 LOG2_RES)
-  if(LOG2_RES)
+  CHECK_FUNCTION_EXISTS(log2 LOG2_LIBM_RES)
+  if(LOG2_LIBM_RES)
     set(LIBM_LIBRARY "m")
   else()
     message(FATAL_ERROR "log2() not found")
   endif()
 
   set(CMAKE_REQUIRED_LIBRARIES "${orig_req_libs}")
+  unset(LOG2_LIBM_RES)
   unset(orig_req_libs)
 endif()
 unset(LOG2_RES)