Add rust-project to the buck2 package
[NixPkgs.git] / pkgs / applications / misc / trenchbroom / default.nix
blob646cac86cb8b9f439b0f1bfa535b47a8ae13097b
2   lib,
3   stdenv,
4   fetchFromGitHub,
5   writeText,
6   cmake,
7   ninja,
8   curl,
9   git,
10   pandoc,
11   pkg-config,
12   unzip,
13   zip,
14   libGL,
15   libGLU,
16   freeimage,
17   freetype,
18   assimp,
19   catch2,
20   fmt,
21   glew,
22   miniz,
23   tinyxml-2,
24   xorg,
25   qtbase,
26   qtwayland,
27   wrapQtAppsHook,
28   copyDesktopItems,
29   makeDesktopItem,
32 stdenv.mkDerivation rec {
33   pname = "TrenchBroom";
34   version = "2024.1";
36   src = fetchFromGitHub {
37     owner = "TrenchBroom";
38     repo = "TrenchBroom";
39     rev = "v${version}";
40     hash = "sha256-HNK/gLbew7MKN6GVStxDb2tyMgyw2l1+dhPr6fSaZ4A=";
41     fetchSubmodules = true;
42   };
43   # Manually simulate a vcpkg installation so that it can link the libraries
44   # properly.
45   postUnpack =
46     let
47       vcpkg_target = "x64-linux";
49       vcpkg_pkgs = [
50         "assimp"
51         "catch2"
52         "fmt"
53         "freeimage"
54         "freetype"
55         "glew"
56         "miniz"
57         "tinyxml2"
58       ];
60       updates_vcpkg_file = writeText "update_vcpkg_trenchbroom" (
61         lib.concatMapStringsSep "\n" (name: ''
62           Package : ${name}
63           Architecture : ${vcpkg_target}
64           Version : 1.0
65           Status : is installed
66         '') vcpkg_pkgs
67       );
68     in
69     ''
70       export VCPKG_ROOT="$TMP/vcpkg"
72       mkdir -p $VCPKG_ROOT/.vcpkg-root
73       mkdir -p $VCPKG_ROOT/installed/${vcpkg_target}/lib
74       mkdir -p $VCPKG_ROOT/installed/vcpkg/updates
75       ln -s ${updates_vcpkg_file} $VCPKG_ROOT/installed/vcpkg/status
76       mkdir -p $VCPKG_ROOT/installed/vcpkg/info
77       ${lib.concatMapStrings (name: ''
78         touch $VCPKG_ROOT/installed/vcpkg/info/${name}_1.0_${vcpkg_target}.list
79       '') vcpkg_pkgs}
81       ln -s ${assimp.lib}/lib/lib* $VCPKG_ROOT/installed/${vcpkg_target}/lib/
82       ln -s ${catch2}/lib/lib* $VCPKG_ROOT/installed/${vcpkg_target}/lib/
83       ln -s ${fmt}/lib/lib* $VCPKG_ROOT/installed/${vcpkg_target}/lib/
84       ln -s ${freeimage}/lib/lib* $VCPKG_ROOT/installed/${vcpkg_target}/lib/
85       ln -s ${freetype}/lib/lib* $VCPKG_ROOT/installed/${vcpkg_target}/lib/
86       ln -s ${glew.out}/lib/lib* $VCPKG_ROOT/installed/${vcpkg_target}/lib/
87       ln -s ${miniz}/lib/lib* $VCPKG_ROOT/installed/${vcpkg_target}/lib/
88       ln -s ${tinyxml-2}/lib/lib* $VCPKG_ROOT/installed/${vcpkg_target}/lib/
89     '';
90   postPatch = ''
91     substituteInPlace common/src/Version.h.in \
92       --subst-var-by APP_VERSION_YEAR ${lib.versions.major version} \
93       --subst-var-by APP_VERSION_NUMBER ${lib.versions.minor version} \
94       --subst-var-by GIT_DESCRIBE v${version}
95     substituteInPlace app/CMakeLists.txt \
96       --replace 'set(CPACK_PACKAGING_INSTALL_PREFIX "/usr")' 'set(CPACK_PACKAGING_INSTALL_PREFIX "'$out'")'
97   '';
99   nativeBuildInputs = [
100     cmake
101     ninja
102     curl
103     git
104     pandoc
105     wrapQtAppsHook
106     copyDesktopItems
107     pkg-config
108     unzip
109     zip
110   ];
111   buildInputs = [
112     libGL
113     libGLU
114     xorg.libXxf86vm
115     xorg.libSM
116     freeimage
117     freetype
118     qtbase
119     qtwayland
120     catch2
121     fmt
122     glew
123     miniz
124     tinyxml-2
125     assimp
126   ];
127   QT_PLUGIN_PATH = "${qtbase}/${qtbase.qtPluginPrefix}";
128   QT_QPA_PLATFORM = "offscreen";
130   cmakeFlags = [
131     "-DCMAKE_MAKE_PROGRAM=ninja"
132     "-DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake"
133     "-DVCPKG_MANIFEST_INSTALL=OFF"
134     # https://github.com/TrenchBroom/TrenchBroom/issues/4002#issuecomment-1125390780
135     "-DCMAKE_PREFIX_PATH=cmake/packages"
136   ];
137   ninjaFlags = [
138     "TrenchBroom"
139   ];
141   postInstall = ''
142     pushd $out/share/TrenchBroom/icons
144     for F in icon_*.png; do
145       SIZE=$(echo $F|sed -e s/icon_// -e s/.png//)
146       DIR=$out/share/icons/hicolor/$SIZE"x"$SIZE/apps
147       mkdir -p $DIR
148       ln -s ../../../../TrenchBroom/icons/$F $DIR/trenchbroom.png
149     done
151     popd
152   '';
154   desktopItems = [
155     (makeDesktopItem {
156       name = "TrenchBroom";
157       desktopName = "TrenchBroom level editor";
158       icon = "trenchbroom";
159       comment = meta.description;
160       categories = [ "Development" ];
161       exec = "trenchbroom";
162     })
163   ];
165   meta = with lib; {
166     homepage = "https://trenchbroom.github.io/";
167     changelog = "https://github.com/TrenchBroom/TrenchBroom/releases/tag/v${version}";
168     description = "Level editor for Quake-engine based games";
169     license = licenses.gpl3Only;
170     maintainers = with maintainers; [ astro ];
171     platforms = [ "x86_64-linux" ];
172   };