# SPDX-License-Identifier: GPL-2.0-or-later
# SPDX-FileCopyrightText: Copyright (C) 2026 Max A. Vilkki a.k.a. codise
#
# Dear ImGui (MIT), docking branch, from lib/ocornut-imgui (v1.92.9b-docking), with the
# SDL3 platform backend and the OpenGL 3 renderer backend.
#
# imgui_demo.cpp is compiled in because it also holds ShowStyleEditor(), which is handy
# while building our theme. It costs nothing in a shipped binary: the linker only pulls
# an object out of a static library when something references it, and nothing in ImGui
# itself does. FreeType fonts (misc/freetype) come with #139.

set(imguiDir "${FLIPSID_LIB_DIR}/ocornut-imgui")

add_library(ext_imgui STATIC
    "${imguiDir}/imgui.cpp"
    "${imguiDir}/imgui_demo.cpp"
    "${imguiDir}/imgui_draw.cpp"
    "${imguiDir}/imgui_tables.cpp"
    "${imguiDir}/imgui_widgets.cpp"
    "${imguiDir}/backends/imgui_impl_sdl3.cpp"
    "${imguiDir}/backends/imgui_impl_opengl3.cpp"
)
add_library(ext::imgui ALIAS ext_imgui)

target_include_directories(ext_imgui SYSTEM PUBLIC
    "${imguiDir}"
    "${imguiDir}/backends"
)

# PUBLIC: every user of imgui.h has to see the same configuration.
target_compile_definitions(ext_imgui PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS)

target_compile_features(ext_imgui PUBLIC cxx_std_11)

# The OpenGL backend's bundled loader (imgui_impl_opengl3_loader.h) opens the GL library
# at run time on every platform (dlopen, or LoadLibrary on Windows), the way SDL does. So
# nothing links against OpenGL and Linux builds don't need GL development packages.
target_link_libraries(ext_imgui PUBLIC ext::SDL3 PRIVATE ${CMAKE_DL_LIBS})

flipsid_configure_third_party(ext_imgui)
