genie.lua 10 KB

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