|
| 1 | +From 13d974246cea7cb24b985008516a947bf393f53c Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jeongseok Lee <jeongseok@meta.com> |
| 3 | +Date: Thu, 23 Jan 2025 15:36:00 -0800 |
| 4 | +Subject: [PATCH 1/2] Add options to use system dependencies |
| 5 | + |
| 6 | +--- |
| 7 | + CMakeLists.txt | 54 ++++++++++++++-------- |
| 8 | + include/vsgImGui/RenderImGui.h | 2 +- |
| 9 | + src/CMakeLists.txt | 74 +++++++++++++++++++++--------- |
| 10 | + src/vsgImGui/RenderImGui.cpp | 4 +- |
| 11 | + src/vsgImGui/SendEventsToImGui.cpp | 2 +- |
| 12 | + 5 files changed, 93 insertions(+), 43 deletions(-) |
| 13 | + |
| 14 | +diff --git a/CMakeLists.txt b/CMakeLists.txt |
| 15 | +index e1679d2..464b8ee 100644 |
| 16 | +--- a/CMakeLists.txt |
| 17 | ++++ b/CMakeLists.txt |
| 18 | +@@ -5,6 +5,10 @@ project(vsgImGui |
| 19 | + DESCRIPTION "VulkanSceneGraph, ImGui and ImPlot integration library" |
| 20 | + LANGUAGES CXX |
| 21 | + ) |
| 22 | ++ |
| 23 | ++option(VSG_IMGUI_USE_SYSTEM_IMGUI "Use system installed ImGui" OFF) |
| 24 | ++option(VSG_IMGUI_USE_SYSTEM_IMPLOT "Use system installed ImPlot" OFF) |
| 25 | ++ |
| 26 | + set(VSGIMGUI_SOVERSION 0) |
| 27 | + SET(VSGIMGUI_RELEASE_CANDIDATE 0) |
| 28 | + |
| 29 | +@@ -27,29 +31,43 @@ find_package(vsg 1.0.5) |
| 30 | + vsg_setup_dir_vars() |
| 31 | + vsg_setup_build_vars() |
| 32 | + |
| 33 | +-if ( (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/imgui/imgui.h) OR |
| 34 | +- (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/implot/implot.h) ) |
| 35 | +- find_package(Git QUIET) |
| 36 | ++if(NOT VSG_IMGUI_USE_SYSTEM_IMGUI OR NOT VSG_IMGUI_USE_SYSTEM_IMPLOT) |
| 37 | ++ if ( (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/imgui/imgui.h) OR |
| 38 | ++ (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/implot/implot.h) ) |
| 39 | ++ find_package(Git QUIET) |
| 40 | + |
| 41 | +- execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive |
| 42 | +- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 43 | +- RESULT_VARIABLE GIT_SUBMOD_RESULT) |
| 44 | ++ execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive |
| 45 | ++ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 46 | ++ RESULT_VARIABLE GIT_SUBMOD_RESULT) |
| 47 | + |
| 48 | +- if(NOT GIT_SUBMOD_RESULT EQUAL "0") |
| 49 | +- message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") |
| 50 | ++ if(NOT GIT_SUBMOD_RESULT EQUAL "0") |
| 51 | ++ message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") |
| 52 | ++ endif() |
| 53 | + endif() |
| 54 | + endif() |
| 55 | + |
| 56 | +-vsg_copy_imgui_headers( |
| 57 | +- FILES |
| 58 | +- ${VSGIMGUI_SOURCE_DIR}/src/imgui/imgui.h |
| 59 | +- ${VSGIMGUI_SOURCE_DIR}/src/imgui/imconfig.h |
| 60 | +- ${VSGIMGUI_SOURCE_DIR}/src/imgui/imgui_internal.h |
| 61 | +- ${VSGIMGUI_SOURCE_DIR}/src/imgui/imstb_textedit.h |
| 62 | +- ${VSGIMGUI_SOURCE_DIR}/src/imgui//misc/cpp/imgui_stdlib.h |
| 63 | +- ${VSGIMGUI_SOURCE_DIR}/src/implot/implot.h |
| 64 | +- ${VSGIMGUI_SOURCE_DIR}/src/implot/implot_internal.h |
| 65 | +-) |
| 66 | ++if(VSG_IMGUI_USE_SYSTEM_IMGUI) |
| 67 | ++ find_package(imgui CONFIG REQUIRED) |
| 68 | ++else() |
| 69 | ++ vsg_copy_imgui_headers( |
| 70 | ++ FILES |
| 71 | ++ ${VSGIMGUI_SOURCE_DIR}/src/imgui/imgui.h |
| 72 | ++ ${VSGIMGUI_SOURCE_DIR}/src/imgui/imconfig.h |
| 73 | ++ ${VSGIMGUI_SOURCE_DIR}/src/imgui/imgui_internal.h |
| 74 | ++ ${VSGIMGUI_SOURCE_DIR}/src/imgui/imstb_textedit.h |
| 75 | ++ ${VSGIMGUI_SOURCE_DIR}/src/imgui//misc/cpp/imgui_stdlib.h |
| 76 | ++ ) |
| 77 | ++endif() |
| 78 | ++ |
| 79 | ++if(VSG_IMGUI_USE_SYSTEM_IMPLOT) |
| 80 | ++ find_package(implot CONFIG REQUIRED) |
| 81 | ++else() |
| 82 | ++ vsg_copy_imgui_headers( |
| 83 | ++ FILES |
| 84 | ++ ${VSGIMGUI_SOURCE_DIR}/src/implot/implot.h |
| 85 | ++ ${VSGIMGUI_SOURCE_DIR}/src/implot/implot_internal.h |
| 86 | ++ ) |
| 87 | ++endif() |
| 88 | + |
| 89 | + vsg_add_target_clang_format( |
| 90 | + FILES |
| 91 | +diff --git a/include/vsgImGui/RenderImGui.h b/include/vsgImGui/RenderImGui.h |
| 92 | +index 26a644d..3e427cd 100644 |
| 93 | +--- a/include/vsgImGui/RenderImGui.h |
| 94 | ++++ b/include/vsgImGui/RenderImGui.h |
| 95 | +@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 96 | + #include <vsg/vk/DescriptorPool.h> |
| 97 | + |
| 98 | + #include <vsgImGui/Export.h> |
| 99 | +-#include <vsgImGui/imgui.h> |
| 100 | ++#include <imgui.h> |
| 101 | + |
| 102 | + namespace vsgImGui |
| 103 | + { |
| 104 | +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt |
| 105 | +index 41d749d..97720b2 100644 |
| 106 | +--- a/src/CMakeLists.txt |
| 107 | ++++ b/src/CMakeLists.txt |
| 108 | +@@ -6,41 +6,60 @@ set(EXTRA_INCLUDES) |
| 109 | + SET(HEADER_PATH ${VSGIMGUI_SOURCE_DIR}/include/vsgImGui) |
| 110 | + |
| 111 | + set(HEADERS |
| 112 | +- ${HEADER_PATH}/imgui.h |
| 113 | + ${HEADER_PATH}/SendEventsToImGui.h |
| 114 | + ${HEADER_PATH}/RenderImGui.h |
| 115 | + ${HEADER_PATH}/Texture.h |
| 116 | +- imgui/imconfig.h |
| 117 | +- imgui/imgui_internal.h |
| 118 | +- imgui/imstb_rectpack.h |
| 119 | +- imgui/imstb_textedit.h |
| 120 | +- imgui/imstb_truetype.h |
| 121 | +- imgui/misc/cpp/imgui_stdlib.h |
| 122 | +- implot/implot.h |
| 123 | +- implot/implot_internal.h |
| 124 | + ) |
| 125 | + |
| 126 | + set(SOURCES |
| 127 | + vsgImGui/RenderImGui.cpp |
| 128 | + vsgImGui/SendEventsToImGui.cpp |
| 129 | + vsgImGui/Texture.cpp |
| 130 | +- imgui/imgui.cpp |
| 131 | +- imgui/imgui_draw.cpp |
| 132 | +- imgui/imgui_tables.cpp |
| 133 | +- imgui/imgui_widgets.cpp |
| 134 | +- imgui/backends/imgui_impl_vulkan.cpp |
| 135 | +- imgui/misc/cpp/imgui_stdlib.cpp |
| 136 | +- implot/implot.cpp |
| 137 | +- implot/implot_items.cpp |
| 138 | + ) |
| 139 | + |
| 140 | +-OPTION(SHOW_DEMO_WINDOW "Toggle the build of the ImGui::ShowDemoWindow(bool*) and ImPlot::ShadowDemoWindow(bool*)" ON) |
| 141 | ++if(NOT VSG_IMGUI_USE_SYSTEM_IMGUI) |
| 142 | ++ set(HEADERS ${HEADERS} |
| 143 | ++ imgui/imgui.h |
| 144 | ++ imgui/imconfig.h |
| 145 | ++ imgui/imgui_internal.h |
| 146 | ++ imgui/imstb_rectpack.h |
| 147 | ++ imgui/imstb_textedit.h |
| 148 | ++ imgui/imstb_truetype.h |
| 149 | ++ imgui/misc/cpp/imgui_stdlib.h |
| 150 | ++ ) |
| 151 | + |
| 152 | +-if (SHOW_DEMO_WINDOW) |
| 153 | + set(SOURCES ${SOURCES} |
| 154 | +- imgui/imgui_demo.cpp |
| 155 | +- implot/implot_demo.cpp |
| 156 | ++ imgui/imgui.cpp |
| 157 | ++ imgui/imgui_draw.cpp |
| 158 | ++ imgui/imgui_tables.cpp |
| 159 | ++ imgui/imgui_widgets.cpp |
| 160 | ++ imgui/backends/imgui_impl_vulkan.cpp |
| 161 | ++ imgui/misc/cpp/imgui_stdlib.cpp |
| 162 | ++ ) |
| 163 | ++endif() |
| 164 | ++ |
| 165 | ++if(NOT VSG_IMGUI_USE_SYSTEM_IMPLOT) |
| 166 | ++ set(HEADERS ${HEADERS} |
| 167 | ++ implot/implot.h |
| 168 | ++ implot/implot_internal.h |
| 169 | + ) |
| 170 | ++ |
| 171 | ++ set(SOURCES ${SOURCES} |
| 172 | ++ implot/implot.cpp |
| 173 | ++ implot/implot_items.cpp |
| 174 | ++ ) |
| 175 | ++endif() |
| 176 | ++ |
| 177 | ++OPTION(SHOW_DEMO_WINDOW "Toggle the build of the ImGui::ShowDemoWindow(bool*) and ImPlot::ShadowDemoWindow(bool*)" ON) |
| 178 | ++ |
| 179 | ++if (SHOW_DEMO_WINDOW) |
| 180 | ++ if(NOT VSG_IMGUI_USE_SYSTEM_IMGUI) |
| 181 | ++ set(HEADERS ${HEADERS} imgui/imgui_demo.cpp) |
| 182 | ++ endif() |
| 183 | ++ |
| 184 | ++ if(NOT VSG_IMGUI_USE_SYSTEM_IMPLOT) |
| 185 | ++ set(SOURCES ${SOURCES} implot/implot_demo.cpp) |
| 186 | ++ endif() |
| 187 | + else() |
| 188 | + set(SOURCES ${SOURCES} |
| 189 | + vsgImGui/fallback_demo.cpp |
| 190 | +@@ -69,6 +88,11 @@ target_include_directories(vsgImGui PUBLIC |
| 191 | + $<INSTALL_INTERFACE:include> |
| 192 | + ${EXTRA_INCLUDES} |
| 193 | + ) |
| 194 | ++if(NOT VSG_IMGUI_USE_SYSTEM_IMGUI) |
| 195 | ++ target_include_directories(vsgImGui PRIVATE |
| 196 | ++ $<BUILD_INTERFACE:${VSGIMGUI_SOURCE_DIR}/src/imgui/backends> |
| 197 | ++ ) |
| 198 | ++endif() |
| 199 | + |
| 200 | + target_link_libraries(vsgImGui |
| 201 | + PUBLIC |
| 202 | +@@ -77,6 +101,14 @@ target_link_libraries(vsgImGui |
| 203 | + ${EXTRA_LIBRARIES} |
| 204 | + ) |
| 205 | + |
| 206 | ++if(VSG_IMGUI_USE_SYSTEM_IMGUI) |
| 207 | ++ target_link_libraries(vsgImGui PUBLIC imgui::imgui) |
| 208 | ++endif() |
| 209 | ++ |
| 210 | ++if(VSG_IMGUI_USE_SYSTEM_IMPLOT) |
| 211 | ++ target_link_libraries(vsgImGui PUBLIC implot::implot) |
| 212 | ++endif() |
| 213 | ++ |
| 214 | + install(TARGETS vsgImGui ${INSTALL_TARGETS_DEFAULT_FLAGS}) |
| 215 | + |
| 216 | + if (BUILD_SHARED_LIBS) |
| 217 | +diff --git a/src/vsgImGui/RenderImGui.cpp b/src/vsgImGui/RenderImGui.cpp |
| 218 | +index 306030b..f0af046 100644 |
| 219 | +--- a/src/vsgImGui/RenderImGui.cpp |
| 220 | ++++ b/src/vsgImGui/RenderImGui.cpp |
| 221 | +@@ -22,9 +22,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 222 | + </editor-fold> */ |
| 223 | + |
| 224 | + #include <vsgImGui/RenderImGui.h> |
| 225 | +-#include <vsgImGui/implot.h> |
| 226 | ++#include <implot.h> |
| 227 | + |
| 228 | +-#include "../imgui/backends/imgui_impl_vulkan.h" |
| 229 | ++#include <imgui_impl_vulkan.h> |
| 230 | + |
| 231 | + #include <vsg/io/Logger.h> |
| 232 | + #include <vsg/vk/State.h> |
| 233 | +diff --git a/src/vsgImGui/SendEventsToImGui.cpp b/src/vsgImGui/SendEventsToImGui.cpp |
| 234 | +index 11de226..ef784fc 100644 |
| 235 | +--- a/src/vsgImGui/SendEventsToImGui.cpp |
| 236 | ++++ b/src/vsgImGui/SendEventsToImGui.cpp |
| 237 | +@@ -22,7 +22,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 238 | + </editor-fold> */ |
| 239 | + |
| 240 | + #include <vsgImGui/SendEventsToImGui.h> |
| 241 | +-#include <vsgImGui/imgui.h> |
| 242 | ++#include <imgui.h> |
| 243 | + |
| 244 | + #include <vsg/ui/KeyEvent.h> |
| 245 | + #include <vsg/ui/PointerEvent.h> |
| 246 | +-- |
| 247 | +2.20.1.windows.1 |
| 248 | + |
0 commit comments