summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt16
-rw-r--r--default.nix26
-rw-r--r--flake.lock26
-rw-r--r--flake.nix17
4 files changed, 81 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 649bd6f..663889f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,9 +4,17 @@ project(meowcraft)
 set(CMAKE_CXX_STANDARD 17)
 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
 
+include(GNUInstallDirs)
+
 # Enable assertions for RelWithDebInfo builds.
 string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
 
+# FIXME: Nixpkgs LLVM currently has problems with LTO on Darwin.
+# See related PR: https://github.com/NixOS/nixpkgs/pull/302481
+# Enable LTO for release builds
+# set_property(TARGET meowcraft PROPERTY
+#         INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
+
 if (NOT UNIX)
     set(GLEW_USE_STATIC_LIBS ON)
 endif (NOT UNIX)
@@ -92,10 +100,6 @@ add_executable(meowcraft
     src/Input.cpp src/Input.hpp
 )
 
-# Enable LTO for release builds
-set_property(TARGET meowcraft PROPERTY
-        INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
-
 if (WIN32)
     set(LINK_FLAGS "-static-libgcc -static-libstdc++ -static -mwindows")
 endif (WIN32)
@@ -120,4 +124,8 @@ make_assets(images/atlas.ppm
     shaders/clouds.frag.glsl shaders/clouds.vert.glsl
     shaders/image_viewer.frag.glsl shaders/image_viewer.vert.glsl
     shaders/block_outline.frag.glsl shaders/block_outline.vert.glsl
+)
+
+install(TARGETS meowcraft
+    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
 )
\ No newline at end of file
diff --git a/default.nix b/default.nix
new file mode 100644
index 0000000..ec42aa9
--- /dev/null
+++ b/default.nix
@@ -0,0 +1,26 @@
+{ lib, stdenv, cmake, glew, glfw }:
+
+stdenv.mkDerivation {
+  pname = "meowcraft";
+  version = "0.0.1";
+
+  src = ./.;
+
+  nativeBuildInputs = [ cmake ];
+  buildInputs = [ glew glfw ];
+  # NOTE: Don't packages usually also add the Apple SDKs as buildInputs?
+  # Like OpenGL.framework, etc.? It seems to work without them, but I'm not sure.
+
+  cmakeFlags = [
+    "-DCMAKE_BUILD_TYPE=Release"
+    "-DCMAKE_INSTALL_PREFIX=\${out}"
+  ];
+
+  meta = with lib; {
+    description = "a dumb minecraft in c++ and opengl.";
+    homepage = "https://git.rnrd.eu/meowcraft";
+    license = licenses.free; # TODO: Choose a specific license.
+    platforms = [ "x86_64-darwin" ];
+    mainProgram = "meowcraft";
+  };
+}
\ No newline at end of file
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..49196a5
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,26 @@
+{
+  "nodes": {
+    "nixpkgs": {
+      "locked": {
+        "lastModified": 1712741485,
+        "narHash": "sha256-bCs0+MSTra80oXAsnM6Oq62WsirOIaijQ/BbUY59tR4=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "b2cf36f43f9ef2ded5711b30b1f393ac423d8f72",
+        "type": "github"
+      },
+      "original": {
+        "id": "nixpkgs",
+        "ref": "nixos-23.11",
+        "type": "indirect"
+      }
+    },
+    "root": {
+      "inputs": {
+        "nixpkgs": "nixpkgs"
+      }
+    }
+  },
+  "root": "root",
+  "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..8d3da4e
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,17 @@
+{
+  description = "a dumb minecraft in c++ and opengl.";
+
+  inputs = {
+    nixpkgs.url = "nixpkgs/nixos-23.11";
+  };
+
+  outputs = { self, nixpkgs }: 
+  let
+    system = "x86_64-darwin";
+    pkgs = import nixpkgs { inherit system; };
+  in {
+    packages = { 
+      ${system}.default = pkgs.callPackage ./. {};
+    };
+  };
+}