Unverified Commit a58b98e9 authored by Fernando Rodrigues's avatar Fernando Rodrigues
Browse files

openmw: refactor



The usual code modernisation (finalAttrs, no with lib; in meta, no pname interpolation), and CMAKE variables now use lib.cmake*.

Signed-off-by: default avatarFernando Rodrigues <alpha@sigmasquadron.net>
parent c1d08345
Loading
Loading
Loading
Loading
+149 −0
Original line number Diff line number Diff line
@@ -8,42 +8,56 @@
  boost,
  bullet,
  cmake,
  collada-dom,
  ffmpeg,
  libXt,
  lua,
  luajit,
  lz4,
  mygui,
  openal,
  openscenegraph,
  pkg-config,
  qttools,
  qt6Packages,
  recastnavigation,
  unshield,
  wrapQtAppsHook,
  yaml-cpp,
}:

  GLPreference ? "GLVND",
}:
let
  GL = "GLVND"; # or "LEGACY";
  inherit (stdenv.hostPlatform) isDarwin isLinux isAarch64;
  isAarch64Linux = isLinux && isAarch64;
in
assert lib.assertOneOf "GLPreference" GLPreference [
  "GLVND"
  "LEGACY"
];
stdenv.mkDerivation (finalAttrs: {
  pname = "openmw";
  version = "0.49.0";

  __structuredAttrs = true;
  strictDeps = true;

  osg' = (openscenegraph.override { colladaSupport = true; }).overrideDerivation (old: {
    patches = [
  osg' = (openscenegraph.override { colladaSupport = true; }).overrideAttrs (oldAttrs: {
    patches = (oldAttrs.patches or [ ]) ++ [
      (fetchpatch {
        # Darwin: Without this patch, OSG won't build osgdb_png.so, which is required by OpenMW.
        name = "darwin-osg-plugins-fix.patch";
        url = "https://gitlab.com/OpenMW/openmw-dep/-/raw/1305497c009dc0e7a6a70fe14f0a2f92b96cbcb4/macos/osg.patch";
        sha256 = "sha256-G8Y+fnR6FRGxECWrei/Ixch3A3PkRfH6b5q9iawsSCY=";
        hash = "sha256-G8Y+fnR6FRGxECWrei/Ixch3A3PkRfH6b5q9iawsSCY=";
      })
    ];
    cmakeFlags =
      (old.cmakeFlags or [ ])
      (oldAttrs.cmakeFlags or [ ])
      ++ [
        "-Wno-dev"
        "-DOpenGL_GL_PREFERENCE=${GL}"
        "-DBUILD_OSG_PLUGINS_BY_DEFAULT=0"
        "-DBUILD_OSG_DEPRECATED_SERIALIZERS=0"
        (lib.cmakeFeature "OpenGL_GL_PREFERENCE" GLPreference)
        (lib.cmakeBool "BUILD_OSG_PLUGINS_BY_DEFAULT" false)
        (lib.cmakeBool "BUILD_OSG_DEPRECATED_SERIALIZERS" false)
      ]
      ++ (map (e: "-DBUILD_OSG_PLUGIN_${e}=1") [
      ++ (map (plugin: lib.cmakeBool "BUILD_OSG_PLUGIN_${plugin}" true) [
        "BMP"
        "DAE"
        "DDS"
@@ -55,76 +69,81 @@ let
      ]);
  });

  bullet' = bullet.overrideDerivation (old: {
    cmakeFlags = (old.cmakeFlags or [ ]) ++ [
  bullet' = bullet.overrideAttrs (oldAttrs: {
    cmakeFlags = (oldAttrs.cmakeFlags or [ ]) ++ [
      "-Wno-dev"
      "-DOpenGL_GL_PREFERENCE=${GL}"
      "-DUSE_DOUBLE_PRECISION=ON"
      "-DBULLET2_MULTITHREADING=ON"
      (lib.cmakeFeature "OpenGL_GL_PREFERENCE" GLPreference)
      (lib.cmakeBool "USE_DOUBLE_PRECISION" true)
      (lib.cmakeBool "BULLET2_MULTITHREADING" true)
    ];
  });

in
stdenv.mkDerivation rec {
  pname = "openmw";
  version = "0.49.0";

  src = fetchFromGitLab {
    owner = "OpenMW";
    repo = "openmw";
    rev = "${pname}-${version}";
    tag = "openmw-${finalAttrs.version}";
    hash = "sha256-Eyjn3jPpo0d7XENg0Ea/3MN60lZBSUAMkz1UtTiIP80=";
  };

  postPatch = ''
    sed '1i#include <memory>' -i components/myguiplatform/myguidatamanager.cpp # gcc12
  ''
  + lib.optionalString stdenv.hostPlatform.isDarwin ''
  # Don't fix Darwin app bundle
  + lib.optionalString isDarwin ''
    sed -i '/fixup_bundle/d' CMakeLists.txt
  '';

  nativeBuildInputs = [
    cmake
    pkg-config
  ]
  ++ (with qt6Packages; [
    wrapQtAppsHook
  ];
  ]);

  # If not set, OSG plugin .so files become shell scripts on Darwin.
  dontWrapQtApps = stdenv.hostPlatform.isDarwin;
  dontWrapQtApps = isDarwin;

  buildInputs = [
    SDL2
    boost
    bullet'
    collada-dom
    ffmpeg
    libXt
    luajit
    (if isAarch64Linux then lua else luajit)
    lz4
    mygui
    openal
    osg'
    qttools
    recastnavigation
    unshield
    yaml-cpp
  ];
  ]
  ++ (with qt6Packages; [
    qttools
  ])
  ++ (with finalAttrs; [
    bullet'
    osg'
  ]);

  cmakeFlags = [
    "-DOpenGL_GL_PREFERENCE=${GL}"
    "-DOPENMW_USE_SYSTEM_RECASTNAVIGATION=1"
  ]
  ++ lib.optionals stdenv.hostPlatform.isDarwin [
    "-DOPENMW_OSX_DEPLOYMENT=ON"
    (lib.cmakeFeature "OpenGL_GL_PREFERENCE" GLPreference)
    (lib.cmakeBool "USE_LUAJIT" (!isAarch64Linux))
    (lib.cmakeBool "OPENMW_USE_SYSTEM_RECASTNAVIGATION" true)
    (lib.cmakeBool "OPENMW_OSX_DEPLOYMENT" isDarwin)
  ];

  meta = with lib; {
  meta = {
    description = "Unofficial open source engine reimplementation of the game Morrowind";
    changelog = "https://gitlab.com/OpenMW/openmw/-/blob/${finalAttrs.src.tag}/CHANGELOG.md";
    homepage = "https://openmw.org";
    license = licenses.gpl3Plus;
    maintainers = with maintainers; [
    license = lib.licenses.gpl3Plus;
    maintainers = with lib.maintainers; [
      marius851000
      sigmasquadron
    ];
    platforms = platforms.linux ++ platforms.darwin;
    platforms = with lib.platforms; linux ++ darwin ++ windows;
    # Nixpkgs' NT infrastructure is currently incapable of building this.
    badPlatforms = lib.platforms.windows;
  };
}
})
+1 −3
Original line number Diff line number Diff line
@@ -14124,9 +14124,7 @@ with pkgs;

  openloco = pkgsi686Linux.callPackage ../games/openloco { };

  openmw = libsForQt5.callPackage ../games/openmw { };

  openmw-tes3mp = libsForQt5.callPackage ../games/openmw/tes3mp.nix { };
  openmw-tes3mp = libsForQt5.callPackage ../games/tes3mp { };

  openraPackages_2019 = import ../games/openra_2019 {
    inherit lib;
Loading