Build tweaks for C files

- Use the full file name for object files in the GN build, e.g.
  file.cc.o instead of file.o. This allows having .cc and .c files with
  the same name.
- Have the pw_auto_add_simple_module CMake function build .c and .cc
  test files together.

Change-Id: I3086a96bcc55b013db4f2c278418c17ce1b9fd82
diff --git a/pw_build/pigweed.cmake b/pw_build/pigweed.cmake
index b238184..e7c8315 100644
--- a/pw_build/pigweed.cmake
+++ b/pw_build/pigweed.cmake
@@ -24,8 +24,10 @@
 #
 #  - The module exposes exactly one library.
 #  - All source files in the module directory are included in the library.
-#  - Each test in the module has exactly one source file and only depends on the
-#    module library.
+#  - Each test in the module has
+#    - exactly one source .cc file,
+#    - optionally, one .c source with the same base name as the .cc file,
+#    - only a dependency on the main module library.
 #  - The module is not a facade.
 #
 # Modules that do not meet these requirements may not use
@@ -78,9 +80,14 @@
 
   foreach(test IN LISTS tests)
     get_filename_component(test_name "${test}" NAME_WE)
+
+    # Find a .c test corresponding with the test .cc file, if any.
+    list(FILTER c_test INCLUDE REGEX "^${test_name}.c$")
+
     pw_add_test("${MODULE}.${test_name}"
       SOURCES
         "${test}"
+        ${c_test}
       DEPS
         "${MODULE}"
       GROUPS
diff --git a/pw_toolchain/arm_gcc.gni b/pw_toolchain/arm_gcc.gni
index a19e2aa..0a1631e 100644
--- a/pw_toolchain/arm_gcc.gni
+++ b/pw_toolchain/arm_gcc.gni
@@ -75,7 +75,10 @@
       depsformat = "gcc"
       description = "as {{output}}"
       outputs = [
-        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
+        # Use {{source_file_part}}, which includes the extension, instead of
+        # {{source_name_part}} so that object files created from <file_name>.c
+        # and <file_name>.cc sources are unique.
+        "{{source_out_dir}}/{{target_output_name}}.{{source_file_part}}.o",
       ]
     }
 
@@ -96,7 +99,7 @@
       depsformat = "gcc"
       description = "cc {{output}}"
       outputs = [
-        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
+        "{{source_out_dir}}/{{target_output_name}}.{{source_file_part}}.o",
       ]
     }
 
@@ -117,7 +120,7 @@
       depsformat = "gcc"
       description = "c++ {{output}}"
       outputs = [
-        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
+        "{{source_out_dir}}/{{target_output_name}}.{{source_file_part}}.o",
       ]
     }
 
diff --git a/pw_toolchain/host_clang.gni b/pw_toolchain/host_clang.gni
index 70aeec2..65143fe 100644
--- a/pw_toolchain/host_clang.gni
+++ b/pw_toolchain/host_clang.gni
@@ -69,7 +69,10 @@
       depsformat = "gcc"
       description = "as {{output}}"
       outputs = [
-        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
+        # Use {{source_file_part}}, which includes the extension, instead of
+        # {{source_name_part}} so that object files created from <file_name>.c
+        # and <file_name>.cc sources are unique.
+        "{{source_out_dir}}/{{target_output_name}}.{{source_file_part}}.o",
       ]
     }
 
@@ -90,7 +93,7 @@
       depsformat = "gcc"
       description = "cc {{output}}"
       outputs = [
-        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
+        "{{source_out_dir}}/{{target_output_name}}.{{source_file_part}}.o",
       ]
     }
 
@@ -111,7 +114,7 @@
       depsformat = "gcc"
       description = "c++ {{output}}"
       outputs = [
-        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
+        "{{source_out_dir}}/{{target_output_name}}.{{source_file_part}}.o",
       ]
     }
 
diff --git a/pw_toolchain/host_gcc.gni b/pw_toolchain/host_gcc.gni
index 20c86ae..d581399 100644
--- a/pw_toolchain/host_gcc.gni
+++ b/pw_toolchain/host_gcc.gni
@@ -62,7 +62,10 @@
       depsformat = "gcc"
       description = "as {{output}}"
       outputs = [
-        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
+        # Use {{source_file_part}}, which includes the extension, instead of
+        # {{source_name_part}} so that object files created from <file_name>.c
+        # and <file_name>.cc sources are unique.
+        "{{source_out_dir}}/{{target_output_name}}.{{source_file_part}}.o",
       ]
     }
 
@@ -72,7 +75,7 @@
       depsformat = "gcc"
       description = "cc {{output}}"
       outputs = [
-        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
+        "{{source_out_dir}}/{{target_output_name}}.{{source_file_part}}.o",
       ]
     }
 
@@ -82,7 +85,7 @@
       depsformat = "gcc"
       description = "c++ {{output}}"
       outputs = [
-        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
+        "{{source_out_dir}}/{{target_output_name}}.{{source_file_part}}.o",
       ]
     }