From 0459fd3ba95819784c2d5954ae39da9188e45775 Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Thu, 25 Feb 2021 16:56:36 +0000 Subject: [PATCH] Make ImGui a module. Signed-off-by: Andrea Odetti --- .gitmodules | 3 ++ source/frontends/sdl/CMakeLists.txt | 76 ++++++++++++----------------- source/frontends/sdl/imgui/imgui | 1 + source/frontends/sdl/main.cpp | 7 --- source/linux/build.sh | 4 +- 5 files changed, 37 insertions(+), 54 deletions(-) create mode 160000 source/frontends/sdl/imgui/imgui diff --git a/.gitmodules b/.gitmodules index 413c77b9..81796f89 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "source/frontends/qt/QHexView"] path = source/frontends/qt/QHexView url = ../../Dax89/QHexView.git +[submodule "source/frontends/sdl/imgui/imgui"] + path = source/frontends/sdl/imgui/imgui + url = ../../ocornut/imgui diff --git a/source/frontends/sdl/CMakeLists.txt b/source/frontends/sdl/CMakeLists.txt index 5345413d..2a30dbaf 100644 --- a/source/frontends/sdl/CMakeLists.txt +++ b/source/frontends/sdl/CMakeLists.txt @@ -1,5 +1,10 @@ include(FindPkgConfig) +find_package(SDL2 REQUIRED) +pkg_search_module(SDL2_IMAGE REQUIRED SDL2_image) +pkg_search_module(GLES2 REQUIRED glesv2) +set(IMGUI_PATH "imgui/imgui") + add_executable(sa2) set(SOURCE_FILES @@ -19,8 +24,6 @@ set(HEADER_FILES renderer/sdlrendererframe.h ) -find_package(SDL2 REQUIRED) -pkg_search_module(SDL2_IMAGE REQUIRED SDL2_image) target_compile_features(sa2 PUBLIC cxx_std_17) @@ -32,6 +35,7 @@ target_include_directories(sa2 PRIVATE target_link_libraries(sa2 PRIVATE ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} + ${GLES2_LIBRARIES} appleii common2 ) @@ -41,52 +45,36 @@ target_sources(sa2 PRIVATE ${HEADER_FILES} ) -set(IMGUI_PATH NONE CACHE PATH "path to imgui") +target_sources(sa2 PRIVATE + imgui/sdlimguiframe.cpp + imgui/image.cpp + imgui/settingshelper.cpp -if (EXISTS ${IMGUI_PATH}/imgui.h) - message("Using IMGUI_PATH=${IMGUI_PATH}") + imgui/sdlimguiframe.h + imgui/image.h + imgui/settingshelper.h + imgui/imconfig.h + imgui/gles.h - pkg_search_module(GLES2 REQUIRED glesv2) + ${IMGUI_PATH}/imgui.h + ${IMGUI_PATH}/imgui.cpp + ${IMGUI_PATH}/imgui_demo.cpp + ${IMGUI_PATH}/imgui_draw.cpp + ${IMGUI_PATH}/imgui_tables.cpp + ${IMGUI_PATH}/imgui_widgets.cpp + ${IMGUI_PATH}/backends/imgui_impl_sdl.cpp + ${IMGUI_PATH}/backends/imgui_impl_opengl3.cpp + ) - target_sources(sa2 PRIVATE - imgui/sdlimguiframe.cpp - imgui/image.cpp - imgui/settingshelper.cpp - - imgui/sdlimguiframe.h - imgui/image.h - imgui/settingshelper.h - imgui/imconfig.h - imgui/gles.h - - ${IMGUI_PATH}/imgui.h - ${IMGUI_PATH}/imgui.cpp - ${IMGUI_PATH}/imgui_demo.cpp - ${IMGUI_PATH}/imgui_draw.cpp - ${IMGUI_PATH}/imgui_tables.cpp - ${IMGUI_PATH}/imgui_widgets.cpp - ${IMGUI_PATH}/backends/imgui_impl_sdl.cpp - ${IMGUI_PATH}/backends/imgui_impl_opengl3.cpp - ) - - target_include_directories(sa2 PRIVATE - ${IMGUI_PATH} - ${IMGUI_PATH}/backends - ) - - target_link_libraries(sa2 PRIVATE - ${GLES2_LIBRARIES} - ) - - target_compile_definitions(sa2 PRIVATE - SA2_IMGUI - IMGUI_IMPL_OPENGL_ES2 - IMGUI_USER_CONFIG="frontends/sdl/imgui/imconfig.h" - ) -else() - message("Bad IMGUI_PATH=${IMGUI_PATH}, skipping imgui code") -endif() +target_include_directories(sa2 PRIVATE + ${IMGUI_PATH} + ${IMGUI_PATH}/backends + ) +target_compile_definitions(sa2 PRIVATE + IMGUI_IMPL_OPENGL_ES2 + IMGUI_USER_CONFIG="frontends/sdl/imgui/imconfig.h" + ) install(TARGETS sa2 DESTINATION bin) diff --git a/source/frontends/sdl/imgui/imgui b/source/frontends/sdl/imgui/imgui new file mode 160000 index 00000000..cdf1926f --- /dev/null +++ b/source/frontends/sdl/imgui/imgui @@ -0,0 +1 @@ +Subproject commit cdf1926f21d17a3d9be7f69434cc18dc65dd6609 diff --git a/source/frontends/sdl/main.cpp b/source/frontends/sdl/main.cpp index 63192b6d..3ee70ce6 100644 --- a/source/frontends/sdl/main.cpp +++ b/source/frontends/sdl/main.cpp @@ -18,10 +18,7 @@ #include "frontends/sdl/utils.h" #include "frontends/sdl/renderer/sdlrendererframe.h" - -#ifdef SA2_IMGUI #include "frontends/sdl/imgui/sdlimguiframe.h" -#endif #include "CardManager.h" #include "Core.h" @@ -115,7 +112,6 @@ void run_sdl(int argc, const char * argv []) std::shared_ptr frame; -#ifdef SA2_IMGUI if (options.imgui) { frame.reset(new sa2::SDLImGuiFrame(options)); @@ -124,9 +120,6 @@ void run_sdl(int argc, const char * argv []) { frame.reset(new sa2::SDLRendererFrame(options)); } -#else - frame.reset(new sa2::SDLRendererFrame(options)); -#endif if (SDL_GL_SetSwapInterval(options.glSwapInterval)) { diff --git a/source/linux/build.sh b/source/linux/build.sh index 9c869bc1..a46e6497 100755 --- a/source/linux/build.sh +++ b/source/linux/build.sh @@ -4,10 +4,8 @@ set -euxo pipefail wget https://raw.githubusercontent.com/libretro/RetroArch/master/libretro-common/include/libretro.h -P libretro-common/include -git clone --depth=1 https://github.com/ocornut/imgui.git - mkdir -p build cd build -cmake -DCMAKE_BUILD_TYPE=RELEASE -DLIBRETRO_COMMON_PATH=../libretro-common -DIMGUI_PATH=../imgui .. +cmake -DCMAKE_BUILD_TYPE=RELEASE -DLIBRETRO_COMMON_PATH=../libretro-common .. make