BUILD.gn 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. spirv_tools_dir = glslang_spirv_tools_dir
  67. if (!defined(glslang_angle)) {
  68. glslang_angle = false
  69. }
  70. config("glslang_public") {
  71. include_dirs = [ "." ]
  72. if (!is_win || is_clang) {
  73. cflags = [ "-Wno-conversion" ]
  74. }
  75. }
  76. config("glslang_hlsl") {
  77. defines = [ "ENABLE_HLSL=1" ]
  78. }
  79. template("glslang_sources_common") {
  80. source_set(target_name) {
  81. public_configs = [ ":glslang_public" ]
  82. if (invoker.enable_hlsl) {
  83. public_configs += [ ":glslang_hlsl" ]
  84. }
  85. sources = [
  86. "OGLCompilersDLL/InitializeDll.cpp",
  87. "OGLCompilersDLL/InitializeDll.h",
  88. "SPIRV/GLSL.ext.AMD.h",
  89. "SPIRV/GLSL.ext.EXT.h",
  90. "SPIRV/GLSL.ext.KHR.h",
  91. "SPIRV/GLSL.ext.NV.h",
  92. "SPIRV/GLSL.std.450.h",
  93. "SPIRV/GlslangToSpv.cpp",
  94. "SPIRV/GlslangToSpv.h",
  95. "SPIRV/InReadableOrder.cpp",
  96. "SPIRV/Logger.cpp",
  97. "SPIRV/Logger.h",
  98. "SPIRV/NonSemanticDebugPrintf.h",
  99. "SPIRV/SPVRemapper.cpp",
  100. "SPIRV/SPVRemapper.h",
  101. "SPIRV/SpvBuilder.cpp",
  102. "SPIRV/SpvBuilder.h",
  103. "SPIRV/SpvPostProcess.cpp",
  104. "SPIRV/SpvTools.h",
  105. "SPIRV/bitutils.h",
  106. "SPIRV/disassemble.cpp",
  107. "SPIRV/disassemble.h",
  108. "SPIRV/doc.cpp",
  109. "SPIRV/doc.h",
  110. "SPIRV/hex_float.h",
  111. "SPIRV/spirv.hpp",
  112. "SPIRV/spvIR.h",
  113. "glslang/GenericCodeGen/CodeGen.cpp",
  114. "glslang/GenericCodeGen/Link.cpp",
  115. "glslang/Include/BaseTypes.h",
  116. "glslang/Include/Common.h",
  117. "glslang/Include/ConstantUnion.h",
  118. "glslang/Include/InfoSink.h",
  119. "glslang/Include/InitializeGlobals.h",
  120. "glslang/Include/PoolAlloc.h",
  121. "glslang/Include/ResourceLimits.h",
  122. "glslang/Include/ShHandle.h",
  123. "glslang/Include/Types.h",
  124. "glslang/Include/arrays.h",
  125. "glslang/Include/intermediate.h",
  126. "glslang/MachineIndependent/Constant.cpp",
  127. "glslang/MachineIndependent/InfoSink.cpp",
  128. "glslang/MachineIndependent/Initialize.cpp",
  129. "glslang/MachineIndependent/Initialize.h",
  130. "glslang/MachineIndependent/IntermTraverse.cpp",
  131. "glslang/MachineIndependent/Intermediate.cpp",
  132. "glslang/MachineIndependent/LiveTraverser.h",
  133. "glslang/MachineIndependent/ParseContextBase.cpp",
  134. "glslang/MachineIndependent/ParseHelper.cpp",
  135. "glslang/MachineIndependent/ParseHelper.h",
  136. "glslang/MachineIndependent/PoolAlloc.cpp",
  137. "glslang/MachineIndependent/RemoveTree.cpp",
  138. "glslang/MachineIndependent/RemoveTree.h",
  139. "glslang/MachineIndependent/Scan.cpp",
  140. "glslang/MachineIndependent/Scan.h",
  141. "glslang/MachineIndependent/ScanContext.h",
  142. "glslang/MachineIndependent/ShaderLang.cpp",
  143. "glslang/MachineIndependent/SymbolTable.cpp",
  144. "glslang/MachineIndependent/SymbolTable.h",
  145. "glslang/MachineIndependent/Versions.cpp",
  146. "glslang/MachineIndependent/Versions.h",
  147. "glslang/MachineIndependent/attribute.cpp",
  148. "glslang/MachineIndependent/attribute.h",
  149. "glslang/MachineIndependent/gl_types.h",
  150. "glslang/MachineIndependent/glslang_tab.cpp",
  151. "glslang/MachineIndependent/glslang_tab.cpp.h",
  152. "glslang/MachineIndependent/intermOut.cpp",
  153. "glslang/MachineIndependent/iomapper.cpp",
  154. "glslang/MachineIndependent/iomapper.h",
  155. "glslang/MachineIndependent/limits.cpp",
  156. "glslang/MachineIndependent/linkValidate.cpp",
  157. "glslang/MachineIndependent/localintermediate.h",
  158. "glslang/MachineIndependent/parseConst.cpp",
  159. "glslang/MachineIndependent/parseVersions.h",
  160. "glslang/MachineIndependent/preprocessor/Pp.cpp",
  161. "glslang/MachineIndependent/preprocessor/PpAtom.cpp",
  162. "glslang/MachineIndependent/preprocessor/PpContext.cpp",
  163. "glslang/MachineIndependent/preprocessor/PpContext.h",
  164. "glslang/MachineIndependent/preprocessor/PpScanner.cpp",
  165. "glslang/MachineIndependent/preprocessor/PpTokens.cpp",
  166. "glslang/MachineIndependent/preprocessor/PpTokens.h",
  167. "glslang/MachineIndependent/propagateNoContraction.cpp",
  168. "glslang/MachineIndependent/propagateNoContraction.h",
  169. "glslang/MachineIndependent/reflection.cpp",
  170. "glslang/MachineIndependent/reflection.h",
  171. "glslang/OSDependent/osinclude.h",
  172. "glslang/Public/ShaderLang.h",
  173. ]
  174. # Workaround gn issue complaining about these not being allowed even though GLSLANG_HLSL is not
  175. # defined.
  176. sources += [
  177. "glslang/HLSL/hlslParseHelper.h",
  178. "glslang/HLSL/hlslParseables.h",
  179. "glslang/HLSL/hlslScanContext.h",
  180. "glslang/HLSL/hlslTokens.h",
  181. ]
  182. if (invoker.enable_hlsl) {
  183. sources += [
  184. "glslang/HLSL/hlslAttributes.cpp",
  185. "glslang/HLSL/hlslAttributes.h",
  186. "glslang/HLSL/hlslGrammar.cpp",
  187. "glslang/HLSL/hlslGrammar.h",
  188. "glslang/HLSL/hlslOpMap.cpp",
  189. "glslang/HLSL/hlslOpMap.h",
  190. "glslang/HLSL/hlslParseHelper.cpp",
  191. "glslang/HLSL/hlslParseables.cpp",
  192. "glslang/HLSL/hlslScanContext.cpp",
  193. "glslang/HLSL/hlslTokenStream.cpp",
  194. "glslang/HLSL/hlslTokenStream.h",
  195. ]
  196. }
  197. defines = []
  198. if (invoker.enable_opt) {
  199. sources += [ "SPIRV/SpvTools.cpp" ]
  200. defines += [ "ENABLE_OPT=1" ]
  201. }
  202. if (invoker.is_angle) {
  203. defines += [ "GLSLANG_ANGLE" ]
  204. }
  205. if (is_win) {
  206. sources += [ "glslang/OSDependent/Windows/ossource.cpp" ]
  207. defines += [ "GLSLANG_OSINCLUDE_WIN32" ]
  208. } else {
  209. sources += [ "glslang/OSDependent/Unix/ossource.cpp" ]
  210. defines += [ "GLSLANG_OSINCLUDE_UNIX" ]
  211. }
  212. if (is_clang) {
  213. cflags = [
  214. "-Wno-extra-semi",
  215. "-Wno-ignored-qualifiers",
  216. "-Wno-implicit-fallthrough",
  217. "-Wno-inconsistent-missing-override",
  218. "-Wno-missing-field-initializers",
  219. "-Wno-newline-eof",
  220. "-Wno-sign-compare",
  221. "-Wno-suggest-destructor-override",
  222. "-Wno-suggest-override",
  223. "-Wno-unused-variable",
  224. ]
  225. }
  226. if (is_win && !is_clang) {
  227. cflags = [
  228. "/wd4018", # signed/unsigned mismatch
  229. "/wd4189", # local variable is initialized but not referenced
  230. ]
  231. }
  232. include_dirs = [ "${target_gen_dir}/include" ]
  233. deps = [ ":glslang_build_info" ]
  234. if (invoker.enable_opt) {
  235. deps += [
  236. "${spirv_tools_dir}:spvtools_opt",
  237. "${spirv_tools_dir}:spvtools_val",
  238. ]
  239. include_dirs += [ "${spirv_tools_dir}/include" ]
  240. }
  241. configs -= _configs_to_remove
  242. configs += _configs_to_add
  243. }
  244. }
  245. glslang_sources_common("glslang_lib_sources") {
  246. enable_opt = !glslang_angle
  247. enable_hlsl = !glslang_angle
  248. is_angle = glslang_angle
  249. }
  250. glslang_sources_common("glslang_sources") {
  251. enable_opt = true
  252. enable_hlsl = true
  253. is_angle = false
  254. }
  255. source_set("glslang_default_resource_limits_sources") {
  256. sources = [
  257. "StandAlone/ResourceLimits.cpp",
  258. "StandAlone/ResourceLimits.h",
  259. "glslang/Include/ResourceLimits.h",
  260. ]
  261. public_configs = [ ":glslang_public" ]
  262. configs -= _configs_to_remove
  263. configs += _configs_to_add
  264. }
  265. executable("glslang_validator") {
  266. sources = [
  267. "StandAlone/DirStackFileIncluder.h",
  268. "StandAlone/StandAlone.cpp",
  269. ]
  270. if (!is_win) {
  271. cflags = [ "-Woverflow" ]
  272. }
  273. defines = [ "ENABLE_OPT=1" ]
  274. deps = [
  275. ":glslang_build_info",
  276. ":glslang_default_resource_limits_sources",
  277. ":glslang_sources",
  278. ]
  279. public_configs = [ ":glslang_hlsl" ]
  280. include_dirs = [
  281. "${target_gen_dir}/include",
  282. "${spirv_tools_dir}/include",
  283. ]
  284. configs -= _configs_to_remove
  285. configs += _configs_to_add
  286. }
  287. executable("spirv-remap") {
  288. sources = [ "StandAlone/spirv-remap.cpp" ]
  289. defines = [ "ENABLE_OPT=1" ]
  290. deps = [ ":glslang_sources" ]
  291. include_dirs = [ "${spirv_tools_dir}/include" ]
  292. configs -= _configs_to_remove
  293. configs += _configs_to_add
  294. }