62 lines
2.3 KiB
CMake
62 lines
2.3 KiB
CMake
# Defines the imgui::imgui target.
|
|
#
|
|
# Dear ImGui is the one dependency the hybrid strategy can't handle uniformly,
|
|
# because upstream ships no CMakeLists at all. The two paths differ in more
|
|
# than provenance:
|
|
#
|
|
# nixpkgs — a real CMake package (imgui::imgui), backends already compiled
|
|
# in, headers installed flat: <imgui_impl_sdl3.h>.
|
|
# upstream — a bare source drop; the backends are loose .cpp files under
|
|
# backends/ that every consumer is expected to compile itself.
|
|
#
|
|
# Both ends up exporting imgui::imgui with backends/ on the include path, so
|
|
# game code writes `#include <imgui_impl_sdl3.h>` either way and never learns
|
|
# which one it got.
|
|
|
|
find_package(imgui CONFIG QUIET)
|
|
|
|
if (imgui_FOUND)
|
|
message(STATUS "ImGui: using system package ${imgui_DIR}")
|
|
|
|
# nixpkgs can be built with the GLFW/OpenGL3 backends instead of the SDL3
|
|
# ones, in which case linking succeeds and the first ImGui_ImplSDL3_*
|
|
# call fails to resolve. Catch that here rather than at link time.
|
|
find_path(SD_IMGUI_SDL3_BACKEND imgui_impl_sdl3.h
|
|
HINTS ${imgui_INCLUDE_DIRS} PATH_SUFFIXES imgui backends)
|
|
if (NOT SD_IMGUI_SDL3_BACKEND)
|
|
message(FATAL_ERROR
|
|
"The installed Dear ImGui has no SDL3 backend (imgui_impl_sdl3.h). "
|
|
"Inside nix this means the imgui override in flake.nix regressed; "
|
|
"outside it, rebuild imgui with the SDL3 + SDL3_Renderer backends.")
|
|
endif ()
|
|
|
|
return()
|
|
endif ()
|
|
|
|
message(STATUS "ImGui: building from source via CPM")
|
|
|
|
CPMAddPackage(
|
|
NAME imgui
|
|
GITHUB_REPOSITORY ocornut/imgui
|
|
GIT_TAG v1.91.4
|
|
DOWNLOAD_ONLY YES)
|
|
|
|
add_library(imgui STATIC
|
|
${imgui_SOURCE_DIR}/imgui.cpp
|
|
${imgui_SOURCE_DIR}/imgui_draw.cpp
|
|
${imgui_SOURCE_DIR}/imgui_tables.cpp
|
|
${imgui_SOURCE_DIR}/imgui_widgets.cpp
|
|
${imgui_SOURCE_DIR}/imgui_demo.cpp
|
|
${imgui_SOURCE_DIR}/backends/imgui_impl_sdl3.cpp
|
|
${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer3.cpp)
|
|
|
|
# SYSTEM so ImGui's headers stop tripping this project's own warning flags —
|
|
# the nixpkgs path gets that for free, this one has to ask.
|
|
target_include_directories(imgui SYSTEM PUBLIC
|
|
${imgui_SOURCE_DIR}
|
|
${imgui_SOURCE_DIR}/backends)
|
|
|
|
target_link_libraries(imgui PUBLIC SDL3::SDL3)
|
|
|
|
add_library(imgui::imgui ALIAS imgui)
|