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
| | Patch submitted upstream: https://github.com/OpenBoardView/OpenBoardView/pull/233
diff --git a/CMakeModules/FindImGui.cmake b/CMakeModules/FindImGui.cmake
new file mode 100644
index 0000000..4d1fa42
--- /dev/null
+++ b/CMakeModules/FindImGui.cmake
@@ -0,0 +1,36 @@
+# Copyright (C) 2018, 2022 Maxim Cournoyer
+# Redistribution and use of this file is allowed according to the terms of the MIT license.
+# For details see the LICENSE file distributed with OpenBoardView.
+# Note:
+# Searching headers and libraries is very simple and is NOT as powerful as scripts
+# distributed with CMake, because LuaDist defines directories to search for.
+# Everyone is encouraged to contact the author with improvements. Maybe this file
+# becomes part of CMake distribution sometimes.
+
+# - Find ImGui
+# Find the native imgui headers and libraries.
+#
+# IMGUI_INCLUDE_DIRS - where to find imgui/imgui.h, etc.
+# IMGUI_LIBRARIES - List of libraries when using imgui.
+# IMGUI_FOUND - True if imgui is found.
+
+# Look for the header file.
+FIND_PATH(IMGUI_INCLUDE_DIR NAMES imgui.h PATH_SUFFIXES imgui)
+
+# Look for the library.
+FIND_LIBRARY(IMGUI_LIBRARY NAMES ImGui imgui)
+
+# Handle the QUIETLY and REQUIRED arguments and set IMGUI_FOUND to TRUE if all listed variables are TRUE.
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(ImGui DEFAULT_MSG IMGUI_LIBRARY IMGUI_INCLUDE_DIR)
+
+# Copy the results to the output variables.
+IF(IMGUI_FOUND)
+ SET(IMGUI_LIBRARIES ${IMGUI_LIBRARY})
+ SET(IMGUI_INCLUDE_DIRS ${IMGUI_INCLUDE_DIR})
+ELSE()
+ SET(IMGUI_LIBRARIES)
+ SET(IMGUI_INCLUDE_DIRS)
+ENDIF()
+
+MARK_AS_ADVANCED(IMGUI_INCLUDE_DIRS IMGUI_LIBRARIES)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 301f933..24bf263 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -76,28 +76,30 @@ endif()
# note: in the future there may be integrated CMake support into imgui
# see: https://github.com/ocornut/imgui/pull/1713
# for now do it manually, after glad and SDL2 because we use the includes for the sdl_opengl examples
-execute_process(
+find_package(ImGui) # search ImGui from system
+if(NOT IMGUI_FOUND) # else fallback to bundled copy
+ execute_process(
COMMAND git submodule update --init src/imgui
- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
-)
-add_definitions("-DImDrawIdx=unsigned int") # short is not enough for us
-add_definitions("-DIMGUI_IMPL_OPENGL_LOADER_GLAD") # We use glad
-# Configure GL3 renderer to be GLES2 compatible if GLES2 is enabled
-if(ENABLE_GLES2)
- add_definitions("-DIMGUI_IMPL_OPENGL_ES2")
-endif()
-
-# workaround for OpenGL include for OpenGL2, need to be glad rather than gl itself
-file(READ "${CMAKE_CURRENT_SOURCE_DIR}/imgui/backends/imgui_impl_opengl2.cpp" input)
-string(REPLACE "OpenGL/gl.h" "glad/glad.h" input "${input}")
-string(REPLACE "GL/gl.h" "glad/glad.h" input "${input}")
-file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/imgui/backends/imgui_impl_opengl2.cpp" "${input}")
-
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/imgui
- ${GLAD_INCLUDE_DIRS}
-)
-
-set(SOURCES
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
+ add_definitions("-DImDrawIdx=unsigned int") # short is not enough for us
+ add_definitions("-DIMGUI_IMPL_OPENGL_LOADER_GLAD") # We use glad
+ # Configure GL3 renderer to be GLES2 compatible if GLES2 is enabled
+ if(ENABLE_GLES2)
+ add_definitions("-DIMGUI_IMPL_OPENGL_ES2")
+ endif()
+
+ # workaround for OpenGL include for OpenGL2, need to be glad rather than gl itself
+ file(READ "${CMAKE_CURRENT_SOURCE_DIR}/imgui/backends/imgui_impl_opengl2.cpp" input)
+ string(REPLACE "OpenGL/gl.h" "glad/glad.h" input "${input}")
+ string(REPLACE "GL/gl.h" "glad/glad.h" input "${input}")
+ file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/imgui/backends/imgui_impl_opengl2.cpp" "${input}")
+
+ set(IMGUI_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/imgui
+ ${CMAKE_CURRENT_SOURCE_DIR}/imgui/examples)
+
+ set(IMGUI_LIBRARIES imgui)
+
+ set(SOURCES
imgui/imgui.cpp
imgui/imgui_draw.cpp
imgui/imgui_tables.cpp
@@ -106,33 +108,35 @@ set(SOURCES
imgui/backends/imgui_impl_sdl.cpp)
-if(ENABLE_GL1)
+ if(ENABLE_GL1)
LIST(APPEND SOURCES
- imgui/backends/imgui_impl_opengl2.cpp
- )
-endif()
-if(ENABLE_GL3)
+ imgui/backends/imgui_impl_opengl2.cpp
+ )
+ endif()
+ if(ENABLE_GL3)
LIST(APPEND SOURCES
- imgui/backends/imgui_impl_opengl3.cpp
- )
-endif()
+ imgui/backends/imgui_impl_opengl3.cpp
+ )
+ endif()
-add_library(imgui STATIC ${SOURCES})
-target_link_libraries(imgui
+ add_library(imgui STATIC ${SOURCES})
+ target_link_libraries(imgui
${GLAD_LIBRARIES}
-)
-if(MINGW)
-target_link_libraries(imgui
- SDL2::SDL2-static
-)
-else()
-target_link_libraries(imgui
- SDL2::SDL2
-)
+ )
+ if(MINGW)
+ target_link_libraries(imgui
+ SDL2::SDL2-static
+ )
+ else()
+ target_link_libraries(imgui
+ SDL2::SDL2
+ )
+ endif()
endif()
-set(IMGUI_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/imgui ${CMAKE_CURRENT_SOURCE_DIR}/imgui/examples)
-
+include_directories(
+ ${IMGUI_INCLUDE_DIRS}
+ ${GLAD_INCLUDE_DIRS})
#install(TARGETS imgui DESTINATION ${INSTALL_ARCHIVE_DIR}) # No need to install a static lib
diff --git a/src/openboardview/CMakeLists.txt b/src/openboardview/CMakeLists.txt
index d049ef9..bb56f70 100644
--- a/src/openboardview/CMakeLists.txt
+++ b/src/openboardview/CMakeLists.txt
@@ -129,7 +129,7 @@ elseif(APPLE)
endif()
target_link_libraries(${PROJECT_NAME_LOWER}
- imgui
+ ${IMGUI_LIBRARIES}
SQLite::SQLite3
${GLAD_LIBRARIES}
${COCOA_LIBRARY}
|