Skip to content

Commit

Permalink
CMake: reviewed all backend options / separate platform and renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Feb 2, 2024
1 parent be8a557 commit da289dd
Show file tree
Hide file tree
Showing 35 changed files with 352 additions and 303 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/DirectX.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:
mkdir build
cd build
if [ "${{ matrix.directx_version }}" = "11" ]; then
cmake .. -DHELLOIMGUI_USE_SDL_DIRECTX11=ON -DCMAKE_BUILD_TYPE=Release;
cmake .. -DHELLOIMGUI_USE_SDL2=ON -DHELLOIMGUI_HAS_DIRECTX11=ON -DCMAKE_BUILD_TYPE=Release;
fi
if [ "${{ matrix.directx_version }}" = "12" ]; then
cmake .. -DHELLOIMGUI_USE_SDL_DIRECTX12=ON -DCMAKE_BUILD_TYPE=Release;
cmake .. -DHELLOIMGUI_USE_SDL2=ON -DHELLOIMGUI_HAS_DIRECTX12=ON -DCMAKE_BUILD_TYPE=Release;
fi
cmake --build . -j 3
2 changes: 1 addition & 1 deletion .github/workflows/Emscripten.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
source ~/emsdk/emsdk_env.sh
mkdir build-emscripten
cd build-emscripten
emcmake cmake .. -DHELLOIMGUI_USE_SDL_OPENGL3=ON
emcmake cmake .. -DHELLOIMGUI_USE_SDL2 -DHELLOIMGUI_HAS_OPENGL3=ON
- name: Build
working-directory: build-emscripten
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/Metal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ jobs:
mkdir build
cd build
if [ "${{ matrix.window_backend }}" = "Glfw" ]; then
cmake .. -DHELLOIMGUI_USE_GLFW_METAL=ON -DCMAKE_BUILD_TYPE=Release;
cmake .. -DHELLOIMGUI_USE_GLFW3=ON -DHELLOIMGUI_HAS_METAL=ON -DCMAKE_BUILD_TYPE=Release;
fi
if [ "${{ matrix.window_backend }}" = "Sdl" ]; then
cmake .. -DHELLOIMGUI_USE_SDL_METAL=ON -DCMAKE_BUILD_TYPE=Release;
cmake .. -DHELLOIMGUI_USE_SDL2=ON -DHELLOIMGUI_HAS_METAL=ON -DCMAKE_BUILD_TYPE=Release;
fi
if [ "${{ matrix.window_backend }}" = "Both" ]; then
cmake .. -DHELLOIMGUI_USE_GLFW_METAL=ON -DHELLOIMGUI_USE_SDL_METAL=ON -DCMAKE_BUILD_TYPE=Release;
cmake .. -DHELLOIMGUI_USE_GLFW3=ON -DHELLOIMGUI_USE_SDL2=ON -DHELLOIMGUI_HAS_METAL=ON -DCMAKE_BUILD_TYPE=Release;
fi
cmake --build . -j 3
4 changes: 2 additions & 2 deletions .github/workflows/MinGW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
mkdir build_x86_64
cd build_x86_64
if [ "${{ matrix.window_backend }}" = "Sdl" ]; then
cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_x86_64.cmake -DCMAKE_BUILD_TYPE=Release -DHELLOIMGUI_USE_SDL_OPENGL3=ON
cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_x86_64.cmake -DCMAKE_BUILD_TYPE=Release -DHELLOIMGUI_USE_SDL2=ON -DHELLOIMGUI_HAS_OPENGL3=ON
fi
if [ "${{ matrix.window_backend }}" = "Glfw" ]; then
cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_x86_64.cmake -DCMAKE_BUILD_TYPE=Release
Expand All @@ -46,7 +46,7 @@ jobs:
mkdir build_i686
cd build_i686
if [ "${{ matrix.window_backend }}" = "Sdl" ]; then
cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_i686.cmake -DCMAKE_BUILD_TYPE=Release -DHELLOIMGUI_USE_SDL_OPENGL3=ON
cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_i686.cmake -DCMAKE_BUILD_TYPE=Release -DHELLOIMGUI_USE_SDL2=ON -DHELLOIMGUI_HAS_OPENGL3=ON
fi
if [ "${{ matrix.window_backend }}" = "Glfw" ]; then
cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_i686.cmake -DCMAKE_BUILD_TYPE=Release
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/Vulkan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ jobs:
mkdir build
cd build
if [ "${{ matrix.window_backend }}" = "Glfw" ]; then
cmake .. -DHELLOIMGUI_USE_GLFW_VULKAN=ON -DHELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED=ON -DCMAKE_BUILD_TYPE=Release;
cmake .. -DHELLOIMGUI_USE_GLFW3=ON -DHELLOIMGUI_HAS_VULKAN=ON -DHELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED=ON -DCMAKE_BUILD_TYPE=Release;
fi
if [ "${{ matrix.window_backend }}" = "Sdl" ]; then
cmake .. -DHELLOIMGUI_USE_SDL_VULKAN=ON -DHELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED=ON -DCMAKE_BUILD_TYPE=Release;
cmake .. -DHELLOIMGUI_USE_SDL2=ON -DHELLOIMGUI_HAS_VULKAN=ON -DHELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED=ON -DCMAKE_BUILD_TYPE=Release;
fi
if [ "${{ matrix.window_backend }}" = "Both" ]; then
cmake .. -DHELLOIMGUI_USE_GLFW_VULKAN=ON -DHELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED=ON -DHELLOIMGUI_USE_SDL_VULKAN=ON -DCMAKE_BUILD_TYPE=Release;
cmake .. -DHELLOIMGUI_USE_GLFW3=ON -DHELLOIMGUI_USE_SDL2=ON -DHELLOIMGUI_HAS_VULKAN=ON -DHELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED=ON -DCMAKE_BUILD_TYPE=Release;
fi
cmake --build . -j 3
2 changes: 1 addition & 1 deletion .github/workflows/Win_Mac_Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
mkdir build
cd build
if [ "${{ matrix.window_backend }}" = "Sdl" ]; then
cmake .. -DHELLOIMGUI_USE_SDL_OPENGL3=ON -DHELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED=ON -DCMAKE_BUILD_TYPE=Release
cmake .. -DHELLOIMGUI_USE_SDL2=ON -DHELLOIMGUI_HAS_OPENGL3=ON -DHELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED=ON -DCMAKE_BUILD_TYPE=Release
fi
if [ "${{ matrix.window_backend }}" = "Glfw" ]; then
cmake .. -DHELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED=ON -DCMAKE_BUILD_TYPE=Release
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/disabled/MacOS_vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ jobs:
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake \
-DHELLOIMGUI_USE_SDL_OPENGL3=ON \
-DHELLOIMGUI_USE_GLFW_OPENGL3=ON \
-DHELLOIMGUI_USE_SDL2=ON \
-DHELLOIMGUI_USE_GLFW3=ON \
-DHELLOIMGUI_HAS_OPENGL3=ON \
-DHELLOIMGUI_USE_GLAD=ON \
-DHELLOIMGUI_BUILD_DOCS=ON \
..
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/disabled/Ubuntu_vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ jobs:
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake \
-DHELLOIMGUI_USE_SDL_OPENGL3=ON \
-DHELLOIMGUI_USE_GLFW_OPENGL3=ON \
-DHELLOIMGUI_USE_SDL2=ON \
-DHELLOIMGUI_USE_GLFW3=ON \
-DHELLOIMGUI_HAS_OPENGL3=ON \
-DHELLOIMGUI_USE_GLAD=ON \
-DHELLOIMGUI_BUILD_DOCS=ON \
..
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/disabled/Windows_vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake -DHELLOIMGUI_USE_SDL_OPENGL3=ON -DHELLOIMGUI_USE_GLFW_OPENGL3=ON -DHELLOIMGUI_USE_GLAD=ON -DHELLOIMGUI_BUILD_DOCS=ON ..
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake -DHELLOIMGUI_USE_SDL2=ON -DHELLOIMGUI_USE_GLFW3=ON -DHELLOIMGUI_HAS_OPENGL3=ON -DHELLOIMGUI_USE_GLAD=ON -DHELLOIMGUI_BUILD_DOCS=ON ..
- name: Build
working-directory: build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/iOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
cmake .. \
-GXcode \
-DCMAKE_TOOLCHAIN_FILE=../hello_imgui_cmake/ios-cmake/ios.toolchain.cmake \
-DHELLOIMGUI_USE_SDL_OPENGL3=ON \
-DHELLOIMGUI_USE_SDL2=ON -DHELLOIMGUI_HAS_OPENGL3=ON \
-DPLATFORM=SIMULATOR64
- name: Build for simulator
Expand Down
66 changes: 32 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,43 +53,41 @@ option(HELLOIMGUI_ADD_APP_WITH_INSTALL "Add cmake install() instructions with he

################################################################################
# <Backends> # do not remove this line (used by the script that generates the documentation)
# Available backends combinations: HelloImGui needs to use at least one of them.
# If you specify no option:
# - HELLOIMGUI_USE_GLFW_OPENGL3 will be used for Windows, Linux, and macOS
# - HELLOIMGUI_USE_SDL_OPENGL3 will be used for Android, iOS and emscripten
#
# Note:
# - Only one rendering backend can be used at a time (OpenGL3, Metal or Vulkan)!
# - You may select multiple platform backends
# (for example, you may select both SDL and Glfw3)
# - Combinations using OpenGL3 as a renderer are easier to use,
# and are recommended, especially for beginners.
################################################################################
# Standard backends:
# Use Glfw3 + OpenGl3
option(HELLOIMGUI_USE_GLFW_OPENGL3 "Build HelloImGui for Glfw3+OpenGL3" OFF)
# Use SDL2 + OpenGL3
option(HELLOIMGUI_USE_SDL_OPENGL3 "Build HelloImGui for SDL2+OpenGL3" OFF)

# Advanced backends, for experienced users:
# Vulkan, Metal, and DirectX11 do work, but you may need to customize the rendering code inside HelloImGui:
# 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)
# Use Glfw3 + Metal (Apple only)
option(HELLOIMGUI_USE_GLFW_METAL "Build HelloImGui for Glfw3+Metal" OFF)
# Use SDL2 + Metal (Apple only)
option(HELLOIMGUI_USE_SDL_METAL "Build HelloImGui for SDL2+Metal" OFF)
# Use Glfw3 + Vulkan
option(HELLOIMGUI_USE_GLFW_VULKAN "Build HelloImGui for Glfw3+Vulkan" OFF)
# Use SDL2 + Vulkan
option(HELLOIMGUI_USE_SDL_VULKAN "Build HelloImGui for SDL2+Vulkan" OFF)
# Use SDL2 + DirectX 11 (Note: there is a known issue with DirectX11, see src/hello_imgui/internal/backend_impls/rendering_dx11.h)
option(HELLOIMGUI_USE_SDL_DIRECTX11 "Build HelloImGui for SDL2+DirectX11" OFF)
# Use Glfw3 + DirectX 11 (Note: there is a known issue with DirectX11, see src/hello_imgui/internal/backend_impls/rendering_dx11.h)
option(HELLOIMGUI_USE_GLFW_DIRECTX11 "Build HelloImGui for Glfw3+DirectX11" OFF)
# Experimental! DirectX12 was not tested, although it does compile!
option(HELLOIMGUI_USE_SDL_DIRECTX12 "Build HelloImGui for SDL2+DirectX12" OFF)

#
################################################################################
# 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)
# </Backends> # do not remove this line (used by the script that generates the documentation)


Expand Down
26 changes: 16 additions & 10 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@
"name": "build_default_glfw",
"description": "Build with default settings (opengl3 and glfw). You need to create a build directory and run from it",
"cacheVariables": {
"HELLOIMGUI_USE_GLFW_OPENGL3": "ON"
"HELLOIMGUI_USE_GLFW3": "ON",
"HELLOIMGUI_HAS_OPENGL3": "ON"
}
},
{
"name": "build_default_sdl",
"description": "Build with default settings (opengl3 and sdl). You need to create a build directory and run from it",
"cacheVariables": {
"HELLOIMGUI_USE_SDL_OPENGL3": "ON"
"HELLOIMGUI_USE_SDL2": "ON",
"HELLOIMGUI_HAS_OPENGL3": "ON"
}
},
{
"name": "build_vcpkg_default",
"description": "Build with vcpkg default settings (opengl3 + sdl and glfw). You need to create a build directory and run from it",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"HELLOIMGUI_USE_GLFW_OPENGL3": "ON",
"HELLOIMGUI_USE_SDL_OPENGL3": "ON",
"HELLOIMGUI_USE_GLFW3": "ON",
"HELLOIMGUI_USE_SDL2": "ON",
"HELLOIMGUI_HAS_OPENGL3": "ON",
"HELLOIMGUI_USE_IMGUI_CMAKE_PACKAGE": "ON"
}
},
Expand All @@ -31,8 +34,9 @@
"binaryDir": "${sourceDir}/build_use_vcpkg_opengl3",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"HELLOIMGUI_USE_GLFW_OPENGL3": "ON",
"HELLOIMGUI_USE_SDL_OPENGL3": "ON",
"HELLOIMGUI_USE_GLFW3": "ON",
"HELLOIMGUI_USE_SDL2": "ON",
"HELLOIMGUI_HAS_OPENGL3": "ON",
"HELLOIMGUI_USE_IMGUI_CMAKE_PACKAGE": "ON"
}
},
Expand All @@ -42,8 +46,9 @@
"binaryDir": "${sourceDir}/build_use_vcpkg_metal",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"HELLOIMGUI_USE_GLFW_METAL": "ON",
"HELLOIMGUI_USE_SDL_METAL": "ON",
"HELLOIMGUI_USE_GLFW3": "ON",
"HELLOIMGUI_USE_SDL2": "ON",
"HELLOIMGUI_HAS_METAL": "ON",
"HELLOIMGUI_USE_IMGUI_CMAKE_PACKAGE": "ON"
}
},
Expand All @@ -53,8 +58,9 @@
"binaryDir": "${sourceDir}/build_use_vcpkg_vulkan",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"HELLOIMGUI_USE_GLFW_VULKAN": "ON",
"HELLOIMGUI_USE_SDL_VULKAN": "ON",
"HELLOIMGUI_USE_GLFW3": "ON",
"HELLOIMGUI_USE_SDL2": "ON",
"HELLOIMGUI_HAS_VULKAN": "ON",
"HELLOIMGUI_USE_IMGUI_CMAKE_PACKAGE": "ON"
}
}
Expand Down
2 changes: 1 addition & 1 deletion _example_integration
2 changes: 1 addition & 1 deletion docs_src/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ See documentation below (extract from [CMakeLists.txt](https://github.com/pthom/

In order to select your own backend, use one of the afore mentioned backend combinations, for example:
```bash
cmake .. -HELLOIMGUI_USE_SDL_OPENGL3=ON
cmake .. -DHELLOIMGUI_USE_SDL2=ON -DHELLOIMGUI_HAS_OPENGL3=ON
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ project(@apkCMake_cmakeProjectName@)
set(HELLOIMGUI_IN_APKCMAKE_GENERATED_PROJECT ON)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/hello_imgui_subrepo/hello_imgui_cmake/")

set(HELLOIMGUI_USE_SDL_OPENGL3 ON CACHE STRING "" FORCE)
set(HELLOIMGUI_USE_SDL2 ON CACHE STRING "" FORCE)
set(HELLOIMGUI_HAS_OPENGL3 ON CACHE STRING "" FORCE)
set(HELLO_IMGUI_ANDROID_ASSETS_FOLDER ${CMAKE_SOURCE_DIR}/../src/main/assets)
add_subdirectory(appDir)
if (NOT TARGET hello_imgui)
Expand Down
Loading

0 comments on commit da289dd

Please sign in to comment.