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