blob: 474375306b852b2d79b835cfed250c4d8024b5c0 [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
Dan Sinclair257b25c2018-09-24 16:35:44 -040049spirv_tools_dir = glslang_spirv_tools_dir
Ryan Harrisoneab46cf2020-07-07 11:45:02 -040050if (!defined(glslang_angle)) {
51 glslang_angle = false
52}
Dan Sinclair257b25c2018-09-24 16:35:44 -040053
54config("glslang_public") {
55 include_dirs = [ "." ]
Shahbaz Youssefia55029d2020-07-05 16:48:34 -040056}
Corentin Wallez9757da42019-08-26 14:13:54 +020057
Shahbaz Youssefia55029d2020-07-05 16:48:34 -040058config("glslang_hlsl") {
59 defines = [ "ENABLE_HLSL=1" ]
Dan Sinclair257b25c2018-09-24 16:35:44 -040060}
61
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -040062template("glslang_sources_common") {
63 source_set(target_name) {
64 public_configs = [ ":glslang_public" ]
Corentin Wallez6857c232018-10-03 13:15:23 -040065
Shahbaz Youssefia55029d2020-07-05 16:48:34 -040066 if (invoker.enable_hlsl) {
67 public_configs += [ ":glslang_hlsl" ]
68 }
69
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -040070 sources = [
71 "OGLCompilersDLL/InitializeDll.cpp",
72 "OGLCompilersDLL/InitializeDll.h",
73 "SPIRV/GLSL.ext.AMD.h",
74 "SPIRV/GLSL.ext.EXT.h",
75 "SPIRV/GLSL.ext.KHR.h",
76 "SPIRV/GLSL.ext.NV.h",
77 "SPIRV/GLSL.std.450.h",
78 "SPIRV/GlslangToSpv.cpp",
79 "SPIRV/GlslangToSpv.h",
80 "SPIRV/InReadableOrder.cpp",
81 "SPIRV/Logger.cpp",
82 "SPIRV/Logger.h",
83 "SPIRV/NonSemanticDebugPrintf.h",
84 "SPIRV/SPVRemapper.cpp",
85 "SPIRV/SPVRemapper.h",
86 "SPIRV/SpvBuilder.cpp",
87 "SPIRV/SpvBuilder.h",
88 "SPIRV/SpvPostProcess.cpp",
89 "SPIRV/SpvTools.cpp",
90 "SPIRV/SpvTools.h",
91 "SPIRV/bitutils.h",
92 "SPIRV/disassemble.cpp",
93 "SPIRV/disassemble.h",
94 "SPIRV/doc.cpp",
95 "SPIRV/doc.h",
96 "SPIRV/hex_float.h",
97 "SPIRV/spirv.hpp",
98 "SPIRV/spvIR.h",
99 "glslang/GenericCodeGen/CodeGen.cpp",
100 "glslang/GenericCodeGen/Link.cpp",
101 "glslang/Include/BaseTypes.h",
102 "glslang/Include/Common.h",
103 "glslang/Include/ConstantUnion.h",
104 "glslang/Include/InfoSink.h",
105 "glslang/Include/InitializeGlobals.h",
106 "glslang/Include/PoolAlloc.h",
107 "glslang/Include/ResourceLimits.h",
108 "glslang/Include/ShHandle.h",
109 "glslang/Include/Types.h",
110 "glslang/Include/arrays.h",
111 "glslang/Include/intermediate.h",
112 "glslang/Include/revision.h",
113 "glslang/MachineIndependent/Constant.cpp",
114 "glslang/MachineIndependent/InfoSink.cpp",
115 "glslang/MachineIndependent/Initialize.cpp",
116 "glslang/MachineIndependent/Initialize.h",
117 "glslang/MachineIndependent/IntermTraverse.cpp",
118 "glslang/MachineIndependent/Intermediate.cpp",
119 "glslang/MachineIndependent/LiveTraverser.h",
120 "glslang/MachineIndependent/ParseContextBase.cpp",
121 "glslang/MachineIndependent/ParseHelper.cpp",
122 "glslang/MachineIndependent/ParseHelper.h",
123 "glslang/MachineIndependent/PoolAlloc.cpp",
124 "glslang/MachineIndependent/RemoveTree.cpp",
125 "glslang/MachineIndependent/RemoveTree.h",
126 "glslang/MachineIndependent/Scan.cpp",
127 "glslang/MachineIndependent/Scan.h",
128 "glslang/MachineIndependent/ScanContext.h",
129 "glslang/MachineIndependent/ShaderLang.cpp",
130 "glslang/MachineIndependent/SymbolTable.cpp",
131 "glslang/MachineIndependent/SymbolTable.h",
132 "glslang/MachineIndependent/Versions.cpp",
133 "glslang/MachineIndependent/Versions.h",
134 "glslang/MachineIndependent/attribute.cpp",
135 "glslang/MachineIndependent/attribute.h",
136 "glslang/MachineIndependent/gl_types.h",
137 "glslang/MachineIndependent/glslang_tab.cpp",
138 "glslang/MachineIndependent/glslang_tab.cpp.h",
139 "glslang/MachineIndependent/intermOut.cpp",
140 "glslang/MachineIndependent/iomapper.cpp",
141 "glslang/MachineIndependent/iomapper.h",
142 "glslang/MachineIndependent/limits.cpp",
143 "glslang/MachineIndependent/linkValidate.cpp",
144 "glslang/MachineIndependent/localintermediate.h",
145 "glslang/MachineIndependent/parseConst.cpp",
146 "glslang/MachineIndependent/parseVersions.h",
147 "glslang/MachineIndependent/preprocessor/Pp.cpp",
148 "glslang/MachineIndependent/preprocessor/PpAtom.cpp",
149 "glslang/MachineIndependent/preprocessor/PpContext.cpp",
150 "glslang/MachineIndependent/preprocessor/PpContext.h",
151 "glslang/MachineIndependent/preprocessor/PpScanner.cpp",
152 "glslang/MachineIndependent/preprocessor/PpTokens.cpp",
153 "glslang/MachineIndependent/preprocessor/PpTokens.h",
154 "glslang/MachineIndependent/propagateNoContraction.cpp",
155 "glslang/MachineIndependent/propagateNoContraction.h",
156 "glslang/MachineIndependent/reflection.cpp",
157 "glslang/MachineIndependent/reflection.h",
158 "glslang/OSDependent/osinclude.h",
159 "glslang/Public/ShaderLang.h",
Dan Sinclair257b25c2018-09-24 16:35:44 -0400160 ]
Dan Sinclair257b25c2018-09-24 16:35:44 -0400161
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400162 # Workaround gn issue complaining about these not being allowed even though GLSLANG_HLSL is not
163 # defined.
164 sources += [
165 "glslang/HLSL/hlslParseHelper.h",
166 "glslang/HLSL/hlslParseables.h",
167 "glslang/HLSL/hlslScanContext.h",
168 "glslang/HLSL/hlslTokens.h",
169 ]
170
171 if (invoker.enable_hlsl) {
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400172 sources += [
173 "glslang/HLSL/hlslAttributes.cpp",
174 "glslang/HLSL/hlslAttributes.h",
175 "glslang/HLSL/hlslGrammar.cpp",
176 "glslang/HLSL/hlslGrammar.h",
177 "glslang/HLSL/hlslOpMap.cpp",
178 "glslang/HLSL/hlslOpMap.h",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400179 "glslang/HLSL/hlslParseHelper.cpp",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400180 "glslang/HLSL/hlslParseables.cpp",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400181 "glslang/HLSL/hlslScanContext.cpp",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400182 "glslang/HLSL/hlslTokenStream.cpp",
183 "glslang/HLSL/hlslTokenStream.h",
184 ]
185 }
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400186
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400187 defines = []
188 if (invoker.enable_opt) {
189 defines += [ "ENABLE_OPT=1" ]
190 }
191
192 if (is_win) {
193 sources += [ "glslang/OSDependent/Windows/ossource.cpp" ]
194 defines += [ "GLSLANG_OSINCLUDE_WIN32" ]
195 } else {
196 sources += [ "glslang/OSDependent/Unix/ossource.cpp" ]
197 defines += [ "GLSLANG_OSINCLUDE_UNIX" ]
198 }
199
200 if (is_clang) {
201 cflags = [
202 "-Wno-extra-semi",
203 "-Wno-ignored-qualifiers",
204 "-Wno-implicit-fallthrough",
205 "-Wno-inconsistent-missing-override",
206 "-Wno-sign-compare",
207 "-Wno-unused-variable",
208 "-Wno-missing-field-initializers",
209 "-Wno-newline-eof",
210 ]
211 }
212 if (is_win && !is_clang) {
213 cflags = [
214 "/wd4018", # signed/unsigned mismatch
215 "/wd4189", # local variable is initialized but not referenced
216 ]
217 }
218
219 if (invoker.enable_opt) {
220 deps = [
221 "${spirv_tools_dir}:spvtools_opt",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400222 "${spirv_tools_dir}:spvtools_val",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400223 ]
224 }
225
226 configs -= _configs_to_remove
227 configs += _configs_to_add
228 }
229}
230
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400231glslang_sources_common("glslang_lib_sources") {
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400232 enable_opt = !glslang_angle
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400233 enable_hlsl = !glslang_angle
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400234}
235
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400236glslang_sources_common("glslang_sources") {
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400237 enable_opt = true
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400238 enable_hlsl = true
Dan Sinclairb29c58e2018-09-24 18:40:38 -0400239}
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500240
241source_set("glslang_default_resource_limits_sources") {
242 sources = [
243 "StandAlone/ResourceLimits.cpp",
244 "StandAlone/ResourceLimits.h",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400245 "glslang/Include/ResourceLimits.h",
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500246 ]
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500247 public_configs = [ ":glslang_public" ]
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400248
David Turnera3f0da52019-10-23 16:07:19 +0200249 configs -= _configs_to_remove
250 configs += _configs_to_add
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500251}
252
Jamie Madille880e962019-03-11 15:45:31 -0400253executable("glslang_validator") {
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500254 sources = [
255 "StandAlone/DirStackFileIncluder.h",
256 "StandAlone/StandAlone.cpp",
257 ]
258 if (!is_win) {
259 cflags = [ "-Woverflow" ]
260 }
Shahbaz Youssefi741fc4a2019-05-16 23:53:15 -0400261 defines = [ "ENABLE_OPT=1" ]
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500262 deps = [
263 ":glslang_default_resource_limits_sources",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400264 ":glslang_sources",
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500265 ]
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400266 public_configs = [ ":glslang_hlsl" ]
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400267
David Turnera3f0da52019-10-23 16:07:19 +0200268 configs -= _configs_to_remove
269 configs += _configs_to_add
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500270}
David 'Digit' Turner1f5799c2019-06-21 14:58:30 +0200271
272executable("spirv-remap") {
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400273 sources = [ "StandAlone/spirv-remap.cpp" ]
David 'Digit' Turner1f5799c2019-06-21 14:58:30 +0200274 defines = [ "ENABLE_OPT=1" ]
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400275 deps = [ ":glslang_sources" ]
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400276
David Turnera3f0da52019-10-23 16:07:19 +0200277 configs -= _configs_to_remove
278 configs += _configs_to_add
David 'Digit' Turner1f5799c2019-06-21 14:58:30 +0200279}