1# 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 36# 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 49action("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 = [ out_file ] 63 args = [ 64 rebase_path(src_dir, root_build_dir), 65 "-i", 66 rebase_path(template_file, root_build_dir), 67 "-o", 68 rebase_path(out_file, root_build_dir), 69 ] 70} 71 72action("glslang_extension_headers") { 73 script = "gen_extension_headers.py" 74 75 out_file = "${target_gen_dir}/include/glslang/glsl_intrinsic_header.h" 76 77 # 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 86 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 98spirv_tools_dir = glslang_spirv_tools_dir 99if (!defined(glslang_angle)) { 100 glslang_angle = false 101} 102 103config("glslang_public") { 104 include_dirs = [ "." ] 105 if (!is_win || is_clang) { 106 cflags = [ "-Wno-conversion" ] 107 } 108} 109 110config("glslang_hlsl") { 111 defines = [ "ENABLE_HLSL=1" ] 112} 113 114template("glslang_sources_common") { 115 source_set(target_name) { 116 public_configs = [ ":glslang_public" ] 117 118 if (invoker.enable_hlsl) { 119 public_configs += [ ":glslang_hlsl" ] 120 } 121 122 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", 141 "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", 160 "glslang/Include/SpirvIntrinsics.h", 161 "glslang/Include/Types.h", 162 "glslang/Include/arrays.h", 163 "glslang/Include/intermediate.h", 164 "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", 181 "glslang/MachineIndependent/SpirvIntrinsics.cpp", 182 "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", 189 "glslang/MachineIndependent/glslang_tab.cpp", 190 "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", 212 ] 213 214 # 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) { 224 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", 231 "glslang/HLSL/hlslParseHelper.cpp", 232 "glslang/HLSL/hlslParseables.cpp", 233 "glslang/HLSL/hlslScanContext.cpp", 234 "glslang/HLSL/hlslTokenStream.cpp", 235 "glslang/HLSL/hlslTokenStream.h", 236 ] 237 } 238 239 defines = [] 240 if (invoker.enable_opt) { 241 sources += [ "SPIRV/SpvTools.cpp" ] 242 defines += [ "ENABLE_OPT=1" ] 243 } 244 if (invoker.is_angle) { 245 defines += [ "GLSLANG_ANGLE" ] 246 } 247 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", 262 "-Wno-missing-field-initializers", 263 "-Wno-newline-eof", 264 "-Wno-sign-compare", 265 "-Wno-suggest-destructor-override", 266 "-Wno-suggest-override", 267 "-Wno-unused-variable", 268 ] 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 277 include_dirs = [ "${target_gen_dir}/include" ] 278 279 deps = [ ":glslang_build_info" ] 280 281 if (invoker.enable_opt) { 282 deps += [ 283 "${spirv_tools_dir}:spvtools_opt", 284 "${spirv_tools_dir}:spvtools_val", 285 ] 286 include_dirs += [ "${spirv_tools_dir}/include" ] 287 } 288 289 configs -= _configs_to_remove 290 configs += _configs_to_add 291 } 292} 293 294glslang_sources_common("glslang_lib_sources") { 295 enable_opt = !glslang_angle 296 enable_hlsl = !glslang_angle 297 is_angle = glslang_angle 298} 299 300glslang_sources_common("glslang_sources") { 301 enable_opt = true 302 enable_hlsl = true 303 is_angle = false 304} 305 306source_set("glslang_default_resource_limits_sources") { 307 sources = [ 308 "StandAlone/ResourceLimits.cpp", 309 "StandAlone/ResourceLimits.h", 310 "glslang/Include/ResourceLimits.h", 311 ] 312 public_configs = [ ":glslang_public" ] 313 314 configs -= _configs_to_remove 315 configs += _configs_to_add 316} 317 318executable("glslang_validator") { 319 sources = [ 320 "StandAlone/DirStackFileIncluder.h", 321 "StandAlone/StandAlone.cpp", 322 ] 323 if (!is_win) { 324 cflags = [ "-Woverflow" ] 325 } 326 defines = [ "ENABLE_OPT=1" ] 327 deps = [ 328 ":glslang_build_info", 329 ":glslang_default_resource_limits_sources", 330 ":glslang_sources", 331 ":glslang_extension_headers", 332 ] 333 public_configs = [ ":glslang_hlsl" ] 334 335 include_dirs = [ 336 "${target_gen_dir}/include", 337 "${spirv_tools_dir}/include", 338 ] 339 340 configs -= _configs_to_remove 341 configs += _configs_to_add 342} 343 344executable("spirv-remap") { 345 sources = [ "StandAlone/spirv-remap.cpp" ] 346 defines = [ "ENABLE_OPT=1" ] 347 deps = [ ":glslang_sources" ] 348 349 include_dirs = [ "${spirv_tools_dir}/include" ] 350 351 configs -= _configs_to_remove 352 configs += _configs_to_add 353} 354