blob: 9525b5d203acbd95283bc0e7e5f95b0fc8c32a39 [file] [log] [blame]
Dan Sinclair257b25c2018-09-24 16:35:44 -04001# 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
David Turnera3f0da52019-10-23 16:07:19 +020036# 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
Ben Claytonfbe9a232020-06-17 11:17:19 +010049action("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
Dan Sinclair257b25c2018-09-24 16:35:44 -040072spirv_tools_dir = glslang_spirv_tools_dir
Ryan Harrisoneab46cf2020-07-07 11:45:02 -040073if (!defined(glslang_angle)) {
74 glslang_angle = false
75}
Dan Sinclair257b25c2018-09-24 16:35:44 -040076
77config("glslang_public") {
78 include_dirs = [ "." ]
Shahbaz Youssefia55029d2020-07-05 16:48:34 -040079}
Corentin Wallez9757da42019-08-26 14:13:54 +020080
Shahbaz Youssefia55029d2020-07-05 16:48:34 -040081config("glslang_hlsl") {
82 defines = [ "ENABLE_HLSL=1" ]
Dan Sinclair257b25c2018-09-24 16:35:44 -040083}
84
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -040085template("glslang_sources_common") {
86 source_set(target_name) {
87 public_configs = [ ":glslang_public" ]
Corentin Wallez6857c232018-10-03 13:15:23 -040088
Shahbaz Youssefia55029d2020-07-05 16:48:34 -040089 if (invoker.enable_hlsl) {
90 public_configs += [ ":glslang_hlsl" ]
91 }
92
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -040093 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",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400112 "SPIRV/SpvTools.h",
113 "SPIRV/bitutils.h",
114 "SPIRV/disassemble.cpp",
115 "SPIRV/disassemble.h",
116 "SPIRV/doc.cpp",
117 "SPIRV/doc.h",
118 "SPIRV/hex_float.h",
119 "SPIRV/spirv.hpp",
120 "SPIRV/spvIR.h",
121 "glslang/GenericCodeGen/CodeGen.cpp",
122 "glslang/GenericCodeGen/Link.cpp",
123 "glslang/Include/BaseTypes.h",
124 "glslang/Include/Common.h",
125 "glslang/Include/ConstantUnion.h",
126 "glslang/Include/InfoSink.h",
127 "glslang/Include/InitializeGlobals.h",
128 "glslang/Include/PoolAlloc.h",
129 "glslang/Include/ResourceLimits.h",
130 "glslang/Include/ShHandle.h",
131 "glslang/Include/Types.h",
132 "glslang/Include/arrays.h",
133 "glslang/Include/intermediate.h",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400134 "glslang/MachineIndependent/Constant.cpp",
135 "glslang/MachineIndependent/InfoSink.cpp",
136 "glslang/MachineIndependent/Initialize.cpp",
137 "glslang/MachineIndependent/Initialize.h",
138 "glslang/MachineIndependent/IntermTraverse.cpp",
139 "glslang/MachineIndependent/Intermediate.cpp",
140 "glslang/MachineIndependent/LiveTraverser.h",
141 "glslang/MachineIndependent/ParseContextBase.cpp",
142 "glslang/MachineIndependent/ParseHelper.cpp",
143 "glslang/MachineIndependent/ParseHelper.h",
144 "glslang/MachineIndependent/PoolAlloc.cpp",
145 "glslang/MachineIndependent/RemoveTree.cpp",
146 "glslang/MachineIndependent/RemoveTree.h",
147 "glslang/MachineIndependent/Scan.cpp",
148 "glslang/MachineIndependent/Scan.h",
149 "glslang/MachineIndependent/ScanContext.h",
150 "glslang/MachineIndependent/ShaderLang.cpp",
151 "glslang/MachineIndependent/SymbolTable.cpp",
152 "glslang/MachineIndependent/SymbolTable.h",
153 "glslang/MachineIndependent/Versions.cpp",
154 "glslang/MachineIndependent/Versions.h",
155 "glslang/MachineIndependent/attribute.cpp",
156 "glslang/MachineIndependent/attribute.h",
157 "glslang/MachineIndependent/gl_types.h",
John Kessenich4f32f932020-07-13 03:39:08 -0600158 "glslang/MachineIndependent/glslang_tab.cpp",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400159 "glslang/MachineIndependent/glslang_tab.cpp.h",
160 "glslang/MachineIndependent/intermOut.cpp",
161 "glslang/MachineIndependent/iomapper.cpp",
162 "glslang/MachineIndependent/iomapper.h",
163 "glslang/MachineIndependent/limits.cpp",
164 "glslang/MachineIndependent/linkValidate.cpp",
165 "glslang/MachineIndependent/localintermediate.h",
166 "glslang/MachineIndependent/parseConst.cpp",
167 "glslang/MachineIndependent/parseVersions.h",
168 "glslang/MachineIndependent/preprocessor/Pp.cpp",
169 "glslang/MachineIndependent/preprocessor/PpAtom.cpp",
170 "glslang/MachineIndependent/preprocessor/PpContext.cpp",
171 "glslang/MachineIndependent/preprocessor/PpContext.h",
172 "glslang/MachineIndependent/preprocessor/PpScanner.cpp",
173 "glslang/MachineIndependent/preprocessor/PpTokens.cpp",
174 "glslang/MachineIndependent/preprocessor/PpTokens.h",
175 "glslang/MachineIndependent/propagateNoContraction.cpp",
176 "glslang/MachineIndependent/propagateNoContraction.h",
177 "glslang/MachineIndependent/reflection.cpp",
178 "glslang/MachineIndependent/reflection.h",
179 "glslang/OSDependent/osinclude.h",
180 "glslang/Public/ShaderLang.h",
Dan Sinclair257b25c2018-09-24 16:35:44 -0400181 ]
Dan Sinclair257b25c2018-09-24 16:35:44 -0400182
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400183 # Workaround gn issue complaining about these not being allowed even though GLSLANG_HLSL is not
184 # defined.
185 sources += [
186 "glslang/HLSL/hlslParseHelper.h",
187 "glslang/HLSL/hlslParseables.h",
188 "glslang/HLSL/hlslScanContext.h",
189 "glslang/HLSL/hlslTokens.h",
190 ]
191
192 if (invoker.enable_hlsl) {
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400193 sources += [
194 "glslang/HLSL/hlslAttributes.cpp",
195 "glslang/HLSL/hlslAttributes.h",
196 "glslang/HLSL/hlslGrammar.cpp",
197 "glslang/HLSL/hlslGrammar.h",
198 "glslang/HLSL/hlslOpMap.cpp",
199 "glslang/HLSL/hlslOpMap.h",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400200 "glslang/HLSL/hlslParseHelper.cpp",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400201 "glslang/HLSL/hlslParseables.cpp",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400202 "glslang/HLSL/hlslScanContext.cpp",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400203 "glslang/HLSL/hlslTokenStream.cpp",
204 "glslang/HLSL/hlslTokenStream.h",
205 ]
206 }
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400207
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400208 defines = []
209 if (invoker.enable_opt) {
Shahbaz Youssefi1ef2e252020-07-03 15:42:53 -0400210 sources += [ "SPIRV/SpvTools.cpp" ]
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400211 defines += [ "ENABLE_OPT=1" ]
212 }
Shahbaz Youssefi1ef2e252020-07-03 15:42:53 -0400213 if (invoker.is_angle) {
214 defines += [ "GLSLANG_ANGLE" ]
215 }
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400216
217 if (is_win) {
218 sources += [ "glslang/OSDependent/Windows/ossource.cpp" ]
219 defines += [ "GLSLANG_OSINCLUDE_WIN32" ]
220 } else {
221 sources += [ "glslang/OSDependent/Unix/ossource.cpp" ]
222 defines += [ "GLSLANG_OSINCLUDE_UNIX" ]
223 }
224
225 if (is_clang) {
226 cflags = [
227 "-Wno-extra-semi",
228 "-Wno-ignored-qualifiers",
229 "-Wno-implicit-fallthrough",
230 "-Wno-inconsistent-missing-override",
231 "-Wno-sign-compare",
232 "-Wno-unused-variable",
233 "-Wno-missing-field-initializers",
234 "-Wno-newline-eof",
235 ]
236 }
237 if (is_win && !is_clang) {
238 cflags = [
239 "/wd4018", # signed/unsigned mismatch
240 "/wd4189", # local variable is initialized but not referenced
241 ]
242 }
243
Ben Claytonfbe9a232020-06-17 11:17:19 +0100244 deps = [ ":glslang_build_info" ]
245
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400246 if (invoker.enable_opt) {
Ben Claytonfbe9a232020-06-17 11:17:19 +0100247 deps += [
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400248 "${spirv_tools_dir}:spvtools_opt",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400249 "${spirv_tools_dir}:spvtools_val",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400250 ]
251 }
252
Ben Claytonfbe9a232020-06-17 11:17:19 +0100253 include_dirs = [ "${target_gen_dir}/include" ]
254
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400255 configs -= _configs_to_remove
256 configs += _configs_to_add
257 }
258}
259
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400260glslang_sources_common("glslang_lib_sources") {
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400261 enable_opt = !glslang_angle
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400262 enable_hlsl = !glslang_angle
Shahbaz Youssefi1ef2e252020-07-03 15:42:53 -0400263 is_angle = glslang_angle
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400264}
265
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400266glslang_sources_common("glslang_sources") {
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400267 enable_opt = true
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400268 enable_hlsl = true
Shahbaz Youssefi1ef2e252020-07-03 15:42:53 -0400269 is_angle = false
Dan Sinclairb29c58e2018-09-24 18:40:38 -0400270}
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500271
272source_set("glslang_default_resource_limits_sources") {
273 sources = [
274 "StandAlone/ResourceLimits.cpp",
275 "StandAlone/ResourceLimits.h",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400276 "glslang/Include/ResourceLimits.h",
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500277 ]
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500278 public_configs = [ ":glslang_public" ]
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400279
David Turnera3f0da52019-10-23 16:07:19 +0200280 configs -= _configs_to_remove
281 configs += _configs_to_add
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500282}
283
Jamie Madille880e962019-03-11 15:45:31 -0400284executable("glslang_validator") {
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500285 sources = [
286 "StandAlone/DirStackFileIncluder.h",
287 "StandAlone/StandAlone.cpp",
288 ]
289 if (!is_win) {
290 cflags = [ "-Woverflow" ]
291 }
Shahbaz Youssefi741fc4a2019-05-16 23:53:15 -0400292 defines = [ "ENABLE_OPT=1" ]
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500293 deps = [
294 ":glslang_default_resource_limits_sources",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400295 ":glslang_sources",
Ben Clayton360ba052020-07-10 13:46:25 +0100296 ":glslang_build_info",
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500297 ]
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400298 public_configs = [ ":glslang_hlsl" ]
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400299
Ben Claytonfbe9a232020-06-17 11:17:19 +0100300 include_dirs = [ "${target_gen_dir}/include" ]
301
David Turnera3f0da52019-10-23 16:07:19 +0200302 configs -= _configs_to_remove
303 configs += _configs_to_add
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500304}
David 'Digit' Turner1f5799c2019-06-21 14:58:30 +0200305
306executable("spirv-remap") {
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400307 sources = [ "StandAlone/spirv-remap.cpp" ]
David 'Digit' Turner1f5799c2019-06-21 14:58:30 +0200308 defines = [ "ENABLE_OPT=1" ]
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400309 deps = [ ":glslang_sources" ]
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400310
David Turnera3f0da52019-10-23 16:07:19 +0200311 configs -= _configs_to_remove
312 configs += _configs_to_add
David 'Digit' Turner1f5799c2019-06-21 14:58:30 +0200313}