Fixed defines from BUILD.gn files

Rather than specifying defines using explicit commands in "cflags"
sections, all defines were moved to generic "defines" sections.

Change-Id: Ica6ee2a2447aae4f8fc6decc3a4f6b40af7ce9fd
Reviewed-on: https://swiftshader-review.googlesource.com/8948
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 57cbf33..bfd68e2 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -13,23 +13,27 @@
 # limitations under the License.
 
 config("swiftshader_config") {
+  defines = [ "STRICT_CONFORMANCE" ]  # Disables OpenGL ES 3.0
+
   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
-      "/DSTRICT_CONFORMANCE", # Disables OpenGL ES 3.0
+    ]
+
+    defines += [
+      "_CRT_SECURE_NO_DEPRECATE",
+      "NOMINMAX",
+      "_WINDLL",
     ]
 
     if (is_debug) {
       cflags += [ "/RTC1" ]  # Run-Time Error Checks
     } else {
-      cflags += [ "/DANGLE_DISABLE_TRACE" ]
+      defines += [ "ANGLE_DISABLE_TRACE" ]
     }
   } else {
     cflags = [
@@ -37,9 +41,11 @@
       "-Wall",
       "-fexceptions",
       "-fno-operator-names",
-      "-D__STDC_CONSTANT_MACROS",
-      "-D__STDC_LIMIT_MACROS",
-      "-DSTRICT_CONFORMANCE", # Disables OpenGL ES 3.0
+    ]
+
+    defines += [
+      "__STDC_CONSTANT_MACROS",
+      "__STDC_LIMIT_MACROS",
     ]
 
     if (is_debug) {
@@ -53,11 +59,14 @@
         "-ffunction-sections",
         "-fdata-sections",
         "-fomit-frame-pointer",
-        "-DANGLE_DISABLE_TRACE",
-        "-DNDEBUG",
         "-O2",
         "-Os",
       ]
+
+      defines += [
+        "ANGLE_DISABLE_TRACE",
+        "NDEBUG",
+      ]
     }
 
     if (target_cpu == "x64") {  # 64 bit version
diff --git a/src/Common/BUILD.gn b/src/Common/BUILD.gn
index 803e043..b13c4f7 100644
--- a/src/Common/BUILD.gn
+++ b/src/Common/BUILD.gn
@@ -17,10 +17,8 @@
   if (is_win) {
     cflags = [ "/wd4201" ]  # nameless struct/union
   } else {
-    cflags = [
-      "-DLOG_TAG=\"swiftshader_common\"",
-      "-msse2",
-    ]
+    cflags = [ "-msse2" ]
+    defines = [ "LOG_TAG=\"swiftshader_common\"" ]
   }
 }
 
diff --git a/src/Main/BUILD.gn b/src/Main/BUILD.gn
index 1206be3..23105e6 100644
--- a/src/Main/BUILD.gn
+++ b/src/Main/BUILD.gn
@@ -24,10 +24,8 @@
       ]
     }
   } else {
-    cflags = [
-      "-DLOG_TAG=\"swiftshader_main\"",
-      "-msse2",
-    ]
+    cflags = [ "-msse2" ]
+    defines = [ "LOG_TAG=\"swiftshader_main\"" ]
   }
 }
 
diff --git a/src/OpenGL/common/BUILD.gn b/src/OpenGL/common/BUILD.gn
index bc5ad97..03acd48 100644
--- a/src/OpenGL/common/BUILD.gn
+++ b/src/OpenGL/common/BUILD.gn
@@ -20,7 +20,7 @@
       "/wd4324",  # structure was padded due to alignment specifier
     ]
   } else {
-    cflags = [ "-DLOG_TAG=\"swiftshader_opengl_common\"" ]
+    defines = [ "LOG_TAG=\"swiftshader_opengl_common\"" ]
   }
 }
 
diff --git a/src/OpenGL/compiler/BUILD.gn b/src/OpenGL/compiler/BUILD.gn
index 881be39..0a85bbe 100644
--- a/src/OpenGL/compiler/BUILD.gn
+++ b/src/OpenGL/compiler/BUILD.gn
@@ -26,10 +26,8 @@
       cflags += [ "/wd4189" ]  # local variable is initialized but not referenced (variables only used in ASSERTS)
     }
   } else {
-    cflags = [
-      "-DLOG_TAG=\"swiftshader_opengl_compiler\"",
-      "-Wno-sign-compare",
-    ]
+    cflags = [ "-Wno-sign-compare" ]
+    defines = [ "LOG_TAG=\"swiftshader_opengl_compiler\"" ]
 
     if (!is_debug) {
       cflags += [ "-Wno-unused-variable" ]  # 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 19352c9..fadd37e 100644
--- a/src/OpenGL/compiler/preprocessor/BUILD.gn
+++ b/src/OpenGL/compiler/preprocessor/BUILD.gn
@@ -21,7 +21,7 @@
       "/wd4702",  # unreachable code (in autogenerated code)
     ]
   } else {
-    cflags = [ "-DLOG_TAG=\"swiftshader_opengl_compiler\"" ]
+    defines = [ "LOG_TAG=\"swiftshader_opengl_compiler\"" ]
   }
 }
 
diff --git a/src/OpenGL/libEGL/BUILD.gn b/src/OpenGL/libEGL/BUILD.gn
index c4fc7df..237d6b6 100644
--- a/src/OpenGL/libEGL/BUILD.gn
+++ b/src/OpenGL/libEGL/BUILD.gn
@@ -14,25 +14,26 @@
 
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_libEGL_private_config") {
+  defines = [ "EGL_EGLEXT_PROTOTYPES" ]
+
   if (is_win) {
     cflags = [
-      "/DEGLAPI=",
-      "/DEGL_EGLEXT_PROTOTYPES",
-      "/DLIBEGL_EXPORTS",
       "/wd4201",  # nameless struct/union
       "/wd4065",  # switch statement contains 'default' but no 'case' labels
     ]
-  } else {
-    cflags = [
-      "-DLOG_TAG=\"swiftshader_libEGL\"",
-      "-DEGL_EGLEXT_PROTOTYPES",
-      "-Wno-sign-compare",
+
+    defines += [
+      "EGLAPI=",
+      "LIBEGL_EXPORTS",
     ]
+  } else {
+    cflags = [ "-Wno-sign-compare" ]
+    defines += [ "LOG_TAG=\"swiftshader_libEGL\"" ]
 
     if (is_linux) {
-      cflags += [ "-DGL_APICALL=__attribute__((visibility(\"protected\")))" ]
+      defines += [ "GL_APICALL=__attribute__((visibility(\"protected\")))" ]
     } else {
-      cflags += [ "-DGL_APICALL=__attribute__((visibility(\"default\")))" ]
+      defines += [ "GL_APICALL=__attribute__((visibility(\"default\")))" ]
     }
   }
 }
diff --git a/src/OpenGL/libGLESv2/BUILD.gn b/src/OpenGL/libGLESv2/BUILD.gn
index cf9d1db..6810341 100644
--- a/src/OpenGL/libGLESv2/BUILD.gn
+++ b/src/OpenGL/libGLESv2/BUILD.gn
@@ -14,36 +14,41 @@
 
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_libGLESv2_private_config") {
+  defines = [
+    "GL_API=",
+    "GL_GLEXT_PROTOTYPES",
+  ]
+
   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
     ]
 
+    defines += [
+      "GL_APICALL=",
+      "LIBGLESV2_EXPORTS",
+    ]
+
     if (is_clang) {
-      cflags += [
-        "-D__STDC_CONSTANT_MACROS",
-        "-D__STDC_LIMIT_MACROS",
+      defines += [
+        "__STDC_CONSTANT_MACROS",
+        "__STDC_LIMIT_MACROS",
       ]
     }
   } else {
-    cflags = [
-      "-DLOG_TAG=\"swiftshader_libGLESv2\"",
-      "-D__STDC_CONSTANT_MACROS",
-      "-D__STDC_LIMIT_MACROS",
-      "-DGL_API=",
-      "-DGL_GLEXT_PROTOTYPES",
-      "-Wno-sign-compare",
+    cflags = [ "-Wno-sign-compare" ]
+
+    defines += [
+      "LOG_TAG=\"swiftshader_libGLESv2\"",
+      "__STDC_CONSTANT_MACROS",
+      "__STDC_LIMIT_MACROS",
     ]
 
     if (is_linux) {
-      cflags += [ "-DGL_APICALL=" ]
+      defines += [ "GL_APICALL=" ]
     } else {
-      cflags += [ "-DGL_APICALL=__attribute__((visibility(\"default\")))" ]
+      defines += [ "GL_APICALL=__attribute__((visibility(\"default\")))" ]
     }
   }
 }
diff --git a/src/Reactor/BUILD.gn b/src/Reactor/BUILD.gn
index 91d46b3..9495847 100644
--- a/src/Reactor/BUILD.gn
+++ b/src/Reactor/BUILD.gn
@@ -141,11 +141,14 @@
     ]
   } else {
     cflags = [
-      "-DLOG_TAG=\"swiftshader_reactor\"",
       "-Wno-unused-local-typedef",
       "-msse2",
-      "-D__STDC_CONSTANT_MACROS",
-      "-D__STDC_LIMIT_MACROS",
+    ]
+
+    defines = [
+      "LOG_TAG=\"swiftshader_reactor\"",
+      "__STDC_CONSTANT_MACROS",
+      "__STDC_LIMIT_MACROS",
     ]
   }
 }
diff --git a/src/Renderer/BUILD.gn b/src/Renderer/BUILD.gn
index 5f0d783..d53efc4 100644
--- a/src/Renderer/BUILD.gn
+++ b/src/Renderer/BUILD.gn
@@ -21,10 +21,11 @@
     ]
   } else {
     cflags = [
-      "-DLOG_TAG=\"swiftshader_renderer\"",
       "-msse2",
       "-Wno-sign-compare",
     ]
+
+    defines = [ "LOG_TAG=\"swiftshader_renderer\"" ]
   }
 }
 
diff --git a/src/Shader/BUILD.gn b/src/Shader/BUILD.gn
index ca8b7d3..9482ef6 100644
--- a/src/Shader/BUILD.gn
+++ b/src/Shader/BUILD.gn
@@ -24,7 +24,7 @@
       cflags += [ "-Wno-sign-compare" ]
     }
   } else {
-    cflags = [ "-DLOG_TAG=\"swiftshader_shader\"" ]
+    defines = [ "LOG_TAG=\"swiftshader_shader\"" ]
   }
 }
 
diff --git a/third_party/LLVM/BUILD.gn b/third_party/LLVM/BUILD.gn
index b06003d..ba33b24 100644
--- a/third_party/LLVM/BUILD.gn
+++ b/third_party/LLVM/BUILD.gn
@@ -51,8 +51,6 @@
   if (is_clang) {
     cflags += [
       "-msse2",
-      "-D__STDC_CONSTANT_MACROS",
-      "-D__STDC_LIMIT_MACROS",
       "-Wno-unused-local-typedef",
       "-Wno-unused-private-field",
       "-Wno-null-dereference",
@@ -62,6 +60,11 @@
       "-Wno-unused-variable",
       "-Wno-unused-result",
     ]
+
+    defines = [
+      "__STDC_CONSTANT_MACROS",
+      "__STDC_LIMIT_MACROS",
+    ]
   }
 }