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