2024-10-04 16:56:33 +00:00
|
|
|
{ stdenv, lib, fetchFromGitHub, cmake, pkg-config
|
2020-04-24 23:36:52 +00:00
|
|
|
, libGL, libXrandr, libXinerama, libXcursor, libX11, libXi, libXext
|
2024-09-19 14:19:46 +00:00
|
|
|
, darwin, fixDarwinDylibNames
|
2024-10-04 16:56:33 +00:00
|
|
|
, wayland
|
2024-07-27 06:49:29 +00:00
|
|
|
, wayland-scanner, wayland-protocols, libxkbcommon, libdecor
|
2024-09-19 14:19:46 +00:00
|
|
|
, withMinecraftPatch ? false
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
2024-09-19 14:19:46 +00:00
|
|
|
let
|
2024-05-15 15:35:15 +00:00
|
|
|
version = "3.4";
|
2024-09-19 14:19:46 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
pname = "glfw${lib.optionalString withMinecraftPatch "-minecraft"}";
|
|
|
|
inherit version;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "glfw";
|
|
|
|
repo = "GLFW";
|
|
|
|
rev = version;
|
2024-09-19 14:19:46 +00:00
|
|
|
hash = "sha256-FcnQPDeNHgov1Z07gjFze0VMz2diOrpbKZCsI96ngz0=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2022-04-15 01:41:22 +00:00
|
|
|
# Fix linkage issues on X11 (https://github.com/NixOS/nixpkgs/issues/142583)
|
2024-09-19 14:19:46 +00:00
|
|
|
patches = [
|
|
|
|
./x11.patch
|
|
|
|
] ++ lib.optionals withMinecraftPatch [
|
|
|
|
./0009-Defer-setting-cursor-position-until-the-cursor-is-lo.patch
|
|
|
|
];
|
2021-07-14 22:03:04 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
propagatedBuildInputs = lib.optionals (!stdenv.hostPlatform.isWindows) [ libGL ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-10-04 16:56:33 +00:00
|
|
|
nativeBuildInputs = [ cmake pkg-config ]
|
2024-09-26 11:04:55 +00:00
|
|
|
++ lib.optionals stdenv.hostPlatform.isDarwin [ fixDarwinDylibNames ]
|
|
|
|
++ lib.optionals stdenv.hostPlatform.isLinux [ wayland-scanner ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-07-14 22:03:04 +00:00
|
|
|
buildInputs =
|
2024-09-26 11:04:55 +00:00
|
|
|
lib.optionals stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [ Carbon Cocoa Kernel ])
|
|
|
|
++ lib.optionals stdenv.hostPlatform.isLinux [
|
2024-05-15 15:35:15 +00:00
|
|
|
wayland
|
|
|
|
wayland-protocols
|
|
|
|
libxkbcommon
|
|
|
|
libX11
|
|
|
|
libXrandr
|
|
|
|
libXinerama
|
|
|
|
libXcursor
|
|
|
|
libXi
|
|
|
|
libXext
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
cmakeFlags = [
|
|
|
|
"-DBUILD_SHARED_LIBS=ON"
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ lib.optionals (!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isWindows) [
|
2021-02-05 17:12:51 +00:00
|
|
|
"-DCMAKE_C_FLAGS=-D_GLFW_GLX_LIBRARY='\"${lib.getLib libGL}/lib/libGL.so.1\"'"
|
2021-07-14 22:03:04 +00:00
|
|
|
"-DCMAKE_C_FLAGS=-D_GLFW_EGL_LIBRARY='\"${lib.getLib libGL}/lib/libEGL.so.1\"'"
|
2021-02-05 17:12:51 +00:00
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-09-26 11:04:55 +00:00
|
|
|
postPatch = lib.optionalString stdenv.hostPlatform.isLinux ''
|
2021-07-14 22:03:04 +00:00
|
|
|
substituteInPlace src/wl_init.c \
|
2024-07-27 06:49:29 +00:00
|
|
|
--replace-fail "libxkbcommon.so.0" "${lib.getLib libxkbcommon}/lib/libxkbcommon.so.0" \
|
|
|
|
--replace-fail "libdecor-0.so.0" "${lib.getLib libdecor}/lib/libdecor-0.so.0" \
|
|
|
|
--replace-fail "libwayland-client.so.0" "${lib.getLib wayland}/lib/libwayland-client.so.0" \
|
|
|
|
--replace-fail "libwayland-cursor.so.0" "${lib.getLib wayland}/lib/libwayland-cursor.so.0" \
|
|
|
|
--replace-fail "libwayland-egl.so.1" "${lib.getLib wayland}/lib/libwayland-egl.so.1"
|
2021-07-14 22:03:04 +00:00
|
|
|
'';
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
# glfw may dlopen libwayland-client.so:
|
2024-09-26 11:04:55 +00:00
|
|
|
postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
|
2024-06-05 15:53:02 +00:00
|
|
|
patchelf ''${!outputLib}/lib/libglfw.so --add-rpath ${lib.getLib wayland}/lib
|
|
|
|
'';
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time";
|
|
|
|
homepage = "https://www.glfw.org/";
|
|
|
|
license = licenses.zlib;
|
2024-09-19 14:19:46 +00:00
|
|
|
maintainers = with maintainers; [ marcweber Scrumplex twey ];
|
2024-01-02 11:29:13 +00:00
|
|
|
platforms = platforms.unix ++ platforms.windows;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|