GN files, initial check in

First version of Chromium build files for SwiftShader.
Works for Linux only at this point.
Other platforms are there, but untested at the moment.

Change-Id: I8f389db9937feda74c7009cf7a22938dab9e69d5
Reviewed-on: https://swiftshader-review.googlesource.com/5520
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/Common/BUILD.gn b/src/Common/BUILD.gn
new file mode 100644
index 0000000..71ccbb9
--- /dev/null
+++ b/src/Common/BUILD.gn
@@ -0,0 +1,49 @@
+# Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Need a separate config to ensure the warnings are added to the end.
+config("swiftshader_common_private_config") {
+  if (is_clang) {
+    cflags = [
+      "-DLOG_TAG=\"swiftshader_common\"",
+      "-msse2",
+    ]
+
+    if (!is_debug) {
+      cflags += [
+        "-DNDEBUG",
+        "-DANGLE_DISABLE_TRACE",
+      ]
+    }
+  }
+}
+
+source_set("swiftshader_common") {
+  sources = [
+    "CPUID.cpp",
+    "Configurator.cpp",
+    "Debug.cpp",
+    "Half.cpp",
+    "Math.cpp",
+    "Memory.cpp",
+    "Resource.cpp",
+    "Socket.cpp",
+    "Thread.cpp",
+    "Timer.cpp",
+  ]
+
+  configs += [
+    ":swiftshader_common_private_config",
+  ]
+}
\ No newline at end of file
diff --git a/src/Main/BUILD.gn b/src/Main/BUILD.gn
new file mode 100644
index 0000000..254256f
--- /dev/null
+++ b/src/Main/BUILD.gn
@@ -0,0 +1,68 @@
+# Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Need a separate config to ensure the warnings are added to the end.
+config("swiftshader_main_private_config") {
+  if (is_clang) {
+    cflags = [
+      "-DLOG_TAG=\"swiftshader_main\"",
+      "-msse2",
+    ]
+
+    if (!is_debug) {
+      cflags += [
+        "-DNDEBUG",
+        "-DANGLE_DISABLE_TRACE",
+      ]
+    }
+  }
+}
+
+source_set("swiftshader_main") {
+  deps = [
+    "../Common:swiftshader_common",
+  ]
+
+  sources = [
+    "Config.cpp",
+    "FrameBuffer.cpp",
+    "SwiftConfig.cpp",
+  ]
+
+  if (host_os == "linux") {
+    sources += [
+      "libX11.cpp",
+      "FrameBufferX11.cpp",
+    ]
+  } else if (host_os == "mac") {
+    sources += [
+      "FrameBufferOSX.mm",
+    ]
+  } else if (host_os == "win") {
+    sources += [
+      "FrameBufferDD.cpp",
+      "FrameBufferGDI.cpp",
+      "FrameBufferWin.cpp",
+    ]
+  }
+
+  configs += [
+    ":swiftshader_main_private_config",
+  ]
+
+  include_dirs = [
+    "..",
+    "../Common",
+  ]
+}
\ No newline at end of file
diff --git a/src/OpenGL/common/BUILD.gn b/src/OpenGL/common/BUILD.gn
new file mode 100644
index 0000000..0a23385
--- /dev/null
+++ b/src/OpenGL/common/BUILD.gn
@@ -0,0 +1,48 @@
+# Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Need a separate config to ensure the warnings are added to the end.
+config("swiftshader_opengl_common_private_config") {
+  if (is_clang) {
+    cflags = [
+      "-DLOG_TAG=\"swiftshader_opengl_common\"",
+    ]
+
+    if (!is_debug) {
+      cflags += [
+        "-DNDEBUG",
+        "-DANGLE_DISABLE_TRACE",
+      ]
+    }
+  }
+}
+
+source_set("swiftshader_opengl_common") {
+  sources = [
+    "debug.cpp",
+    "Image.cpp",
+    "Object.cpp",
+    "MatrixStack.cpp",
+  ]
+
+  configs += [
+    ":swiftshader_opengl_common_private_config",
+  ]
+
+  include_dirs = [
+    "..",
+    "../..",
+    "../../../include",
+  ]
+}
\ No newline at end of file
diff --git a/src/OpenGL/compiler/BUILD.gn b/src/OpenGL/compiler/BUILD.gn
new file mode 100644
index 0000000..a7b4c2b
--- /dev/null
+++ b/src/OpenGL/compiler/BUILD.gn
@@ -0,0 +1,82 @@
+# Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Need a separate config to ensure the warnings are added to the end.
+config("swiftshader_opengl_compiler_private_config") {
+  if (is_clang) {
+    cflags = [
+      "-DLOG_TAG=\"swiftshader_opengl_compiler\"",
+      "-Wno-sign-compare",
+    ]
+
+    if (!is_debug) {
+      cflags += [
+        "-DNDEBUG",
+        "-DANGLE_DISABLE_TRACE",
+      ]
+    }
+  }
+}
+
+source_set("swiftshader_opengl_compiler") {
+  deps = [
+    "preprocessor:swiftshader_opengl_preprocessor",
+  ]
+
+  sources = [
+    "AnalyzeCallDepth.cpp",
+    "Compiler.cpp",
+    "debug.cpp",
+    "Diagnostics.cpp",
+    "DirectiveHandler.cpp",
+    "glslang_lex.cpp",
+    "glslang_tab.cpp",
+    "InfoSink.cpp",
+    "Initialize.cpp",
+    "InitializeParseContext.cpp",
+    "IntermTraverse.cpp",
+    "Intermediate.cpp",
+    "intermOut.cpp",
+    "OutputASM.cpp",
+    "parseConst.cpp",
+    "ParseHelper.cpp",
+    "PoolAlloc.cpp",
+    "SymbolTable.cpp",
+    "TranslatorASM.cpp",
+    "util.cpp",
+    "ValidateGlobalInitializer.cpp",
+    "ValidateLimitations.cpp",
+    "ValidateSwitch.cpp",
+  ]
+
+  if ((host_os == "linux") || (host_os == "mac")) {
+    sources += [
+      "ossource_posix.cpp",
+    ]
+  } else if (host_os == "win") {
+    sources += [
+      "ossource_win.cpp",
+    ]
+  }
+
+  configs += [
+    ":swiftshader_opengl_compiler_private_config",
+  ]
+
+  include_dirs = [
+    "..",
+    "../..",
+    "../../../include",
+  ]
+}
\ No newline at end of file
diff --git a/src/OpenGL/compiler/preprocessor/BUILD.gn b/src/OpenGL/compiler/preprocessor/BUILD.gn
new file mode 100644
index 0000000..6c6ff25
--- /dev/null
+++ b/src/OpenGL/compiler/preprocessor/BUILD.gn
@@ -0,0 +1,49 @@
+# Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Need a separate config to ensure the warnings are added to the end.
+config("swiftshader_opengl_preprocessor_private_config") {
+  if (is_clang) {
+    cflags = [
+      "-DLOG_TAG=\"swiftshader_opengl_compiler\"",
+    ]
+
+    if (!is_debug) {
+      cflags += [
+        "-DNDEBUG",
+        "-DANGLE_DISABLE_TRACE",
+      ]
+    }
+  }
+}
+
+source_set("swiftshader_opengl_preprocessor") {
+  sources = [
+    "Diagnostics.cpp",
+    "DirectiveHandler.cpp",
+    "DirectiveParser.cpp",
+    "ExpressionParser.cpp",
+    "Input.cpp",
+    "Lexer.cpp",
+    "Macro.cpp",
+    "MacroExpander.cpp",
+    "Preprocessor.cpp",
+    "Token.cpp",
+    "Tokenizer.cpp",
+  ]
+
+  configs += [
+    ":swiftshader_opengl_preprocessor_private_config",
+  ]
+}
\ No newline at end of file
diff --git a/src/OpenGL/libEGL/BUILD.gn b/src/OpenGL/libEGL/BUILD.gn
new file mode 100644
index 0000000..ddd4b94
--- /dev/null
+++ b/src/OpenGL/libEGL/BUILD.gn
@@ -0,0 +1,69 @@
+# Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Need a separate config to ensure the warnings are added to the end.
+config("swiftshader_libEGL_private_config") {
+  if (is_clang) {
+    cflags = [
+      "-DLOG_TAG=\"swiftshader_libEGL\"",
+      "-DEGLAPI=",
+      "-DEGL_EGLEXT_PROTOTYPES",
+      "-Wno-sign-compare",
+    ]
+
+    if (!is_debug) {
+      cflags += [
+        "-DNDEBUG",
+        "-DANGLE_DISABLE_TRACE",
+      ]
+    }
+  }
+}
+
+shared_library("swiftshader_libEGL") {
+  deps = [
+    "../../Common:swiftshader_common",
+    "../../Reactor:swiftshader_reactor",
+    "../../Renderer:swiftshader_renderer",
+    "../../OpenGL/common:swiftshader_opengl_common",
+    "../../OpenGL/compiler:swiftshader_opengl_compiler",
+    "../../Shader:swiftshader_shader",
+    "../../Main:swiftshader_main",
+    "../../../third_party/LLVM:swiftshader_llvm",
+  ]
+
+  sources = [
+    "Config.cpp",
+    "Display.cpp",
+    "Surface.cpp",
+    "libEGL.cpp",
+    "main.cpp",
+  ]
+
+  if (host_os == "mac") {
+    sources += [
+      "OSXUtils.mm",
+    ]
+  }
+
+  configs += [
+    ":swiftshader_libEGL_private_config",
+  ]
+
+  include_dirs = [
+    "../../../include",
+    "../..",
+    "..",
+  ]
+}
\ No newline at end of file
diff --git a/src/OpenGL/libGLESv2/BUILD.gn b/src/OpenGL/libGLESv2/BUILD.gn
new file mode 100644
index 0000000..90a811f
--- /dev/null
+++ b/src/OpenGL/libGLESv2/BUILD.gn
@@ -0,0 +1,81 @@
+# Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Need a separate config to ensure the warnings are added to the end.
+config("swiftshader_libGLESv2_private_config") {
+  if (is_clang) {
+    cflags = [
+      "-DLOG_TAG=\"swiftshader_libGLESv2\"",
+      "-fno-operator-names",
+      "-D__STDC_CONSTANT_MACROS",
+      "-D__STDC_LIMIT_MACROS",
+      "-DGL_API=",
+      "-DGL_APICALL=",
+      "-DGL_GLEXT_PROTOTYPES",
+      "-Wno-sign-compare",
+    ]
+
+    if (!is_debug) {
+      cflags += [
+        "-DNDEBUG",
+        "-DANGLE_DISABLE_TRACE",
+      ]
+    }
+  }
+}
+
+shared_library("swiftshader_libGLESv2") {
+  deps = [
+    "../../Common:swiftshader_common",
+    "../../Reactor:swiftshader_reactor",
+    "../../Renderer:swiftshader_renderer",
+    "../../OpenGL/common:swiftshader_opengl_common",
+    "../../OpenGL/compiler:swiftshader_opengl_compiler",
+    "../../Shader:swiftshader_shader",
+    "../../Main:swiftshader_main",
+    "../../../third_party/LLVM:swiftshader_llvm",
+  ]
+
+  sources = [
+    "Buffer.cpp",
+    "Context.cpp",
+    "Device.cpp",
+    "Fence.cpp",
+    "Framebuffer.cpp",
+    "IndexDataManager.cpp",
+    "libGLESv2.cpp",
+    "libGLESv3.cpp",
+    "main.cpp",
+    "Program.cpp",
+    "Query.cpp",
+    "Renderbuffer.cpp",
+    "ResourceManager.cpp",
+    "Shader.cpp",
+    "Texture.cpp",
+    "TransformFeedback.cpp",
+    "utilities.cpp",
+    "VertexArray.cpp",
+    "VertexDataManager.cpp",
+  ]
+
+  configs += [
+    ":swiftshader_libGLESv2_private_config",
+  ]
+
+  include_dirs = [
+    "../../../include",
+    "../..",
+    "..",
+  ]
+}
\ No newline at end of file
diff --git a/src/Reactor/BUILD.gn b/src/Reactor/BUILD.gn
new file mode 100644
index 0000000..aa65be2
--- /dev/null
+++ b/src/Reactor/BUILD.gn
@@ -0,0 +1,62 @@
+# Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Need a separate config to ensure the warnings are added to the end.
+config("swiftshader_reactor_private_config") {
+  if (is_clang) {
+    cflags = [
+      "-DLOG_TAG=\"swiftshader_reactor\"",
+      "-Wno-unused-local-typedef",
+      "-msse2",
+      "-D__STDC_CONSTANT_MACROS",
+      "-D__STDC_LIMIT_MACROS",
+    ]
+
+    if (!is_debug) {
+      cflags += [
+        "-DNDEBUG",
+        "-DANGLE_DISABLE_TRACE",
+      ]
+    }
+  }
+}
+
+source_set("swiftshader_reactor") {
+  deps = [
+    "../Common:swiftshader_common",
+    "../../third_party/LLVM:swiftshader_llvm",
+  ]
+
+  sources = [
+    "Nucleus.cpp",
+    "Routine.cpp",
+    "RoutineManager.cpp",
+  ]
+
+  if (host_os == "win") {
+    sources += [
+      "DLL.cpp",
+    ]
+  }
+
+  configs += [
+    ":swiftshader_reactor_private_config",
+  ]
+
+  include_dirs = [
+    "..",
+    "../Common",
+    "../../third_party/LLVM/include/",
+  ]
+}
\ No newline at end of file
diff --git a/src/Renderer/BUILD.gn b/src/Renderer/BUILD.gn
new file mode 100644
index 0000000..ee5213d
--- /dev/null
+++ b/src/Renderer/BUILD.gn
@@ -0,0 +1,72 @@
+# Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Need a separate config to ensure the warnings are added to the end.
+config("swiftshader_renderer_private_config") {
+  if (is_clang) {
+    cflags = [
+      "-DLOG_TAG=\"swiftshader_renderer\"",
+      "-fno-operator-names",
+      "-msse2",
+      "-Wno-sign-compare",
+    ]
+
+    if (!is_debug) {
+      cflags += [
+        "-DNDEBUG",
+        "-DANGLE_DISABLE_TRACE",
+      ]
+    }
+  }
+}
+
+source_set("swiftshader_renderer") {
+  deps = [
+    "../Common:swiftshader_common",
+    "../Shader:swiftshader_shader",
+    "../Main:swiftshader_main",
+  ]
+
+  sources = [
+    "Blitter.cpp",
+    "Clipper.cpp",
+    "Color.cpp",
+    "Context.cpp",
+    "ETC_Decoder.cpp",
+    "Matrix.cpp",
+    "PixelProcessor.cpp",
+    "Plane.cpp",
+    "Point.cpp",
+    "QuadRasterizer.cpp",
+    "Renderer.cpp",
+    "Sampler.cpp",
+    "SetupProcessor.cpp",
+    "Surface.cpp",
+    "TextureStage.cpp",
+    "Vector.cpp",
+    "VertexProcessor.cpp",
+  ]
+
+  configs += [
+    ":swiftshader_renderer_private_config",
+  ]
+
+  include_dirs = [
+    ".",
+    "..",
+    "../Common",
+    "../Main",
+    "../Shader",
+  ]
+}
\ No newline at end of file
diff --git a/src/Shader/BUILD.gn b/src/Shader/BUILD.gn
new file mode 100644
index 0000000..3e9a96c
--- /dev/null
+++ b/src/Shader/BUILD.gn
@@ -0,0 +1,65 @@
+# Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Need a separate config to ensure the warnings are added to the end.
+config("swiftshader_shader_private_config") {
+  if (is_clang) {
+    cflags = [
+      "-DLOG_TAG=\"swiftshader_shader\"",
+      "-fno-operator-names",
+    ]
+
+    if (!is_debug) {
+      cflags += [
+        "-DNDEBUG",
+        "-DANGLE_DISABLE_TRACE",
+      ]
+    }
+  }
+}
+
+source_set("swiftshader_shader") {
+  deps = [
+    "../Common:swiftshader_common",
+    "../Main:swiftshader_main",
+  ]
+
+  sources = [
+    "Constants.cpp",
+    "PixelPipeline.cpp",
+    "PixelProgram.cpp",
+    "PixelRoutine.cpp",
+    "PixelShader.cpp",
+    "SamplerCore.cpp",
+    "SetupRoutine.cpp",
+    "Shader.cpp",
+    "ShaderCore.cpp",
+    "VertexPipeline.cpp",
+    "VertexProgram.cpp",
+    "VertexRoutine.cpp",
+    "VertexShader.cpp",
+  ]
+
+  configs += [
+    ":swiftshader_shader_private_config",
+  ]
+
+  include_dirs = [
+    ".",
+    "..",
+    "../Common",
+    "../Main",
+    "../Renderer",
+  ]
+}
\ No newline at end of file