soldat-unstable: build using CMake

This will be the build system going forward, so it seems sensible to
support it right away. There's no neat way to use the system
GameNetworkingSockets upstream yet, so we add a hack for now.

Proactively decrease platforms to Linux only since the CMake doesn't
quite use GNUInstallDirs on Darwin and Windows unfortunately.
This commit is contained in:
sternenseemann 2021-10-17 14:29:11 +02:00 committed by sterni
parent d37d84bdca
commit 4e50d99934
2 changed files with 33 additions and 39 deletions

View File

@ -1,6 +1,6 @@
{ lib, stdenv, fetchFromGitHub, fpc, zip, makeWrapper
, SDL2, freetype, physfs, openal, gamenetworkingsockets
, xorg, autoPatchelfHook
, xorg, autoPatchelfHook, cmake
}:
let
@ -49,45 +49,27 @@ stdenv.mkDerivation rec {
sha256 = "0r39d1394q7kabsgq6vpdlzwsajxafsg23i0r273nggfvs3m805z";
};
nativeBuildInputs = [ fpc makeWrapper autoPatchelfHook ];
patches = [
# Don't build GameNetworkingSockets as an ExternalProject,
# see https://github.com/Soldat/soldat/issues/73
./gamenetworkingsockets-no-external.patch
];
nativeBuildInputs = [ fpc makeWrapper autoPatchelfHook cmake ];
cmakeFlags = [
"-DADD_ASSETS=OFF" # We provide base's smods via nix
];
buildInputs = [ SDL2 freetype physfs openal gamenetworkingsockets ];
# TODO(@sternenseemann): set proper rpath via cmake, so we don't need autoPatchelfHook
runtimeDependencies = [ xorg.libX11 ];
buildPhase = ''
runHook preBuild
mkdir -p client/build server/build
# build .so from stb headers
pushd client/libs/stb
make
popd
# build client
pushd client
make mode=release
popd
# build server
pushd server
make mode=release
popd
runHook postBuild
'';
installPhase = ''
runHook preInstall
install -Dm644 client/libs/stb/libstb.so -t $out/lib
install -Dm755 client/build/soldat_* $out/bin/soldat
install -Dm755 server/build/soldatserver_* $out/bin/soldatserver
# make sure soldat{,server} find their game archive,
# let them write their state and configuration files
# to $XDG_CONFIG_HOME/soldat/soldat{,server} unless
# the user specifies otherwise.
# make sure soldat{,server} find their game archive,
# let them write their state and configuration files
# to $XDG_CONFIG_HOME/soldat/soldat{,server} unless
# the user specifies otherwise.
postInstall = ''
for p in $out/bin/soldatserver $out/bin/soldat; do
configDir="\''${XDG_CONFIG_HOME:-\$HOME/.config}/soldat/$(basename "$p")"
@ -97,8 +79,6 @@ stdenv.mkDerivation rec {
--add-flags "-fs_userpath \"$configDir\"" \
--add-flags "-fs_basepath \"${base}/share/soldat\""
done
runHook postInstall
'';
meta = with lib; {
@ -106,7 +86,7 @@ stdenv.mkDerivation rec {
license = [ licenses.mit base.meta.license ];
inherit (src.meta) homepage;
maintainers = [ maintainers.sternenseemann ];
platforms = platforms.x86_64 ++ platforms.i686;
platforms = [ "x86_64-linux" "i686-linux" ];
# portability currently mainly limited by fpc
# in nixpkgs which doesn't work on darwin,
# aarch64 and arm support should be possible:

View File

@ -0,0 +1,14 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1084048..1ea4c84 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -143,7 +143,8 @@ if(BUILD_CLIENT OR BUILD_SERVER)
file(WRITE ${PROJECT_BINARY_DIR}/bin/steam_appid.txt "638490")
else()
# GameNetworkingSockets
- add_subdirectory(shared/libs/GameNetworkingSockets)
+ # add_subdirectory(shared/libs/GameNetworkingSockets)
+ find_package(GameNetworkingSockets REQUIRED)
endif()
endif()