Set CMAKE_CXX_STANDARD if we seem to need to set it. :/

Change-Id: I550ff1b4542bf9fc34cfe50e7fa4ac8fb55cc804
Reviewed-on: https://code-review.googlesource.com/c/re2/+/59910
Reviewed-by: Perry Lorier <perryl@google.com>
Reviewed-by: Paul Wankadia <junyer@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e10de15..6edbdcd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -10,6 +10,12 @@
 include(CTest)
 include(GNUInstallDirs)
 
+# Unlike GCC and upstream Clang, AppleClang still defaults to `-std=c++98`
+# for some reason. Set CMAKE_CXX_STANDARD if we seem to need to set it. :/
+if(APPLE AND NOT CMAKE_CXX_FLAGS MATCHES "-std=" AND NOT CMAKE_CXX_STANDARD)
+  set(CMAKE_CXX_STANDARD 11)
+endif()
+
 option(BUILD_SHARED_LIBS "build shared libraries" OFF)
 option(USEPCRE "use PCRE in tests and benchmarks" OFF)