Split examples, test and utils in their own BUILD.gn

The basic change was to copy-paste targets in the new BUILD.gn files and
fixup paths / add includes. There's a couple more changes that had to be
done at the same time:

 - Multiple files need to know if GLFW is supported so the variable was
moved to dawn_features.gni.
 - The gtest_and_gmock target used to abstract between Dawn's copy of
GTest/GMock is only needed by tests and was moved in src/tests/BUILD.gn.
 - A leftover dawn_end2end_tests target is left in the main BUILD.gn
file that is an exact copy of the on in src/tests/BUILD.gn. This is
because the GN path is hardcoded in Chromium's isolate_map.pyl that also
can't support GN groups. The only way to move a target I could figure
out was to duplicate it temporarily.

Bug: chromium:1064305
Change-Id: I96820e9d6510b8c9b9112c3e6cd8df2413f04287
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/19201
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
diff --git a/examples/BUILD.gn b/examples/BUILD.gn
new file mode 100644
index 0000000..f14be6e
--- /dev/null
+++ b/examples/BUILD.gn
@@ -0,0 +1,103 @@
+# Copyright 2020 The Dawn Authors
+#
+# 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.
+
+import("../scripts/dawn_overrides_with_defaults.gni")
+
+group("dawn_samples") {
+  deps = [
+    ":Animometer",
+    ":CHelloTriangle",
+    ":ComputeBoids",
+    ":CppHelloTriangle",
+    ":CubeReflection",
+    ":ManualSwapChainTest",
+  ]
+}
+
+# Static library to contain code and dependencies common to all samples
+static_library("dawn_sample_utils") {
+  sources = [
+    "SampleUtils.cpp",
+    "SampleUtils.h",
+  ]
+
+  # Export all of these as public deps so that `gn check` allows includes
+  public_deps = [
+    "${dawn_root}/src/common",
+    "${dawn_root}/src/dawn:dawncpp",
+    "${dawn_root}/src/dawn:libdawn_proc",
+    "${dawn_root}/src/dawn_native",
+    "${dawn_root}/src/dawn_wire",
+    "${dawn_root}/src/utils:dawn_bindings",
+    "${dawn_root}/src/utils:dawn_glfw",
+    "${dawn_root}/src/utils:dawn_utils",
+  ]
+  public_configs = [ "${dawn_root}/src/common:dawn_internal" ]
+}
+
+# Template for samples to avoid listing dawn_sample_utils as a dep every time
+template("dawn_sample") {
+  executable(target_name) {
+    deps = [
+      ":dawn_sample_utils",
+    ]
+    forward_variables_from(invoker, "*", [ "deps" ])
+
+    if (defined(invoker.deps)) {
+      deps += invoker.deps
+    }
+  }
+}
+
+dawn_sample("CppHelloTriangle") {
+  sources = [
+    "CppHelloTriangle.cpp",
+  ]
+}
+
+dawn_sample("CHelloTriangle") {
+  sources = [
+    "CHelloTriangle.cpp",
+  ]
+}
+
+dawn_sample("ComputeBoids") {
+  sources = [
+    "ComputeBoids.cpp",
+  ]
+  deps = [
+    "${dawn_root}/third_party:glm",
+  ]
+}
+
+dawn_sample("Animometer") {
+  sources = [
+    "Animometer.cpp",
+  ]
+}
+
+dawn_sample("CubeReflection") {
+  sources = [
+    "CubeReflection.cpp",
+  ]
+  deps = [
+    "${dawn_root}/third_party:glm",
+  ]
+}
+
+dawn_sample("ManualSwapChainTest") {
+  sources = [
+    "ManualSwapChainTest.cpp",
+  ]
+}