Skip to content

Commit 2373bd6

Browse files
committed
Premake: experimental premake5 script.
(neater vs project output but certainly less standard than cmake)
1 parent 3346544 commit 2373bd6

File tree

2 files changed

+305
-0
lines changed

2 files changed

+305
-0
lines changed

examples/premake5-lib.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
project "imgui"
2+
kind "StaticLib"
3+
files { "../*.h", "../*.cpp" }
4+
vpaths { ["imgui"] = { "../*.cpp", "../*.h", "../misc/natvis/*.natvis" } }
5+
filter { "toolset:msc*" }
6+
files { "../misc/natvis/*.natvis" }
7+

examples/premake5.lua

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

0 commit comments

Comments
 (0)