genie.lua 9.8 KB

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