# SPDX-License-Identifier: GPL-2.0-or-later
# SPDX-FileCopyrightText: Copyright (C) 2026 Max A. Vilkki a.k.a. codise
#
# ImPlot (MIT), from lib/implot: the filter curve graphs (DESIGN §5, #248). Built against
# our ImGui (ext::imgui), whose configuration it has to share.
#
# implot_demo.cpp is compiled in for the same reason as imgui_demo.cpp: a reference while
# building the graphs, and nothing in a shipped binary unless something calls it.

set(implotDir "${FLIPSID_LIB_DIR}/implot")

add_library(ext_implot STATIC
    "${implotDir}/implot.cpp"
    "${implotDir}/implot_items.cpp"
    "${implotDir}/implot_demo.cpp"
)
add_library(ext::implot ALIAS ext_implot)
# The demo ORs two flag enums together, deprecated in C++20 (GCC warns); not ours to fix.
set_source_files_properties("${implotDir}/implot_demo.cpp" PROPERTIES
    COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-deprecated-enum-enum-conversion>")

# The plot functions only for the types we plot. ImPlot's default ten types made
# implot_items.cpp the build's slowest file by far (74 s alone at -O3 on an Intel i9, a 31 MB
# object); two take 20 s and 7 MB. The demo plots ints too, so calling ImPlot's demo window
# would need them added back (a link error says so).
target_compile_definitions(ext_implot PRIVATE "IMPLOT_CUSTOM_NUMERIC_TYPES=(float)(double)")

target_include_directories(ext_implot SYSTEM PUBLIC "${implotDir}")
target_link_libraries(ext_implot PUBLIC ext::imgui)
target_compile_features(ext_implot PUBLIC cxx_std_11)

flipsid_configure_third_party(ext_implot)
