genie.lua 11 KB

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