genie.lua 11 KB

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