Simplify fuzzer targets to ease adding additional targets

BUG=tint:199

Change-Id: Ic42c8e5ea03f012e2be8e9bdbf46490bdc0048a9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/26120
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index 21da911..22c9cb1 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1157,16 +1157,16 @@
 if (build_with_chromium) {
   import("//testing/libfuzzer/fuzzer_test.gni")
 
-  source_set("tint_wgsl_reader_fuzzer_src") {
+  fuzzer_test("tint_wgsl_reader_fuzzer") {
     sources = [ "fuzzers/tint_wgsl_reader_fuzzer.cc" ]
+
     configs += [ ":tint_common_config" ]
     public_configs = [ ":tint_public_config" ]
-    deps = [ ":libtint_wgsl_reader_src" ]
-  }
 
-  fuzzer_test("tint_wgsl_reader_fuzzer") {
-    sources = []
-    deps = [ ":tint_wgsl_reader_fuzzer_src" ]
+    deps = [
+      ":libtint_wgsl_reader_src",
+      ":tint_wgsl_reader_fuzzer_src",
+    ]
   }
 }
 
diff --git a/fuzzers/CMakeLists.txt b/fuzzers/CMakeLists.txt
index 86f8a64..2f0c7d5 100644
--- a/fuzzers/CMakeLists.txt
+++ b/fuzzers/CMakeLists.txt
@@ -12,11 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# TODO(rharrison): Make a generic fuzzer target template once we have more
-#                  fuzzers.
-
-if ({TINT_BUILD_WGSL_READER})
-  add_executable(tint_wgsl_reader_fuzzer tint_wgsl_reader_fuzzer.cc)
+function(add_tint_fuzzer NAME)
+  add_executable(${NAME} ${NAME}.cc)
   target_link_libraries(tint_fuzz libtint)
   tint_default_compile_options(tint_fuzz)
   target_link_options(tint_fuzz PRIVATE
@@ -27,8 +24,12 @@
     -g
   )
 
-  target_compile_options(tint_wgsl_reader_fuzzer PRIVATE
+  target_compile_options(${NAME} PRIVATE
     -fsanitize=fuzzer,address,undefined
     -Wno-missing-prototypes
   )
+endfunction()
+
+if ({TINT_BUILD_WGSL_READER})
+  add_tint_fuzzer(tint_wgsl_reader_fuzzer)
 endif()