Refactor the CMake scripts.

Change-Id: Ib5df245afaa639be21eae1df579dda1e66aa73ee
Reviewed-on: https://code-review.googlesource.com/c/37953
Reviewed-by: Paul Wankadia <[email protected]>
diff --git a/kokoro/cmake.sh b/kokoro/cmake.sh
new file mode 100755
index 0000000..0cb79f5
--- /dev/null
+++ b/kokoro/cmake.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+set -eux
+
+cd git/re2
+
+case "${KOKORO_JOB_NAME}" in
+  */windows-*)
+    CMAKE_G_A_FLAGS=('-G' 'Visual Studio 14 2015' '-A' 'x64')
+    ;;
+  *)
+    CMAKE_G_A_FLAGS=()
+    ;;
+esac
+
+cmake -D CMAKE_BUILD_TYPE=Debug "${CMAKE_G_A_FLAGS[@]}" .
+cmake --build . --config Debug --clean-first
+ctest -C Debug --output-on-failure -E 'dfa|exhaustive|random'
+
+cmake -D CMAKE_BUILD_TYPE=Release "${CMAKE_G_A_FLAGS[@]}" .
+cmake --build . --config Release --clean-first
+ctest -C Release --output-on-failure -E 'dfa|exhaustive|random'
+
+exit 0
diff --git a/kokoro/macos-cmake.sh b/kokoro/macos-cmake.sh
index a87931f..ef4b7dc 100755
--- a/kokoro/macos-cmake.sh
+++ b/kokoro/macos-cmake.sh
@@ -1,14 +1,4 @@
 #!/bin/bash
 set -eux
-
-cd git/re2
-
-cmake -D CMAKE_BUILD_TYPE=Debug .
-cmake --build . --config Debug --clean-first
-ctest -C Debug --output-on-failure -E 'dfa|exhaustive|random'
-
-cmake -D CMAKE_BUILD_TYPE=Release .
-cmake --build . --config Release --clean-first
-ctest -C Release --output-on-failure -E 'dfa|exhaustive|random'
-
-exit 0
+bash git/re2/kokoro/cmake.sh
+exit $?
diff --git a/kokoro/windows-cmake.bat b/kokoro/windows-cmake.bat
index 90363bc..77a4db9 100755
--- a/kokoro/windows-cmake.bat
+++ b/kokoro/windows-cmake.bat
@@ -1,2 +1,2 @@
-bash git/re2/kokoro/windows-cmake.sh
+bash git/re2/kokoro/cmake.sh
 EXIT /B %ERRORLEVEL%
diff --git a/kokoro/windows-cmake.sh b/kokoro/windows-cmake.sh
deleted file mode 100755
index f43b2b3..0000000
--- a/kokoro/windows-cmake.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/bash
-set -eux
-
-cd git/re2
-
-cmake -D CMAKE_BUILD_TYPE=Debug -G 'Visual Studio 14 2015' -A x64 .
-cmake --build . --config Debug --clean-first
-ctest -C Debug --output-on-failure -E 'dfa|exhaustive|random'
-
-cmake -D CMAKE_BUILD_TYPE=Release -G 'Visual Studio 14 2015' -A x64 .
-cmake --build . --config Release --clean-first
-ctest -C Release --output-on-failure -E 'dfa|exhaustive|random'
-
-exit 0