Initial commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
# Bootstraps CPM.cmake.
|
||||
#
|
||||
# Inside the nix devShell CPM_CMAKE_PATH points at the nixpkgs-provided copy,
|
||||
# so a fresh configure touches the network zero times. Everywhere else this
|
||||
# falls back to the pinned release download, byte-identical to that copy
|
||||
# (verified: both hash to a609e875...), so the two paths cannot diverge.
|
||||
|
||||
set(CPM_DOWNLOAD_VERSION 0.42.3)
|
||||
set(CPM_DOWNLOAD_HASH
|
||||
SHA256=a609e875fd532b067174250f6abbc3dac22fe2d64869783fb1e80bda1625c844)
|
||||
|
||||
# CPM caches its own path in CPM_DIRECTORY, and when a later include comes from
|
||||
# a different path it assumes an enclosing project already loaded CPM, then
|
||||
# returns without defining CPMAddPackage. The two copies above live at
|
||||
# different paths (as does every nix store revision of the first), so a build
|
||||
# dir configured both inside and outside the devShell broke with "Unknown CMake
|
||||
# command". Nothing loads CPM before the top-level project, so a cached value
|
||||
# here is always stale.
|
||||
if (PROJECT_IS_TOP_LEVEL)
|
||||
unset(CPM_DIRECTORY CACHE)
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{CPM_CMAKE_PATH} AND EXISTS "$ENV{CPM_CMAKE_PATH}")
|
||||
message(STATUS "CPM: using $ENV{CPM_CMAKE_PATH}")
|
||||
include("$ENV{CPM_CMAKE_PATH}")
|
||||
else ()
|
||||
set(CPM_DOWNLOAD_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake")
|
||||
file(
|
||||
DOWNLOAD
|
||||
"https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake"
|
||||
"${CPM_DOWNLOAD_LOCATION}"
|
||||
EXPECTED_HASH ${CPM_DOWNLOAD_HASH})
|
||||
include("${CPM_DOWNLOAD_LOCATION}")
|
||||
endif ()
|
||||
@@ -0,0 +1,61 @@
|
||||
# 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)
|
||||
@@ -0,0 +1,28 @@
|
||||
# CLion toolchain environment file: Settings > Build, Execution, Deployment >
|
||||
# Toolchains > Add environment > From file. CLion sources it before CMake,
|
||||
# builds, runs and debugging, so all of them see the nix devShell.
|
||||
#
|
||||
# The direnv plugin cannot do this on its own: it only writes variables into
|
||||
# Run/Debug configurations, and a CMake reload is not one.
|
||||
#
|
||||
# direnv searches upward for .envrc, so export from this file's directory
|
||||
# instead of relying on whatever working directory CLion sources it from.
|
||||
# CLion sources through the user's login shell ($SHELL -l -i -c), which
|
||||
# shapes the rest:
|
||||
# - The file's own path has to be found in zsh as well as bash. The zsh
|
||||
# spelling sits inside eval so other shells never parse it.
|
||||
# - No shell `cd`. An interactive zsh carries direnv's chpwd hook, which
|
||||
# loads the env inside the cd subshell and leaves `direnv export` with
|
||||
# nothing to print. `env -C` changes directory in the child instead.
|
||||
if [ -n "${BASH_SOURCE:-}" ]; then
|
||||
_sd_self=$BASH_SOURCE
|
||||
elif [ -n "${ZSH_VERSION:-}" ]; then
|
||||
eval '_sd_self=${(%):-%x}'
|
||||
fi
|
||||
|
||||
if [ -n "${_sd_self:-}" ]; then
|
||||
eval "$(env -C "$(dirname "$_sd_self")" direnv export bash)"
|
||||
else
|
||||
eval "$(direnv export bash)"
|
||||
fi
|
||||
unset _sd_self
|
||||
Reference in New Issue
Block a user