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