genie.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  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. linkoptions {
  254. "-s TOTAL_MEMORY=256MB",
  255. "--memory-init-file 1",
  256. }
  257. removeflags {
  258. "OptimizeSpeed",
  259. }
  260. flags {
  261. "Optimize"
  262. }
  263. configuration { "linux-* or freebsd", "not linux-steamlink" }
  264. links {
  265. "X11",
  266. "GL",
  267. "pthread",
  268. }
  269. configuration { "linux-steamlink" }
  270. links {
  271. "EGL",
  272. "GLESv2",
  273. "SDL2",
  274. "pthread",
  275. }
  276. configuration { "rpi" }
  277. links {
  278. "X11",
  279. "brcmGLESv2",
  280. "brcmEGL",
  281. "bcm_host",
  282. "vcos",
  283. "vchiq_arm",
  284. "pthread",
  285. }
  286. configuration { "osx" }
  287. linkoptions {
  288. "-framework Cocoa",
  289. "-framework QuartzCore",
  290. "-framework OpenGL",
  291. "-weak_framework Metal",
  292. }
  293. configuration { "ios* or tvos*" }
  294. kind "ConsoleApp"
  295. linkoptions {
  296. "-framework CoreFoundation",
  297. "-framework Foundation",
  298. "-framework OpenGLES",
  299. "-framework UIKit",
  300. "-framework QuartzCore",
  301. "-weak_framework Metal",
  302. }
  303. configuration { "xcode*", "ios" }
  304. kind "WindowedApp"
  305. files {
  306. path.join(BGFX_DIR, "examples/runtime/iOS-Info.plist"),
  307. }
  308. configuration { "xcode*", "tvos" }
  309. kind "WindowedApp"
  310. files {
  311. path.join(BGFX_DIR, "examples/runtime/tvOS-Info.plist"),
  312. }
  313. configuration { "qnx*" }
  314. targetextension ""
  315. links {
  316. "EGL",
  317. "GLESv2",
  318. }
  319. configuration {}
  320. strip()
  321. end
  322. function exampleProject(_combined, ...)
  323. if _combined then
  324. project ("examples")
  325. uuid (os.uuid("examples"))
  326. kind "WindowedApp"
  327. for _, name in ipairs({...}) do
  328. files {
  329. path.join(BGFX_DIR, "examples", name, "**.c"),
  330. path.join(BGFX_DIR, "examples", name, "**.cpp"),
  331. path.join(BGFX_DIR, "examples", name, "**.h"),
  332. }
  333. removefiles {
  334. path.join(BGFX_DIR, "examples", name, "**.bin.h"),
  335. }
  336. end
  337. files {
  338. path.join(BGFX_DIR, "examples/25-c99/helloworld.c"), -- hack for _main_
  339. }
  340. exampleProjectDefaults()
  341. else
  342. for _, name in ipairs({...}) do
  343. project ("example-" .. name)
  344. uuid (os.uuid("example-" .. name))
  345. kind "WindowedApp"
  346. files {
  347. path.join(BGFX_DIR, "examples", name, "**.c"),
  348. path.join(BGFX_DIR, "examples", name, "**.cpp"),
  349. path.join(BGFX_DIR, "examples", name, "**.h"),
  350. }
  351. removefiles {
  352. path.join(BGFX_DIR, "examples", name, "**.bin.h"),
  353. }
  354. defines {
  355. "ENTRY_CONFIG_IMPLEMENT_MAIN=1",
  356. }
  357. exampleProjectDefaults()
  358. end
  359. end
  360. end
  361. dofile "bgfx.lua"
  362. group "libs"
  363. bgfxProject("", "StaticLib", {})
  364. dofile(path.join(BX_DIR, "scripts/bx.lua"))
  365. dofile(path.join(BIMG_DIR, "scripts/bimg.lua"))
  366. dofile(path.join(BIMG_DIR, "scripts/bimg_decode.lua"))
  367. if _OPTIONS["with-tools"] then
  368. dofile(path.join(BIMG_DIR, "scripts/bimg_encode.lua"))
  369. end
  370. if _OPTIONS["with-examples"]
  371. or _OPTIONS["with-combined-examples"]
  372. or _OPTIONS["with-tools"] then
  373. group "examples"
  374. dofile "example-common.lua"
  375. end
  376. if _OPTIONS["with-examples"]
  377. or _OPTIONS["with-combined-examples"] then
  378. group "examples"
  379. exampleProject(_OPTIONS["with-combined-examples"]
  380. , "00-helloworld"
  381. , "01-cubes"
  382. , "02-metaballs"
  383. , "03-raymarch"
  384. , "04-mesh"
  385. , "05-instancing"
  386. , "06-bump"
  387. , "07-callback"
  388. , "08-update"
  389. , "09-hdr"
  390. , "10-font"
  391. , "11-fontsdf"
  392. , "12-lod"
  393. , "13-stencil"
  394. , "14-shadowvolumes"
  395. , "15-shadowmaps-simple"
  396. , "16-shadowmaps"
  397. , "17-drawstress"
  398. , "18-ibl"
  399. , "19-oit"
  400. , "20-nanovg"
  401. , "21-deferred"
  402. , "22-windows"
  403. , "23-vectordisplay"
  404. , "24-nbody"
  405. , "26-occlusion"
  406. , "27-terrain"
  407. , "28-wireframe"
  408. , "29-debugdraw"
  409. , "30-picking"
  410. , "31-rsm"
  411. , "32-particles"
  412. , "33-pom"
  413. , "34-mvs"
  414. , "35-dynamic"
  415. , "36-sky"
  416. , "37-gpudrivenrendering"
  417. , "38-bloom"
  418. , "39-assao"
  419. , "40-svt"
  420. , "41-tess"
  421. )
  422. -- C99 source doesn't compile under WinRT settings
  423. if not premake.vstudio.iswinrt() then
  424. exampleProject(false, "25-c99")
  425. end
  426. end
  427. if _OPTIONS["with-shared-lib"] then
  428. group "libs"
  429. bgfxProject("-shared-lib", "SharedLib", {})
  430. end
  431. if _OPTIONS["with-tools"] then
  432. group "tools"
  433. dofile "shaderc.lua"
  434. dofile "texturec.lua"
  435. dofile "texturev.lua"
  436. dofile "geometryc.lua"
  437. dofile "geometryv.lua"
  438. end