bgfx.lua 7.7 KB

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