Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a GLFW/Vulkan backend. #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ if(IMGUI_WITH_BACKEND)
list(APPEND IMGUI_INTERFACE_LIBS dxgi)
# list(APPEND IMGUI_INTERFACE_LIBS d3dcompiler)
endif()
if(IMGUI_BACKEND_VULKAN)
message(STATUS "[ImGui] Including backend api: [Vulkan]")
list(APPEND PUBLIC_H_FILES ${BACKENDS_DIR}/imgui_impl_vulkan.h)
list(APPEND PUBLIC_CXX_FILES ${BACKENDS_DIR}/imgui_impl_vulkan.cpp)
list(APPEND IMGUI_INTERFACE_LIBS Vulkan)
endif()
endif()

set(PROJECT_FILES
Expand Down Expand Up @@ -141,6 +147,10 @@ if(IMGUI_BACKEND_DX12)
target_compile_definitions(${PROJECT_NAME} PRIVATE ImTextureID=ImU64)
endif()

if(IMGUI_BACKEND_VULKAN)
target_link_libraries(${PROJECT_NAME} PRIVATE glfw vulkan)
endif()

target_compile_options(${PROJECT_NAME}
PUBLIC
$<$<CXX_COMPILER_ID:MSVC>:$<$<CONFIG:Debug>:/MTd>>
Expand Down
8 changes: 7 additions & 1 deletion CMakeOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ option(IMGUI_WITH_BACKEND

# TODO: Validate configurations based on the given input combination
# TODO: Add support for other platforms WIN32, SDL, GLFW, GLUT, ANDROID, APPLE, ALLEGRO5
set(IMGUI_BACKEND_PLATFORM "WIN32" CACHE STRING "")
if (WIN32)
set(IMGUI_BACKEND_PLATFORM "WIN32" CACHE STRING "")
endif()


##################################################################################################################
Expand All @@ -45,3 +47,7 @@ cmake_dependent_option(IMGUI_BACKEND_DX12
"Set to ON to include DX12 backend files." OFF
"IMGUI_WITH_BACKEND" ON
)
cmake_dependent_option(IMGUI_BACKEND_VULKAN
"Set to ON to include Vulkan backend files." OFF
"IMGUI_WITH_BACKEND" ON
)
16 changes: 10 additions & 6 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# ImGui Example App
# MSVC app using Direct3D9. Similar approach should follow on other platforms.
# ImGui Example Apps
# Similar approach should follow on other platforms.
#
cmake_minimum_required(VERSION 3.15)

Expand All @@ -21,7 +21,11 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/dist" CACHE PATH "" FORCE)
endif()

add_subdirectory(win32_dx9)
add_subdirectory(win32_dx10)
add_subdirectory(win32_dx11)
add_subdirectory(win32_dx12)
if(WIN32)
add_subdirectory(win32_dx9)
add_subdirectory(win32_dx10)
add_subdirectory(win32_dx11)
add_subdirectory(win32_dx12)
else()
add_subdirectory(glfw_vulkan)
endif()
43 changes: 43 additions & 0 deletions examples/glfw_vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# ImGui Example App
# Example app using GLFW+Vulkan renderer. Similar approach should follow on other platforms.
#
cmake_minimum_required(VERSION 3.15)


##################################################################################################################
# PROJECT
##################################################################################################################

project(imgui_app_glfw_vulkan
LANGUAGES CXX
DESCRIPTION "ImGui app."
)

set(CMAKE_VERBOSE_MAKEFILE TRUE)

get_filename_component(PROJECT_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}" PATH)
get_filename_component(PROJECT_ROOT_DIR "${PROJECT_ROOT_DIR}" PATH)
set(ImGui_INSTALL_DIR "${PROJECT_ROOT_DIR}/build/dist")

set(ImGui_DIR "${ImGui_INSTALL_DIR}/lib/cmake")
list(APPEND CMAKE_PREFIX_PATH ${ImGui_DIR})
find_package(ImGui CONFIG REQUIRED)

# CMake's regex engine is almost unusable. Therefore we use native's shell to replace the include headers
# to match with the wrapped library directory structure.
set(MAIN_CXX "${PROJECT_ROOT_DIR}/imgui/examples/example_glfw_vulkan/main.cpp")
set(MAIN_CXX_OUT "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
execute_process(COMMAND powershell
(Get-Content -Path ${MAIN_CXX})
-replace '\(include\\s+\)\"\(imgui.*\)\"', '$1<imgui/$2>' | Out-File ${MAIN_CXX_OUT}
)

add_executable(${PROJECT_NAME} ${MAIN_CXX_OUT})
target_link_libraries(${PROJECT_NAME} PRIVATE ImGui::imgui)

# This allows to debug when compiling ImGui as shared library
string(REPLACE "/" "\\" VS_DEBUGGER_ENV ${ImGui_INSTALL_DIR})
set_target_properties(${PROJECT_NAME} PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=${VS_DEBUGGER_ENV}\\bin;$(PATH)")

install(TARGETS ${PROJECT_NAME})