Move compiler platform flags into src/cmake/DawnCompilerPlatformFlags cmake module

Change-Id: Ia749c5e0cf54b244445b58362ef1ac306290b242
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/194907
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Jaswant Panchumarti <jaswant.panchumarti@kitware.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jaswant Panchumarti <jaswant.panchumarti@kitware.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d006d49..36b2d1b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -272,6 +272,7 @@
 # Include utility CMake modules
 ################################################################################
 include(DawnCompilerExtraFlags)
+include(DawnCompilerPlatformFlags)
 
 message(STATUS "Dawn build D3D11 backend: ${DAWN_ENABLE_D3D11}")
 message(STATUS "Dawn build D3D12 backend: ${DAWN_ENABLE_D3D12}")
@@ -402,40 +403,6 @@
 set(TINT_SPIRV_HEADERS_DIR ${DAWN_SPIRV_HEADERS_DIR})
 set(TINT_SPIRV_TOOLS_DIR   ${DAWN_SPIRV_TOOLS_DIR})
 
-# CMake < 3.15 sets /W3 in CMAKE_CXX_FLAGS. Remove it if it's there.
-# See https://gitlab.kitware.com/cmake/cmake/-/issues/18317
-if (MSVC)
-  if (CMAKE_CXX_FLAGS MATCHES "/W3")
-    string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
-  endif()
-endif()
-
-if (${TINT_CHECK_CHROMIUM_STYLE})
-   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -add-plugin -Xclang find-bad-constructs")
-endif()
-
-if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC"))
-  set(COMPILER_IS_CLANG_CL TRUE)
-endif()
-
-if((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR
-    ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND
-     (NOT COMPILER_IS_CLANG_CL)))
-  set(COMPILER_IS_CLANG TRUE)
-endif()
-
-if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
-  set(COMPILER_IS_GNU TRUE)
-endif()
-
-if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR COMPILER_IS_CLANG)
-  set(COMPILER_IS_LIKE_GNU TRUE)
-endif()
-
-# Enable msbuild multiprocessor builds
-if (MSVC AND NOT COMPILER_IS_CLANG_CL)
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
-endif()
 
 ################################################################################
 # Run on all subdirectories
diff --git a/src/cmake/DawnCompilerPlatformFlags.cmake b/src/cmake/DawnCompilerPlatformFlags.cmake
new file mode 100644
index 0000000..efa4271
--- /dev/null
+++ b/src/cmake/DawnCompilerPlatformFlags.cmake
@@ -0,0 +1,65 @@
+# Copyright 2024 The Dawn & Tint Authors
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this
+#    list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+#    this list of conditions and the following disclaimer in the documentation
+#    and/or other materials provided with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its
+#    contributors may be used to endorse or promote products derived from
+#    this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# CMake < 3.15 sets /W3 in CMAKE_CXX_FLAGS. Remove it if it's there.
+# See https://gitlab.kitware.com/cmake/cmake/-/issues/18317
+if (CMAKE_VERSION VERSION_LESS 3.15.0)
+  if (MSVC)
+    if (CMAKE_CXX_FLAGS MATCHES "/W3")
+      string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+    endif ()
+  endif ()
+endif ()
+
+if (TINT_CHECK_CHROMIUM_STYLE)
+  set(CMAKE_CXX_FLAGS
+    "${CMAKE_CXX_FLAGS} -Xclang -add-plugin -Xclang find-bad-constructs")
+endif ()
+
+if ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+    AND (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC"))
+  set(COMPILER_IS_CLANG_CL TRUE)
+endif ()
+
+if ((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR
+    ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND
+     (NOT COMPILER_IS_CLANG_CL)))
+  set(COMPILER_IS_CLANG TRUE)
+endif ()
+
+if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+  set(COMPILER_IS_GNU TRUE)
+endif ()
+
+if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR COMPILER_IS_CLANG)
+  set(COMPILER_IS_LIKE_GNU TRUE)
+endif ()
+
+# Enable msbuild multiprocessor builds
+if (MSVC AND NOT COMPILER_IS_CLANG_CL)
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
+endif ()