include(FetchContent)
include(SetupVulkan)

if(NOT DEFINED IMGUI_REPO)
    set(IMGUI_REPO https://github.com/ocornut/imgui.git)
endif ()

project(imgui_internal VERSION 1.0 LANGUAGES C CXX)

set(IMGUI_SRC_DIR ${CMAKE_BINARY_DIR}/3rdParty/imgui/imgui-src)

FetchContent_Populate(imgui
        GIT_REPOSITORY ${IMGUI_REPO}
        GIT_SHALLOW TRUE
        GIT_TAG v1.90-docking
        SOURCE_DIR ${IMGUI_SRC_DIR}
)

add_library(imgui_internal STATIC
            ${IMGUI_SRC_DIR}/imgui.cpp
            ${IMGUI_SRC_DIR}/imgui_draw.cpp
            ${IMGUI_SRC_DIR}/imgui_demo.cpp
            ${IMGUI_SRC_DIR}/imgui_tables.cpp
            ${IMGUI_SRC_DIR}/imgui_widgets.cpp
            ${IMGUI_SRC_DIR}/backends/imgui_impl_vulkan.cpp
)

if (glfw_FOUND)
    target_sources(imgui_internal PRIVATE ${IMGUI_SRC_DIR}/backends/imgui_impl_glfw.cpp)
    target_link_libraries(imgui_internal PUBLIC glfw)
endif ()

SetupVulkan(imgui_internal)
target_include_directories(imgui_internal PUBLIC ${Vulkan_INCLUDE_DIR})

target_include_directories(imgui_internal
                           PUBLIC
                           ${IMGUI_SRC_DIR}
                           ${IMGUI_SRC_DIR}/backends
)

set_property(TARGET imgui_internal PROPERTY CXX_STANDARD 17)
