bgfx.lua 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. --
  2. -- Copyright 2010-2021 Branimir Karadzic. All rights reserved.
  3. -- License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. --
  5. function filesexist(_srcPath, _dstPath, _files)
  6. for _, file in ipairs(_files) do
  7. file = path.getrelative(_srcPath, file)
  8. local filePath = path.join(_dstPath, file)
  9. if not os.isfile(filePath) then return false end
  10. end
  11. return true
  12. end
  13. function overridefiles(_srcPath, _dstPath, _files)
  14. local remove = {}
  15. local add = {}
  16. for _, file in ipairs(_files) do
  17. file = path.getrelative(_srcPath, file)
  18. local filePath = path.join(_dstPath, file)
  19. if not os.isfile(filePath) then return end
  20. table.insert(remove, path.join(_srcPath, file))
  21. table.insert(add, filePath)
  22. end
  23. removefiles {
  24. remove,
  25. }
  26. files {
  27. add,
  28. }
  29. end
  30. function bgfxProjectBase(_kind, _defines)
  31. kind (_kind)
  32. if _kind == "SharedLib" then
  33. defines {
  34. "BGFX_SHARED_LIB_BUILD=1",
  35. }
  36. links {
  37. "bimg",
  38. "bx",
  39. }
  40. configuration { "vs20* or mingw*" }
  41. links {
  42. "gdi32",
  43. "psapi",
  44. }
  45. configuration { "mingw*" }
  46. linkoptions {
  47. "-shared",
  48. }
  49. configuration { "linux-*" }
  50. buildoptions {
  51. "-fPIC",
  52. }
  53. links {
  54. "X11",
  55. "GL",
  56. "pthread",
  57. }
  58. configuration { "android*" }
  59. targetextension ".so"
  60. configuration { "android*" ,"Debug"}
  61. linkoptions {
  62. "-Wl,-soname,libbgfx-shared-libDebug.so",
  63. }
  64. configuration { "android*" ,"Release"}
  65. linkoptions {
  66. "-Wl,-soname,libbgfx-shared-libRelease.so",
  67. }
  68. configuration {}
  69. else
  70. configuration { "android*" }
  71. linkoptions {
  72. "-Wl,--fix-cortex-a8",
  73. }
  74. configuration {}
  75. end
  76. includedirs {
  77. path.join(BGFX_DIR, "3rdparty"),
  78. path.join(BX_DIR, "include"),
  79. path.join(BIMG_DIR, "include"),
  80. }
  81. defines (_defines)
  82. links {
  83. "bx",
  84. }
  85. if _OPTIONS["with-glfw"] then
  86. defines {
  87. "BGFX_CONFIG_MULTITHREADED=0",
  88. }
  89. end
  90. configuration { "Debug" }
  91. defines {
  92. "BGFX_CONFIG_DEBUG=1",
  93. }
  94. configuration { "vs* or mingw*", "not durango" }
  95. includedirs {
  96. path.join(BGFX_DIR, "3rdparty/dxsdk/include"),
  97. }
  98. configuration { "android*" }
  99. links {
  100. "EGL",
  101. "GLESv2",
  102. }
  103. configuration { "winstore*" }
  104. linkoptions {
  105. "/ignore:4264" -- LNK4264: archiving object file compiled with /ZW into a static library; note that when authoring Windows Runtime types it is not recommended to link with a static library that contains Windows Runtime metadata
  106. }
  107. configuration { "*clang*" }
  108. buildoptions {
  109. "-Wno-microsoft-enum-value", -- enumerator value is not representable in the underlying type 'int'
  110. "-Wno-microsoft-const-init", -- default initialization of an object of const type '' without a user-provided default constructor is a Microsoft extension
  111. }
  112. configuration { "osx*" }
  113. buildoptions { "-x objective-c++" } -- additional build option for osx
  114. linkoptions {
  115. "-framework Cocoa",
  116. "-framework QuartzCore",
  117. "-framework OpenGL",
  118. "-weak_framework Metal",
  119. "-weak_framework MetalKit",
  120. }
  121. configuration { "not NX32", "not NX64" }
  122. includedirs {
  123. -- NX has EGL headers modified...
  124. path.join(BGFX_DIR, "3rdparty/khronos"),
  125. }
  126. configuration {}
  127. includedirs {
  128. path.join(BGFX_DIR, "include"),
  129. }
  130. files {
  131. path.join(BGFX_DIR, "include/**.h"),
  132. path.join(BGFX_DIR, "src/**.cpp"),
  133. path.join(BGFX_DIR, "src/**.h"),
  134. path.join(BGFX_DIR, "scripts/**.natvis"),
  135. }
  136. removefiles {
  137. path.join(BGFX_DIR, "src/**.bin.h"),
  138. }
  139. overridefiles(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-gnm"), {
  140. path.join(BGFX_DIR, "src/renderer_gnm.cpp"),
  141. path.join(BGFX_DIR, "src/renderer_gnm.h"),
  142. })
  143. overridefiles(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-nvn"), {
  144. path.join(BGFX_DIR, "src/renderer_nvn.cpp"),
  145. path.join(BGFX_DIR, "src/renderer_nvn.h"),
  146. })
  147. if _OPTIONS["with-webgpu"] then
  148. defines {
  149. "BGFX_CONFIG_RENDERER_WEBGPU=1",
  150. "BGFX_CONFIG_DEBUG_ANNOTATION=0", -- does not work
  151. }
  152. local generator = "out/Cmake"
  153. configuration { "wasm*" }
  154. defines {
  155. "BGFX_CONFIG_RENDERER_OPENGL=0",
  156. "BGFX_CONFIG_RENDERER_OPENGLES=0",
  157. }
  158. configuration { "not wasm*" }
  159. includedirs {
  160. path.join(DAWN_DIR, "src/include"),
  161. path.join(DAWN_DIR, "third_party/vulkan-deps/vulkan-headers/src/include"),
  162. path.join(DAWN_DIR, generator, "gen/src/include"),
  163. }
  164. files {
  165. path.join(DAWN_DIR, generator, "gen/src/dawn/webgpu_cpp.cpp"),
  166. }
  167. configuration { "vs*" }
  168. defines {
  169. "NTDDI_VERSION=NTDDI_WIN10_RS2",
  170. -- We can't say `=_WIN32_WINNT_WIN10` here because some files do
  171. -- `#if WINVER < 0x0600` without including windows.h before,
  172. -- and then _WIN32_WINNT_WIN10 isn't yet known to be 0x0A00.
  173. "_WIN32_WINNT=0x0A00",
  174. "WINVER=0x0A00",
  175. }
  176. configuration {}
  177. end
  178. if _OPTIONS["with-amalgamated"] then
  179. excludes {
  180. path.join(BGFX_DIR, "src/bgfx.cpp"),
  181. path.join(BGFX_DIR, "src/debug_**.cpp"),
  182. path.join(BGFX_DIR, "src/dxgi.cpp"),
  183. path.join(BGFX_DIR, "src/glcontext_**.cpp"),
  184. path.join(BGFX_DIR, "src/hmd**.cpp"),
  185. path.join(BGFX_DIR, "src/image.cpp"),
  186. path.join(BGFX_DIR, "src/nvapi.cpp"),
  187. path.join(BGFX_DIR, "src/renderer_**.cpp"),
  188. path.join(BGFX_DIR, "src/shader**.cpp"),
  189. path.join(BGFX_DIR, "src/topology.cpp"),
  190. path.join(BGFX_DIR, "src/vertexlayout.cpp"),
  191. }
  192. configuration { "xcode* or osx* or ios*" }
  193. files {
  194. path.join(BGFX_DIR, "src/amalgamated.mm"),
  195. }
  196. excludes {
  197. path.join(BGFX_DIR, "src/glcontext_**.mm"),
  198. path.join(BGFX_DIR, "src/renderer_**.mm"),
  199. path.join(BGFX_DIR, "src/amalgamated.cpp"),
  200. }
  201. configuration { "not (xcode* or osx* or ios*)" }
  202. excludes {
  203. path.join(BGFX_DIR, "src/**.mm"),
  204. }
  205. configuration {}
  206. else
  207. configuration { "xcode* or osx* or ios*" }
  208. files {
  209. path.join(BGFX_DIR, "src/glcontext_**.mm"),
  210. path.join(BGFX_DIR, "src/renderer_**.mm"),
  211. }
  212. configuration {}
  213. excludes {
  214. path.join(BGFX_DIR, "src/amalgamated.**"),
  215. }
  216. end
  217. if filesexist(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-gnm"), {
  218. path.join(BGFX_DIR, "scripts/bgfx.lua"), }) then
  219. dofile(path.join(BGFX_DIR, "../bgfx-gnm/scripts/bgfx.lua") )
  220. end
  221. if filesexist(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-nvn"), {
  222. path.join(BGFX_DIR, "scripts/bgfx.lua"), }) then
  223. dofile(path.join(BGFX_DIR, "../bgfx-nvn/scripts/bgfx.lua") )
  224. end
  225. configuration {}
  226. end
  227. function bgfxProject(_name, _kind, _defines)
  228. project ("bgfx" .. _name)
  229. uuid (os.uuid("bgfx" .. _name))
  230. bgfxProjectBase(_kind, _defines)
  231. copyLib()
  232. end
  233. if _OPTIONS["with-webgpu"] then
  234. function usesWebGPU()
  235. configuration { "wasm*" }
  236. linkoptions {
  237. "-s USE_WEBGPU=1",
  238. }
  239. configuration { "not wasm*" }
  240. local generator = "out/Cmake"
  241. includedirs {
  242. path.join(DAWN_DIR, "src/include"),
  243. path.join(DAWN_DIR, generator, "gen/src/include"),
  244. }
  245. libdirs {
  246. path.join(DAWN_DIR, generator),
  247. path.join(DAWN_DIR, generator, "src/common/Debug"),
  248. path.join(DAWN_DIR, generator, "src/dawn/Debug"),
  249. path.join(DAWN_DIR, generator, "src/dawn_native/Debug"),
  250. path.join(DAWN_DIR, generator, "src/dawn_platform/Debug"),
  251. path.join(DAWN_DIR, generator, "third_party/tint/src/Debug"),
  252. path.join(DAWN_DIR, generator, "third_party/vulkan-deps/spirv-tools/src/source/Debug"),
  253. path.join(DAWN_DIR, generator, "third_party/vulkan-deps/spirv-tools/src/source/opt/Debug"),
  254. path.join(DAWN_DIR, generator, "third_party/vulkan-deps/spirv-cross/src/Debug"),
  255. }
  256. links {
  257. -- shared
  258. --"dawn_proc_shared",
  259. --"dawn_native_shared",
  260. --"shaderc_spvc_shared",
  261. -- static
  262. "dawn_common",
  263. "dawn_proc",
  264. "dawn_native",
  265. "dawn_platform",
  266. ----"shaderc",
  267. "tint",
  268. "SPIRV-Tools",
  269. "SPIRV-Tools-opt",
  270. "spirv-cross-cored",
  271. "spirv-cross-hlsld",
  272. "spirv-cross-glsld",
  273. "spirv-cross-msld",
  274. --"spirv-cross-reflectd",
  275. }
  276. removeflags {
  277. "FatalWarnings",
  278. }
  279. configuration {}
  280. end
  281. end