blob: 09a0c719dedb974b147006775671690079384d5a [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",
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",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400135 "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",
Dan Sinclair257b25c2018-09-24 16:35:44 -0400182 ]
Dan Sinclair257b25c2018-09-24 16:35:44 -0400183
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400184 # 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) {
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400194 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",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400201 "glslang/HLSL/hlslParseHelper.cpp",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400202 "glslang/HLSL/hlslParseables.cpp",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400203 "glslang/HLSL/hlslScanContext.cpp",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400204 "glslang/HLSL/hlslTokenStream.cpp",
205 "glslang/HLSL/hlslTokenStream.h",
206 ]
207 }
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400208
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400209 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
Ben Claytonfbe9a232020-06-17 11:17:19 +0100241 deps = [ ":glslang_build_info" ]
242
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400243 if (invoker.enable_opt) {
Ben Claytonfbe9a232020-06-17 11:17:19 +0100244 deps += [
245 ":glslang_build_info",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400246 "${spirv_tools_dir}:spvtools_opt",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400247 "${spirv_tools_dir}:spvtools_val",
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400248 ]
249 }
250
Ben Claytonfbe9a232020-06-17 11:17:19 +0100251 include_dirs = [ "${target_gen_dir}/include" ]
252
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400253 configs -= _configs_to_remove
254 configs += _configs_to_add
255 }
256}
257
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400258glslang_sources_common("glslang_lib_sources") {
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400259 enable_opt = !glslang_angle
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400260 enable_hlsl = !glslang_angle
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400261}
262
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400263glslang_sources_common("glslang_sources") {
Shahbaz Youssefi8f8f1bc2020-07-03 12:34:06 -0400264 enable_opt = true
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400265 enable_hlsl = true
Dan Sinclairb29c58e2018-09-24 18:40:38 -0400266}
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500267
268source_set("glslang_default_resource_limits_sources") {
269 sources = [
270 "StandAlone/ResourceLimits.cpp",
271 "StandAlone/ResourceLimits.h",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400272 "glslang/Include/ResourceLimits.h",
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500273 ]
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500274 public_configs = [ ":glslang_public" ]
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400275
David Turnera3f0da52019-10-23 16:07:19 +0200276 configs -= _configs_to_remove
277 configs += _configs_to_add
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500278}
279
Jamie Madille880e962019-03-11 15:45:31 -0400280executable("glslang_validator") {
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500281 sources = [
282 "StandAlone/DirStackFileIncluder.h",
283 "StandAlone/StandAlone.cpp",
284 ]
285 if (!is_win) {
286 cflags = [ "-Woverflow" ]
287 }
Shahbaz Youssefi741fc4a2019-05-16 23:53:15 -0400288 defines = [ "ENABLE_OPT=1" ]
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500289 deps = [
290 ":glslang_default_resource_limits_sources",
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400291 ":glslang_sources",
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500292 ]
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400293 public_configs = [ ":glslang_hlsl" ]
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400294
Ben Claytonfbe9a232020-06-17 11:17:19 +0100295 include_dirs = [ "${target_gen_dir}/include" ]
296
David Turnera3f0da52019-10-23 16:07:19 +0200297 configs -= _configs_to_remove
298 configs += _configs_to_add
Jamie Madill0ceaebc2019-01-18 14:53:31 -0500299}
David 'Digit' Turner1f5799c2019-06-21 14:58:30 +0200300
301executable("spirv-remap") {
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400302 sources = [ "StandAlone/spirv-remap.cpp" ]
David 'Digit' Turner1f5799c2019-06-21 14:58:30 +0200303 defines = [ "ENABLE_OPT=1" ]
Shahbaz Youssefia55029d2020-07-05 16:48:34 -0400304 deps = [ ":glslang_sources" ]
Ryan Harrison1aeceae2019-10-15 11:17:53 -0400305
David Turnera3f0da52019-10-23 16:07:19 +0200306 configs -= _configs_to_remove
307 configs += _configs_to_add
David 'Digit' Turner1f5799c2019-06-21 14:58:30 +0200308}