genie.lua 10 KB

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