premake5.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. -- We use Premake5 to generate project files (Visual Studio solutions, XCode solutions, Makefiles, etc.)
  2. -- Download Premake5: at https://premake.github.io/download
  3. -- YOU NEED PREMAKE 5.0.0-alpha10 or later
  4. --------- HELP
  5. -- To reduce friction for people who don't aren't used to Premake, we list some concrete usage examples.
  6. if _ACTION == nil then
  7. print "-----------------------------------------"
  8. print " DEAR IMGUI EXAMPLES - PROJECT GENERATOR"
  9. print "-----------------------------------------"
  10. print "Usage:"
  11. print " premake5 [generator] [options]"
  12. print "Examples:"
  13. print " premake5 vs2010"
  14. print " premake5 vs2019 --with-sdl2 --with-vulkan"
  15. print " premake5 xcode4 --with-glfw"
  16. print " premake5 gmake2 --with-glfw --cc=clang"
  17. print "Generators:"
  18. print " codelite gmake gmake2 vs2008 vs2010 vs2012 vs2013 vs2015 vs2017 xcode4 etc."
  19. print "Options:"
  20. print " --with-dx9 Enable dear imgui DirectX 9 example"
  21. print " --with-dx10 Enable dear imgui DirectX 10 example"
  22. print " --with-dx11 Enable dear imgui DirectX 11 example"
  23. print " --with-dx12 Enable dear imgui DirectX 12 example (vs2015+)"
  24. print " --with-glfw Enable dear imgui GLFW examples"
  25. print " --with-sdl2 Enable dear imgui SDL2 examples"
  26. print " --with-vulkan Enable dear imgui Vulkan example"
  27. print " --cc=clang Compile with Clang"
  28. print " --cc=gcc Compile with GCC"
  29. print "Project and object files will be created in the build/ folder. You can delete your build/ folder at any time."
  30. print ""
  31. end
  32. ---------- OPTIONS
  33. newoption { trigger = "with-dx9", description="Enable dear imgui DirectX 9 example" }
  34. newoption { trigger = "with-dx10", description="Enable dear imgui DirectX 10 example" }
  35. newoption { trigger = "with-dx11", description="Enable dear imgui DirectX 11 example" }
  36. newoption { trigger = "with-dx12", description="Enable dear imgui DirectX 12 example" }
  37. newoption { trigger = "with-glfw", description="Enable dear imgui GLFW examples" }
  38. newoption { trigger = "with-sdl2", description="Enable dear imgui SDL2 examples" }
  39. newoption { trigger = "with-vulkan", description="Enable dear imgui Vulkan example" }
  40. -- Enable/detect default options under Windows
  41. if _ACTION ~= nil and ((os.istarget ~= nil and os.istarget("windows")) or (os.is ~= nil and os.is("windows"))) then
  42. print("( enabling --with-dx9 )");
  43. print("( enabling --with-dx10 )");
  44. print("( enabling --with-dx11 )");
  45. _OPTIONS["with-dx9"] = 1
  46. _OPTIONS["with-dx10"] = 1
  47. _OPTIONS["with-dx11"] = 1
  48. if _ACTION >= "vs2015" then
  49. print("( enabling --with-dx12 because compiler is " .. _ACTION .. " )");
  50. _OPTIONS["with-dx12"] = 1
  51. end
  52. print("( enabling --with-glfw because GLFW is included in the libs/ folder )");
  53. _OPTIONS["with-glfw"] = 1
  54. if os.getenv("SDL2_DIR") then
  55. print("( enabling --with-sdl2 because SDL2_DIR environment variable was found )");
  56. _OPTIONS["with-sdl2"] = 1
  57. end
  58. if os.getenv("VULKAN_SDK") then
  59. print("( enabling --with-vulkan because VULKAN_SDK environment variable was found )");
  60. _OPTIONS["with-vulkan"] = 1
  61. end
  62. end
  63. --------- HELPER FUNCTIONS
  64. -- Helper function: add dear imgui source files into project
  65. function imgui_as_src(fs_path, project_path)
  66. if (project_path == nil) then project_path = fs_path; end; -- default to same virtual folder as the file system folder (in this project it would be ".." !)
  67. files { fs_path .. "/*.cpp", fs_path .. "/*.h" }
  68. includedirs { fs_path, fs_path .. "/backends" }
  69. vpaths { [project_path] = { fs_path .. "/*.*", fs_path .. "/misc/debuggers/*.natvis" } } -- add in a specific folder of the Visual Studio project
  70. filter { "toolset:msc*" }
  71. files { fs_path .. "/misc/debuggers/*.natvis" }
  72. filter {}
  73. end
  74. -- Helper function: add dear imgui as a library (uncomment the 'include "premake5-lib"' line)
  75. --include "premake5-lib"
  76. function imgui_as_lib(fs_path)
  77. includedirs { fs_path, fs_path .. "/backends" }
  78. links "imgui"
  79. end
  80. --------- SOLUTION, PROJECTS
  81. workspace "imgui_examples"
  82. configurations { "Debug", "Release" }
  83. platforms { "x86", "x86_64" }
  84. location "build/"
  85. symbols "On"
  86. warnings "Extra"
  87. --flags { "FatalCompileWarnings"}
  88. filter { "configurations:Debug" }
  89. optimize "Off"
  90. filter { "configurations:Release" }
  91. optimize "On"
  92. filter { "toolset:clang", "system:windows" }
  93. buildoptions { "-Xclang", "-flto-visibility-public-std" } -- Remove "warning LNK4049: locally defined symbol ___std_terminate imported"
  94. -- example_win32_directx11 (Win32 + DirectX 11)
  95. -- We have DX11 as the first project because this is what Visual Studio uses
  96. if (_OPTIONS["with-dx11"]) then
  97. project "example_win32_directx11"
  98. kind "ConsoleApp"
  99. imgui_as_src ("..", "imgui")
  100. --imgui_as_lib ("..")
  101. files { "../backends/imgui_impl_win32.*", "../backends/imgui_impl_dx11.*", "example_win32_directx11/*.cpp", "example_win32_directx11/*.h", "README.txt" }
  102. vpaths { ["sources"] = "./**" }
  103. filter { "system:windows", "toolset:msc-v80 or msc-v90 or msc-v100" }
  104. includedirs { "$(DXSDK_DIR)/Include" }
  105. filter { "system:windows", "toolset:msc-v80 or msc-v90 or msc-v100", "platforms:x86" }
  106. libdirs { "$(DXSDK_DIR)/Lib/x86" }
  107. filter { "system:windows", "toolset:msc-v80 or msc-v90 or msc-v100", "platforms:x86_64" }
  108. libdirs { "$(DXSDK_DIR)/Lib/x64" }
  109. filter { "system:windows" }
  110. links { "d3d11", "d3dcompiler", "dxgi" }
  111. end
  112. -- example_win32_directx9 (Win32 + DirectX 9)
  113. if (_OPTIONS["with-dx9"]) then
  114. project "example_win32_directx9"
  115. kind "ConsoleApp"
  116. imgui_as_src ("..", "imgui")
  117. --imgui_as_lib ("..")
  118. files { "../backends/imgui_impl_win32.*", "../backends/imgui_impl_dx9.*", "example_win32_directx9/*.cpp", "example_win32_directx9/*.h", "README.txt" }
  119. vpaths { ["sources"] = "./**" }
  120. filter { "system:windows" }
  121. links { "d3d9" }
  122. end
  123. -- example_win32_directx10 (Win32 + DirectX 10)
  124. if (_OPTIONS["with-dx10"]) then
  125. project "example_win32_directx10"
  126. kind "ConsoleApp"
  127. imgui_as_src ("..", "imgui")
  128. --imgui_as_lib ("..")
  129. files { "../backends/imgui_impl_win32.*", "../backends/imgui_impl_dx10.*", "example_win32_directx10/*.cpp", "example_win32_directx10/*.h", "README.txt" }
  130. vpaths { ["sources"] = "./**" }
  131. filter { "system:windows", "toolset:msc-v80 or msc-v90 or msc-v100" }
  132. includedirs { "$(DXSDK_DIR)/Include" }
  133. filter { "system:windows", "toolset:msc-v80 or msc-v90 or msc-v100", "platforms:x86" }
  134. libdirs { "$(DXSDK_DIR)/Lib/x86" }
  135. filter { "system:windows", "toolset:msc-v80 or msc-v90 or msc-v100", "platforms:x86_64" }
  136. libdirs { "$(DXSDK_DIR)/Lib/x64" }
  137. filter { "system:windows" }
  138. links { "d3d10", "d3dcompiler", "dxgi" }
  139. end
  140. -- example_win32_directx12 (Win32 + DirectX 12)
  141. if (_OPTIONS["with-dx12"]) then
  142. project "example_win32_directx12"
  143. kind "ConsoleApp"
  144. systemversion "10.0.16299.0"
  145. imgui_as_src ("..", "imgui")
  146. --imgui_as_lib ("..")
  147. files { "../backends/imgui_impl_win32.*", "../backends/imgui_impl_dx12.*", "example_win32_directx12/*.cpp", "example_win32_directx12/*.h", "README.txt" }
  148. vpaths { ["sources"] = "./**" }
  149. filter { "system:windows" }
  150. links { "d3d12", "d3dcompiler", "dxgi" }
  151. end
  152. -- example_glfw_opengl2 (GLFW + OpenGL2)
  153. if (_OPTIONS["with-glfw"]) then
  154. project "example_glfw_opengl2"
  155. kind "ConsoleApp"
  156. imgui_as_src ("..", "imgui")
  157. --imgui_as_lib ("..")
  158. files { "../backends/imgui_impl_glfw.*", "../backends/imgui_impl_opengl2.*", "example_glfw_opengl2/*.h", "example_glfw_opengl2/*.cpp", "README.txt"}
  159. vpaths { ["sources"] = "./**" }
  160. includedirs { "libs/glfw/include" }
  161. filter { "system:windows", "platforms:x86" }
  162. libdirs { "libs/glfw/lib-vc2010-32" }
  163. filter { "system:windows", "platforms:x86_64" }
  164. libdirs { "libs/glfw/lib-vc2010-64" }
  165. filter { "system:windows" }
  166. ignoredefaultlibraries { "msvcrt" }
  167. links { "opengl32", "glfw3" }
  168. filter { "system:linux" }
  169. links { "glfw3" }
  170. filter { "system:macosx" }
  171. libdirs { "/usr/local/lib" }
  172. links { "glfw" }
  173. linkoptions { "-framework OpenGL" }
  174. end
  175. -- example_glfw_opengl3 (GLFW + OpenGL3)
  176. if (_OPTIONS["with-glfw"]) then
  177. project "example_glfw_opengl3"
  178. kind "ConsoleApp"
  179. imgui_as_src ("..", "imgui")
  180. --imgui_as_lib ("..")
  181. vpaths { ["sources"] = "./**" }
  182. files { "../backends/imgui_impl_glfw.*", "../backends/imgui_impl_opengl3.*", "example_glfw_opengl3/*.h", "example_glfw_opengl3/*.cpp", "./README.txt" }
  183. includedirs { "libs/glfw/include" }
  184. filter { "system:windows", "platforms:x86" }
  185. libdirs { "libs/glfw/lib-vc2010-32" }
  186. filter { "system:windows", "platforms:x86_64" }
  187. libdirs { "libs/glfw/lib-vc2010-64" }
  188. filter { "system:windows" }
  189. ignoredefaultlibraries { "msvcrt" }
  190. links { "opengl32", "glfw3" }
  191. filter { "system:linux" }
  192. links { "glfw3" }
  193. filter { "system:macosx" }
  194. libdirs { "/usr/local/lib" }
  195. links { "glfw" }
  196. linkoptions { "-framework OpenGL" }
  197. end
  198. -- example_glfw_vulkan (GLFW + Vulkan)
  199. if (_OPTIONS["with-vulkan"]) then
  200. project "example_glfw_vulkan"
  201. kind "ConsoleApp"
  202. imgui_as_src ("..", "imgui")
  203. --imgui_as_lib ("..")
  204. vpaths { ["sources"] = "./**" }
  205. files { "../backends/imgui_impl_glfw*", "../backends/imgui_impl_vulkan.*", "example_glfw_vulkan/*.h", "example_glfw_vulkan/*.cpp", "./README.txt" }
  206. includedirs { "libs/glfw/include", "%VULKAN_SDK%/include" }
  207. filter { "system:windows", "platforms:x86" }
  208. libdirs { "libs/glfw/lib-vc2010-32", "%VULKAN_SDK%/lib32" }
  209. filter { "system:windows", "platforms:x86_64" }
  210. libdirs { "libs/glfw/lib-vc2010-64", "%VULKAN_SDK%/lib" }
  211. filter { "system:windows" }
  212. ignoredefaultlibraries { "msvcrt" }
  213. links { "vulkan-1", "glfw3" }
  214. filter { "system:linux" }
  215. links { "glfw3" } -- FIXME: missing Vulkan. missing macosx version
  216. end
  217. -- example_null (no rendering)
  218. if (true) then
  219. project "example_null"
  220. kind "ConsoleApp"
  221. imgui_as_src ("..", "imgui")
  222. --imgui_as_lib ("..")
  223. vpaths { ["sources"] = "./**" }
  224. files { "example_null/*.h", "example_null/*.cpp", "./README.txt" }
  225. filter { "system:windows" }
  226. ignoredefaultlibraries { "msvcrt" }
  227. end
  228. -- example_sdl2_sdlrenderer2 (SDL2 + SDL_Renderer)
  229. if (_OPTIONS["with-sdl2"]) then
  230. project "example_sdl2_sdlrenderer2"
  231. kind "ConsoleApp"
  232. imgui_as_src ("..", "imgui")
  233. --imgui_as_lib ("..")
  234. vpaths { ["sources"] = "./**" }
  235. files { "../backends/imgui_impl_sdl2*", "../backends/imgui_impl_sdlrenderer2.*", "example_sdl2_sdlrenderer2/*.h", "example_sdl2_sdlrenderer2/*.cpp", "./README.txt" }
  236. includedirs { "%SDL2_DIR%/include" }
  237. filter { "system:windows", "platforms:x86" }
  238. libdirs { "%SDL2_DIR%/lib/x86" }
  239. filter { "system:windows", "platforms:x86_64" }
  240. libdirs { "%SDL2_DIR%/lib/x64" }
  241. filter { "system:windows" }
  242. ignoredefaultlibraries { "msvcrt" }
  243. links { "SDL2", "SDL2main" }
  244. end
  245. -- example_sdl2_opengl2 (SDL2 + OpenGL2)
  246. if (_OPTIONS["with-sdl2"]) then
  247. project "example_sdl2_opengl2"
  248. kind "ConsoleApp"
  249. imgui_as_src ("..", "imgui")
  250. --imgui_as_lib ("..")
  251. vpaths { ["sources"] = "./**" }
  252. files { "../backends/imgui_impl_sdl2*", "../backends/imgui_impl_opengl2.*", "example_sdl2_opengl2/*.h", "example_sdl2_opengl2/*.cpp", "./README.txt" }
  253. includedirs { "%SDL2_DIR%/include" }
  254. filter { "system:windows", "platforms:x86" }
  255. libdirs { "%SDL2_DIR%/lib/x86" }
  256. filter { "system:windows", "platforms:x86_64" }
  257. libdirs { "%SDL2_DIR%/lib/x64" }
  258. filter { "system:windows" }
  259. ignoredefaultlibraries { "msvcrt" }
  260. links { "SDL2", "SDL2main", "opengl32" }
  261. end
  262. -- example_sdl2_opengl3 (SDL2 + OpenGL3)
  263. if (_OPTIONS["with-sdl2"]) then
  264. project "example_sdl2_opengl3"
  265. kind "ConsoleApp"
  266. imgui_as_src ("..", "imgui")
  267. --imgui_as_lib ("..")
  268. vpaths { ["sources"] = "./**" }
  269. files { "../backends/imgui_impl_sdl2*", "../backends/imgui_impl_opengl3.*", "example_sdl2_opengl3/*.h", "example_sdl2_opengl3/*.cpp", "./README.txt" }
  270. includedirs { "%SDL2_DIR%/include" }
  271. filter { "system:windows", "platforms:x86" }
  272. libdirs { "%SDL2_DIR%/lib/x86" }
  273. filter { "system:windows", "platforms:x86_64" }
  274. libdirs { "%SDL2_DIR%/lib/x64" }
  275. filter { "system:windows" }
  276. ignoredefaultlibraries { "msvcrt" }
  277. links { "SDL2", "SDL2main", "opengl32" }
  278. end
  279. -- example_sdl2_vulkan (SDL2 + Vulkan)
  280. if (_OPTIONS["with-sdl2"] and _OPTIONS["with-vulkan"]) then
  281. project "example_sdl2_vulkan"
  282. kind "ConsoleApp"
  283. imgui_as_src ("..", "imgui")
  284. --imgui_as_lib ("..")
  285. vpaths { ["sources"] = "./**" }
  286. files { "../backends/imgui_impl_sdl2*", "../backends/imgui_impl_vulkan.*", "example_sdl2_vulkan/*.h", "example_sdl2_vulkan/*.cpp", "./README.txt" }
  287. includedirs { "%SDL2_DIR%/include", "%VULKAN_SDK%/include" }
  288. filter { "system:windows", "platforms:x86" }
  289. libdirs { "%SDL2_DIR%/lib/x86", "%VULKAN_SDK%/lib32" }
  290. filter { "system:windows", "platforms:x86_64" }
  291. libdirs { "%SDL2_DIR%/lib/x64", "%VULKAN_SDK%/lib" }
  292. filter { "system:windows" }
  293. ignoredefaultlibraries { "msvcrt" }
  294. links { "SDL2", "SDL2main", "vulkan-1" }
  295. end