From 3fd23b56ebc24815a5d7c1b80a4912c4288ee823 Mon Sep 17 00:00:00 2001 From: Pascal Thomet Date: Tue, 6 Feb 2024 09:57:06 +0100 Subject: [PATCH] Review CMake / backend selection --- .github/workflows/cpp_lib.yml | 2 +- .github/workflows/ios.yml | 1 - CMakeLists.txt | 88 +++++++++++-------- _example_integration | 2 +- .../imgui_example_glfw_opengl3.cpp | 4 +- .../imgui_bundle_build_lib.cmake | 4 +- 6 files changed, 55 insertions(+), 46 deletions(-) diff --git a/.github/workflows/cpp_lib.yml b/.github/workflows/cpp_lib.yml index e73c097e..e820cd79 100644 --- a/.github/workflows/cpp_lib.yml +++ b/.github/workflows/cpp_lib.yml @@ -36,5 +36,5 @@ jobs: run: | mkdir build cd build - cmake .. -DHELLOIMGUI_USE_GLFW_OPENGL3=ON -DHELLOIMGUI_USE_SDL_OPENGL3=ON -DCMAKE_BUILD_TYPE=Release -DHELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED=ON + cmake .. -DHELLOIMGUI_USE_GLFW3=ON -DHELLOIMGUI_USE_SDL2=ON -DHELLOIMGUI_HAS_OPENGL3=ON -DCMAKE_BUILD_TYPE=Release -DHELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED=ON cmake --build . --config Release -j 3 diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 82fb0cf3..7659908c 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -35,7 +35,6 @@ jobs: cmake .. \ -GXcode \ -DCMAKE_TOOLCHAIN_FILE=../external/imgui_bundle/external/hello_imgui/hello_imgui/hello_imgui_cmake/ios-cmake/ios.toolchain.cmake \ - -DHELLOIMGUI_USE_SDL_OPENGL3=ON \ -DPLATFORM=SIMULATOR64 - name: Build for simulator diff --git a/CMakeLists.txt b/CMakeLists.txt index 42eb5109..3b2ef8e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,47 @@ include(${CMAKE_CURRENT_LIST_DIR}/external/hello_imgui/hello_imgui/hello_imgui_c include(${HELLOIMGUI_CMAKE_PATH}/hello_imgui_build_lib.cmake) +# Backends +# ----------------------------------------------------------------------------- +# # do not remove this line (used by the script that generates the documentation) +# (this part is a direct copy from HelloImGui CmakeList, reproduced here for convenience) +# You need to select at least two backends: +# +# - At least one (or more) rendering backend (OpenGL3, Metal, Vulkan, DirectX11, DirectX12) +# Make your choice according to your needs and your target platforms, between: +# -DHELLOIMGUI_HAS_OPENGL3=ON # This is the recommended choice, especially for beginners +# -DHELLOIMGUI_HAS_METAL=ON # Apple only, advanced users only +# -DHELLOIMGUI_HAS_VULKAN=ON # Advanced users only +# -DHELLOIMGUI_HAS_DIRECTX11=ON # Windows only, still experimental +# -DHELLOIMGUI_HAS_DIRECTX12=ON # Windows only, advanced users only, still experimental +# +# - At least one (or more) platform backend (SDL2, Glfw3): +# Make your choice according to your needs and your target platforms, between: +# -DHELLOIMGUI_USE_SDL2=ON +# -DHELLOIMGUI_USE_GLFW3=ON +# +# If you make no choice, the default will be selected: +# HELLOIMGUI_USE_GLFW3 + HELLOIMGUI_HAS_OPENGL3 +# +# Note about rendering backends: +# OpenGL3 is the recommended choice as a starting point, especially for beginners. +# Vulkan, Metal, and DirectX11, DirectX12 do work, but you may need to customize the rendering code inside HelloImGui: +# see src/hello_imgui/internal/backend_impls/rendering_xxxx.[h,cpp] +# (using those backends probably implies that you want to heavily customize the rendering code) +# +################################################################################ +# Platform backends: +option(HELLOIMGUI_USE_GLFW3 "Use Glfw3 as a platform backend" OFF) +option(HELLOIMGUI_USE_SDL2 "Use Sdl2 as a platform backend" OFF) +# Rendering backends +option(HELLOIMGUI_HAS_OPENGL3 "Use OpenGL3 as a rendering backend" OFF) +option(HELLOIMGUI_HAS_METAL "Use Metal as a rendering backend" OFF) +option(HELLOIMGUI_HAS_VULKAN "Use Vulkan as a rendering backend" OFF) +option(HELLOIMGUI_HAS_DIRECTX11 "Use DirectX11 as a rendering backend" OFF) +option(HELLOIMGUI_HAS_DIRECTX12 "Use DirectX12 as a rendering backend" OFF) +# # do not remove this line (used by the script that generates the documentation) + + # IMGUI_BUNDLE_BUILD_PYTHON: include python support # ----------------------------------------------------------------------------- # (OFF when building the cpp library; ON by default when using pip install. @@ -51,47 +92,16 @@ else() set(IMGUI_BUNDLE_BUILD_CPP ON) endif() - -# ----------------------------------------------------------------------------- -# BACKENDS -# Backends are defined by a combination of a platform backend (Sdl2, Glfw3), -# and a renderer backend (OpenGL3, Vulkan, Metal, etc) -# -# By default, imgui_bundle will use -# - Glfw+OpenGL3 on desktop platforms (Windows, Linux, macOS): -# -DHELLOIMGUI_USE_GLFW_OPENGL3=ON -# - SDL+OpenGl3 on emscripten, iOS and Android: -# -DHELLOIMGUI_USE_SDL_OPENGL3=ON -# -# Notes: -# - For python bindings: -# we force the usage of Glfw+OpenGL3 (HELLOIMGUI_USE_GLFW_OPENGL3), but you can use SDL via a pure python backend. -# glfw will be built from the submodule external/glfw/glfw -# - Glfw3 may be downloaded automatically if not found as a system library: -# set HELLOIMGUI_DOWNLOAD_GLFW_IF_NEEDED to OFF to disable this behavior -# (HELLOIMGUI_DOWNLOAD_GLFW_IF_NEEDED is OFF by default under Linux) -# - SDL2 may be downloaded automatically if not found as a system library: -# set HELLOIMGUI_DOWNLOAD_SDL_IF_NEEDED to OFF to disable this behavior. -# (HELLOIMGUI_DOWNLOAD_SDL_IF_NEEDED is OFF by default under Linux) -# ----------------------------------------------------------------------------- -_him_check_if_no_backend_selected(no_backend_selected) -# Select default backend if none selected -if (no_backend_selected) - if (EMSCRIPTEN OR ANDROID OR IOS) - set(default_use_glfw_opengl3 OFF) - set(default_use_sdl_opengl3 ON) - else() - set(default_use_glfw_opengl3 ON) - set(default_use_sdl_opengl3 OFF) - endif() - option(HELLOIMGUI_USE_GLFW_OPENGL3 "Use GLFW+OpenGL3 backend" ${default_use_glfw_opengl3}) - option(HELLOIMGUI_USE_SDL_OPENGL3 "Use SDL+OpenGL3 backend" ${default_use_sdl_opengl3}) -endif() - # For python bindings, we force the usage of Glfw+OpenGL3 if(IMGUI_BUNDLE_BUILD_PYTHON) - set(HELLOIMGUI_USE_GLFW_OPENGL3 ON CACHE BOOL "" FORCE) - set(HELLOIMGUI_USE_SDL_OPENGL3 OFF CACHE BOOL "" FORCE) + set(HELLOIMGUI_USE_GLFW3 ON CACHE BOOL "" FORCE) + set(HELLOIMGUI_HAS_OPENGL3 ON CACHE BOOL "" FORCE) + + set(HELLOIMGUI_USE_SDL2 OFF CACHE BOOL "" FORCE) + set(HELLOIMGUI_HAS_METAL OFF CACHE BOOL "" FORCE) + set(HELLOIMGUI_HAS_VULKAN OFF CACHE BOOL "" FORCE) + set(HELLOIMGUI_HAS_DIRECTX11 OFF CACHE BOOL "" FORCE) + set(HELLOIMGUI_HAS_DIRECTX12 OFF CACHE BOOL "" FORCE) endif() # ----------------------------------------------------------------------------- diff --git a/_example_integration b/_example_integration index 350577ab..91532912 160000 --- a/_example_integration +++ b/_example_integration @@ -1 +1 @@ -Subproject commit 350577ab438f613b5e6272fe10e47008cbd842ac +Subproject commit 91532912c16833d9a14ed37badefd30c7a859bd3 diff --git a/bindings/imgui_bundle/demos_cpp/demos_immapp/imgui_example_glfw_opengl3.cpp b/bindings/imgui_bundle/demos_cpp/demos_immapp/imgui_example_glfw_opengl3.cpp index b1127076..78519ba0 100644 --- a/bindings/imgui_bundle/demos_cpp/demos_immapp/imgui_example_glfw_opengl3.cpp +++ b/bindings/imgui_bundle/demos_cpp/demos_immapp/imgui_example_glfw_opengl3.cpp @@ -1,4 +1,4 @@ -#ifdef HELLOIMGUI_USE_GLFW_OPENGL3 +#if defined(HELLOIMGUI_HAS_OPENGL3) && defined(HELLOIMGUI_USE_GLFW3) #ifndef __EMSCRIPTEN__ // to keep the build process simple, this demo is currently disabled with emscripten (although ImGui and Imgui Bundle are perfectly compatible with emscripten) @@ -222,7 +222,7 @@ int main(int, char**) int main(int, char**) {} #endif -#else // #ifdef HELLOIMGUI_USE_GLFW_OPENGL3 +#else // #if defined(HELLOIMGUI_HAS_OPENGL3) && defined(HELLOIMGUI_USE_GLFW3) #include int main() { printf("Glfw not found!"); } #endif \ No newline at end of file diff --git a/imgui_bundle_cmake/imgui_bundle_build_lib.cmake b/imgui_bundle_cmake/imgui_bundle_build_lib.cmake index a5cee70c..270c04be 100644 --- a/imgui_bundle_cmake/imgui_bundle_build_lib.cmake +++ b/imgui_bundle_cmake/imgui_bundle_build_lib.cmake @@ -65,10 +65,10 @@ endfunction() function(ibd_shout_on_deprecated_options) if (DEFINED IMGUI_BUNDLE_WITH_GLFW) - message(FATAL_ERROR "IMGUI_BUNDLE_WITH_GLFW is deprecated. Please use HELLOIMGUI_USE_GLFW_OPENGL3 instead") + message(FATAL_ERROR "IMGUI_BUNDLE_WITH_GLFW is deprecated. Please use HELLOIMGUI_USE_GLFW3 + HELLOIMGUI_HAS_OPENGL3 instead") endif() if (DEFINED IMGUI_BUNDLE_WITH_SDL) - message(FATAL_ERROR "IMGUI_BUNDLE_WITH_SDL is deprecated. Please use HELLOIMGUI_USE_SDL_OPENGL3 instead") + message(FATAL_ERROR "IMGUI_BUNDLE_WITH_SDL is deprecated. Please use HELLOIMGUI_USE_SDL2 + HELLOIMGUI_HAS_OPENGL3 instead") endif() endfunction()