glfw3: general improvements (#358007)

This commit is contained in:
Sefa Eyeoglu 2024-11-23 18:58:15 +01:00 committed by GitHub
commit 9ef8694ce2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 82 additions and 62 deletions

View File

@ -1,24 +1,25 @@
{ stdenv {
, lib stdenv,
, fetchFromGitHub lib,
, cmake fetchFromGitHub,
, pkg-config cmake,
, libGL pkg-config,
, vulkan-loader libGL,
, libXrandr vulkan-loader,
, libXinerama libXrandr,
, libXcursor libXinerama,
, libX11 libXcursor,
, libXi libX11,
, libXext libXi,
, darwin libXext,
, fixDarwinDylibNames libXxf86vm,
, wayland fixDarwinDylibNames,
, wayland-scanner wayland,
, wayland-protocols wayland-scanner,
, libxkbcommon wayland-protocols,
, libdecor libxkbcommon,
, withMinecraftPatch ? false libdecor,
withMinecraftPatch ? false,
}: }:
let let
version = "3.4"; version = "3.4";
@ -35,59 +36,75 @@ stdenv.mkDerivation {
}; };
# Fix linkage issues on X11 (https://github.com/NixOS/nixpkgs/issues/142583) # Fix linkage issues on X11 (https://github.com/NixOS/nixpkgs/issues/142583)
patches = [ patches =
./x11.patch [
] ++ lib.optionals withMinecraftPatch [ ./x11.patch
./0009-Defer-setting-cursor-position-until-the-cursor-is-lo.patch ]
]; ++ lib.optionals withMinecraftPatch [
./0009-Defer-setting-cursor-position-until-the-cursor-is-lo.patch
];
propagatedBuildInputs = lib.optionals (!stdenv.hostPlatform.isWindows) [ libGL ]; propagatedBuildInputs = lib.optionals (!stdenv.hostPlatform.isWindows) [ libGL ];
nativeBuildInputs = [ cmake pkg-config ] nativeBuildInputs =
[
cmake
pkg-config
]
++ lib.optionals stdenv.hostPlatform.isDarwin [ fixDarwinDylibNames ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ fixDarwinDylibNames ]
++ lib.optionals stdenv.hostPlatform.isLinux [ wayland-scanner ]; ++ lib.optionals stdenv.hostPlatform.isLinux [ wayland-scanner ];
buildInputs = buildInputs = lib.optionals stdenv.hostPlatform.isLinux [
lib.optionals stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [ Carbon Cocoa Kernel ]) wayland
++ lib.optionals stdenv.hostPlatform.isLinux [ wayland-protocols
wayland libxkbcommon
wayland-protocols libX11
libxkbcommon libXrandr
libX11 libXinerama
libXrandr libXcursor
libXinerama libXi
libXcursor libXext
libXi libXxf86vm
libXext
];
cmakeFlags = [
"-DBUILD_SHARED_LIBS=ON"
] ++ lib.optionals (!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isWindows) [
"-DCMAKE_C_FLAGS=-D_GLFW_GLX_LIBRARY='\"${lib.getLib libGL}/lib/libGL.so.1\"'"
"-DCMAKE_C_FLAGS=-D_GLFW_EGL_LIBRARY='\"${lib.getLib libGL}/lib/libEGL.so.1\"'"
"-DCMAKE_C_FLAGS=-D_GLFW_VULKAN_LIBRARY='\"${lib.getLib vulkan-loader}/lib/libvulkan.so.1\"'"
]; ];
postPatch = lib.optionalString stdenv.hostPlatform.isLinux '' postPatch = lib.optionalString stdenv.hostPlatform.isLinux ''
substituteInPlace src/wl_init.c \ substituteInPlace src/wl_init.c \
--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 "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-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-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"' \
--replace-fail "libwayland-egl.so.1" "${lib.getLib wayland}/lib/libwayland-egl.so.1" --replace-fail '"libxkbcommon.so.0"' '"${lib.getLib libxkbcommon}/lib/libxkbcommon.so.0"'
''; '';
# glfw may dlopen libwayland-client.so: cmakeFlags = [
postFixup = lib.optionalString stdenv.hostPlatform.isLinux '' # Static linking isn't supported
patchelf ''${!outputLib}/lib/libglfw.so --add-rpath ${lib.getLib wayland}/lib (lib.cmakeBool "BUILD_SHARED_LIBS" true)
''; ];
meta = with lib; { env = lib.optionalAttrs (!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isWindows) {
NIX_CFLAGS_COMPILE = toString [
"-D_GLFW_GLX_LIBRARY=\"${lib.getLib libGL}/lib/libGLX.so.0\""
"-D_GLFW_EGL_LIBRARY=\"${lib.getLib libGL}/lib/libEGL.so.1\""
"-D_GLFW_OPENGL_LIBRARY=\"${lib.getLib libGL}/lib/libGL.so.1\""
"-D_GLFW_GLESV1_LIBRARY=\"${lib.getLib libGL}/lib/libGLESv1_CM.so.1\""
"-D_GLFW_GLESV2_LIBRARY=\"${lib.getLib libGL}/lib/libGLESv2.so.2\""
"-D_GLFW_VULKAN_LIBRARY=\"${lib.getLib vulkan-loader}/lib/libvulkan.so.1\""
# This currently omits _GLFW_OSMESA_LIBRARY. Is it even used?
];
};
strictDeps = true;
__structuredAttrs = true;
meta = {
description = "Multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time"; description = "Multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time";
homepage = "https://www.glfw.org/"; homepage = "https://www.glfw.org/";
license = licenses.zlib; license = lib.licenses.zlib;
maintainers = with maintainers; [ marcweber Scrumplex twey ]; maintainers = with lib.maintainers; [
platforms = platforms.unix ++ platforms.windows; marcweber
Scrumplex
twey
];
platforms = lib.platforms.unix ++ lib.platforms.windows;
}; };
} }

View File

@ -2,17 +2,20 @@ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a0be580e..ba143851 100644 index a0be580e..ba143851 100644
--- a/src/CMakeLists.txt --- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt +++ b/src/CMakeLists.txt
@@ -219,6 +219,13 @@ if (GLFW_BUILD_X11) @@ -219,6 +219,16 @@ if (GLFW_BUILD_X11)
if (NOT X11_Xshape_INCLUDE_PATH) if (NOT X11_Xshape_INCLUDE_PATH)
message(FATAL_ERROR "X Shape headers not found; install libxext development package") message(FATAL_ERROR "X Shape headers not found; install libxext development package")
endif() endif()
+ +
+ target_link_libraries(glfw PRIVATE ${X11_Xrandr_LIB} + target_link_libraries(glfw PRIVATE ${X11_Xrandr_LIB}
+ ${X11_Xinerama_LIB} + ${X11_Xinerama_LIB}
+ ${X11_X11_xcb_LIB}
+ ${X11_Xrender_LIB}
+ ${X11_Xkb_LIB} + ${X11_Xkb_LIB}
+ ${X11_Xcursor_LIB} + ${X11_Xcursor_LIB}
+ ${X11_Xi_LIB} + ${X11_Xi_LIB}
+ ${X11_Xshape_LIB}) + ${X11_Xxf86vm_LIB}
+ ${X11_Xext_LIB})
endif() endif()
if (UNIX AND NOT APPLE) if (UNIX AND NOT APPLE)