Skip to content

Commit f75ce42

Browse files
committed
Add simple CMake support for imgui
1 parent ec2c805 commit f75ce42

File tree

7 files changed

+287
-12
lines changed

7 files changed

+287
-12
lines changed

CMakeLists.txt

+275
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
cmake_minimum_required(VERSION 3.13) # CMake version check
2+
project(imgui) # Create project "imgui"
3+
set(CMAKE_CXX_STANDARD 14) # Enable c++14 standard
4+
5+
6+
# You may have to manually set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER respectively to clang
7+
# set(CMAKE_C_COMPILER "/usr/local/bin/clang")
8+
# set(CMAKE_CXX_COMPILER "/usr/local/bin/clang++")
9+
10+
11+
# Add all .cpp files of project root directory as source file
12+
set(SOURCE_FILES imgui.cpp imgui_draw.cpp imgui_demo.cpp imgui_tables.cpp imgui_widgets.cpp) # Add all .cpp files of project root directory as source files
13+
14+
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
15+
16+
# Add library target with source files listed in SOURCE_FILES variable
17+
add_library(imgui ${SOURCE_FILES})
18+
19+
option(BUILD_BACKEND_ALLEGRO5 "Build backend allegro5" OFF)
20+
option(BUILD_BACKEND_ANDROID "Build backend android" OFF)
21+
option(BUILD_BACKEND_DX_9 "Build backend directX 9" OFF)
22+
option(BUILD_BACKEND_DX_10 "Build backend directX 10" OFF)
23+
option(BUILD_BACKEND_DX_11 "Build backend directX 11" OFF)
24+
option(BUILD_BACKEND_DX_12 "Build backend directX 12" OFF)
25+
option(BUILD_BACKEND_GLFW "Build backend GLFW" ON)
26+
option(BUILD_BACKEND_GLUT "Build backend GLUT" ON)
27+
option(BUILD_BACKEND_METAL "Build backend METAL" OFF)
28+
option(BUILD_BACKEND_OPENGL_2 "Build backend OPENGL 2" OFF)
29+
option(BUILD_BACKEND_OPENGL_3 "Build backend OPENGL 3" OFF)
30+
option(BUILD_BACKEND_OSX "Build backend OSX / Cocoa" OFF)
31+
option(BUILD_BACKEND_SDL "Build backend SDL" OFF)
32+
option(BUILD_BACKEND_VULKAN "Build backend VULKAN" ON)
33+
option(BUILD_BACKEND_WEBGPU "Build backend WEBGPU" OFF)
34+
option(BUILD_BACKEND_WIN32 "Build backend WIN32" OFF)
35+
36+
include_directories(./)
37+
# Add library target with source files listed under backends folder
38+
if(${BUILD_BACKEND_ALLEGRO5})
39+
set(BACKEND_FILE ./backends/imgui_impl_allegro5.cpp)
40+
add_library(imgui_backend_allegro5 ${BACKEND_FILE})
41+
endif()
42+
if(${BUILD_BACKEND_ANDROID})
43+
set(BACKEND_FILE ./backends/imgui_impl_android.cpp)
44+
add_library(imgui_backend_android ${BACKEND_FILE})
45+
endif()
46+
if(${BUILD_BACKEND_DX_9})
47+
set(BACKEND_FILE ./backends/imgui_impl_dx9.cpp)
48+
add_library(imgui_backend_dx9 ${BACKEND_FILE})
49+
endif()
50+
if(${BUILD_BACKEND_DX_10})
51+
set(BACKEND_FILE ./backends/imgui_impl_dx10.cpp)
52+
add_library(imgui_backend_dx10 ${BACKEND_FILE})
53+
endif()
54+
if(${BUILD_BACKEND_DX_11})
55+
set(BACKEND_FILE ./backends/imgui_impl_dx11.cpp)
56+
add_library(imgui_backend_dx11 ${BACKEND_FILE})
57+
endif()
58+
if(${BUILD_BACKEND_DX_12})
59+
set(BACKEND_FILE ./backends/imgui_impl_dx12.cpp)
60+
add_library(imgui_backend_dx12 ${BACKEND_FILE})
61+
endif()
62+
if(${BUILD_BACKEND_GLFW})
63+
set(BACKEND_FILE ./backends/imgui_impl_glfw.cpp)
64+
add_library(imgui_backend_glfw ${BACKEND_FILE})
65+
endif()
66+
if(${BUILD_BACKEND_GLUT})
67+
set(BACKEND_FILE ./backends/imgui_impl_glut.cpp)
68+
add_library(imgui_backend_glut ${BACKEND_FILE})
69+
endif()
70+
if(${BUILD_BACKEND_METAL})
71+
set(BACKEND_FILE ./backends/imgui_impl_metal.mm)
72+
add_library(imgui_backend_metal ${BACKEND_FILE})
73+
endif()
74+
if(${BUILD_BACKEND_OPENGL_2})
75+
set(BACKEND_FILE ./backends/imgui_impl_opengl2.cpp)
76+
add_library(imgui_backend_opengl2 ${BACKEND_FILE})
77+
endif()
78+
if(${BUILD_BACKEND_OPENGL_3})
79+
set(BACKEND_FILE ./backends/imgui_impl_opengl3.cpp)
80+
add_library(imgui_backend_opengl3 ${BACKEND_FILE})
81+
endif()
82+
if(${BUILD_BACKEND_OSX})
83+
set(BACKEND_FILE ./backends/imgui_impl_osx.mm)
84+
add_library(imgui_backend_osx ${BACKEND_FILE})
85+
endif()
86+
if(${BUILD_BACKEND_SDL})
87+
set(BACKEND_FILE ./backends/imgui_impl_sdl.cpp ./backends/imgui_impl_sdlrenderer.cpp)
88+
add_library(imgui_backend_sdl ${BACKEND_FILE})
89+
endif()
90+
if(${BUILD_BACKEND_VULKAN})
91+
set(BACKEND_FILE ./backends/imgui_impl_vulkan.cpp)
92+
add_library(imgui_backend_vulkan ${BACKEND_FILE})
93+
endif()
94+
if(${BUILD_BACKEND_WEBGPU})
95+
set(BACKEND_FILE ./backends/imgui_impl_wgpu.cpp)
96+
add_library(imgui_backend_wgpu ${BACKEND_FILE})
97+
endif()
98+
if(${BUILD_BACKEND_WIN32})
99+
set(BACKEND_FILE ./backends/imgui_impl_win32.cpp)
100+
add_library(imgui_backend_win32 ${BACKEND_FILE})
101+
endif()
102+
103+
104+
105+
option(BUILD_EXAMPLE_ALLEGRO5 "Build example allegro5" OFF)
106+
option(BUILD_EXAMPLE_ANDROID_OPENGL3 "Build example android opengl 3" OFF)
107+
option(BUILD_EXAMPLE_APPLE_METAL "Build example apple metal 9" OFF)
108+
option(BUILD_EXAMPLE_APPLE_OPENGL2 "Build example apple opengl 2" OFF)
109+
option(BUILD_EXAMPLE_EMSCRIPTEN_OPENGL3 "Build example emscripten opengl 3" OFF)
110+
option(BUILD_EXAMPLE_EMSCRIPTEN_WGPU "Build example emscripten wgpu" OFF)
111+
option(BUILD_EXAMPLE_GLFW_METAL "Build example glfw metal" OFF)
112+
option(BUILD_EXAMPLE_GLFW_OPENGL2 "Build example glfw opengl 2" OFF)
113+
option(BUILD_EXAMPLE_GLFW_OPENGL3 "Build example glfw opengl 3" OFF)
114+
option(BUILD_EXAMPLE_GLFW_VULKAN "Build example glfw vulkan" OFF)
115+
option(BUILD_EXAMPLE_GLUT_OPENGL2 "Build example glut opengl 2" OFF)
116+
option(BUILD_EXAMPLE_NULL "Build example null" OFF)
117+
option(BUILD_EXAMPLE_SDL_DIRECTX11 "Build example SDL directx 11" OFF)
118+
option(BUILD_EXAMPLE_SDL_METAL "Build example SDL metal" OFF)
119+
option(BUILD_EXAMPLE_SDL_OPENGL2 "Build example SDL opengl 2" OFF)
120+
option(BUILD_EXAMPLE_SDL_OPENGL3 "Build example SDL opengl 3" OFF)
121+
option(BUILD_EXAMPLE_SDL_SDLRENDERER "Build example SDL SDLRenderer" OFF)
122+
option(BUILD_EXAMPLE_SDL_VULKAN "Build example SDL vulkan" OFF)
123+
option(BUILD_EXAMPLE_WIN32_DIRECTX9 "Build example win32 directx 9" OFF)
124+
option(BUILD_EXAMPLE_WIN32_DIRECTX10 "Build example win32 directx 10" OFF)
125+
option(BUILD_EXAMPLE_WIN32_DIRECTX11 "Build example win32 directx 11" OFF)
126+
option(BUILD_EXAMPLE_WIN32_DIRECTX12 "Build example win32 directx 12" OFF)
127+
128+
129+
# find_package(allegro CONFIG REQUIRED) # for CMake packages
130+
find_package(PkgConfig REQUIRED) # For .pc packages
131+
132+
133+
include_directories(./backends)
134+
if(${BUILD_EXAMPLE_ALLEGRO5})
135+
pkg_check_modules(ALLEGRO5 REQUIRED allegro-5 allegro_primitives-5)
136+
set(EXAMPLE_MAIN_FILE ./examples/example_allegro5/main.cpp)
137+
add_executable(example_allegro5 ${EXAMPLE_MAIN_FILE})
138+
target_link_libraries(example_allegro5 imgui imgui_backend_allegro5 ${ALLEGRO5_LIBRARIES})
139+
endif()
140+
if(${BUILD_EXAMPLE_ANDROID_OPENGL3})
141+
pkg_check_modules(OPENGL3 REQUIRED opengl)
142+
set(EXAMPLE_MAIN_FILE ./examples/example_android_opengl3/main.cpp)
143+
add_executable(example_android_opengl3 ${EXAMPLE_MAIN_FILE})
144+
target_link_libraries(example_android_opengl3 imgui imgui_backend_android imgui_backend_opengl3 OpenGL)
145+
endif()
146+
if(${BUILD_EXAMPLE_APPLE_METAL})
147+
pkg_check_modules(METAL REQUIRED metal)
148+
set(EXAMPLE_MAIN_FILE ./examples/example_apple_metal/main.mm)
149+
add_executable(example_apple_metal ${EXAMPLE_MAIN_FILE})
150+
target_link_libraries(example_apple_metal imgui imgui_backend_osx imgui_backend_metal)
151+
endif()
152+
if(${BUILD_EXAMPLE_APPLE_OPENGL2})
153+
pkg_check_modules(OPENGL2 REQUIRED opengl)
154+
set(EXAMPLE_MAIN_FILE ./examples/example_apple_opengl2/main.mm)
155+
add_executable(example_apple_opengl2 ${EXAMPLE_MAIN_FILE})
156+
target_link_libraries(example_apple_opengl2 imgui imgui_backend_osx imgui_backend_opengl2)
157+
endif()
158+
if(${BUILD_EXAMPLE_EMSCRIPTEN_OPENGL3})
159+
pkg_check_modules(OPENGL3 REQUIRED opengl)
160+
set(EXAMPLE_MAIN_FILE ./examples/example_emscripten_opengl3/main.cpp)
161+
add_executable(example_emscripten_opengl3 ${EXAMPLE_MAIN_FILE})
162+
target_link_libraries(example_emscripten_opengl3 imgui imgui_backend_opengl3)
163+
endif()
164+
if(${BUILD_EXAMPLE_EMSCRIPTEN_WGPU})
165+
pkg_check_modules(WEBGPU REQUIRED webgpu)
166+
set(EXAMPLE_MAIN_FILE ./examples/example_emscripten_wgpu/main.cpp)
167+
add_executable(example_emscripten_wgpu ${EXAMPLE_MAIN_FILE})
168+
target_link_libraries(example_emscripten_wgpu imgui imgui_backend_wgpu)
169+
endif()
170+
if(${BUILD_EXAMPLE_GLFW_METAL})
171+
pkg_check_modules(GLFW REQUIRED glfw3)
172+
pkg_check_modules(METAL REQUIRED metal)
173+
set(EXAMPLE_MAIN_FILE ./examples/example_glfw_metal/main.mm)
174+
add_executable(example_glfw_metal ${EXAMPLE_MAIN_FILE})
175+
target_link_libraries(example_glfw_metal imgui imgui_backend_glfw imgui_backend_metal glfw)
176+
endif()
177+
if(${BUILD_EXAMPLE_GLFW_OPENGL2})
178+
pkg_check_modules(GLFW REQUIRED glfw3)
179+
pkg_check_modules(OPENGL2 REQUIRED opengl)
180+
set(EXAMPLE_MAIN_FILE ./examples/example_glfw_opengl2/main.cpp)
181+
add_executable(example_glfw_opengl2 ${EXAMPLE_MAIN_FILE})
182+
target_link_libraries(example_glfw_opengl2 imgui imgui_backend_glfw imgui_backend_opengl2 glfw OpenGL)
183+
endif()
184+
if(${BUILD_EXAMPLE_GLFW_OPENGL3})
185+
pkg_check_modules(GLFW REQUIRED glfw3)
186+
pkg_check_modules(OPENGL3 REQUIRED opengl)
187+
set(EXAMPLE_MAIN_FILE ./examples/example_glfw_opengl3/main.cpp)
188+
add_executable(example_glfw_opengl3 ${EXAMPLE_MAIN_FILE})
189+
target_link_libraries(example_glfw_opengl3 imgui imgui_backend_glfw imgui_backend_opengl3 glfw OpenGL)
190+
endif()
191+
if(${BUILD_EXAMPLE_GLFW_VULKAN})
192+
pkg_check_modules(GLFW REQUIRED glfw3)
193+
pkg_check_modules(VULKAN REQUIRED vulkan)
194+
set(EXAMPLE_MAIN_FILE ./examples/example_glfw_vulkan/main.cpp)
195+
add_executable(example_glfw_vulkan ${EXAMPLE_MAIN_FILE})
196+
target_link_libraries(example_glfw_vulkan imgui imgui_backend_glfw imgui_backend_vulkan glfw vulkan)
197+
endif()
198+
if(${BUILD_EXAMPLE_GLUT_OPENGL2})
199+
pkg_check_modules(GLUT REQUIRED glut)
200+
pkg_check_modules(OPENGL2 REQUIRED opengl)
201+
set(EXAMPLE_MAIN_FILE ./examples/example_glut_opengl2/main.cpp)
202+
add_executable(example_glut_opengl2 ${EXAMPLE_MAIN_FILE})
203+
target_link_libraries(example_glut_opengl2 imgui imgui_backend_glut imgui_backend_opengl2 glut OpenGL)
204+
endif()
205+
if(${BUILD_EXAMPLE_NULL})
206+
set(EXAMPLE_MAIN_FILE ./examples/example_null/main.cpp)
207+
add_executable(example_null ${EXAMPLE_MAIN_FILE})
208+
target_link_libraries(example_null imgui)
209+
endif()
210+
if(${BUILD_EXAMPLE_SDL_DIRECTX11})
211+
pkg_check_modules(SDL2 REQUIRED sdl2)
212+
pkg_check_modules(DX11 REQUIRED dx11)
213+
set(EXAMPLE_MAIN_FILE ./examples/example_sdl_directx11/main.cpp)
214+
add_executable(example_sdl_directx11 ${EXAMPLE_MAIN_FILE})
215+
target_link_libraries(example_sdl_directx11 imgui imgui_backend_sdl imgui_backend_dx11 ${SDL2_LIBRARIES} ${DX11_LIBRARIES})
216+
endif()
217+
if(${BUILD_EXAMPLE_SDL_METAL})
218+
pkg_check_modules(SDL2 REQUIRED sdl2)
219+
set(EXAMPLE_MAIN_FILE ./examples/example_sdl_metal/main.cpp)
220+
add_executable(example_sdl_metal ${EXAMPLE_MAIN_FILE})
221+
target_link_libraries(example_sdl_metal imgui imgui_backend_sdl imgui_backend_metal ${SDL2_LIBRARIES} )
222+
endif()
223+
if(${BUILD_EXAMPLE_SDL_OPENGL2})
224+
pkg_check_modules(SDL2 REQUIRED sdl2)
225+
pkg_check_modules(OPENGL2 REQUIRED opengl)
226+
set(EXAMPLE_MAIN_FILE ./examples/example_sdl_opengl2/main.cpp)
227+
add_executable(example_sdl_opengl2 ${EXAMPLE_MAIN_FILE})
228+
target_link_libraries(example_sdl_opengl2 imgui imgui_backend_sdl imgui_backend_opengl2 ${SDL2_LIBRARIES} ${OPENGL2_LIBRARIES})
229+
endif()
230+
if(${BUILD_EXAMPLE_SDL_OPENGL3})
231+
pkg_check_modules(SDL2 REQUIRED sdl2)
232+
pkg_check_modules(OPENGL3 REQUIRED opengl)
233+
set(EXAMPLE_MAIN_FILE ./examples/example_sdl_opengl3/main.cpp)
234+
add_executable(example_sdl_opengl3 ${EXAMPLE_MAIN_FILE})
235+
target_link_libraries(example_sdl_opengl3 imgui imgui_backend_sdl imgui_backend_opengl3 ${SDL2_LIBRARIES} ${OPENGL3_LIBRARIES})
236+
endif()
237+
if(${BUILD_EXAMPLE_SDL_SDLRENDERER})
238+
pkg_check_modules(SDL2 REQUIRED sdl2)
239+
set(EXAMPLE_MAIN_FILE ./examples/example_sdl_sdlrenderer/main.cpp)
240+
add_executable(example_sdl_sdlrenderer ${EXAMPLE_MAIN_FILE})
241+
target_link_libraries(example_sdl_sdlrenderer imgui imgui_backend_sdl ${SDL2_LIBRARIES})
242+
endif()
243+
if(${BUILD_EXAMPLE_SDL_VULKAN})
244+
pkg_check_modules(SDL2 REQUIRED sdl2)
245+
pkg_check_modules(VULKAN REQUIRED vulkan)
246+
set(EXAMPLE_MAIN_FILE ./examples/example_sdl_vulkan/main.cpp)
247+
add_executable(example_sdl_vulkan ${EXAMPLE_MAIN_FILE})
248+
target_link_libraries(example_sdl_vulkan imgui imgui_backend_sdl imgui_backend_vulkan ${SDL2_LIBRARIES} vulkan)
249+
endif()
250+
if(${BUILD_EXAMPLE_WIN32_DIRECTX9})
251+
pkg_check_modules(DX9 REQUIRED dx9)
252+
set(EXAMPLE_MAIN_FILE ./examples/example_win32_directx9/main.cpp)
253+
add_executable(example_win32_directx9 ${EXAMPLE_MAIN_FILE})
254+
target_link_libraries(example_win32_directx9 imgui imgui_backend_dx9)
255+
endif()
256+
if(${BUILD_EXAMPLE_WIN32_DIRECTX10})
257+
pkg_check_modules(DX10 REQUIRED dx10)
258+
set(EXAMPLE_MAIN_FILE ./examples/example_win32_directx10/main.cpp)
259+
add_executable(example_win32_directx10 ${EXAMPLE_MAIN_FILE})
260+
target_link_libraries(example_win32_directx10 imgui imgui_backend_dx10)
261+
endif()
262+
if(${BUILD_EXAMPLE_WIN32_DIRECTX11})
263+
pkg_check_modules(DX11 REQUIRED dx11)
264+
set(EXAMPLE_MAIN_FILE ./examples/example_win32_directx11/main.cpp)
265+
add_executable(example_win32_directx11 ${EXAMPLE_MAIN_FILE})
266+
target_link_libraries(example_win32_directx11 imgui imgui_backend_dx11)
267+
endif()
268+
if(${BUILD_EXAMPLE_WIN32_DIRECTX12})
269+
pkg_check_modules(DX12 REQUIRED dx12)
270+
set(EXAMPLE_MAIN_FILE ./examples/example_win32_directx12/main.cpp)
271+
add_executable(example_win32_directx12 ${EXAMPLE_MAIN_FILE})
272+
target_link_libraries(example_win32_directx12 imgui imgui_backend_dx12)
273+
endif()
274+
275+

backends/imgui_impl_sdl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
#include "imgui_impl_sdl.h"
6565

6666
// SDL
67-
#include <SDL.h>
68-
#include <SDL_syswm.h>
67+
#include <SDL2/SDL.h>
68+
#include <SDL2/SDL_syswm.h>
6969
#if defined(__APPLE__)
7070
#include <TargetConditionals.h>
7171
#endif

backends/imgui_impl_sdlrenderer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
#endif
3333

3434
// SDL
35-
#include <SDL.h>
36-
#if !SDL_VERSION_ATLEAST(2,0,17)
35+
#include <SDL2/SDL.h>
36+
#if !SDL_VERSION_ATLEAST(2,0,20)
3737
#error This backend requires SDL 2.0.17+ because of SDL_RenderGeometry() function
3838
#endif
3939

examples/example_sdl_opengl2/main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include "imgui_impl_sdl.h"
1212
#include "imgui_impl_opengl2.h"
1313
#include <stdio.h>
14-
#include <SDL.h>
15-
#include <SDL_opengl.h>
14+
#include <SDL2/SDL.h>
15+
#include <SDL2/SDL_opengl.h>
1616

1717
// Main code
1818
int main(int, char**)

examples/example_sdl_opengl3/main.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
#include "imgui_impl_sdl.h"
88
#include "imgui_impl_opengl3.h"
99
#include <stdio.h>
10-
#include <SDL.h>
10+
#include <SDL2/SDL.h>
1111
#if defined(IMGUI_IMPL_OPENGL_ES2)
12-
#include <SDL_opengles2.h>
12+
#include <SDL2/SDL_opengles2.h>
1313
#else
14-
#include <SDL_opengl.h>
14+
#include <SDL2/SDL_opengl.h>
1515
#endif
1616

1717
// Main code

examples/example_sdl_sdlrenderer/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "imgui_impl_sdl.h"
1212
#include "imgui_impl_sdlrenderer.h"
1313
#include <stdio.h>
14-
#include <SDL.h>
14+
#include <SDL2/SDL.h>
1515

1616
#if !SDL_VERSION_ATLEAST(2,0,17)
1717
#error This backend requires SDL 2.0.17+ because of SDL_RenderGeometry() function

examples/example_sdl_vulkan/main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#include "imgui_impl_vulkan.h"
1515
#include <stdio.h> // printf, fprintf
1616
#include <stdlib.h> // abort
17-
#include <SDL.h>
18-
#include <SDL_vulkan.h>
17+
#include <SDL2/SDL.h>
18+
#include <SDL2/SDL_vulkan.h>
1919
#include <vulkan/vulkan.h>
2020

2121
//#define IMGUI_UNLIMITED_FRAME_RATE

0 commit comments

Comments
 (0)