# Copyright 2018 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("../../gni/angle.gni")

# glslang
# -------

config("glslang_config") {
  include_dirs = [
    "src",
    "src/glslang/Public",
  ]
}

config("glslang_internal_config") {
  cflags = []
  if (is_clang || !is_win) {
    cflags += [
      "-Wno-ignored-qualifiers",
      "-Wno-reorder",
    ]
  }
  if (!is_clang && !is_win) {
    cflags += [ "-Wno-unused-function" ]
  }
}

static_library("glslang") {
  sources = [
    "src/OGLCompilersDLL/InitializeDll.cpp",
    "src/OGLCompilersDLL/InitializeDll.h",
    "src/SPIRV/GLSL.ext.KHR.h",
    "src/SPIRV/GLSL.std.450.h",
    "src/SPIRV/GlslangToSpv.cpp",
    "src/SPIRV/GlslangToSpv.h",
    "src/SPIRV/InReadableOrder.cpp",
    "src/SPIRV/Logger.cpp",
    "src/SPIRV/Logger.h",
    "src/SPIRV/SpvBuilder.cpp",
    "src/SPIRV/SpvBuilder.h",
    "src/SPIRV/bitutils.h",
    "src/SPIRV/disassemble.cpp",
    "src/SPIRV/disassemble.h",
    "src/SPIRV/doc.cpp",
    "src/SPIRV/doc.h",
    "src/SPIRV/hex_float.h",
    "src/SPIRV/spirv.hpp",
    "src/SPIRV/spvIR.h",
    "src/StandAlone/ResourceLimits.cpp",
    "src/StandAlone/ResourceLimits.h",
    "src/glslang/GenericCodeGen/CodeGen.cpp",
    "src/glslang/GenericCodeGen/Link.cpp",
    "src/glslang/Include/BaseTypes.h",
    "src/glslang/Include/Common.h",
    "src/glslang/Include/ConstantUnion.h",
    "src/glslang/Include/InfoSink.h",
    "src/glslang/Include/InitializeGlobals.h",
    "src/glslang/Include/PoolAlloc.h",
    "src/glslang/Include/ResourceLimits.h",
    "src/glslang/Include/ShHandle.h",
    "src/glslang/Include/Types.h",
    "src/glslang/Include/arrays.h",
    "src/glslang/Include/intermediate.h",
    "src/glslang/Include/revision.h",
    "src/glslang/MachineIndependent/Constant.cpp",
    "src/glslang/MachineIndependent/InfoSink.cpp",
    "src/glslang/MachineIndependent/Initialize.cpp",
    "src/glslang/MachineIndependent/Initialize.h",
    "src/glslang/MachineIndependent/IntermTraverse.cpp",
    "src/glslang/MachineIndependent/Intermediate.cpp",
    "src/glslang/MachineIndependent/LiveTraverser.h",
    "src/glslang/MachineIndependent/ParseContextBase.cpp",
    "src/glslang/MachineIndependent/ParseHelper.cpp",
    "src/glslang/MachineIndependent/ParseHelper.h",
    "src/glslang/MachineIndependent/PoolAlloc.cpp",
    "src/glslang/MachineIndependent/RemoveTree.cpp",
    "src/glslang/MachineIndependent/RemoveTree.h",
    "src/glslang/MachineIndependent/Scan.cpp",
    "src/glslang/MachineIndependent/Scan.h",
    "src/glslang/MachineIndependent/ScanContext.h",
    "src/glslang/MachineIndependent/ShaderLang.cpp",
    "src/glslang/MachineIndependent/SymbolTable.cpp",
    "src/glslang/MachineIndependent/SymbolTable.h",
    "src/glslang/MachineIndependent/Versions.cpp",
    "src/glslang/MachineIndependent/Versions.h",
    "src/glslang/MachineIndependent/gl_types.h",
    "src/glslang/MachineIndependent/glslang.y",
    "src/glslang/MachineIndependent/glslang_tab.cpp",
    "src/glslang/MachineIndependent/glslang_tab.cpp.h",
    "src/glslang/MachineIndependent/intermOut.cpp",
    "src/glslang/MachineIndependent/iomapper.cpp",
    "src/glslang/MachineIndependent/iomapper.h",
    "src/glslang/MachineIndependent/limits.cpp",
    "src/glslang/MachineIndependent/linkValidate.cpp",
    "src/glslang/MachineIndependent/localintermediate.h",
    "src/glslang/MachineIndependent/parseConst.cpp",
    "src/glslang/MachineIndependent/parseVersions.h",
    "src/glslang/MachineIndependent/preprocessor/Pp.cpp",
    "src/glslang/MachineIndependent/preprocessor/PpAtom.cpp",
    "src/glslang/MachineIndependent/preprocessor/PpContext.cpp",
    "src/glslang/MachineIndependent/preprocessor/PpContext.h",
    "src/glslang/MachineIndependent/preprocessor/PpScanner.cpp",
    "src/glslang/MachineIndependent/preprocessor/PpTokens.cpp",
    "src/glslang/MachineIndependent/preprocessor/PpTokens.h",
    "src/glslang/MachineIndependent/propagateNoContraction.cpp",
    "src/glslang/MachineIndependent/propagateNoContraction.h",
    "src/glslang/MachineIndependent/reflection.cpp",
    "src/glslang/MachineIndependent/reflection.h",
    "src/glslang/OSDependent/osinclude.h",
    "src/glslang/Public/ShaderLang.h",
  ]
  public_configs = [ ":glslang_config" ]
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [ "//build/config/compiler:no_chromium_code" ]
  configs += [ ":glslang_internal_config" ]

  if (is_win) {
    cflags = [
      "/wd4100",  # Unreferenced formal parameter
      "/wd4456",  # Declaration hides previous local declaration
      "/wd4457",  # Declaration hides function parameter
      "/wd4458",  # Declaration hides class member
      "/wd4702",  # Unreachable code (from glslang_tab.cpp)
      "/wd4718",  # Recursive call has no side effects (from PpContext.cpp)
    ]

    sources += [ "src/glslang/OSDependent/Windows/ossource.cpp" ]
  }
  if (is_linux || is_android) {
    sources += [ "src/glslang/OSDependent/Unix/ossource.cpp" ]
  }
}

executable("glslang_validator") {
  sources = [
    "src/StandAlone/DirStackFileIncluder.h",
    "src/StandAlone/StandAlone.cpp",
  ]
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [ "//build/config/compiler:no_chromium_code" ]
  deps = [
    "//build/config:exe_and_shlib_deps",
  ]
  public_deps = [
    ":glslang",
  ]
}
