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 99 100config("glslang_public") { 101 include_dirs = [ "." ] 102 if (!is_win || is_clang) { 103 cflags = [ "-Wno-conversion" ] 104 } 105} 106 107config("glslang_hlsl") { 108 defines = [ "ENABLE_HLSL=1" ] 109} 110 111template("glslang_sources_common") { 112 source_set(target_name) { 113 public_configs = [ ":glslang_public" ] 114 115 if (invoker.enable_hlsl) { 116 public_configs += [ ":glslang_hlsl" ] 117 } 118 119 sources = [ 120 "SPIRV/GLSL.ext.AMD.h", 121 "SPIRV/GLSL.ext.EXT.h", 122 "SPIRV/GLSL.ext.KHR.h", 123 "SPIRV/GLSL.ext.NV.h", 124 "SPIRV/GLSL.ext.ARM.h", 125 "SPIRV/GLSL.ext.QCOM.h", 126 "SPIRV/GLSL.std.450.h", 127 "SPIRV/GlslangToSpv.cpp", 128 "SPIRV/GlslangToSpv.h", 129 "SPIRV/InReadableOrder.cpp", 130 "SPIRV/Logger.cpp", 131 "SPIRV/Logger.h", 132 "SPIRV/NonSemanticDebugPrintf.h", 133 "SPIRV/NonSemanticShaderDebugInfo100.h", 134 "SPIRV/SPVRemapper.cpp", 135 "SPIRV/SPVRemapper.h", 136 "SPIRV/SpvBuilder.cpp", 137 "SPIRV/SpvBuilder.h", 138 "SPIRV/SpvPostProcess.cpp", 139 "SPIRV/SpvTools.h", 140 "SPIRV/bitutils.h", 141 "SPIRV/disassemble.cpp", 142 "SPIRV/disassemble.h", 143 "SPIRV/doc.cpp", 144 "SPIRV/doc.h", 145 "SPIRV/hex_float.h", 146 "SPIRV/spirv.hpp", 147 "SPIRV/spvIR.h", 148 "glslang/GenericCodeGen/CodeGen.cpp", 149 "glslang/GenericCodeGen/Link.cpp", 150 "glslang/Include/BaseTypes.h", 151 "glslang/Include/Common.h", 152 "glslang/Include/ConstantUnion.h", 153 "glslang/Include/InfoSink.h", 154 "glslang/Include/InitializeGlobals.h", 155 "glslang/Include/PoolAlloc.h", 156 "glslang/Include/ResourceLimits.h", 157 "glslang/Include/ShHandle.h", 158 "glslang/Include/SpirvIntrinsics.h", 159 "glslang/Include/Types.h", 160 "glslang/Include/arrays.h", 161 "glslang/Include/intermediate.h", 162 "glslang/Include/visibility.h", 163 "glslang/MachineIndependent/Constant.cpp", 164 "glslang/MachineIndependent/InfoSink.cpp", 165 "glslang/MachineIndependent/Initialize.cpp", 166 "glslang/MachineIndependent/Initialize.h", 167 "glslang/MachineIndependent/IntermTraverse.cpp", 168 "glslang/MachineIndependent/Intermediate.cpp", 169 "glslang/MachineIndependent/LiveTraverser.h", 170 "glslang/MachineIndependent/ParseContextBase.cpp", 171 "glslang/MachineIndependent/ParseHelper.cpp", 172 "glslang/MachineIndependent/ParseHelper.h", 173 "glslang/MachineIndependent/PoolAlloc.cpp", 174 "glslang/MachineIndependent/RemoveTree.cpp", 175 "glslang/MachineIndependent/RemoveTree.h", 176 "glslang/MachineIndependent/Scan.cpp", 177 "glslang/MachineIndependent/Scan.h", 178 "glslang/MachineIndependent/ScanContext.h", 179 "glslang/MachineIndependent/ShaderLang.cpp", 180 "glslang/MachineIndependent/SpirvIntrinsics.cpp", 181 "glslang/MachineIndependent/SymbolTable.cpp", 182 "glslang/MachineIndependent/SymbolTable.h", 183 "glslang/MachineIndependent/Versions.cpp", 184 "glslang/MachineIndependent/Versions.h", 185 "glslang/MachineIndependent/attribute.cpp", 186 "glslang/MachineIndependent/attribute.h", 187 "glslang/MachineIndependent/gl_types.h", 188 "glslang/MachineIndependent/glslang_tab.cpp", 189 "glslang/MachineIndependent/glslang_tab.cpp.h", 190 "glslang/MachineIndependent/intermOut.cpp", 191 "glslang/MachineIndependent/iomapper.cpp", 192 "glslang/MachineIndependent/iomapper.h", 193 "glslang/MachineIndependent/limits.cpp", 194 "glslang/MachineIndependent/linkValidate.cpp", 195 "glslang/MachineIndependent/localintermediate.h", 196 "glslang/MachineIndependent/parseConst.cpp", 197 "glslang/MachineIndependent/parseVersions.h", 198 "glslang/MachineIndependent/preprocessor/Pp.cpp", 199 "glslang/MachineIndependent/preprocessor/PpAtom.cpp", 200 "glslang/MachineIndependent/preprocessor/PpContext.cpp", 201 "glslang/MachineIndependent/preprocessor/PpContext.h", 202 "glslang/MachineIndependent/preprocessor/PpScanner.cpp", 203 "glslang/MachineIndependent/preprocessor/PpTokens.cpp", 204 "glslang/MachineIndependent/preprocessor/PpTokens.h", 205 "glslang/MachineIndependent/propagateNoContraction.cpp", 206 "glslang/MachineIndependent/propagateNoContraction.h", 207 "glslang/MachineIndependent/reflection.cpp", 208 "glslang/MachineIndependent/reflection.h", 209 "glslang/OSDependent/osinclude.h", 210 "glslang/Public/ShaderLang.h", 211 ] 212 213 # Workaround gn issue complaining about these not being allowed even though GLSLANG_HLSL is not 214 # defined. 215 sources += [ 216 "glslang/HLSL/hlslParseHelper.h", 217 "glslang/HLSL/hlslParseables.h", 218 "glslang/HLSL/hlslScanContext.h", 219 "glslang/HLSL/hlslTokens.h", 220 ] 221 222 if (invoker.enable_hlsl) { 223 sources += [ 224 "glslang/HLSL/hlslAttributes.cpp", 225 "glslang/HLSL/hlslAttributes.h", 226 "glslang/HLSL/hlslGrammar.cpp", 227 "glslang/HLSL/hlslGrammar.h", 228 "glslang/HLSL/hlslOpMap.cpp", 229 "glslang/HLSL/hlslOpMap.h", 230 "glslang/HLSL/hlslParseHelper.cpp", 231 "glslang/HLSL/hlslParseables.cpp", 232 "glslang/HLSL/hlslScanContext.cpp", 233 "glslang/HLSL/hlslTokenStream.cpp", 234 "glslang/HLSL/hlslTokenStream.h", 235 ] 236 } 237 238 defines = [ "ENABLE_SPIRV=1" ] 239 if (invoker.enable_opt) { 240 sources += [ "SPIRV/SpvTools.cpp" ] 241 defines += [ "ENABLE_OPT=1" ] 242 } 243 244 if (is_win) { 245 sources += [ "glslang/OSDependent/Windows/ossource.cpp" ] 246 defines += [ "GLSLANG_OSINCLUDE_WIN32" ] 247 } else { 248 sources += [ "glslang/OSDependent/Unix/ossource.cpp" ] 249 defines += [ "GLSLANG_OSINCLUDE_UNIX" ] 250 } 251 252 if (is_clang) { 253 cflags = [ 254 "-Wno-extra-semi", 255 "-Wno-ignored-qualifiers", 256 "-Wno-implicit-fallthrough", 257 "-Wno-inconsistent-missing-override", 258 "-Wno-missing-field-initializers", 259 "-Wno-newline-eof", 260 "-Wno-sign-compare", 261 "-Wno-suggest-destructor-override", 262 "-Wno-suggest-override", 263 "-Wno-unused-variable", 264 ] 265 } 266 if (is_win && !is_clang) { 267 cflags = [ 268 "/wd4018", # signed/unsigned mismatch 269 "/wd4189", # local variable is initialized but not referenced 270 ] 271 } 272 273 include_dirs = [ "${target_gen_dir}/include" ] 274 275 deps = [ ":glslang_build_info" ] 276 277 if (invoker.enable_opt) { 278 deps += [ 279 "${spirv_tools_dir}:spvtools_opt", 280 "${spirv_tools_dir}:spvtools_val", 281 ] 282 include_dirs += [ "${spirv_tools_dir}/include" ] 283 } 284 285 configs -= _configs_to_remove 286 configs += _configs_to_add 287 } 288} 289 290glslang_sources_common("glslang_lib_sources") { 291 enable_opt = true 292 enable_hlsl = true 293} 294 295glslang_sources_common("glslang_sources") { 296 enable_opt = true 297 enable_hlsl = true 298} 299 300source_set("glslang_default_resource_limits_sources") { 301 sources = [ 302 "glslang/ResourceLimits/ResourceLimits.cpp", 303 "glslang/Public/ResourceLimits.h", 304 "glslang/Include/ResourceLimits.h", 305 "glslang/Include/visibility.h", 306 ] 307 public_configs = [ ":glslang_public" ] 308 309 configs -= _configs_to_remove 310 configs += _configs_to_add 311} 312 313executable("glslang_validator") { 314 sources = [ 315 "StandAlone/DirStackFileIncluder.h", 316 "StandAlone/StandAlone.cpp", 317 ] 318 if (!is_win) { 319 cflags = [ "-Woverflow" ] 320 } 321 defines = [ 322 "ENABLE_OPT=1", 323 "ENABLE_SPIRV=1", 324 ] 325 deps = [ 326 ":glslang_build_info", 327 ":glslang_default_resource_limits_sources", 328 ":glslang_sources", 329 ":glslang_extension_headers", 330 ] 331 public_configs = [ ":glslang_hlsl" ] 332 333 include_dirs = [ 334 "${target_gen_dir}/include", 335 "${spirv_tools_dir}/include", 336 ] 337 338 configs -= _configs_to_remove 339 configs += _configs_to_add 340} 341 342executable("spirv-remap") { 343 sources = [ "StandAlone/spirv-remap.cpp" ] 344 defines = [ 345 "ENABLE_OPT=1", 346 "ENABLE_SPIRV=1", 347 ] 348 deps = [ ":glslang_sources" ] 349 350 include_dirs = [ "${spirv_tools_dir}/include" ] 351 352 configs -= _configs_to_remove 353 configs += _configs_to_add 354} 355