pw_presubmit: Add GCC CMake "step"

This step does not yet pass.

Change-Id: Ie4fcdc9829c1217779ed48ce7b0f79ecc292f950
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/79240
Reviewed-by: Ewout van Bekkum <ewout@google.com>
Commit-Queue: Rob Mohr <mohrr@google.com>
diff --git a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
index a8dbe93..8a1ebc1 100755
--- a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
+++ b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
@@ -269,26 +269,44 @@
     build.ninja(ctx.output_dir, "fuzzers")
 
 
-def _run_cmake(ctx: PresubmitContext) -> None:
+def _run_cmake(ctx: PresubmitContext, toolchain='host_clang') -> None:
     build.install_package(ctx.package_root, 'nanopb')
 
-    toolchain = ctx.root / 'pw_toolchain' / 'host_clang' / 'toolchain.cmake'
+    env = None
+    if 'clang' in toolchain:
+        env = build.env_with_clang_vars()
+
+    toolchain_path = ctx.root / 'pw_toolchain' / toolchain / 'toolchain.cmake'
     build.cmake(ctx.root,
                 ctx.output_dir,
-                f'-DCMAKE_TOOLCHAIN_FILE={toolchain}',
+                f'-DCMAKE_TOOLCHAIN_FILE={toolchain_path}',
                 '-DCMAKE_EXPORT_COMPILE_COMMANDS=1',
                 f'-Ddir_pw_third_party_nanopb={ctx.package_root / "nanopb"}',
                 '-Dpw_third_party_nanopb_ADD_SUBDIRECTORY=ON',
-                env=build.env_with_clang_vars())
+                env=env)
 
 
 @filter_paths(endswith=(*format_code.C_FORMAT.extensions, '.cmake',
                         'CMakeLists.txt'))
-def cmake_tests(ctx: PresubmitContext):
-    _run_cmake(ctx)
+def cmake_clang(ctx: PresubmitContext):
+    _run_cmake(ctx, toolchain='host_clang')
     build.ninja(ctx.output_dir, 'pw_apps', 'pw_run_tests.modules')
 
 
+@filter_paths(endswith=(*format_code.C_FORMAT.extensions, '.cmake',
+                        'CMakeLists.txt'))
+def cmake_gcc(ctx: PresubmitContext):
+    _run_cmake(ctx, toolchain='host_gcc')
+    build.ninja(ctx.output_dir, 'pw_apps', 'pw_run_tests.modules')
+
+
+# TODO(mohrr) Remove after removing from LUCI config.
+@filter_paths(endswith=(*format_code.C_FORMAT.extensions, '.cmake',
+                        'CMakeLists.txt'))
+def cmake_tests(ctx: PresubmitContext):
+    cmake_clang(ctx)
+
+
 # TODO(pwbug/180): Slowly add modules here that work with bazel until all
 # modules are added. Then replace with //...
 _MODULES_THAT_BUILD_WITH_BAZEL = [
@@ -741,6 +759,8 @@
     oss_fuzz_build,
     # TODO(pwbug/346): Enable all Bazel tests when they're fixed.
     bazel_test,
+    cmake_clang,
+    cmake_gcc,
     cmake_tests,
     gn_boringssl_build,
     build.gn_gen_check,
@@ -781,7 +801,7 @@
     # TODO(pwbug/141): Re-enable CMake and Bazel for Mac after we have fixed the
     # the clang issues. The problem is that all clang++ invocations need the
     # two extra flags: "-nostdc++" and "${clang_prefix}/../lib/libc++.a".
-    cmake_tests if sys.platform != 'darwin' else (),
+    cmake_clang if sys.platform != 'darwin' else (),
 )
 
 FULL = (