1# Copyright (C) 2018 Google, Inc.
2#
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8#
9#    Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11#
12#    Redistributions in binary form must reproduce the above
13#    copyright notice, this list of conditions and the following
14#    disclaimer in the documentation and/or other materials provided
15#    with the distribution.
16#
17#    Neither the name of Google Inc. nor the names of its
18#    contributors may be used to endorse or promote products derived
19#    from this software without specific prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25# COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32# POSSIBILITY OF SUCH DAMAGE.
33
34import("//build_overrides/glslang.gni")
35
36# Both Chromium and Fuchsia use by default a set of warning errors
37# that is far too strict to compile this project. These are also
38# typically appended after |cflags|, overriding target-specific
39# definitions. To work around this, determine which configs to
40# add and remove in order to succesfully build the project.
41if (defined(is_fuchsia_tree) && is_fuchsia_tree) {
42  _configs_to_remove = [ "//build/config:default_warnings" ]
43  _configs_to_add = []
44} else {
45  _configs_to_remove = [ "//build/config/compiler:chromium_code" ]
46  _configs_to_add = [ "//build/config/compiler:no_chromium_code" ]
47}
48
49action("glslang_build_info") {
50  script = "build_info.py"
51
52  src_dir = "."
53  changes_file = "CHANGES.md"
54  template_file = "build_info.h.tmpl"
55  out_file = "${target_gen_dir}/include/glslang/build_info.h"
56
57  inputs = [
58    changes_file,
59    script,
60    template_file,
61  ]
62  outputs = [ out_file ]
63  args = [
64    rebase_path(src_dir, root_build_dir),
65    "-i",
66    rebase_path(template_file, root_build_dir),
67    "-o",
68    rebase_path(out_file, root_build_dir),
69  ]
70}
71
72action("glslang_extension_headers") {
73  script = "gen_extension_headers.py"
74
75  out_file = "${target_gen_dir}/include/glslang/glsl_intrinsic_header.h"
76
77  # Fuchsia GN build rules require all GN actions to be hermetic and they
78  # should correctly and fully state their inputs and outpus (see
79  # https://fuchsia.dev/fuchsia-src/development/build/hermetic_actions
80  # for details). All input files of the script should be added to the
81  # |sources| list.
82  sources = [
83    "glslang/ExtensionHeaders/GL_EXT_shader_realtime_clock.glsl",
84  ]
85
86  inputs = [
87    script
88  ]
89  outputs = [ out_file ]
90  args = [
91    "-i",
92    rebase_path("glslang/ExtensionHeaders", root_build_dir),
93    "-o",
94    rebase_path(out_file, root_build_dir),
95  ]
96}
97
98spirv_tools_dir = glslang_spirv_tools_dir
99
100config("glslang_public") {
101  include_dirs = [ "." ]
102  if (!is_win || is_clang) {
103    cflags = [ "-Wno-conversion" ]
104  }
105}
106
107config("glslang_hlsl") {
108  defines = [ "ENABLE_HLSL=1" ]
109}
110
111template("glslang_sources_common") {
112  source_set(target_name) {
113    public_configs = [ ":glslang_public" ]
114
115    if (invoker.enable_hlsl) {
116      public_configs += [ ":glslang_hlsl" ]
117    }
118
119    sources = [
120      "SPIRV/GLSL.ext.AMD.h",
121      "SPIRV/GLSL.ext.EXT.h",
122      "SPIRV/GLSL.ext.KHR.h",
123      "SPIRV/GLSL.ext.NV.h",
124      "SPIRV/GLSL.ext.ARM.h",
125      "SPIRV/GLSL.ext.QCOM.h",
126      "SPIRV/GLSL.std.450.h",
127      "SPIRV/GlslangToSpv.cpp",
128      "SPIRV/GlslangToSpv.h",
129      "SPIRV/InReadableOrder.cpp",
130      "SPIRV/Logger.cpp",
131      "SPIRV/Logger.h",
132      "SPIRV/NonSemanticDebugPrintf.h",
133      "SPIRV/NonSemanticShaderDebugInfo100.h",
134      "SPIRV/SPVRemapper.cpp",
135      "SPIRV/SPVRemapper.h",
136      "SPIRV/SpvBuilder.cpp",
137      "SPIRV/SpvBuilder.h",
138      "SPIRV/SpvPostProcess.cpp",
139      "SPIRV/SpvTools.h",
140      "SPIRV/bitutils.h",
141      "SPIRV/disassemble.cpp",
142      "SPIRV/disassemble.h",
143      "SPIRV/doc.cpp",
144      "SPIRV/doc.h",
145      "SPIRV/hex_float.h",
146      "SPIRV/spirv.hpp",
147      "SPIRV/spvIR.h",
148      "glslang/GenericCodeGen/CodeGen.cpp",
149      "glslang/GenericCodeGen/Link.cpp",
150      "glslang/Include/BaseTypes.h",
151      "glslang/Include/Common.h",
152      "glslang/Include/ConstantUnion.h",
153      "glslang/Include/InfoSink.h",
154      "glslang/Include/InitializeGlobals.h",
155      "glslang/Include/PoolAlloc.h",
156      "glslang/Include/ResourceLimits.h",
157      "glslang/Include/ShHandle.h",
158      "glslang/Include/SpirvIntrinsics.h",
159      "glslang/Include/Types.h",
160      "glslang/Include/arrays.h",
161      "glslang/Include/intermediate.h",
162      "glslang/MachineIndependent/Constant.cpp",
163      "glslang/MachineIndependent/InfoSink.cpp",
164      "glslang/MachineIndependent/Initialize.cpp",
165      "glslang/MachineIndependent/Initialize.h",
166      "glslang/MachineIndependent/IntermTraverse.cpp",
167      "glslang/MachineIndependent/Intermediate.cpp",
168      "glslang/MachineIndependent/LiveTraverser.h",
169      "glslang/MachineIndependent/ParseContextBase.cpp",
170      "glslang/MachineIndependent/ParseHelper.cpp",
171      "glslang/MachineIndependent/ParseHelper.h",
172      "glslang/MachineIndependent/PoolAlloc.cpp",
173      "glslang/MachineIndependent/RemoveTree.cpp",
174      "glslang/MachineIndependent/RemoveTree.h",
175      "glslang/MachineIndependent/Scan.cpp",
176      "glslang/MachineIndependent/Scan.h",
177      "glslang/MachineIndependent/ScanContext.h",
178      "glslang/MachineIndependent/ShaderLang.cpp",
179      "glslang/MachineIndependent/SpirvIntrinsics.cpp",
180      "glslang/MachineIndependent/SymbolTable.cpp",
181      "glslang/MachineIndependent/SymbolTable.h",
182      "glslang/MachineIndependent/Versions.cpp",
183      "glslang/MachineIndependent/Versions.h",
184      "glslang/MachineIndependent/attribute.cpp",
185      "glslang/MachineIndependent/attribute.h",
186      "glslang/MachineIndependent/gl_types.h",
187      "glslang/MachineIndependent/glslang_tab.cpp",
188      "glslang/MachineIndependent/glslang_tab.cpp.h",
189      "glslang/MachineIndependent/intermOut.cpp",
190      "glslang/MachineIndependent/iomapper.cpp",
191      "glslang/MachineIndependent/iomapper.h",
192      "glslang/MachineIndependent/limits.cpp",
193      "glslang/MachineIndependent/linkValidate.cpp",
194      "glslang/MachineIndependent/localintermediate.h",
195      "glslang/MachineIndependent/parseConst.cpp",
196      "glslang/MachineIndependent/parseVersions.h",
197      "glslang/MachineIndependent/preprocessor/Pp.cpp",
198      "glslang/MachineIndependent/preprocessor/PpAtom.cpp",
199      "glslang/MachineIndependent/preprocessor/PpContext.cpp",
200      "glslang/MachineIndependent/preprocessor/PpContext.h",
201      "glslang/MachineIndependent/preprocessor/PpScanner.cpp",
202      "glslang/MachineIndependent/preprocessor/PpTokens.cpp",
203      "glslang/MachineIndependent/preprocessor/PpTokens.h",
204      "glslang/MachineIndependent/propagateNoContraction.cpp",
205      "glslang/MachineIndependent/propagateNoContraction.h",
206      "glslang/MachineIndependent/reflection.cpp",
207      "glslang/MachineIndependent/reflection.h",
208      "glslang/OSDependent/osinclude.h",
209      "glslang/Public/ShaderLang.h",
210    ]
211
212    # Workaround gn issue complaining about these not being allowed even though GLSLANG_HLSL is not
213    # defined.
214    sources += [
215      "glslang/HLSL/hlslParseHelper.h",
216      "glslang/HLSL/hlslParseables.h",
217      "glslang/HLSL/hlslScanContext.h",
218      "glslang/HLSL/hlslTokens.h",
219    ]
220
221    if (invoker.enable_hlsl) {
222      sources += [
223        "glslang/HLSL/hlslAttributes.cpp",
224        "glslang/HLSL/hlslAttributes.h",
225        "glslang/HLSL/hlslGrammar.cpp",
226        "glslang/HLSL/hlslGrammar.h",
227        "glslang/HLSL/hlslOpMap.cpp",
228        "glslang/HLSL/hlslOpMap.h",
229        "glslang/HLSL/hlslParseHelper.cpp",
230        "glslang/HLSL/hlslParseables.cpp",
231        "glslang/HLSL/hlslScanContext.cpp",
232        "glslang/HLSL/hlslTokenStream.cpp",
233        "glslang/HLSL/hlslTokenStream.h",
234      ]
235    }
236
237    defines = []
238    if (invoker.enable_opt) {
239      sources += [ "SPIRV/SpvTools.cpp" ]
240      defines += [ "ENABLE_OPT=1" ]
241    }
242
243    if (is_win) {
244      sources += [ "glslang/OSDependent/Windows/ossource.cpp" ]
245      defines += [ "GLSLANG_OSINCLUDE_WIN32" ]
246    } else {
247      sources += [ "glslang/OSDependent/Unix/ossource.cpp" ]
248      defines += [ "GLSLANG_OSINCLUDE_UNIX" ]
249    }
250
251    if (is_clang) {
252      cflags = [
253        "-Wno-extra-semi",
254        "-Wno-ignored-qualifiers",
255        "-Wno-implicit-fallthrough",
256        "-Wno-inconsistent-missing-override",
257        "-Wno-missing-field-initializers",
258        "-Wno-newline-eof",
259        "-Wno-sign-compare",
260        "-Wno-suggest-destructor-override",
261        "-Wno-suggest-override",
262        "-Wno-unused-variable",
263      ]
264    }
265    if (is_win && !is_clang) {
266      cflags = [
267        "/wd4018",  # signed/unsigned mismatch
268        "/wd4189",  # local variable is initialized but not referenced
269      ]
270    }
271
272    include_dirs = [ "${target_gen_dir}/include" ]
273
274    deps = [ ":glslang_build_info" ]
275
276    if (invoker.enable_opt) {
277      deps += [
278        "${spirv_tools_dir}:spvtools_opt",
279        "${spirv_tools_dir}:spvtools_val",
280      ]
281      include_dirs += [ "${spirv_tools_dir}/include" ]
282    }
283
284    configs -= _configs_to_remove
285    configs += _configs_to_add
286  }
287}
288
289glslang_sources_common("glslang_lib_sources") {
290  enable_opt = true
291  enable_hlsl = true
292}
293
294glslang_sources_common("glslang_sources") {
295  enable_opt = true
296  enable_hlsl = true
297}
298
299source_set("glslang_default_resource_limits_sources") {
300  sources = [
301    "glslang/ResourceLimits/ResourceLimits.cpp",
302    "glslang/Public/ResourceLimits.h",
303    "glslang/Include/ResourceLimits.h",
304  ]
305  public_configs = [ ":glslang_public" ]
306
307  configs -= _configs_to_remove
308  configs += _configs_to_add
309}
310
311executable("glslang_validator") {
312  sources = [
313    "StandAlone/DirStackFileIncluder.h",
314    "StandAlone/StandAlone.cpp",
315  ]
316  if (!is_win) {
317    cflags = [ "-Woverflow" ]
318  }
319  defines = [ "ENABLE_OPT=1" ]
320  deps = [
321    ":glslang_build_info",
322    ":glslang_default_resource_limits_sources",
323    ":glslang_sources",
324    ":glslang_extension_headers",
325  ]
326  public_configs = [ ":glslang_hlsl" ]
327
328  include_dirs = [
329    "${target_gen_dir}/include",
330    "${spirv_tools_dir}/include",
331  ]
332
333  configs -= _configs_to_remove
334  configs += _configs_to_add
335}
336
337executable("spirv-remap") {
338  sources = [ "StandAlone/spirv-remap.cpp" ]
339  defines = [ "ENABLE_OPT=1" ]
340  deps = [ ":glslang_sources" ]
341
342  include_dirs = [ "${spirv_tools_dir}/include" ]
343
344  configs -= _configs_to_remove
345  configs += _configs_to_add
346}
347