Add a IREE_ENABLE_CCACHE build option. OFF by default. (#3689)

* Add a IREE_ENABLE_CCACHE build option. OFF by default.

If enabled, this will try to detect ccache, and if found, CMake will
be told to use it. No-op if ccache is not found.

* move down to the right section
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8d7e8ba..bbff376 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -229,6 +229,14 @@
 option(IREE_ENABLE_ASAN "Enable address sanitizer" OFF)
 option(IREE_ENABLE_MSAN "Enable memory sanitizer" OFF)
 option(IREE_ENABLE_TSAN "Enable thread sanitizer" OFF)
+option(IREE_ENABLE_CCACHE "Use ccache if installed to speed up rebuilds." OFF)
+
+if (${IREE_ENABLE_CCACHE})
+  find_program(CCACHE_PROGRAM ccache)
+  if(CCACHE_PROGRAM)
+      set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
+  endif()
+endif()
 
 #-------------------------------------------------------------------------------
 # IREE utility definitions