BUILD.gn 11 KB

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