cmake: cache HAVE_* results to skip feature checks on re-runs (#2137)

Without caching, HAVE_${VAR} was lost between cmake runs, so the
early-exit guard never fired and all feature test messages re-printed
on every reconfigure.

Now HAVE_${VAR} is written to the CMake cache (INTERNAL) on both
success and failure. Also fix the guard to not promote a cached 0 to 1.
diff --git a/cmake/CXXFeatureCheck.cmake b/cmake/CXXFeatureCheck.cmake
index ee5b759..59ccddf 100644
--- a/cmake/CXXFeatureCheck.cmake
+++ b/cmake/CXXFeatureCheck.cmake
@@ -24,8 +24,9 @@
   string(TOUPPER ${FILE} VAR)
   string(TOUPPER "HAVE_${VAR}" FEATURE)
   if (DEFINED HAVE_${VAR})
-    set(HAVE_${VAR} 1 PARENT_SCOPE)
-    add_definitions(-DHAVE_${VAR})
+    if(HAVE_${VAR})
+      add_definitions(-DHAVE_${VAR})
+    endif()
     return()
   endif()
 
@@ -67,10 +68,11 @@
   if(COMPILE_${FEATURE})
     if(DEFINED RUN_${FEATURE} AND RUN_${FEATURE} EQUAL 0)
       message(STATUS "Performing Test ${FEATURE} -- success")
-      set(HAVE_${VAR} 1 PARENT_SCOPE)
+      set(HAVE_${VAR} 1 CACHE INTERNAL "")
       add_definitions(-DHAVE_${VAR})
     else()
       message(STATUS "Performing Test ${FEATURE} -- compiled but failed to run")
+      set(HAVE_${VAR} 0 CACHE INTERNAL "")
     endif()
   else()
     if(CXXFEATURECHECK_DEBUG)
@@ -78,5 +80,6 @@
     else()
       message(STATUS "Performing Test ${FEATURE} -- failed to compile")
     endif()
+    set(HAVE_${VAR} 0 CACHE INTERNAL "")
   endif()
 endfunction()