Update glsl.versionOverride.geom
[platform/upstream/glslang.git] / BUILD.gn
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
34 import("//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.
41 if (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
49 action("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
72 action("glslang_extension_headers") {
73   script = "gen_extension_headers.py"
74
75   out_file = "${target_gen_dir}/include/glslang/glsl_intrinsic_header.h"
76
77   inputs = [
78     script
79   ]
80   outputs = [ out_file ]
81   args = [
82     "-i",
83     rebase_path("glslang/ExtensionHeaders", root_build_dir),
84     "-o",
85     rebase_path(out_file, root_build_dir),
86   ]
87 }
88
89 spirv_tools_dir = glslang_spirv_tools_dir
90 if (!defined(glslang_angle)) {
91   glslang_angle = false
92 }
93
94 config("glslang_public") {
95   include_dirs = [ "." ]
96   if (!is_win || is_clang) {
97     cflags = [ "-Wno-conversion" ]
98   }
99 }
100
101 config("glslang_hlsl") {
102   defines = [ "ENABLE_HLSL=1" ]
103 }
104
105 template("glslang_sources_common") {
106   source_set(target_name) {
107     public_configs = [ ":glslang_public" ]
108
109     if (invoker.enable_hlsl) {
110       public_configs += [ ":glslang_hlsl" ]
111     }
112
113     sources = [
114       "OGLCompilersDLL/InitializeDll.cpp",
115       "OGLCompilersDLL/InitializeDll.h",
116       "SPIRV/GLSL.ext.AMD.h",
117       "SPIRV/GLSL.ext.EXT.h",
118       "SPIRV/GLSL.ext.KHR.h",
119       "SPIRV/GLSL.ext.NV.h",
120       "SPIRV/GLSL.std.450.h",
121       "SPIRV/GlslangToSpv.cpp",
122       "SPIRV/GlslangToSpv.h",
123       "SPIRV/InReadableOrder.cpp",
124       "SPIRV/Logger.cpp",
125       "SPIRV/Logger.h",
126       "SPIRV/NonSemanticDebugPrintf.h",
127       "SPIRV/SPVRemapper.cpp",
128       "SPIRV/SPVRemapper.h",
129       "SPIRV/SpvBuilder.cpp",
130       "SPIRV/SpvBuilder.h",
131       "SPIRV/SpvPostProcess.cpp",
132       "SPIRV/SpvTools.h",
133       "SPIRV/bitutils.h",
134       "SPIRV/disassemble.cpp",
135       "SPIRV/disassemble.h",
136       "SPIRV/doc.cpp",
137       "SPIRV/doc.h",
138       "SPIRV/hex_float.h",
139       "SPIRV/spirv.hpp",
140       "SPIRV/spvIR.h",
141       "glslang/GenericCodeGen/CodeGen.cpp",
142       "glslang/GenericCodeGen/Link.cpp",
143       "glslang/Include/BaseTypes.h",
144       "glslang/Include/Common.h",
145       "glslang/Include/ConstantUnion.h",
146       "glslang/Include/InfoSink.h",
147       "glslang/Include/InitializeGlobals.h",
148       "glslang/Include/PoolAlloc.h",
149       "glslang/Include/ResourceLimits.h",
150       "glslang/Include/ShHandle.h",
151       "glslang/Include/SpirvIntrinsics.h",
152       "glslang/Include/Types.h",
153       "glslang/Include/arrays.h",
154       "glslang/Include/intermediate.h",
155       "glslang/MachineIndependent/Constant.cpp",
156       "glslang/MachineIndependent/InfoSink.cpp",
157       "glslang/MachineIndependent/Initialize.cpp",
158       "glslang/MachineIndependent/Initialize.h",
159       "glslang/MachineIndependent/IntermTraverse.cpp",
160       "glslang/MachineIndependent/Intermediate.cpp",
161       "glslang/MachineIndependent/LiveTraverser.h",
162       "glslang/MachineIndependent/ParseContextBase.cpp",
163       "glslang/MachineIndependent/ParseHelper.cpp",
164       "glslang/MachineIndependent/ParseHelper.h",
165       "glslang/MachineIndependent/PoolAlloc.cpp",
166       "glslang/MachineIndependent/RemoveTree.cpp",
167       "glslang/MachineIndependent/RemoveTree.h",
168       "glslang/MachineIndependent/Scan.cpp",
169       "glslang/MachineIndependent/Scan.h",
170       "glslang/MachineIndependent/ScanContext.h",
171       "glslang/MachineIndependent/ShaderLang.cpp",
172       "glslang/MachineIndependent/SpirvIntrinsics.cpp",
173       "glslang/MachineIndependent/SymbolTable.cpp",
174       "glslang/MachineIndependent/SymbolTable.h",
175       "glslang/MachineIndependent/Versions.cpp",
176       "glslang/MachineIndependent/Versions.h",
177       "glslang/MachineIndependent/attribute.cpp",
178       "glslang/MachineIndependent/attribute.h",
179       "glslang/MachineIndependent/gl_types.h",
180       "glslang/MachineIndependent/glslang_tab.cpp",
181       "glslang/MachineIndependent/glslang_tab.cpp.h",
182       "glslang/MachineIndependent/intermOut.cpp",
183       "glslang/MachineIndependent/iomapper.cpp",
184       "glslang/MachineIndependent/iomapper.h",
185       "glslang/MachineIndependent/limits.cpp",
186       "glslang/MachineIndependent/linkValidate.cpp",
187       "glslang/MachineIndependent/localintermediate.h",
188       "glslang/MachineIndependent/parseConst.cpp",
189       "glslang/MachineIndependent/parseVersions.h",
190       "glslang/MachineIndependent/preprocessor/Pp.cpp",
191       "glslang/MachineIndependent/preprocessor/PpAtom.cpp",
192       "glslang/MachineIndependent/preprocessor/PpContext.cpp",
193       "glslang/MachineIndependent/preprocessor/PpContext.h",
194       "glslang/MachineIndependent/preprocessor/PpScanner.cpp",
195       "glslang/MachineIndependent/preprocessor/PpTokens.cpp",
196       "glslang/MachineIndependent/preprocessor/PpTokens.h",
197       "glslang/MachineIndependent/propagateNoContraction.cpp",
198       "glslang/MachineIndependent/propagateNoContraction.h",
199       "glslang/MachineIndependent/reflection.cpp",
200       "glslang/MachineIndependent/reflection.h",
201       "glslang/OSDependent/osinclude.h",
202       "glslang/Public/ShaderLang.h",
203     ]
204
205     # Workaround gn issue complaining about these not being allowed even though GLSLANG_HLSL is not
206     # defined.
207     sources += [
208       "glslang/HLSL/hlslParseHelper.h",
209       "glslang/HLSL/hlslParseables.h",
210       "glslang/HLSL/hlslScanContext.h",
211       "glslang/HLSL/hlslTokens.h",
212     ]
213
214     if (invoker.enable_hlsl) {
215       sources += [
216         "glslang/HLSL/hlslAttributes.cpp",
217         "glslang/HLSL/hlslAttributes.h",
218         "glslang/HLSL/hlslGrammar.cpp",
219         "glslang/HLSL/hlslGrammar.h",
220         "glslang/HLSL/hlslOpMap.cpp",
221         "glslang/HLSL/hlslOpMap.h",
222         "glslang/HLSL/hlslParseHelper.cpp",
223         "glslang/HLSL/hlslParseables.cpp",
224         "glslang/HLSL/hlslScanContext.cpp",
225         "glslang/HLSL/hlslTokenStream.cpp",
226         "glslang/HLSL/hlslTokenStream.h",
227       ]
228     }
229
230     defines = []
231     if (invoker.enable_opt) {
232       sources += [ "SPIRV/SpvTools.cpp" ]
233       defines += [ "ENABLE_OPT=1" ]
234     }
235     if (invoker.is_angle) {
236       defines += [ "GLSLANG_ANGLE" ]
237     }
238
239     if (is_win) {
240       sources += [ "glslang/OSDependent/Windows/ossource.cpp" ]
241       defines += [ "GLSLANG_OSINCLUDE_WIN32" ]
242     } else {
243       sources += [ "glslang/OSDependent/Unix/ossource.cpp" ]
244       defines += [ "GLSLANG_OSINCLUDE_UNIX" ]
245     }
246
247     if (is_clang) {
248       cflags = [
249         "-Wno-extra-semi",
250         "-Wno-ignored-qualifiers",
251         "-Wno-implicit-fallthrough",
252         "-Wno-inconsistent-missing-override",
253         "-Wno-missing-field-initializers",
254         "-Wno-newline-eof",
255         "-Wno-sign-compare",
256         "-Wno-suggest-destructor-override",
257         "-Wno-suggest-override",
258         "-Wno-unused-variable",
259       ]
260     }
261     if (is_win && !is_clang) {
262       cflags = [
263         "/wd4018",  # signed/unsigned mismatch
264         "/wd4189",  # local variable is initialized but not referenced
265       ]
266     }
267
268     include_dirs = [ "${target_gen_dir}/include" ]
269
270     deps = [ ":glslang_build_info" ]
271
272     if (invoker.enable_opt) {
273       deps += [
274         "${spirv_tools_dir}:spvtools_opt",
275         "${spirv_tools_dir}:spvtools_val",
276       ]
277       include_dirs += [ "${spirv_tools_dir}/include" ]
278     }
279
280     configs -= _configs_to_remove
281     configs += _configs_to_add
282   }
283 }
284
285 glslang_sources_common("glslang_lib_sources") {
286   enable_opt = !glslang_angle
287   enable_hlsl = !glslang_angle
288   is_angle = glslang_angle
289 }
290
291 glslang_sources_common("glslang_sources") {
292   enable_opt = true
293   enable_hlsl = true
294   is_angle = false
295 }
296
297 source_set("glslang_default_resource_limits_sources") {
298   sources = [
299     "StandAlone/ResourceLimits.cpp",
300     "StandAlone/ResourceLimits.h",
301     "glslang/Include/ResourceLimits.h",
302   ]
303   public_configs = [ ":glslang_public" ]
304
305   configs -= _configs_to_remove
306   configs += _configs_to_add
307 }
308
309 executable("glslang_validator") {
310   sources = [
311     "StandAlone/DirStackFileIncluder.h",
312     "StandAlone/StandAlone.cpp",
313   ]
314   if (!is_win) {
315     cflags = [ "-Woverflow" ]
316   }
317   defines = [ "ENABLE_OPT=1" ]
318   deps = [
319     ":glslang_build_info",
320     ":glslang_default_resource_limits_sources",
321     ":glslang_sources",
322     ":glslang_extension_headers",
323   ]
324   public_configs = [ ":glslang_hlsl" ]
325
326   include_dirs = [
327     "${target_gen_dir}/include",
328     "${spirv_tools_dir}/include",
329   ]
330
331   configs -= _configs_to_remove
332   configs += _configs_to_add
333 }
334
335 executable("spirv-remap") {
336   sources = [ "StandAlone/spirv-remap.cpp" ]
337   defines = [ "ENABLE_OPT=1" ]
338   deps = [ ":glslang_sources" ]
339
340   include_dirs = [ "${spirv_tools_dir}/include" ]
341
342   configs -= _configs_to_remove
343   configs += _configs_to_add
344 }