genie.lua 9.9 KB

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