blob: 973ca98b55e96cff96eb7bdcde8e8e58bc27056d [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
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 = [ "." ]
jonahryandavis3ce14862020-10-07 13:32:49 -040079 if (!is_win || is_clang) {
80 cflags = [ "-Wno-conversion" ]
81 }
Shahbaz Youssefia55029d2020-07-05 16:48:34 -040082}
Corentin Wallez9757da42019-08-26 14:13:54 +020083
Shahbaz Youssefia55029d2020-07-05 16:48:34 -040084config("glslang_hlsl") {
85 defines = [ "ENABLE_HLSL=1" ]
Dan Sinclair257b25c2018-09-24 16:35:44 -040086}
87
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -040088template("glslang_sources_common") {
89 source_set(target_name) {
90 public_configs = [ ":glslang_public" ]
Corentin Wallez6857c232018-10-03 13:15:23 -040091
Shahbaz Youssefia55029d2020-07-05 16:48:34 -040092 if (invoker.enable_hlsl) {
93 public_configs += [ ":glslang_hlsl" ]
94 }
95
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -040096 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",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400115 "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",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400137 "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",
John Kessenich4f32f932020-07-13 03:39:08 -0600161 "glslang/MachineIndependent/glslang_tab.cpp",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400162 "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",
Dan Sinclair257b25c2018-09-24 16:35:44 -0400184 ]
Dan Sinclair257b25c2018-09-24 16:35:44 -0400185
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400186 # 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) {
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400196 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",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400203 "glslang/HLSL/hlslParseHelper.cpp",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400204 "glslang/HLSL/hlslParseables.cpp",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400205 "glslang/HLSL/hlslScanContext.cpp",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400206 "glslang/HLSL/hlslTokenStream.cpp",
207 "glslang/HLSL/hlslTokenStream.h",
208 ]
209 }
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400210
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400211 defines = []
212 if (invoker.enable_opt) {
Shahbaz Youssefi1ef2e252020-07-03 15:42:53 -0400213 sources += [ "SPIRV/SpvTools.cpp" ]
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400214 defines += [ "ENABLE_OPT=1" ]
215 }
Shahbaz Youssefi1ef2e252020-07-03 15:42:53 -0400216 if (invoker.is_angle) {
217 defines += [ "GLSLANG_ANGLE" ]
218 }
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400219
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",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400234 "-Wno-missing-field-initializers",
235 "-Wno-newline-eof",
Jamie Madillbb52b5e2020-08-26 00:54:50 -0400236 "-Wno-sign-compare",
237 "-Wno-suggest-destructor-override",
238 "-Wno-suggest-override",
239 "-Wno-unused-variable",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400240 ]
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
pheonixc897c3b2020-11-02 13:40:50 -0800249 include_dirs = [ "${target_gen_dir}/include" ]
250
Ben Claytonfbe9a232020-06-17 11:17:19 +0100251 deps = [ ":glslang_build_info" ]
252
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400253 if (invoker.enable_opt) {
Ben Claytonfbe9a232020-06-17 11:17:19 +0100254 deps += [
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400255 "${spirv_tools_dir}:spvtools_opt",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400256 "${spirv_tools_dir}:spvtools_val",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400257 ]
pheonixc897c3b2020-11-02 13:40:50 -0800258 include_dirs += [ "${spirv_tools_dir}/include" ]
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400259 }
260
261 configs -= _configs_to_remove
262 configs += _configs_to_add
263 }
264}
265
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400266glslang_sources_common("glslang_lib_sources") {
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400267 enable_opt = !glslang_angle
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400268 enable_hlsl = !glslang_angle
Shahbaz Youssefi1ef2e252020-07-03 15:42:53 -0400269 is_angle = glslang_angle
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400270}
271
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400272glslang_sources_common("glslang_sources") {
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400273 enable_opt = true
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400274 enable_hlsl = true
Shahbaz Youssefi1ef2e252020-07-03 15:42:53 -0400275 is_angle = false
Dan Sinclairb29c58e2018-09-24 18:40:38 -0400276}
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500277
278source_set("glslang_default_resource_limits_sources") {
279 sources = [
280 "StandAlone/ResourceLimits.cpp",
281 "StandAlone/ResourceLimits.h",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400282 "glslang/Include/ResourceLimits.h",
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500283 ]
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500284 public_configs = [ ":glslang_public" ]
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400285
David Turnera3f0da52019-10-23 16:07:19 +0200286 configs -= _configs_to_remove
287 configs += _configs_to_add
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500288}
289
Jamie Madille880e962019-03-11 15:45:31 -0400290executable("glslang_validator") {
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500291 sources = [
292 "StandAlone/DirStackFileIncluder.h",
293 "StandAlone/StandAlone.cpp",
294 ]
295 if (!is_win) {
296 cflags = [ "-Woverflow" ]
297 }
Shahbaz Youssefi741fc4a2019-05-16 23:53:15 -0400298 defines = [ "ENABLE_OPT=1" ]
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500299 deps = [
Jamie Madillbb52b5e2020-08-26 00:54:50 -0400300 ":glslang_build_info",
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500301 ":glslang_default_resource_limits_sources",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400302 ":glslang_sources",
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500303 ]
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400304 public_configs = [ ":glslang_hlsl" ]
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400305
pheonixc897c3b2020-11-02 13:40:50 -0800306 include_dirs = [
307 "${target_gen_dir}/include",
308 "${spirv_tools_dir}/include",
309 ]
Ben Claytonfbe9a232020-06-17 11:17:19 +0100310
David Turnera3f0da52019-10-23 16:07:19 +0200311 configs -= _configs_to_remove
312 configs += _configs_to_add
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500313}
David 'Digit' Turner1f5799c2019-06-21 14:58:30 +0200314
315executable("spirv-remap") {
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400316 sources = [ "StandAlone/spirv-remap.cpp" ]
David 'Digit' Turner1f5799c2019-06-21 14:58:30 +0200317 defines = [ "ENABLE_OPT=1" ]
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400318 deps = [ ":glslang_sources" ]
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400319
Courtney Goeltzenleuchterd550beb2020-11-02 21:22:55 -0700320 include_dirs = [ "${spirv_tools_dir}/include" ]
pheonixc897c3b2020-11-02 13:40:50 -0800321
David Turnera3f0da52019-10-23 16:07:19 +0200322 configs -= _configs_to_remove
323 configs += _configs_to_add
David 'Digit' Turner1f5799c2019-06-21 14:58:30 +0200324}