Fixed build files for Windows clang

Made Windows files work for Windows clang.
Verified on Linux and Windows Visual Studio
compiler to make sure nothing was broken.

Change-Id: I82815491579cdfca602660279f6831c8820249f6
Reviewed-on: https://swiftshader-review.googlesource.com/7052
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Corentin Wallez <cwallez@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 97f37ec..7e4cef7 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -13,7 +13,28 @@
 # limitations under the License.
 
 config("swiftshader_config") {
-  if (is_clang) {
+  if (is_win) {
+    cflags = [
+      "/GS", # Detects some buffer overruns
+      "/Zc:wchar_t",
+      "/D_CRT_SECURE_NO_DEPRECATE",
+      "/DNOMINMAX",
+      "/D_WINDLL",
+      "/EHsc",
+      "/nologo",
+      "/Gd", # Default calling convention
+    ]
+
+    if (is_debug) {
+      cflags += [
+        "/RTC1", # Run-Time Error Checks
+      ]
+    } else {
+      cflags += [
+        "/DANGLE_DISABLE_TRACE",
+      ]
+    }
+  } else {
     cflags = [
       "-std=c++11",
     ]
@@ -53,29 +74,6 @@
         "-m32",
       ]
     }
-  } else {
-    if (host_os == "win") {
-      cflags = [
-        "/GS", # Detects some buffer overruns
-        "/Zc:wchar_t",
-        "/D_CRT_SECURE_NO_DEPRECATE",
-        "/DNOMINMAX",
-        "/D_WINDLL",
-        "/EHsc",
-        "/nologo",
-        "/Gd", # Default calling convention
-      ]
-
-      if (is_debug) {
-        cflags += [
-          "/RTC1", # Run-Time Error Checks
-        ]
-      } else {
-        cflags += [
-          "/DANGLE_DISABLE_TRACE",
-        ]
-      }
-    }
   }
 }
 
diff --git a/src/Common/BUILD.gn b/src/Common/BUILD.gn
index c68e9da..96c73f8 100644
--- a/src/Common/BUILD.gn
+++ b/src/Common/BUILD.gn
@@ -14,17 +14,15 @@
 
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_common_private_config") {
-  if (is_clang) {
+  if (is_win) {
+    cflags = [
+      "/wd4201", # nameless struct/union
+    ]
+  } else {
     cflags = [
       "-DLOG_TAG=\"swiftshader_common\"",
       "-msse2",
     ]
-  } else {
-    if (host_os == "win") {
-      cflags = [
-        "/wd4201", # nameless struct/union
-      ]
-    }
   }
 }
 
diff --git a/src/Main/BUILD.gn b/src/Main/BUILD.gn
index 361ae54..849f49e 100644
--- a/src/Main/BUILD.gn
+++ b/src/Main/BUILD.gn
@@ -14,17 +14,23 @@
 
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_main_private_config") {
-  if (is_clang) {
+  if (is_win) {
+    cflags = [
+      "/wd4201", # nameless struct/union
+    ]
+
+    if (is_clang) {
+      cflags += [
+        "-Wno-overloaded-virtual",
+        "-Wno-string-conversion",
+        "-Wno-sign-compare",
+      ]
+    }
+  } else {
     cflags = [
       "-DLOG_TAG=\"swiftshader_main\"",
       "-msse2",
     ]
-  } else {
-    if (host_os == "win") {
-      cflags = [
-        "/wd4201", # nameless struct/union
-      ]
-    }
   }
 }
 
diff --git a/src/OpenGL/common/BUILD.gn b/src/OpenGL/common/BUILD.gn
index 97e2f05..bf80c44 100644
--- a/src/OpenGL/common/BUILD.gn
+++ b/src/OpenGL/common/BUILD.gn
@@ -14,17 +14,21 @@
 
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_opengl_common_private_config") {
-  if (is_clang) {
+  if (is_win) {
+    cflags = [
+      "/wd4201", # nameless struct/union
+      "/wd4324", # structure was padded due to alignment specifier
+    ]
+
+    if (is_clang) {
+      cflags += [
+        "-Wno-delete-incomplete",
+      ]
+    }
+  } else {
     cflags = [
       "-DLOG_TAG=\"swiftshader_opengl_common\"",
     ]
-  } else {
-    if (host_os == "win") {
-      cflags = [
-        "/wd4201", # nameless struct/union
-        "/wd4324", # structure was padded due to alignment specifier
-      ]
-    }
   }
 }
 
diff --git a/src/OpenGL/compiler/BUILD.gn b/src/OpenGL/compiler/BUILD.gn
index 0f958d3..89e54e3 100644
--- a/src/OpenGL/compiler/BUILD.gn
+++ b/src/OpenGL/compiler/BUILD.gn
@@ -14,7 +14,27 @@
 
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_opengl_compiler_private_config") {
-  if (is_clang) {
+  if (is_win) {
+    cflags = [
+      "/wd4005", # macro redefinition (in autogenerated code)
+      "/wd4201", # nameless struct/union
+      "/wd4267", # conversion from size_t to int/unsigned int
+      "/wd4702", # unreachable code (in autogenerated code)
+    ]
+
+    if (!is_debug) {
+      cflags += [
+        "/wd4189", # local variable is initialized but not referenced (variables only used in ASSERTS)
+      ]
+    }
+
+    if (is_clang) {
+      cflags += [
+        "-Wno-unused-function",
+        "-Wno-unused-variable",
+      ]
+    }
+  } else {
     cflags = [
       "-DLOG_TAG=\"swiftshader_opengl_compiler\"",
       "-Wno-sign-compare",
@@ -25,21 +45,6 @@
         "-Wno-unused-variable", # local variable is initialized but not referenced (variables only used in ASSERTS)
       ]
     }
-  } else {
-    if (host_os == "win") {
-      cflags = [
-        "/wd4005", # macro redefinition (in autogenerated code)
-        "/wd4201", # nameless struct/union
-        "/wd4267", # conversion from size_t to int/unsigned int
-        "/wd4702", # unreachable code (in autogenerated code)
-      ]
-
-      if (!is_debug) {
-        cflags += [
-          "/wd4189", # local variable is initialized but not referenced (variables only used in ASSERTS)
-        ]
-      }
-    }
   }
 }
 
diff --git a/src/OpenGL/compiler/preprocessor/BUILD.gn b/src/OpenGL/compiler/preprocessor/BUILD.gn
index 71ba50d..c0fe53b 100644
--- a/src/OpenGL/compiler/preprocessor/BUILD.gn
+++ b/src/OpenGL/compiler/preprocessor/BUILD.gn
@@ -14,18 +14,16 @@
 
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_opengl_preprocessor_private_config") {
-  if (is_clang) {
+  if (is_win) {
+    cflags = [
+      "/wd4005", # macro redefinition (in autogenerated code)
+      "/wd4267", # conversion from size_t to int/unsigned int (in autogenerated code)
+      "/wd4702", # unreachable code (in autogenerated code)
+    ]
+  } else {
     cflags = [
       "-DLOG_TAG=\"swiftshader_opengl_compiler\"",
     ]
-  } else {
-    if (host_os == "win") {
-      cflags = [
-        "/wd4005", # macro redefinition (in autogenerated code)
-        "/wd4267", # conversion from size_t to int/unsigned int (in autogenerated code)
-        "/wd4702", # unreachable code (in autogenerated code)
-      ]
-    }
   }
 }
 
diff --git a/src/OpenGL/libEGL/BUILD.gn b/src/OpenGL/libEGL/BUILD.gn
index 485cda9..35692bb 100644
--- a/src/OpenGL/libEGL/BUILD.gn
+++ b/src/OpenGL/libEGL/BUILD.gn
@@ -14,23 +14,27 @@
 
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_libEGL_private_config") {
-  if (is_clang) {
+  if (is_win) {
+    cflags = [
+      "/DEGLAPI=",
+      "/DEGL_EGLEXT_PROTOTYPES",
+      "/DLIBEGL_EXPORTS",
+      "/wd4201", # nameless struct/union
+      "/wd4065", # switch statement contains 'default' but no 'case' labels
+    ]
+
+    if (is_clang) {
+      cflags += [
+        "-Wno-unused-function",
+      ]
+    }
+  } else {
     cflags = [
       "-DLOG_TAG=\"swiftshader_libEGL\"",
       "-DEGLAPI=",
       "-DEGL_EGLEXT_PROTOTYPES",
       "-Wno-sign-compare",
     ]
-  } else {
-    if (host_os == "win") {
-      cflags = [
-        "/DEGLAPI=",
-        "/DEGL_EGLEXT_PROTOTYPES",
-        "/DLIBEGL_EXPORTS",
-        "/wd4201", # nameless struct/union
-        "/wd4065", # switch statement contains 'default' but no 'case' labels
-      ]
-    }
   }
 }
 
diff --git a/src/OpenGL/libGLESv2/BUILD.gn b/src/OpenGL/libGLESv2/BUILD.gn
index 5d3455d..a7c9a3b 100644
--- a/src/OpenGL/libGLESv2/BUILD.gn
+++ b/src/OpenGL/libGLESv2/BUILD.gn
@@ -14,10 +14,27 @@
 
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_libGLESv2_private_config") {
-  if (is_clang) {
+  if (is_win) {
+    cflags = [
+      "/DGL_API=",
+      "/DGL_APICALL=",
+      "/DGL_GLEXT_PROTOTYPES",
+      "/DLIBGLESV2_EXPORTS",
+      "/wd4201", # nameless struct/union
+      "/wd4324", # structure was padded due to alignment specifier
+    ]
+
+    if (is_clang)
+    {
+      cflags += [
+        "-Wno-delete-incomplete",
+        "-D__STDC_CONSTANT_MACROS",
+        "-D__STDC_LIMIT_MACROS",
+      ]
+    }
+  } else {
     cflags = [
       "-DLOG_TAG=\"swiftshader_libGLESv2\"",
-      "-fno-operator-names",
       "-D__STDC_CONSTANT_MACROS",
       "-D__STDC_LIMIT_MACROS",
       "-DGL_API=",
@@ -25,17 +42,6 @@
       "-DGL_GLEXT_PROTOTYPES",
       "-Wno-sign-compare",
     ]
-  } else {
-    if (host_os == "win") {
-      cflags = [
-        "/DGL_API=",
-        "/DGL_APICALL=",
-        "/DGL_GLEXT_PROTOTYPES",
-        "/DLIBGLESV2_EXPORTS",
-        "/wd4201", # nameless struct/union
-        "/wd4324", # structure was padded due to alignment specifier
-      ]
-    }
   }
 }
 
diff --git a/src/Reactor/BUILD.gn b/src/Reactor/BUILD.gn
index 86132fe..d6cb5c9 100644
--- a/src/Reactor/BUILD.gn
+++ b/src/Reactor/BUILD.gn
@@ -14,7 +14,18 @@
 
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_reactor_private_config") {
-  if (is_clang) {
+  if (is_win) {
+    cflags = [
+      "/wd4201", # nameless struct/union
+      "/wd4245", # conversion from int to unsigned int (llvm)
+    ]
+
+    if (is_clang) {
+      cflags += [
+        "-Wno-delete-incomplete",
+      ]
+    }
+  } else {
     cflags = [
       "-DLOG_TAG=\"swiftshader_reactor\"",
       "-Wno-unused-local-typedef",
@@ -22,13 +33,6 @@
       "-D__STDC_CONSTANT_MACROS",
       "-D__STDC_LIMIT_MACROS",
     ]
-  } else {
-    if (host_os == "win") {
-      cflags = [
-        "/wd4201", # nameless struct/union
-        "/wd4245", # conversion from int to unsigned int (llvm)
-      ]
-    }
   }
 }
 
diff --git a/src/Renderer/BUILD.gn b/src/Renderer/BUILD.gn
index 86e581a..cec4b3b 100644
--- a/src/Renderer/BUILD.gn
+++ b/src/Renderer/BUILD.gn
@@ -14,20 +14,24 @@
 
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_renderer_private_config") {
-  if (is_clang) {
+  if (is_win) {
+    cflags = [
+      "/wd4201", # nameless struct/union
+      "/wd4324", # structure was padded due to alignment specifier
+    ]
+
+    if (is_clang) {
+      cflags += [
+        "-Wno-delete-incomplete",
+        "-Wno-microsoft-template",
+      ]
+    }
+  } else {
     cflags = [
       "-DLOG_TAG=\"swiftshader_renderer\"",
-      "-fno-operator-names",
       "-msse2",
       "-Wno-sign-compare",
     ]
-  } else {
-    if (host_os == "win") {
-      cflags = [
-        "/wd4201", # nameless struct/union
-        "/wd4324", # structure was padded due to alignment specifier
-      ]
-    }
   }
 }
 
diff --git a/src/Shader/BUILD.gn b/src/Shader/BUILD.gn
index 7d15f85..288fe9c 100644
--- a/src/Shader/BUILD.gn
+++ b/src/Shader/BUILD.gn
@@ -14,18 +14,22 @@
 
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_shader_private_config") {
-  if (is_clang) {
+  if (is_win) {
     cflags = [
-      "-DLOG_TAG=\"swiftshader_shader\"",
-      "-fno-operator-names",
+      "/wd4201", # nameless struct/union
+      "/wd4324", # structure was padded due to alignment specifier
     ]
-  } else {
-    if (host_os == "win") {
-      cflags = [
-        "/wd4201", # nameless struct/union
-        "/wd4324", # structure was padded due to alignment specifier
+
+    if (is_clang) {
+      cflags += [
+        "-Wno-sign-compare",
+        "-Wno-delete-incomplete",
       ]
     }
+  } else {
+    cflags = [
+      "-DLOG_TAG=\"swiftshader_shader\"",
+    ]
   }
 }
 
diff --git a/third_party/LLVM/BUILD.gn b/third_party/LLVM/BUILD.gn
index eac83d4..761f6c8 100644
--- a/third_party/LLVM/BUILD.gn
+++ b/third_party/LLVM/BUILD.gn
@@ -14,9 +14,44 @@
 
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_llvm_private_config") {
+  cflags = []
+
+  if (is_win) {
+    cflags += [
+      "/wd4005",
+      "/wd4065",
+      "/wd4146",
+      "/wd4245",
+      "/wd4267",
+      "/wd4310",
+      "/wd4319",
+      "/wd4334",
+      "/wd4389",
+      "/wd4624",
+      "/wd4701",
+      "/wd4702",
+      "/wd4703",
+      "/wd4706",
+      "/wd4800",
+    ]
+
+    if (!is_debug) {
+      cflags += [
+        "/wd4324",
+      ]
+    }
+
+    if (is_clang) {
+      cflags += [
+        "-Wno-format",
+        "-Wno-sign-compare",
+        "-Wno-macro-redefined",
+      ]
+    }
+  }
+
   if (is_clang) {
-    cflags = [
-      "-fno-operator-names",
+    cflags += [
       "-msse2",
       "-D__STDC_CONSTANT_MACROS",
       "-D__STDC_LIMIT_MACROS",
@@ -28,32 +63,6 @@
       "-Wno-deprecated-declarations",
       "-Wno-unused-variable",
     ]
-  } else {
-    if (host_os == "win") {
-      cflags = [
-        "/wd4005",
-        "/wd4065",
-        "/wd4146",
-        "/wd4245",
-        "/wd4267",
-        "/wd4310",
-        "/wd4319",
-        "/wd4334",
-        "/wd4389",
-        "/wd4624",
-        "/wd4701",
-        "/wd4702",
-        "/wd4703",
-        "/wd4706",
-        "/wd4800",
-      ]
-
-      if (!is_debug) {
-        cflags += [
-          "/wd4324",
-        ]
-      }
-    }
   }
 }