-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
390 lines (327 loc) · 11.3 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
cmake_minimum_required(VERSION 3.8)
project(cimgui_impl)
set (CMAKE_CXX_STANDARD 11)
#general settings
option(BACKENDS_ANDROID "Enable Android backend" ON)
option(BACKENDS_WIN32 "Enable Win32 backend" ON)
option(BACKENDS_D3D9 "Enable Direct3D 9 backend" ON)
option(BACKENDS_D3D10 "Enable Direct3D 10 backend" ON)
option(BACKENDS_D3D11 "Enable Direct3D 11 backend" ON)
option(BACKENDS_D3D12 "Enable Direct3D 12 backend" ON)
option(BACKENDS_VULKAN "Enable Vulkan backend" ON)
option(BACKENDS_OPENGL3 "Enable OpenGL 3 backend" ON)
option(BACKENDS_OPENGL2 "Enable OpenGL 2 backend" ON)
option(BACKENDS_METAL "Enable Metal backend" ON)
option(BACKENDS_OSX "Enable OSX backend" ON)
option(BACKENDS_BASE_ONLY "Only base backends" OFF)
option(BACKENDS_GLFW "Enable GLFW backend" ON)
option(BACKENDS_GLFW_ONLY "Only GLFW backend" OFF)
option(BACKENDS_SDL2 "Enable SDL2 backend" ON)
option(BACKENDS_SDL2_ONLY "Only SDL2 backend" OFF)
option(BACKENDS_NO_GRAPHICS "Disables all graphics backends" OFF)
option(BACKENDS_NO_BASE "Disables all base backends" OFF)
option(IMGUI_WCHAR32 "Build with ImWChar32" OFF)
if (BACKENDS_GLFW_ONLY AND BACKENDS_SDL2_ONLY)
message(FATAL_ERROR "You cannot set both BACKENDS_GLFW_ONLY and BACKENDS_SDL2_ONLY")
endif()
if (BACKENDS_BASE_ONLY)
set(BACKENDS_GLFW OFF)
set(BACKENDS_SDL2 OFF)
set(lib_name "ImGuiImpl")
endif()
if (BACKENDS_SDL2_ONLY)
set(BACKENDS_GLFW OFF)
set(BACKENDS_SDL2 ON)
set(BACKENDS_NO_BASE ON)
set(lib_name "ImGuiImplSDL2")
endif()
if (BACKENDS_GLFW_ONLY)
set(BACKENDS_GLFW ON)
set(BACKENDS_SDL2 OFF)
set(BACKENDS_NO_BASE ON)
set(lib_name "ImGuiImplGLFW")
endif()
if (BACKENDS_BASE_ONLY AND BACKENDS_NO_BASE)
message(FATAL_ERROR "You cannot set both BACKENDS_BASE_ONLY and BACKENDS_NO_BASE (note this can happen if you set BACKENDS_BASE_ONLY and any other ONLY option)")
endif()
if (BACKENDS_NO_BASE)
set(BACKENDS_WIN32 OFF)
set(BACKENDS_OSX OFF)
set(BACKENDS_NO_GRAPHICS ON)
endif()
if (BACKENDS_NO_GRAPHICS)
set(BACKENDS_D3D9 OFF)
set(BACKENDS_D3D10 OFF)
set(BACKENDS_D3D11 OFF)
set(BACKENDS_D3D12 OFF)
set(BACKENDS_OPENGL3 OFF)
set(BACKENDS_OPENGL2 OFF)
set(BACKENDS_VULKAN OFF)
set(BACKENDS_METAL OFF)
endif()
# Automatically detect platform and set options accordingly
if(WIN32)
message(STATUS "Configuring for Windows...")
set(BACKENDS_METAL OFF)
set(BACKENDS_OSX OFF)
set(BACKENDS_ANDROID OFF)
elseif(APPLE)
message(STATUS "Configuring for macOS...")
set(BACKENDS_WIN32 OFF)
set(BACKENDS_D3D9 OFF)
set(BACKENDS_D3D10 OFF)
set(BACKENDS_D3D11 OFF)
set(BACKENDS_D3D12 OFF)
set(BACKENDS_VULKAN OFF)
set(BACKENDS_ANDROID OFF)
elseif(ANDROID)
message("Configuring for Android...")
set(BACKENDS_D3D9 OFF)
set(BACKENDS_D3D10 OFF)
set(BACKENDS_D3D11 OFF)
set(BACKENDS_D3D12 OFF)
set(BACKENDS_WIN32 OFF)
set(BACKENDS_OPENGL2 OFF)
set(BACKENDS_VULKAN OFF) # Too complicated at the moment maybe adding it later.
set(BACKENDS_GLFW OFF)
set(BACKENDS_SDL2 OFF)
set(BACKENDS_METAL OFF)
set(BACKENDS_OSX OFF)
elseif(UNIX AND NOT APPLE)
message(STATUS "Configuring for Linux...")
set(BACKENDS_WIN32 OFF)
set(BACKENDS_D3D9 OFF)
set(BACKENDS_D3D10 OFF)
set(BACKENDS_D3D11 OFF)
set(BACKENDS_D3D12 OFF)
set(BACKENDS_METAL OFF)
set(BACKENDS_OSX OFF)
set(BACKENDS_ANDROID OFF)
endif()
set(BACKENDS_FOLDER "imgui/backends/")
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/imgui/imgui_tables.cpp)
set(TABLES_SOURCE "imgui/imgui_tables.cpp")
else()
set(TABLES_SOURCE "")
endif()
include_directories(imgui)
add_definitions("-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1")
include_directories()
set(IMGUI_SOURCES
cimgui_impl.cpp
imgui/imgui.cpp
imgui/imgui_draw.cpp
imgui/imgui_demo.cpp
imgui/imgui_widgets.cpp
${TABLES_SOURCE}
)
if (APPLE)
list(APPEND IMGUI_SOURCES cimgui_impl.mm)
endif()
set(IMGUI_LIBRARIES )
add_compile_definitions("IMGUI_IMPL_OPENGL_LOADER_GL3W")
#optional adding freetype
option(IMGUI_FREETYPE "add Freetype2" OFF)
if(IMGUI_FREETYPE)
FIND_PACKAGE(freetype REQUIRED PATHS ${FREETYPE_PATH})
list(APPEND IMGUI_LIBRARIES freetype)
list(APPEND IMGUI_SOURCES imgui/misc/freetype/imgui_freetype.cpp)
add_definitions("-DCIMGUI_FREETYPE=1")
endif()
message("Building with:")
if (BACKENDS_ANDROID AND ANDROID)
message("Backends Android: ON")
# android
list(APPEND IMGUI_LIBRARIES android)
list(APPEND IMGUI_SOURCES ${BACKENDS_FOLDER}imgui_impl_android.cpp)
endif()
if (BACKENDS_WIN32 AND WIN32)
message("Backends Win32: ON")
# win32
list(APPEND IMGUI_SOURCES ${BACKENDS_FOLDER}imgui_impl_win32.cpp)
if (BACKENDS_D3D9)
message("Backends D3D9: ON")
# dx9
list(APPEND IMGUI_SOURCES ${BACKENDS_FOLDER}imgui_impl_dx9.cpp)
endif()
if (BACKENDS_D3D10)
message("Backends D3D10: ON")
# dx10
list(APPEND IMGUI_SOURCES ${BACKENDS_FOLDER}imgui_impl_dx10.cpp)
endif()
if (BACKENDS_D3D11)
message("Backends D3D11: ON")
# dx11
list(APPEND IMGUI_SOURCES ${BACKENDS_FOLDER}imgui_impl_dx11.cpp)
endif()
if (BACKENDS_D3D12)
message("Backends D3D12: ON")
# dx12
list(APPEND IMGUI_LIBRARIES dxgi.lib)
list(APPEND IMGUI_SOURCES ${BACKENDS_FOLDER}imgui_impl_dx12.cpp)
endif()
endif()
if (BACKENDS_VULKAN)
message("Backends Vulkan: ON")
# vulkan
find_package(Vulkan REQUIRED)
list(APPEND IMGUI_LIBRARIES Vulkan::Vulkan)
list(APPEND IMGUI_SOURCES ${BACKENDS_FOLDER}imgui_impl_vulkan.cpp)
endif()
# OSX
if (BACKENDS_OSX AND APPLE)
message("Backends OSX: ON")
find_library(COCOA_FRAMEWORK Cocoa REQUIRED)
find_library(GAMECONTROLLER_FRAMEWORK GameController REQUIRED)
list(APPEND IMGUI_LIBRARIES ${COCOA_FRAMEWORK} ${GAMECONTROLLER_FRAMEWORK})
list(APPEND IMGUI_SOURCES ${BACKENDS_FOLDER}imgui_impl_osx.mm)
endif()
# Metal
if (BACKENDS_METAL AND APPLE)
message("Backends Metal: ON")
find_library(METAL_FRAMEWORK Metal REQUIRED)
find_library(QUARTZCORE_FRAMEWORK QuartzCore REQUIRED)
list(APPEND IMGUI_LIBRARIES ${METAL_FRAMEWORK} ${QUARTZCORE_FRAMEWORK})
list(APPEND IMGUI_SOURCES ${BACKENDS_FOLDER}imgui_impl_metal.mm)
endif()
# GLFW
if (BACKENDS_GLFW)
message("Backends GLFW: ON")
find_package(glfw3 REQUIRED)
list(APPEND IMGUI_LIBRARIES glfw)
list(APPEND IMGUI_SOURCES ${BACKENDS_FOLDER}imgui_impl_glfw.cpp)
endif()
#opengl3
if (BACKENDS_OPENGL3)
message("Backends OPENGL3: ON")
if (ANDROID)
find_library(GLES_LIB GLESv3)
list(APPEND IMGUI_LIBRARIES EGL GLESv3)
else()
find_package(OpenGL REQUIRED)
list(APPEND IMGUI_LIBRARIES OpenGL::GL OpenGL::GLU)
endif()
list(APPEND IMGUI_SOURCES ${BACKENDS_FOLDER}imgui_impl_opengl3.cpp)
include_directories(imgui/examples/libs/gl3w)
message(STATUS "OpenGL_LIBRARIES: ${OPENGL_LIBRARIES}")
endif()
#opengl2
if (BACKENDS_OPENGL2)
message("Backends OPENGL2: ON")
list(APPEND IMGUI_SOURCES ${BACKENDS_FOLDER}imgui_impl_opengl2.cpp)
include_directories(imgui/examples/libs/gl3w)
if (!BACKENDS_OPENGL3)
find_package(OpenGL REQUIRED)
list(APPEND IMGUI_LIBRARIES OpenGL::GL OpenGL::GLU)
endif(!BACKENDS_OPENGL3)
endif()
#sdl2
if (BACKENDS_SDL2)
message("Backends SDL2: ON")
list(APPEND IMGUI_SOURCES ${BACKENDS_FOLDER}imgui_impl_sdl2.cpp)
list(APPEND IMGUI_SOURCES ${BACKENDS_FOLDER}imgui_impl_sdlrenderer2.cpp)
find_package(SDL2 CONFIG REQUIRED)
if(SDL2_FOUND)
get_target_property(SDL_INCLUDE SDL2::SDL2 INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "sdlinclude is " ${SDL_INCLUDE})
if ("${SDL_INCLUDE}" STREQUAL "" OR "${SDL_INCLUDE}" STREQUAL "SDL_INCLUDE-NOTFOUND") #if not found latest SDL2 cmake config use older
message(STATUS "sdlinclude2 is " ${SDL2_INCLUDE_DIRS})
include_directories(${SDL2_INCLUDE_DIRS})
set(IMGUI_SDL_LIBRARY ${SDL2_LIBRARIES})
message(STATUS IMGUI_SDL_LIBRARY ${SDL2_LIBRARIES})
else()#use new one SDL2 config
include_directories(${SDL_INCLUDE})
set(IMGUI_SDL_LIBRARY SDL2::SDL2)
set(SDL_MAIN SDL2::SDL2main)
message(STATUS ${SDL_MAIN} ${IMGUI_SDL_LIBRARY})
endif()
else(SDL2_FOUND)
if(DEFINED SDL_PATH)
message(FATAL_ERROR "Cannot find SDL at SDL_PATH")
else(DEFINED SDL_PATH)
message(FATAL_ERROR "Cannot find SDL. Maybe try specifying SDL_PATH?")
endif(DEFINED SDL_PATH)
endif(SDL2_FOUND)
endif(BACKENDS_SDL2)
add_library(cimgui_impl SHARED ${IMGUI_SOURCES})
if(DEFINED lib_name)
set_target_properties(cimgui_impl PROPERTIES OUTPUT_NAME ${lib_name})
endif()
if(APPLE)
if(BACKENDS_SDL2)
add_custom_command(TARGET cimgui_impl POST_BUILD COMMAND install_name_tool -change /opt/homebrew/opt/sdl2/lib/libSDL2-2.0.0.dylib @loader_path/libSDL2.dylib $<TARGET_FILE:cimgui_impl>)
add_custom_command(TARGET cimgui_impl POST_BUILD COMMAND install_name_tool -change /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib @loader_path/libSDL2.dylib $<TARGET_FILE:cimgui_impl>)
endif(BACKENDS_SDL2)
if(BACKENDS_GLFW)
add_custom_command(TARGET cimgui_impl POST_BUILD COMMAND install_name_tool -change /opt/homebrew/opt/glfw/lib/libglfw.3.dylib @loader_path/libglfw.dylib $<TARGET_FILE:cimgui_impl>)
add_custom_command(TARGET cimgui_impl POST_BUILD COMMAND install_name_tool -change /usr/local/opt/glfw/lib/libglfw.3.dylib @loader_path/libglfw.dylib $<TARGET_FILE:cimgui_impl>)
endif(BACKENDS_GLFW)
elseif(UNIX AND NOT APPLE)
set_target_properties(cimgui_impl PROPERTIES INSTALL_RPATH "\$ORIGIN" BUILD_WITH_INSTALL_RPATH TRUE)
if(BACKENDS_SDL2)
add_custom_command(TARGET cimgui_impl POST_BUILD COMMAND patchelf --replace-needed libSDL2-2.0.so.0 libSDL2.so $<TARGET_FILE:cimgui_impl>)
endif(BACKENDS_SDL2)
if(BACKENDS_GLFW)
add_custom_command(TARGET cimgui_impl POST_BUILD COMMAND patchelf --replace-needed libglfw.so.3 libglfw.so $<TARGET_FILE:cimgui_impl>)
endif(BACKENDS_GLFW)
endif()
if (IMGUI_WCHAR32)
target_compile_definitions(cimgui_impl PRIVATE IMGUI_USE_WCHAR32)
endif()
if(BACKENDS_ANDROID)
target_compile_definitions(cimgui_impl PRIVATE CIMGUI_USE_ANDROID)
endif()
if(BACKENDS_WIN32)
target_compile_definitions(cimgui_impl PRIVATE CIMGUI_USE_WIN32)
endif()
if(BACKENDS_OSX)
target_compile_definitions(cimgui_impl PRIVATE CIMGUI_USE_OSX)
endif()
if(BACKENDS_D3D9)
target_compile_definitions(cimgui_impl PRIVATE CIMGUI_USE_D3D9)
endif()
if(BACKENDS_D3D10)
target_compile_definitions(cimgui_impl PRIVATE CIMGUI_USE_D3D10)
endif()
if(BACKENDS_D3D11)
target_compile_definitions(cimgui_impl PRIVATE CIMGUI_USE_D3D11)
endif()
if(BACKENDS_D3D12)
target_compile_definitions(cimgui_impl PRIVATE CIMGUI_USE_D3D12)
endif()
if(BACKENDS_METAL)
target_compile_definitions(cimgui_impl PRIVATE CIMGUI_USE_METAL)
endif()
if(BACKENDS_VULKAN)
target_compile_definitions(cimgui_impl PRIVATE CIMGUI_USE_VULKAN)
endif()
if(BACKENDS_GLFW)
target_compile_definitions(cimgui_impl PRIVATE CIMGUI_USE_GLFW)
endif()
if(BACKENDS_OPENGL2)
target_compile_definitions(cimgui_impl PRIVATE CIMGUI_USE_OPENGL2)
endif()
if(BACKENDS_OPENGL3)
target_compile_definitions(cimgui_impl PRIVATE CIMGUI_USE_OPENGL3)
endif()
if(BACKENDS_SDL2)
target_compile_definitions(cimgui_impl PRIVATE CIMGUI_USE_SDL2)
target_compile_definitions(cimgui_impl PRIVATE CIMGUI_USE_SDL2Renderer)
endif()
if (MSVC)
target_link_libraries(cimgui_impl PRIVATE ${IMGUI_LIBRARIES} ${IMGUI_SDL_LIBRARY} delayimp)
else(MSVC)
target_link_libraries(cimgui_impl PRIVATE ${IMGUI_LIBRARIES} ${IMGUI_SDL_LIBRARY})
endif()
if (MSVC)
if(BACKENDS_GLFW)
target_link_options(cimgui_impl PRIVATE "/DELAYLOAD:glfw3.dll")
endif()
if(BACKENDS_SDL2)
target_link_options(cimgui_impl PRIVATE "/DELAYLOAD:SDL2.dll")
endif()
endif()
install(TARGETS cimgui_impl
LIBRARY DESTINATION .
ARCHIVE DESTINATION .
)