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/ohos.gni") 35import("build_overrides/glslang.gni") 36 37# Both Chromium and Fuchsia use by default a set of warning errors 38# that is far too strict to compile this project. These are also 39# typically appended after |cflags|, overriding target-specific 40# definitions. To work around this, determine which configs to 41# add and remove in order to succesfully build the project. 42if (defined(is_fuchsia_tree) && is_fuchsia_tree) { 43 _configs_to_remove = [ "//build/config:default_warnings" ] 44 _configs_to_add = [] 45} else { 46 _configs_to_remove = [ "//build/config/compiler:chromium_code" ] 47 _configs_to_add = [ "//build/config/compiler:no_chromium_code" ] 48} 49 50action("glslang_build_info") { 51 script = "build_info.py" 52 53 src_dir = "." 54 changes_file = "CHANGES.md" 55 template_file = "build_info.h.tmpl" 56 out_file = "${target_gen_dir}/include/glslang/build_info.h" 57 58 inputs = [ 59 changes_file, 60 script, 61 template_file, 62 ] 63 outputs = [ out_file ] 64 args = [ 65 rebase_path(src_dir, root_build_dir), 66 "-i", 67 rebase_path(template_file, root_build_dir), 68 "-o", 69 rebase_path(out_file, root_build_dir), 70 ] 71} 72 73action("glslang_extension_headers") { 74 script = "gen_extension_headers.py" 75 76 out_file = "${target_gen_dir}/include/glslang/glsl_intrinsic_header.h" 77 78 # Fuchsia GN build rules require all GN actions to be hermetic and they 79 # should correctly and fully state their inputs and outpus (see 80 # https://fuchsia.dev/fuchsia-src/development/build/hermetic_actions 81 # for details). All input files of the script should be added to the 82 # |sources| list. 83 sources = [ "glslang/ExtensionHeaders/GL_EXT_shader_realtime_clock.glsl" ] 84 85 inputs = [ script ] 86 outputs = [ out_file ] 87 args = [ 88 "-i", 89 rebase_path("glslang/ExtensionHeaders", root_build_dir), 90 "-o", 91 rebase_path(out_file, root_build_dir), 92 ] 93} 94 95spirv_tools_dir = glslang_spirv_tools_dir 96 97config("glslang_public") { 98 include_dirs = [ "." ] 99 if (!is_win || is_clang) { 100 cflags = [ "-Wno-conversion" ] 101 } 102} 103 104config("glslang_hlsl") { 105 defines = [ "ENABLE_HLSL=1" ] 106} 107 108template("glslang_sources_common") { 109 source_set(target_name) { 110 public_configs = [ ":glslang_public" ] 111 112 if (invoker.enable_hlsl) { 113 public_configs += [ ":glslang_hlsl" ] 114 } 115 116 sources = [ 117 "SPIRV/GLSL.ext.AMD.h", 118 "SPIRV/GLSL.ext.ARM.h", 119 "SPIRV/GLSL.ext.EXT.h", 120 "SPIRV/GLSL.ext.KHR.h", 121 "SPIRV/GLSL.ext.NV.h", 122 "SPIRV/GLSL.ext.QCOM.h", 123 "SPIRV/GLSL.std.450.h", 124 "SPIRV/GlslangToSpv.cpp", 125 "SPIRV/GlslangToSpv.h", 126 "SPIRV/InReadableOrder.cpp", 127 "SPIRV/Logger.cpp", 128 "SPIRV/Logger.h", 129 "SPIRV/NonSemanticDebugPrintf.h", 130 "SPIRV/NonSemanticShaderDebugInfo100.h", 131 "SPIRV/SPVRemapper.cpp", 132 "SPIRV/SPVRemapper.h", 133 "SPIRV/SpvBuilder.cpp", 134 "SPIRV/SpvBuilder.h", 135 "SPIRV/SpvPostProcess.cpp", 136 "SPIRV/SpvTools.h", 137 "SPIRV/bitutils.h", 138 "SPIRV/disassemble.cpp", 139 "SPIRV/disassemble.h", 140 "SPIRV/doc.cpp", 141 "SPIRV/doc.h", 142 "SPIRV/hex_float.h", 143 "SPIRV/spirv.hpp", 144 "SPIRV/spvIR.h", 145 "glslang/GenericCodeGen/CodeGen.cpp", 146 "glslang/GenericCodeGen/Link.cpp", 147 "glslang/Include/BaseTypes.h", 148 "glslang/Include/Common.h", 149 "glslang/Include/ConstantUnion.h", 150 "glslang/Include/InfoSink.h", 151 "glslang/Include/InitializeGlobals.h", 152 "glslang/Include/PoolAlloc.h", 153 "glslang/Include/ResourceLimits.h", 154 "glslang/Include/ShHandle.h", 155 "glslang/Include/SpirvIntrinsics.h", 156 "glslang/Include/Types.h", 157 "glslang/Include/arrays.h", 158 "glslang/Include/intermediate.h", 159 "glslang/MachineIndependent/Constant.cpp", 160 "glslang/MachineIndependent/InfoSink.cpp", 161 "glslang/MachineIndependent/Initialize.cpp", 162 "glslang/MachineIndependent/Initialize.h", 163 "glslang/MachineIndependent/IntermTraverse.cpp", 164 "glslang/MachineIndependent/Intermediate.cpp", 165 "glslang/MachineIndependent/LiveTraverser.h", 166 "glslang/MachineIndependent/ParseContextBase.cpp", 167 "glslang/MachineIndependent/ParseHelper.cpp", 168 "glslang/MachineIndependent/ParseHelper.h", 169 "glslang/MachineIndependent/PoolAlloc.cpp", 170 "glslang/MachineIndependent/RemoveTree.cpp", 171 "glslang/MachineIndependent/RemoveTree.h", 172 "glslang/MachineIndependent/Scan.cpp", 173 "glslang/MachineIndependent/Scan.h", 174 "glslang/MachineIndependent/ScanContext.h", 175 "glslang/MachineIndependent/ShaderLang.cpp", 176 "glslang/MachineIndependent/SpirvIntrinsics.cpp", 177 "glslang/MachineIndependent/SymbolTable.cpp", 178 "glslang/MachineIndependent/SymbolTable.h", 179 "glslang/MachineIndependent/Versions.cpp", 180 "glslang/MachineIndependent/Versions.h", 181 "glslang/MachineIndependent/attribute.cpp", 182 "glslang/MachineIndependent/attribute.h", 183 "glslang/MachineIndependent/gl_types.h", 184 "glslang/MachineIndependent/glslang_tab.cpp", 185 "glslang/MachineIndependent/glslang_tab.cpp.h", 186 "glslang/MachineIndependent/intermOut.cpp", 187 "glslang/MachineIndependent/iomapper.cpp", 188 "glslang/MachineIndependent/iomapper.h", 189 "glslang/MachineIndependent/limits.cpp", 190 "glslang/MachineIndependent/linkValidate.cpp", 191 "glslang/MachineIndependent/localintermediate.h", 192 "glslang/MachineIndependent/parseConst.cpp", 193 "glslang/MachineIndependent/parseVersions.h", 194 "glslang/MachineIndependent/preprocessor/Pp.cpp", 195 "glslang/MachineIndependent/preprocessor/PpAtom.cpp", 196 "glslang/MachineIndependent/preprocessor/PpContext.cpp", 197 "glslang/MachineIndependent/preprocessor/PpContext.h", 198 "glslang/MachineIndependent/preprocessor/PpScanner.cpp", 199 "glslang/MachineIndependent/preprocessor/PpTokens.cpp", 200 "glslang/MachineIndependent/preprocessor/PpTokens.h", 201 "glslang/MachineIndependent/propagateNoContraction.cpp", 202 "glslang/MachineIndependent/propagateNoContraction.h", 203 "glslang/MachineIndependent/reflection.cpp", 204 "glslang/MachineIndependent/reflection.h", 205 "glslang/OSDependent/osinclude.h", 206 "glslang/Public/ShaderLang.h", 207 ] 208 209 # Workaround gn issue complaining about these not being allowed even though GLSLANG_HLSL is not 210 # defined. 211 sources += [ 212 "glslang/HLSL/hlslParseHelper.h", 213 "glslang/HLSL/hlslParseables.h", 214 "glslang/HLSL/hlslScanContext.h", 215 "glslang/HLSL/hlslTokens.h", 216 ] 217 218 if (invoker.enable_hlsl) { 219 sources += [ 220 "glslang/HLSL/hlslAttributes.cpp", 221 "glslang/HLSL/hlslAttributes.h", 222 "glslang/HLSL/hlslGrammar.cpp", 223 "glslang/HLSL/hlslGrammar.h", 224 "glslang/HLSL/hlslOpMap.cpp", 225 "glslang/HLSL/hlslOpMap.h", 226 "glslang/HLSL/hlslParseHelper.cpp", 227 "glslang/HLSL/hlslParseables.cpp", 228 "glslang/HLSL/hlslScanContext.cpp", 229 "glslang/HLSL/hlslTokenStream.cpp", 230 "glslang/HLSL/hlslTokenStream.h", 231 ] 232 } 233 234 defines = [] 235 if (invoker.enable_opt) { 236 sources += [ "SPIRV/SpvTools.cpp" ] 237 defines += [ "ENABLE_OPT=1" ] 238 } 239 240 if (is_win) { 241 sources += [ "glslang/OSDependent/Windows/ossource.cpp" ] 242 defines += [ "GLSLANG_OSINCLUDE_WIN32" ] 243 } else { 244 sources += [ "glslang/OSDependent/Unix/ossource.cpp" ] 245 defines += [ "GLSLANG_OSINCLUDE_UNIX" ] 246 } 247 248 if (is_clang) { 249 cflags = [ 250 "-Wno-extra-semi", 251 "-Wno-ignored-qualifiers", 252 "-Wno-implicit-fallthrough", 253 "-Wno-inconsistent-missing-override", 254 "-Wno-missing-field-initializers", 255 "-Wno-newline-eof", 256 "-Wno-sign-compare", 257 "-Wno-suggest-destructor-override", 258 "-Wno-suggest-override", 259 "-Wno-unused-variable", 260 ] 261 } 262 if (is_win && !is_clang) { 263 cflags = [ 264 "/wd4018", # signed/unsigned mismatch 265 "/wd4189", # local variable is initialized but not referenced 266 ] 267 } 268 269 include_dirs = [ "${target_gen_dir}/include" ] 270 271 deps = [ ":glslang_build_info" ] 272 273 if (invoker.enable_opt) { 274 deps += [ 275 "${spirv_tools_dir}:spvtools_opt", 276 "${spirv_tools_dir}:spvtools_val", 277 ] 278 include_dirs += [ "${spirv_tools_dir}/include" ] 279 } 280 if (build_ohos_sdk) { 281 defines += [ "OH_SDK" ] 282 cflags += [ "-std=c++17" ] 283 } else { 284 configs -= _configs_to_remove 285 configs += _configs_to_add 286 } 287 } 288} 289 290glslang_sources_common("glslang_lib_sources") { 291 enable_opt = false 292 enable_hlsl = true 293} 294 295glslang_sources_common("glslang_sources") { 296 enable_opt = false 297 enable_hlsl = true 298} 299 300source_set("glslang_default_resource_limits_sources") { 301 sources = [ 302 "glslang/Include/ResourceLimits.h", 303 "glslang/Public/ResourceLimits.h", 304 "glslang/ResourceLimits/ResourceLimits.cpp", 305 ] 306 public_configs = [ ":glslang_public" ] 307 if (!build_ohos_sdk) { 308 configs -= _configs_to_remove 309 configs += _configs_to_add 310 } 311} 312 313ohos_executable("glslang_validator") { 314 sources = [ 315 "StandAlone/DirStackFileIncluder.h", 316 "StandAlone/StandAlone.cpp", 317 ] 318 if (!is_win) { 319 cflags = [ 320 "-Woverflow", 321 "-std=c++17", 322 ] 323 } else { 324 cflags = [ "-std=c++17" ] 325 } 326 defines = [ 327 "ENABLE_OPT=1", 328 "OH_SDK", 329 ] 330 deps = [ 331 ":glslang_build_info", 332 ":glslang_default_resource_limits_sources", 333 ":glslang_extension_headers", 334 ":glslang_sources", 335 ] 336 public_configs = [ ":glslang_hlsl" ] 337 338 include_dirs = [ 339 "${target_gen_dir}/include", 340 "${spirv_tools_dir}/include", 341 ] 342 install_enable = true 343 part_name = "graphic_2d" 344 subsystem_name = "graphic" 345} 346 347ohos_executable("spirv-remap") { 348 sources = [ "StandAlone/spirv-remap.cpp" ] 349 defines = [ 350 "ENABLE_OPT=1", 351 "OH_SDK", 352 ] 353 deps = [ ":glslang_sources" ] 354 cflags = [ "-std=c++17" ] 355 include_dirs = [ "${spirv_tools_dir}/include" ] 356 install_enable = true 357 part_name = "graphic_2d" 358 subsystem_name = "graphic" 359} 360 361group("glslang") { 362 deps = [ 363 "//third_party/glslang/SPIRV:libdeqp_spirv", 364 "//third_party/glslang/SPIRV:libdeqp_spvremapper", 365 "//third_party/glslang/glslang:libdeqp_glslang", 366 ] 367} 368