blob: 4dd0a55396f9b1f9b5d10b83c123bc825c438b9d [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 ]
Jamie Madillbb52b5e2020-08-26 00:54:50 -040062 outputs = [ out_file ]
Ben Claytonfbe9a232020-06-17 11:17:19 +010063 args = [
64 rebase_path(src_dir, root_build_dir),
Jamie Madillbb52b5e2020-08-26 00:54:50 -040065 "-i",
66 rebase_path(template_file, root_build_dir),
67 "-o",
68 rebase_path(out_file, root_build_dir),
Ben Claytonfbe9a232020-06-17 11:17:19 +010069 ]
70}
71
amhagan035a3bb2021-09-01 11:33:21 -040072action("glslang_extension_headers") {
73 script = "gen_extension_headers.py"
74
75 out_file = "${target_gen_dir}/include/glslang/glsl_intrinsic_header.h"
76
Yilong Li97833802022-01-01 15:08:35 -080077 # 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
amhagan035a3bb2021-09-01 11:33:21 -040086 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
Dan Sinclair257b25c2018-09-24 16:35:44 -040098spirv_tools_dir = glslang_spirv_tools_dir
Ryan Harrisoneab46cf2020-07-07 11:45:02 -040099if (!defined(glslang_angle)) {
100 glslang_angle = false
101}
Dan Sinclair257b25c2018-09-24 16:35:44 -0400102
103config("glslang_public") {
104 include_dirs = [ "." ]
jonahryandavis3ce14862020-10-07 13:32:49 -0400105 if (!is_win || is_clang) {
106 cflags = [ "-Wno-conversion" ]
107 }
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400108}
Corentin Wallez9757da42019-08-26 14:13:54 +0200109
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400110config("glslang_hlsl") {
111 defines = [ "ENABLE_HLSL=1" ]
Dan Sinclair257b25c2018-09-24 16:35:44 -0400112}
113
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400114template("glslang_sources_common") {
115 source_set(target_name) {
116 public_configs = [ ":glslang_public" ]
Corentin Wallez6857c232018-10-03 13:15:23 -0400117
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400118 if (invoker.enable_hlsl) {
119 public_configs += [ ":glslang_hlsl" ]
120 }
121
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400122 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/SPVRemapper.cpp",
137 "SPIRV/SPVRemapper.h",
138 "SPIRV/SpvBuilder.cpp",
139 "SPIRV/SpvBuilder.h",
140 "SPIRV/SpvPostProcess.cpp",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400141 "SPIRV/SpvTools.h",
142 "SPIRV/bitutils.h",
143 "SPIRV/disassemble.cpp",
144 "SPIRV/disassemble.h",
145 "SPIRV/doc.cpp",
146 "SPIRV/doc.h",
147 "SPIRV/hex_float.h",
148 "SPIRV/spirv.hpp",
149 "SPIRV/spvIR.h",
150 "glslang/GenericCodeGen/CodeGen.cpp",
151 "glslang/GenericCodeGen/Link.cpp",
152 "glslang/Include/BaseTypes.h",
153 "glslang/Include/Common.h",
154 "glslang/Include/ConstantUnion.h",
155 "glslang/Include/InfoSink.h",
156 "glslang/Include/InitializeGlobals.h",
157 "glslang/Include/PoolAlloc.h",
158 "glslang/Include/ResourceLimits.h",
159 "glslang/Include/ShHandle.h",
Rex Xu65a7fb72021-04-25 16:52:35 +0800160 "glslang/Include/SpirvIntrinsics.h",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400161 "glslang/Include/Types.h",
162 "glslang/Include/arrays.h",
163 "glslang/Include/intermediate.h",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400164 "glslang/MachineIndependent/Constant.cpp",
165 "glslang/MachineIndependent/InfoSink.cpp",
166 "glslang/MachineIndependent/Initialize.cpp",
167 "glslang/MachineIndependent/Initialize.h",
168 "glslang/MachineIndependent/IntermTraverse.cpp",
169 "glslang/MachineIndependent/Intermediate.cpp",
170 "glslang/MachineIndependent/LiveTraverser.h",
171 "glslang/MachineIndependent/ParseContextBase.cpp",
172 "glslang/MachineIndependent/ParseHelper.cpp",
173 "glslang/MachineIndependent/ParseHelper.h",
174 "glslang/MachineIndependent/PoolAlloc.cpp",
175 "glslang/MachineIndependent/RemoveTree.cpp",
176 "glslang/MachineIndependent/RemoveTree.h",
177 "glslang/MachineIndependent/Scan.cpp",
178 "glslang/MachineIndependent/Scan.h",
179 "glslang/MachineIndependent/ScanContext.h",
180 "glslang/MachineIndependent/ShaderLang.cpp",
Rex Xu65a7fb72021-04-25 16:52:35 +0800181 "glslang/MachineIndependent/SpirvIntrinsics.cpp",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400182 "glslang/MachineIndependent/SymbolTable.cpp",
183 "glslang/MachineIndependent/SymbolTable.h",
184 "glslang/MachineIndependent/Versions.cpp",
185 "glslang/MachineIndependent/Versions.h",
186 "glslang/MachineIndependent/attribute.cpp",
187 "glslang/MachineIndependent/attribute.h",
188 "glslang/MachineIndependent/gl_types.h",
John Kessenich4f32f932020-07-13 03:39:08 -0600189 "glslang/MachineIndependent/glslang_tab.cpp",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400190 "glslang/MachineIndependent/glslang_tab.cpp.h",
191 "glslang/MachineIndependent/intermOut.cpp",
192 "glslang/MachineIndependent/iomapper.cpp",
193 "glslang/MachineIndependent/iomapper.h",
194 "glslang/MachineIndependent/limits.cpp",
195 "glslang/MachineIndependent/linkValidate.cpp",
196 "glslang/MachineIndependent/localintermediate.h",
197 "glslang/MachineIndependent/parseConst.cpp",
198 "glslang/MachineIndependent/parseVersions.h",
199 "glslang/MachineIndependent/preprocessor/Pp.cpp",
200 "glslang/MachineIndependent/preprocessor/PpAtom.cpp",
201 "glslang/MachineIndependent/preprocessor/PpContext.cpp",
202 "glslang/MachineIndependent/preprocessor/PpContext.h",
203 "glslang/MachineIndependent/preprocessor/PpScanner.cpp",
204 "glslang/MachineIndependent/preprocessor/PpTokens.cpp",
205 "glslang/MachineIndependent/preprocessor/PpTokens.h",
206 "glslang/MachineIndependent/propagateNoContraction.cpp",
207 "glslang/MachineIndependent/propagateNoContraction.h",
208 "glslang/MachineIndependent/reflection.cpp",
209 "glslang/MachineIndependent/reflection.h",
210 "glslang/OSDependent/osinclude.h",
211 "glslang/Public/ShaderLang.h",
Dan Sinclair257b25c2018-09-24 16:35:44 -0400212 ]
Dan Sinclair257b25c2018-09-24 16:35:44 -0400213
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400214 # Workaround gn issue complaining about these not being allowed even though GLSLANG_HLSL is not
215 # defined.
216 sources += [
217 "glslang/HLSL/hlslParseHelper.h",
218 "glslang/HLSL/hlslParseables.h",
219 "glslang/HLSL/hlslScanContext.h",
220 "glslang/HLSL/hlslTokens.h",
221 ]
222
223 if (invoker.enable_hlsl) {
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400224 sources += [
225 "glslang/HLSL/hlslAttributes.cpp",
226 "glslang/HLSL/hlslAttributes.h",
227 "glslang/HLSL/hlslGrammar.cpp",
228 "glslang/HLSL/hlslGrammar.h",
229 "glslang/HLSL/hlslOpMap.cpp",
230 "glslang/HLSL/hlslOpMap.h",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400231 "glslang/HLSL/hlslParseHelper.cpp",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400232 "glslang/HLSL/hlslParseables.cpp",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400233 "glslang/HLSL/hlslScanContext.cpp",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400234 "glslang/HLSL/hlslTokenStream.cpp",
235 "glslang/HLSL/hlslTokenStream.h",
236 ]
237 }
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400238
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400239 defines = []
240 if (invoker.enable_opt) {
Shahbaz Youssefi1ef2e252020-07-03 15:42:53 -0400241 sources += [ "SPIRV/SpvTools.cpp" ]
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400242 defines += [ "ENABLE_OPT=1" ]
243 }
Shahbaz Youssefi1ef2e252020-07-03 15:42:53 -0400244 if (invoker.is_angle) {
245 defines += [ "GLSLANG_ANGLE" ]
246 }
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400247
248 if (is_win) {
249 sources += [ "glslang/OSDependent/Windows/ossource.cpp" ]
250 defines += [ "GLSLANG_OSINCLUDE_WIN32" ]
251 } else {
252 sources += [ "glslang/OSDependent/Unix/ossource.cpp" ]
253 defines += [ "GLSLANG_OSINCLUDE_UNIX" ]
254 }
255
256 if (is_clang) {
257 cflags = [
258 "-Wno-extra-semi",
259 "-Wno-ignored-qualifiers",
260 "-Wno-implicit-fallthrough",
261 "-Wno-inconsistent-missing-override",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400262 "-Wno-missing-field-initializers",
263 "-Wno-newline-eof",
Jamie Madillbb52b5e2020-08-26 00:54:50 -0400264 "-Wno-sign-compare",
265 "-Wno-suggest-destructor-override",
266 "-Wno-suggest-override",
267 "-Wno-unused-variable",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400268 ]
269 }
270 if (is_win && !is_clang) {
271 cflags = [
272 "/wd4018", # signed/unsigned mismatch
273 "/wd4189", # local variable is initialized but not referenced
274 ]
275 }
276
pheonixc897c3b2020-11-02 13:40:50 -0800277 include_dirs = [ "${target_gen_dir}/include" ]
278
Ben Claytonfbe9a232020-06-17 11:17:19 +0100279 deps = [ ":glslang_build_info" ]
280
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400281 if (invoker.enable_opt) {
Ben Claytonfbe9a232020-06-17 11:17:19 +0100282 deps += [
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400283 "${spirv_tools_dir}:spvtools_opt",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400284 "${spirv_tools_dir}:spvtools_val",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400285 ]
pheonixc897c3b2020-11-02 13:40:50 -0800286 include_dirs += [ "${spirv_tools_dir}/include" ]
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400287 }
288
289 configs -= _configs_to_remove
290 configs += _configs_to_add
291 }
292}
293
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400294glslang_sources_common("glslang_lib_sources") {
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400295 enable_opt = !glslang_angle
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400296 enable_hlsl = !glslang_angle
Shahbaz Youssefi1ef2e252020-07-03 15:42:53 -0400297 is_angle = glslang_angle
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400298}
299
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400300glslang_sources_common("glslang_sources") {
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400301 enable_opt = true
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400302 enable_hlsl = true
Shahbaz Youssefi1ef2e252020-07-03 15:42:53 -0400303 is_angle = false
Dan Sinclairb29c58e2018-09-24 18:40:38 -0400304}
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500305
306source_set("glslang_default_resource_limits_sources") {
307 sources = [
308 "StandAlone/ResourceLimits.cpp",
309 "StandAlone/ResourceLimits.h",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400310 "glslang/Include/ResourceLimits.h",
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500311 ]
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500312 public_configs = [ ":glslang_public" ]
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400313
David Turnera3f0da52019-10-23 16:07:19 +0200314 configs -= _configs_to_remove
315 configs += _configs_to_add
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500316}
317
Jamie Madille880e962019-03-11 15:45:31 -0400318executable("glslang_validator") {
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500319 sources = [
320 "StandAlone/DirStackFileIncluder.h",
321 "StandAlone/StandAlone.cpp",
322 ]
323 if (!is_win) {
324 cflags = [ "-Woverflow" ]
325 }
Shahbaz Youssefi741fc4a2019-05-16 23:53:15 -0400326 defines = [ "ENABLE_OPT=1" ]
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500327 deps = [
Jamie Madillbb52b5e2020-08-26 00:54:50 -0400328 ":glslang_build_info",
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500329 ":glslang_default_resource_limits_sources",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400330 ":glslang_sources",
amhagan035a3bb2021-09-01 11:33:21 -0400331 ":glslang_extension_headers",
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500332 ]
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400333 public_configs = [ ":glslang_hlsl" ]
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400334
pheonixc897c3b2020-11-02 13:40:50 -0800335 include_dirs = [
336 "${target_gen_dir}/include",
337 "${spirv_tools_dir}/include",
338 ]
Ben Claytonfbe9a232020-06-17 11:17:19 +0100339
David Turnera3f0da52019-10-23 16:07:19 +0200340 configs -= _configs_to_remove
341 configs += _configs_to_add
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500342}
David 'Digit' Turner1f5799c2019-06-21 14:58:30 +0200343
344executable("spirv-remap") {
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400345 sources = [ "StandAlone/spirv-remap.cpp" ]
David 'Digit' Turner1f5799c2019-06-21 14:58:30 +0200346 defines = [ "ENABLE_OPT=1" ]
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400347 deps = [ ":glslang_sources" ]
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400348
Courtney Goeltzenleuchterd550beb2020-11-02 21:22:55 -0700349 include_dirs = [ "${spirv_tools_dir}/include" ]
pheonixc897c3b2020-11-02 13:40:50 -0800350
David Turnera3f0da52019-10-23 16:07:19 +0200351 configs -= _configs_to_remove
352 configs += _configs_to_add
David 'Digit' Turner1f5799c2019-06-21 14:58:30 +0200353}