Build: Verify that we're compiling with C++14.

Better to have a descriptive compiler error message than weird missing symbols.

Bug: b/147359661
Change-Id: I66c0e5beb1e94f79210528867c990ab3e0f8b0ae
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/39949
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2b0f1e4..341435a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1768,6 +1768,7 @@
     ${VULKAN_DIR}/*.cpp
     ${VULKAN_DIR}/*.h
     ${VULKAN_DIR}/*.hpp
+    ${SOURCE_DIR}/System/Build.cpp
     ${SOURCE_DIR}/System/Build.hpp
     ${SOURCE_DIR}/System/CPUID.cpp
     ${SOURCE_DIR}/System/CPUID.hpp
diff --git a/src/Android.bp b/src/Android.bp
index 081a58a..79bb946 100644
--- a/src/Android.bp
+++ b/src/Android.bp
@@ -571,6 +571,7 @@
     ],
 
     srcs: [
+        "System/Build.cpp",
         "System/CPUID.cpp",
         "System/Configurator.cpp",
         "System/Half.cpp",
diff --git a/src/System/BUILD.gn b/src/System/BUILD.gn
index ebd31e8..c90c835 100644
--- a/src/System/BUILD.gn
+++ b/src/System/BUILD.gn
@@ -36,6 +36,7 @@
 
 swiftshader_source_set("System") {
   sources = [
+    "Build.cpp",
     "CPUID.cpp",
     "Configurator.cpp",
     "Debug.cpp",
diff --git a/src/System/Build.cpp b/src/System/Build.cpp
new file mode 100644
index 0000000..5552ae5
--- /dev/null
+++ b/src/System/Build.cpp
@@ -0,0 +1,45 @@
+// Copyright 2020 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#if defined(_MSVC_LANG)
+#	define CPP_VERSION _MSVC_LANG
+#elif defined(__cplusplus)
+// Note: This must come after checking for _MSVC_LANG.
+// See https://developercommunity.visualstudio.com/content/problem/139261/msvc-incorrectly-defines-cplusplus.html
+#	define CPP_VERSION __cplusplus
+#endif
+
+#if !defined(CPP_VERSION) || CPP_VERSION <= 1
+#	error "Unable to identify C++ language version"
+#endif
+
+// The template and dummy function below verifies the compiler is using at least
+// C++14. It will print an error message containing the actual C++ version if
+// the version is < 14.
+
+namespace {
+
+template<int version>
+class cpp
+{
+	static_assert(version >= 2014, "SwiftShader requires at least C++14");
+};
+
+void check_cpp_version()
+{
+	cpp<CPP_VERSION / 100>();
+	(void)&check_cpp_version;  // dummy reference to avoid unreferenced function warning.
+}
+
+}  // namespace