diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | CMakeLists.txt | 78 | ||||
| -rw-r--r-- | Makefile | 55 | ||||
| -rw-r--r-- | flake.nix | 113 |
4 files changed, 148 insertions, 101 deletions
@@ -1,6 +1,9 @@ # Prerequisites *.d +# Build dir +build/ + # Object files obj/ *.o diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..6779659 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,78 @@ +cmake_minimum_required(VERSION 3.10) +project(dungeon_crawler VERSION 0.1.0 LANGUAGES C) + +set(CMAKE_C_STANDARD 99) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +option(USE_NIX "Use Nix-provided dependencies instead of FetchContent" OFF) + +if(USE_NIX) + find_package(raylib 5.5 REQUIRED) +else() + include(FetchContent) + FetchContent_Declare( + raylib + GIT_REPOSITORY https://github.com/raysan5/raylib.git + GIT_TAG 5.5.0 + GIT_SHALLOW TRUE + ) + FetchContent_Declare( + raytmx + GIT_REPOSITORY https://github.com/luphi/raytmx.git + GIT_TAG d4e09bc + ) + FetchContent_Declare( + hoxml + GIT_REPOSITORY https://github.com/luphi/hoxml.git + GIT_TAG 12938da + ) + + set(RAYLIB_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) + set(RAYLIB_BUILD_TESTS OFF CACHE BOOL "" FORCE) + set(RAYLIB_INSTALL OFF CACHE BOOL "" FORCE) + set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) + set(HOXML_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) + + FetchContent_MakeAvailable(raylib raytmx hoxml) +endif() + +file(GLOB_RECURSE SOURCES ${CMAKE_SOURCE_DIR}/src/*.c) + +file(GLOB_RECURSE HEADERS ${CMAKE_SOURCE_DIR}/include/*.h) +list(FILTER HEADERS EXCLUDE REGEX "raylib|raymath|rlgl|raytmx|hoxml") + +add_executable(dungeon_game ${SOURCES} ${HEADERS}) + +target_include_directories(dungeon_game PRIVATE ${CMAKE_SOURCE_DIR}/include) + +if(USE_NIX) + target_link_libraries(dungeon_game PRIVATE raylib m) +else() + target_include_directories(dungeon_game PRIVATE + ${raylib_SOURCE_DIR}/src + ${raytmx_SOURCE_DIR} + ${hoxml_SOURCE_DIR}/external + ) + target_link_libraries(dungeon_game PRIVATE raylib hoxml raytmx m) +endif() + +if(WIN32) + target_link_libraries(dungeon_game PRIVATE gdi32 winmm) +elseif(APPLE) + target_link_libraries(dungeon_game PRIVATE "-framework Cocoa") +endif() + +# Copy assets +add_custom_command(TARGET dungeon_game POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_SOURCE_DIR}/assets + $<TARGET_FILE_DIR:dungeon_game>/assets +) + +if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") + target_compile_options(dungeon_game PRIVATE -Wall -Wextra -O2) +endif() + +install(TARGETS dungeon_game DESTINATION bin) +install(DIRECTORY ${CMAKE_SOURCE_DIR}/assets/ DESTINATION bin/assets) diff --git a/Makefile b/Makefile deleted file mode 100644 index f1983d9..0000000 --- a/Makefile +++ /dev/null @@ -1,55 +0,0 @@ -# --- Compiler Settings --- -CC ?= gcc -PKG_CONFIG ?= pkg-config - -# Check if raylib is available via pkg-config -HAS_RAYLIB_PC := $(shell $(PKG_CONFIG) --exists raylib && echo yes) - -ifeq ($(HAS_RAYLIB_PC),yes) - RAYLIB_CFLAGS := $(shell $(PKG_CONFIG) --cflags raylib) - RAYLIB_LIBS := $(shell $(PKG_CONFIG) --libs raylib) -else - # Fallback for systems without raylib pkg-config (using local lib/ and standard flags) - RAYLIB_CFLAGS := - RAYLIB_LIBS := -Llib -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -Wl,-rpath=./lib -endif - -# User CFLAGS/LDFLAGS can be passed from environment -CFLAGS += -Wall -Wextra -std=c99 -O2 -Iinclude $(RAYLIB_CFLAGS) -LDFLAGS += $(RAYLIB_LIBS) -lm - -# --- Project Directories --- -SRC_DIR = src -OBJ_DIR = obj -BIN_DIR = bin - -# --- Files --- -SRCS = $(wildcard $(SRC_DIR)/*.c) -OBJS = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRCS)) - -# --- Output Binary --- -TARGET = $(BIN_DIR)/dungeon_game - -# --- Build Rules --- -all: $(TARGET) - -$(TARGET): $(OBJS) | $(BIN_DIR) - @echo "Linking $@" - $(CC) $(OBJS) -o $@ $(LDFLAGS) - @echo "Build successful! Run with: ./$(TARGET)" - -$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR) - @echo "Compiling $<" - $(CC) $(CFLAGS) -c $< -o $@ - -$(BIN_DIR): - mkdir -p $(BIN_DIR) - -$(OBJ_DIR): - mkdir -p $(OBJ_DIR) - -clean: - @echo "Cleaning up..." - rm -rf $(OBJ_DIR) $(BIN_DIR) - -.PHONY: all clean @@ -1,5 +1,5 @@ { - description = "Raylib C/C++ Dev Environment"; + description = "Dungeon project dev environment with Raylib 5.5, raytmx, and hoxml"; inputs = { nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; @@ -15,74 +15,95 @@ "aarch64-darwin" ]; - forEachSystem = nixpkgs.lib.genAttrs supportedSystems; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; in { - packages = forEachSystem (system: + packages = forAllSystems ( + system: let - pkgs = nixpkgs.legacyPackages.${system}; + pkgs = import nixpkgs { inherit system; }; + + myRaylib = pkgs.raylib.overrideAttrs (oldAttrs: { + version = "5.5"; + src = pkgs.fetchFromGitHub { + owner = "raysan5"; + repo = "raylib"; + rev = "c1ab645ca298a2801097931d1079b10ff7eb9df8"; + hash = "sha256-J99i4z4JF7d6mJNuJIB0rHNDhXJ5AEkG0eBvvuBLHrY="; + }; + }); + + raytmx = pkgs.stdenv.mkDerivation { + pname = "raytmx"; + version = "d4e09bc"; + src = pkgs.fetchFromGitHub { + owner = "luphi"; + repo = "raytmx"; + rev = "d4e09bcfa7a2fb553853b15b25f0fa74f6cb8912"; + hash = "sha256-uahAiQ2HucRV86/ZOoYw03mhd8hLVcGPmheG5cy44oU="; + }; + installPhase = '' + mkdir -p $out/include + cp raytmx.h $out/include/ + ''; + }; + + hoxml = pkgs.stdenv.mkDerivation { + pname = "hoxml"; + version = "12938da"; + src = pkgs.fetchFromGitHub { + owner = "luphi"; + repo = "hoxml"; + rev = "12938da4ce3217ce7986acfc7745744acb7c5dfb"; + hash = "sha256-h5fouCX0+GRtEnJ5KlaIyDTj5I0oFmlUj8NsvjKzGho="; + }; + installPhase = '' + mkdir -p $out/include + cp hoxml.h $out/include/ + ''; + }; + in { default = pkgs.stdenv.mkDerivation { - pname = "dungeon-crawler"; + pname = "dungeon"; version = "0.1.0"; + src = ./.; - nativeBuildInputs = with pkgs; [ - pkg-config - gnumake + buildInputs = [ + myRaylib + raytmx + hoxml ]; - buildInputs = with pkgs; [ - raylib - ] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [ - libGL - libX11 - libXrandr - libXi - libXcursor - libXinerama + nativeBuildInputs = [ + pkgs.pkg-config + pkgs.cmake ]; - buildPhase = '' - make - ''; - - installPhase = '' - mkdir -p $out/bin - cp bin/dungeon_game $out/bin/dungeon-crawler - ''; + cmakeFlags = [ "-DUSE_NIX=ON" ]; }; - }); - - apps = forEachSystem (system: { - default = { - type = "app"; - program = "${self.packages.${system}.default}/bin/dungeon-crawler"; - }; - }); + } + ); - devShells = forEachSystem ( + devShells = forAllSystems ( system: let - pkgs = nixpkgs.legacyPackages.${system}; + pkgs = import nixpkgs { inherit system; }; in { default = pkgs.mkShell { inputsFrom = [ self.packages.${system}.default ]; - packages = with pkgs; [ - gcc - clang-tools - gdb - tiled - zsh - ]; - shellHook = '' - export SHELL=${pkgs.zsh}/bin/zsh - echo "Raylib dev shell loaded." - ''; }; } ); + + apps = forAllSystems (system: { + default = { + type = "app"; + program = "${self.packages.${system}.default}/bin/dungeon_game"; + }; + }); }; } |
