diff --git a/CMakeLists.txt b/CMakeLists.txt index 31dbf78..b2e56a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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 $<$:$<$:/MTd>> diff --git a/CMakeOptions.cmake b/CMakeOptions.cmake index 92e8304..71046d2 100644 --- a/CMakeOptions.cmake +++ b/CMakeOptions.cmake @@ -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() ################################################################################################################## @@ -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 +) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 920e4ef..bb0ac6d 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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) @@ -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() diff --git a/examples/glfw_vulkan/CMakeLists.txt b/examples/glfw_vulkan/CMakeLists.txt new file mode 100644 index 0000000..a6cd3a0 --- /dev/null +++ b/examples/glfw_vulkan/CMakeLists.txt @@ -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' | 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})