Subject: [bug#73287] [PATCH 3/3] gnu: Add trenchbroom.

From: James Smith <[email-masked]>
Date: Sun, 15 Sep 2024 19:16:24 -0700

* gnu/packages/game-development.scm: (trenchbroom): New variable.

Change-Id: I50691b1db2010cd8c2c7f04bdfd80278b9e14aed
---
 gnu/packages/game-development.scm | 93 +++++++++++++++++++++++++++++++
 1 file changed, 93 insertions(+)

diff --git a/gnu/packages/game-development.scm b/gnu/packages/game-development.scm
index d61b4d633a..abc144f535 100644
--- a/gnu/packages/game-development.scm
+++ b/gnu/packages/game-development.scm
@@ -91,12 +91,14 @@ (define-module (gnu packages game-development)
   #:use-module (gnu packages graphviz)
   #:use-module (gnu packages gtk)
   #:use-module (gnu packages guile)
+  #:use-module (gnu packages haskell-xyz)
   #:use-module (gnu packages icu4c)
   #:use-module (gnu packages image)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages llvm)
   #:use-module (gnu packages lua)
   #:use-module (gnu packages m4)
+  #:use-module (gnu packages maths)
   #:use-module (gnu packages mp3)
   #:use-module (gnu packages multiprecision)
   #:use-module (gnu packages music)
@@ -104,6 +106,7 @@ (define-module (gnu packages game-development)
   #:use-module (gnu packages networking)
   #:use-module (gnu packages pcre)
   #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages pretty-print)
   #:use-module (gnu packages pulseaudio)
   #:use-module (gnu packages python)
   #:use-module (gnu packages python-crypto)
@@ -121,6 +124,7 @@ (define-module (gnu packages game-development)
   #:use-module (gnu packages texinfo)
   #:use-module (gnu packages textutils)
   #:use-module (gnu packages tls)
+  #:use-module (gnu packages version-control)
   #:use-module (gnu packages video)
   #:use-module (gnu packages vulkan)
   #:use-module (gnu packages web)
@@ -674,6 +678,95 @@ (define-public tiled
     ;; under BSD-2.
     (license license:gpl2+)))
 
+(define-public trenchbroom
+  (package
+    (name "trenchbroom")
+    (version "2024.1")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/TrenchBroom/TrenchBroom")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "1xysz7rkjy11wp9sshdqllmlw8qb65f1zlljpw3q22483szwzxnb"))))
+    (build-system cmake-build-system)
+    (arguments
+     (list #:configure-flags
+           #~(list "-DCMAKE_BUILD_TYPE=Release" "-G" "Unix Makefiles"
+                   "-DCMAKE_PREFIX_PATH=cmake/packages"
+                   (string-append "-DFREEIMAGE_INCLUDE_PATH="
+                                  #$freeimage "/include")
+                   (string-append "-DFREEIMAGE_LIBRARY="
+                                  #$freeimage "/lib/libfreeimage.so")
+                   (string-append "-Dfreetype_INCLUDE_DIR="
+                                  #$freetype "/include/freetype2")
+                   (string-append "-Dfreetype_LIBRARY="
+                                  #$freetype "/lib/libfreetype.so"))
+           #:phases
+           #~(modify-phases %standard-phases
+               (add-after 'unpack 'fix-build-system
+                 (lambda _
+                   (substitute* "CMakeLists.txt"
+                     (("set\\(CMAKE_TOOLCHAIN_FILE")
+                      "#set(CMAKE_TOOLCHAIN_FILE"))
+                   (substitute* "app/CMakeLists.txt"
+                     (("/usr") #$output))))
+               (add-before 'build 'set-environment-variables
+                 (lambda _
+                   ;; Set home so fontconfig can write cache.
+                   (setenv "HOME" (getenv "TEMP"))
+                   ;; Set QT platform for offscreen rendering.
+                   (setenv "QT_QPA_PLATFORM" "offscreen")
+                   (setenv "XDG_RUNTIME_DIR" (getenv "TEMP"))))
+               (add-after 'install 'wrap-trenchbroom
+                 (lambda _
+                   (wrap-program (string-append #$output "/bin/trenchbroom")
+                     ;; TrenchBroom needs $XDG_DATA_DIRS set to find game
+                     ;; configs.
+                     `("XDG_DATA_DIRS" ":" prefix
+                       (,(string-append #$output "/share")))
+                     ;; TrenchBroom also doesn't work well with Wayland backend.
+                     '("QT_QPA_PLATFORM" = ("xcb")))))
+               (add-after 'install 'install-desktop-file
+                 (lambda _
+                   (make-desktop-entry-file
+                    (string-append #$output "/share/applications/"
+                                   #$(package-name this-package) ".desktop")
+                    #:name "TrenchBroom"
+                    #:comment #$(package-synopsis this-package)
+                    #:exec #$name
+                    #:icon #$name
+                    #:categories '("Development")
+                    #:keywords '("quake" "level" "editor")))))
+           #:tests? #f)) ; No tests.
+    (inputs
+     (list assimp
+           bash-minimal
+           catch2
+           fmt
+           freeglut
+           freeimage
+           freetype
+           glew
+           glm
+           glu
+           libxxf86vm
+           mesa
+           miniz
+           qtbase-5
+           qtsvg-5
+           tinyxml2))
+    (native-inputs (list git pandoc python p7zip))
+    (home-page "https://kristianduske.com/trenchbroom/")
+    (synopsis "Cross-platform level editor for Quake-engine based games")
+    (description "TrenchBroom is a cross-platform level editor for Quake-engine
+based games.  It supports Quake, Quake 2, and Hexen 2.  TrenchBroom is easy and
+provides many simple and advanced tools to create complex and interesting levels
+with ease.")
+    (license license:gpl3+)))
+
 (define-public tsukundere
   (package
     (name "tsukundere")
-- 
2.46.0