genie.lua 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. --
  2. -- Copyright 2010-2019 Branimir Karadzic. All rights reserved.
  3. -- License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. --
  5. newoption {
  6. trigger = "with-amalgamated",
  7. description = "Enable amalgamated build.",
  8. }
  9. newoption {
  10. trigger = "with-sdl",
  11. description = "Enable SDL entry.",
  12. }
  13. newoption {
  14. trigger = "with-glfw",
  15. description = "Enable GLFW entry.",
  16. }
  17. newoption {
  18. trigger = "with-wayland",
  19. description = "Use Wayland backend.",
  20. }
  21. newoption {
  22. trigger = "with-profiler",
  23. description = "Enable build with intrusive profiler.",
  24. }
  25. newoption {
  26. trigger = "with-shared-lib",
  27. description = "Enable building shared library.",
  28. }
  29. newoption {
  30. trigger = "with-tools",
  31. description = "Enable building tools.",
  32. }
  33. newoption {
  34. trigger = "with-combined-examples",
  35. description = "Enable building examples (combined as single executable).",
  36. }
  37. newoption {
  38. trigger = "with-examples",
  39. description = "Enable building examples.",
  40. }
  41. newaction {
  42. trigger = "idl",
  43. description = "Generate bgfx interface source code",
  44. execute = function ()
  45. local gen = require "bgfx-codegen"
  46. local function generate(tempfile, outputfile, indent)
  47. local codes = gen.apply(tempfile)
  48. codes = gen.format(codes, {indent = indent})
  49. gen.write(codes, outputfile)
  50. print("Generating: " .. outputfile)
  51. end
  52. generate("temp.bgfx.h" , "../include/bgfx/c99/bgfx.h", " ")
  53. generate("temp.bgfx.idl.inl", "../src/bgfx.idl.inl", "\t")
  54. generate("temp.defines.h", "../include/bgfx/defines.h", "\t")
  55. do
  56. local csgen = require "bindings-cs"
  57. csgen.write(csgen.gen(), "../bindings/cs/bgfx.cs")
  58. end
  59. os.exit()
  60. end
  61. }
  62. solution "bgfx"
  63. configurations {
  64. "Debug",
  65. "Release",
  66. }
  67. if _ACTION:match "xcode*" then
  68. platforms {
  69. "Universal",
  70. }
  71. else
  72. platforms {
  73. "x32",
  74. "x64",
  75. -- "Xbox360",
  76. "Native", -- for targets where bitness is not specified
  77. }
  78. end
  79. language "C++"
  80. startproject "example-00-helloworld"
  81. MODULE_DIR = path.getabsolute("../")
  82. BGFX_DIR = path.getabsolute("..")
  83. BX_DIR = os.getenv("BX_DIR")
  84. BIMG_DIR = os.getenv("BIMG_DIR")
  85. local BGFX_BUILD_DIR = path.join(BGFX_DIR, ".build")
  86. local BGFX_THIRD_PARTY_DIR = path.join(BGFX_DIR, "3rdparty")
  87. if not BX_DIR then
  88. BX_DIR = path.getabsolute(path.join(BGFX_DIR, "../bx"))
  89. end
  90. if not BIMG_DIR then
  91. BIMG_DIR = path.getabsolute(path.join(BGFX_DIR, "../bimg"))
  92. end
  93. if not os.isdir(BX_DIR) or not os.isdir(BIMG_DIR) then
  94. if not os.isdir(BX_DIR) then
  95. print("bx not found at " .. BX_DIR)
  96. end
  97. if not os.isdir(BIMG_DIR) then
  98. print("bimg not found at " .. BIMG_DIR)
  99. end
  100. print("For more info see: https://bkaradzic.github.io/bgfx/build.html")
  101. os.exit()
  102. end
  103. dofile (path.join(BX_DIR, "scripts/toolchain.lua"))
  104. if not toolchain(BGFX_BUILD_DIR, BGFX_THIRD_PARTY_DIR) then
  105. return -- no action specified
  106. end
  107. function copyLib()
  108. end
  109. if _OPTIONS["with-wayland"] then
  110. defines { "WL_EGL_PLATFORM=1" }
  111. end
  112. if _OPTIONS["with-sdl"] then
  113. if os.is("windows") then
  114. if not os.getenv("SDL2_DIR") then
  115. print("Set SDL2_DIR enviroment variable.")
  116. end
  117. end
  118. end
  119. if _OPTIONS["with-profiler"] then
  120. defines {
  121. "ENTRY_CONFIG_PROFILER=1",
  122. "BGFX_CONFIG_PROFILER=1",
  123. }
  124. end
  125. function exampleProjectDefaults()
  126. debugdir (path.join(BGFX_DIR, "examples/runtime"))
  127. includedirs {
  128. path.join(BX_DIR, "include"),
  129. path.join(BIMG_DIR, "include"),
  130. path.join(BGFX_DIR, "include"),
  131. path.join(BGFX_DIR, "3rdparty"),
  132. path.join(BGFX_DIR, "examples/common"),
  133. }
  134. flags {
  135. "FatalWarnings",
  136. }
  137. links {
  138. "example-common",
  139. "example-glue",
  140. "bgfx",
  141. "bimg_decode",
  142. "bimg",
  143. "bx",
  144. }
  145. if _OPTIONS["with-sdl"] then
  146. defines { "ENTRY_CONFIG_USE_SDL=1" }
  147. links { "SDL2" }
  148. configuration { "linux or freebsd" }
  149. if _OPTIONS["with-wayland"] then
  150. links {
  151. "wayland-egl",
  152. }
  153. end
  154. configuration { "osx" }
  155. libdirs { "$(SDL2_DIR)/lib" }
  156. configuration {}
  157. end
  158. if _OPTIONS["with-glfw"] then
  159. defines { "ENTRY_CONFIG_USE_GLFW=1" }
  160. links { "glfw3" }
  161. configuration { "linux or freebsd" }
  162. if _OPTIONS["with-wayland"] then
  163. links {
  164. "wayland-egl",
  165. }
  166. else
  167. links {
  168. "Xrandr",
  169. "Xinerama",
  170. "Xi",
  171. "Xxf86vm",
  172. "Xcursor",
  173. }
  174. end
  175. configuration { "osx" }
  176. linkoptions {
  177. "-framework CoreVideo",
  178. "-framework IOKit",
  179. }
  180. configuration {}
  181. end
  182. configuration { "vs*", "x32 or x64" }
  183. linkoptions {
  184. "/ignore:4199", -- LNK4199: /DELAYLOAD:*.dll ignored; no imports found from *.dll
  185. }
  186. links { -- this is needed only for testing with GLES2/3 on Windows with VS2008
  187. "DelayImp",
  188. }
  189. configuration { "vs201*", "x32 or x64" }
  190. linkoptions { -- this is needed only for testing with GLES2/3 on Windows with VS201x
  191. "/DELAYLOAD:\"libEGL.dll\"",
  192. "/DELAYLOAD:\"libGLESv2.dll\"",
  193. }
  194. configuration { "mingw*" }
  195. targetextension ".exe"
  196. links {
  197. "gdi32",
  198. "psapi",
  199. }
  200. configuration { "vs20*", "x32 or x64" }
  201. links {
  202. "gdi32",
  203. "psapi",
  204. }
  205. configuration { "durango" }
  206. links {
  207. "d3d11_x",
  208. "d3d12_x",
  209. "combase",
  210. "kernelx",
  211. }
  212. configuration { "winstore*" }
  213. removelinks {
  214. "DelayImp",
  215. "gdi32",
  216. "psapi"
  217. }
  218. links {
  219. "d3d11",
  220. "d3d12",
  221. "dxgi"
  222. }
  223. linkoptions {
  224. "/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
  225. }
  226. -- WinRT targets need their own output directories or build files stomp over each other
  227. configuration { "x32", "winstore*" }
  228. targetdir (path.join(BGFX_BUILD_DIR, "win32_" .. _ACTION, "bin", _name))
  229. objdir (path.join(BGFX_BUILD_DIR, "win32_" .. _ACTION, "obj", _name))
  230. configuration { "x64", "winstore*" }
  231. targetdir (path.join(BGFX_BUILD_DIR, "win64_" .. _ACTION, "bin", _name))
  232. objdir (path.join(BGFX_BUILD_DIR, "win64_" .. _ACTION, "obj", _name))
  233. configuration { "ARM", "winstore*" }
  234. targetdir (path.join(BGFX_BUILD_DIR, "arm_" .. _ACTION, "bin", _name))
  235. objdir (path.join(BGFX_BUILD_DIR, "arm_" .. _ACTION, "obj", _name))
  236. configuration { "mingw-clang" }
  237. kind "ConsoleApp"
  238. configuration { "android*" }
  239. kind "ConsoleApp"
  240. targetextension ".so"
  241. linkoptions {
  242. "-shared",
  243. }
  244. links {
  245. "EGL",
  246. "GLESv2",
  247. }
  248. configuration { "asmjs" }
  249. kind "ConsoleApp"
  250. targetextension ".bc"
  251. configuration { "linux-* or freebsd", "not linux-steamlink" }
  252. links {
  253. "X11",
  254. "GL",
  255. "pthread",
  256. }
  257. configuration { "linux-steamlink" }
  258. links {
  259. "EGL",
  260. "GLESv2",
  261. "SDL2",
  262. "pthread",
  263. }
  264. configuration { "rpi" }
  265. links {
  266. "X11",
  267. "brcmGLESv2",
  268. "brcmEGL",
  269. "bcm_host",
  270. "vcos",
  271. "vchiq_arm",
  272. "pthread",
  273. }
  274. configuration { "osx" }
  275. linkoptions {
  276. "-framework Cocoa",
  277. "-framework QuartzCore",
  278. "-framework OpenGL",
  279. "-weak_framework Metal",
  280. }
  281. configuration { "ios* or tvos*" }
  282. kind "ConsoleApp"
  283. linkoptions {
  284. "-framework CoreFoundation",
  285. "-framework Foundation",
  286. "-framework OpenGLES",
  287. "-framework UIKit",
  288. "-framework QuartzCore",
  289. "-weak_framework Metal",
  290. }
  291. configuration { "xcode*", "ios" }
  292. kind "WindowedApp"
  293. files {
  294. path.join(BGFX_DIR, "examples/runtime/iOS-Info.plist"),
  295. }
  296. configuration { "xcode*", "tvos" }
  297. kind "WindowedApp"
  298. files {
  299. path.join(BGFX_DIR, "examples/runtime/tvOS-Info.plist"),
  300. }
  301. configuration { "qnx*" }
  302. targetextension ""
  303. links {
  304. "EGL",
  305. "GLESv2",
  306. }
  307. configuration {}
  308. strip()
  309. end
  310. function exampleProject(_combined, ...)
  311. if _combined then
  312. project ("examples")
  313. uuid (os.uuid("examples"))
  314. kind "WindowedApp"
  315. for _, name in ipairs({...}) do
  316. files {
  317. path.join(BGFX_DIR, "examples", name, "**.c"),
  318. path.join(BGFX_DIR, "examples", name, "**.cpp"),
  319. path.join(BGFX_DIR, "examples", name, "**.h"),
  320. }
  321. removefiles {
  322. path.join(BGFX_DIR, "examples", name, "**.bin.h"),
  323. }
  324. end
  325. files {
  326. path.join(BGFX_DIR, "examples/25-c99/helloworld.c"), -- hack for _main_
  327. }
  328. exampleProjectDefaults()
  329. else
  330. for _, name in ipairs({...}) do
  331. project ("example-" .. name)
  332. uuid (os.uuid("example-" .. name))
  333. kind "WindowedApp"
  334. files {
  335. path.join(BGFX_DIR, "examples", name, "**.c"),
  336. path.join(BGFX_DIR, "examples", name, "**.cpp"),
  337. path.join(BGFX_DIR, "examples", name, "**.h"),
  338. }
  339. removefiles {
  340. path.join(BGFX_DIR, "examples", name, "**.bin.h"),
  341. }
  342. defines {
  343. "ENTRY_CONFIG_IMPLEMENT_MAIN=1",
  344. }
  345. exampleProjectDefaults()
  346. end
  347. end
  348. end
  349. dofile "bgfx.lua"
  350. group "libs"
  351. bgfxProject("", "StaticLib", {})
  352. dofile(path.join(BX_DIR, "scripts/bx.lua"))
  353. dofile(path.join(BIMG_DIR, "scripts/bimg.lua"))
  354. dofile(path.join(BIMG_DIR, "scripts/bimg_decode.lua"))
  355. if _OPTIONS["with-tools"] then
  356. dofile(path.join(BIMG_DIR, "scripts/bimg_encode.lua"))
  357. end
  358. if _OPTIONS["with-examples"]
  359. or _OPTIONS["with-combined-examples"]
  360. or _OPTIONS["with-tools"] then
  361. group "examples"
  362. dofile "example-common.lua"
  363. end
  364. if _OPTIONS["with-examples"]
  365. or _OPTIONS["with-combined-examples"] then
  366. group "examples"
  367. exampleProject(_OPTIONS["with-combined-examples"]
  368. , "00-helloworld"
  369. , "01-cubes"
  370. , "02-metaballs"
  371. , "03-raymarch"
  372. , "04-mesh"
  373. , "05-instancing"
  374. , "06-bump"
  375. , "07-callback"
  376. , "08-update"
  377. , "09-hdr"
  378. , "10-font"
  379. , "11-fontsdf"
  380. , "12-lod"
  381. , "13-stencil"
  382. , "14-shadowvolumes"
  383. , "15-shadowmaps-simple"
  384. , "16-shadowmaps"
  385. , "17-drawstress"
  386. , "18-ibl"
  387. , "19-oit"
  388. , "20-nanovg"
  389. , "21-deferred"
  390. , "22-windows"
  391. , "23-vectordisplay"
  392. , "24-nbody"
  393. , "26-occlusion"
  394. , "27-terrain"
  395. , "28-wireframe"
  396. , "29-debugdraw"
  397. , "30-picking"
  398. , "31-rsm"
  399. , "32-particles"
  400. , "33-pom"
  401. , "34-mvs"
  402. , "35-dynamic"
  403. , "36-sky"
  404. , "37-gpudrivenrendering"
  405. , "38-bloom"
  406. , "39-assao"
  407. , "40-svt"
  408. , "41-tess"
  409. )
  410. -- C99 source doesn't compile under WinRT settings
  411. if not premake.vstudio.iswinrt() then
  412. exampleProject(false, "25-c99")
  413. end
  414. end
  415. if _OPTIONS["with-shared-lib"] then
  416. group "libs"
  417. bgfxProject("-shared-lib", "SharedLib", {})
  418. end
  419. if _OPTIONS["with-tools"] then
  420. group "tools"
  421. dofile "shaderc.lua"
  422. dofile "texturec.lua"
  423. dofile "texturev.lua"
  424. dofile "geometryc.lua"
  425. dofile "geometryv.lua"
  426. end