bgfx.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. --
  2. -- Copyright 2010-2020 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. configuration {}
  54. end
  55. includedirs {
  56. path.join(BGFX_DIR, "3rdparty"),
  57. path.join(BX_DIR, "include"),
  58. path.join(BIMG_DIR, "include"),
  59. }
  60. defines {
  61. _defines,
  62. }
  63. links {
  64. "bx",
  65. }
  66. if _OPTIONS["with-glfw"] then
  67. defines {
  68. "BGFX_CONFIG_MULTITHREADED=0",
  69. }
  70. end
  71. configuration { "Debug" }
  72. defines {
  73. "BGFX_CONFIG_DEBUG=1",
  74. }
  75. configuration { "vs* or mingw*", "not durango" }
  76. includedirs {
  77. path.join(BGFX_DIR, "3rdparty/dxsdk/include"),
  78. }
  79. configuration { "android*" }
  80. links {
  81. "EGL",
  82. "GLESv2",
  83. }
  84. configuration { "winstore*" }
  85. linkoptions {
  86. "/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
  87. }
  88. configuration { "*clang*" }
  89. buildoptions {
  90. "-Wno-microsoft-enum-value", -- enumerator value is not representable in the underlying type 'int'
  91. "-Wno-microsoft-const-init", -- default initialization of an object of const type '' without a user-provided default constructor is a Microsoft extension
  92. }
  93. configuration { "osx" }
  94. buildoptions { "-x objective-c++" } -- additional build option for osx
  95. linkoptions {
  96. "-framework Cocoa",
  97. "-framework QuartzCore",
  98. "-framework OpenGL",
  99. "-weak_framework Metal",
  100. "-weak_framework MetalKit",
  101. }
  102. configuration { "not NX32", "not NX64" }
  103. includedirs {
  104. -- NX has EGL headers modified...
  105. path.join(BGFX_DIR, "3rdparty/khronos"),
  106. }
  107. configuration {}
  108. includedirs {
  109. path.join(BGFX_DIR, "include"),
  110. }
  111. files {
  112. path.join(BGFX_DIR, "include/**.h"),
  113. path.join(BGFX_DIR, "src/**.cpp"),
  114. path.join(BGFX_DIR, "src/**.h"),
  115. path.join(BGFX_DIR, "scripts/**.natvis"),
  116. }
  117. removefiles {
  118. path.join(BGFX_DIR, "src/**.bin.h"),
  119. }
  120. overridefiles(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-gnm"), {
  121. path.join(BGFX_DIR, "src/renderer_gnm.cpp"),
  122. path.join(BGFX_DIR, "src/renderer_gnm.h"),
  123. })
  124. overridefiles(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-nvn"), {
  125. path.join(BGFX_DIR, "src/renderer_nvn.cpp"),
  126. path.join(BGFX_DIR, "src/renderer_nvn.h"),
  127. })
  128. if _OPTIONS["with-amalgamated"] then
  129. excludes {
  130. path.join(BGFX_DIR, "src/bgfx.cpp"),
  131. path.join(BGFX_DIR, "src/debug_**.cpp"),
  132. path.join(BGFX_DIR, "src/dxgi.cpp"),
  133. path.join(BGFX_DIR, "src/glcontext_**.cpp"),
  134. path.join(BGFX_DIR, "src/hmd**.cpp"),
  135. path.join(BGFX_DIR, "src/image.cpp"),
  136. path.join(BGFX_DIR, "src/nvapi.cpp"),
  137. path.join(BGFX_DIR, "src/renderer_**.cpp"),
  138. path.join(BGFX_DIR, "src/shader**.cpp"),
  139. path.join(BGFX_DIR, "src/topology.cpp"),
  140. path.join(BGFX_DIR, "src/vertexlayout.cpp"),
  141. }
  142. configuration { "xcode* or osx or ios*" }
  143. files {
  144. path.join(BGFX_DIR, "src/amalgamated.mm"),
  145. }
  146. excludes {
  147. path.join(BGFX_DIR, "src/glcontext_**.mm"),
  148. path.join(BGFX_DIR, "src/renderer_**.mm"),
  149. path.join(BGFX_DIR, "src/amalgamated.cpp"),
  150. }
  151. configuration { "not (xcode* or osx or ios*)" }
  152. excludes {
  153. path.join(BGFX_DIR, "src/**.mm"),
  154. }
  155. configuration {}
  156. else
  157. configuration { "xcode* or osx or ios*" }
  158. files {
  159. path.join(BGFX_DIR, "src/glcontext_**.mm"),
  160. path.join(BGFX_DIR, "src/renderer_**.mm"),
  161. }
  162. configuration {}
  163. excludes {
  164. path.join(BGFX_DIR, "src/amalgamated.**"),
  165. }
  166. end
  167. if filesexist(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-gnm"), {
  168. path.join(BGFX_DIR, "scripts/bgfx.lua"), }) then
  169. dofile(path.join(BGFX_DIR, "../bgfx-gnm/scripts/bgfx.lua") )
  170. end
  171. if filesexist(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-nvn"), {
  172. path.join(BGFX_DIR, "scripts/bgfx.lua"), }) then
  173. dofile(path.join(BGFX_DIR, "../bgfx-nvn/scripts/bgfx.lua") )
  174. end
  175. configuration {}
  176. end
  177. function bgfxProject(_name, _kind, _defines)
  178. project ("bgfx" .. _name)
  179. uuid (os.uuid("bgfx" .. _name))
  180. bgfxProjectBase(_kind, _defines)
  181. copyLib()
  182. end