genie.lua 9.8 KB

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