From 953a49f3ac9accd92c2f7a9f69a75e9ae1b48fab Mon Sep 17 00:00:00 2001
From: Dimitry Ishenko <dimitry.ishenko@gmail.com>
Date: Wed, 13 May 2026 16:13:13 -0400
Subject: [PATCH 2/4] Patch CMakeLists.txt

Upstream patch: https://github.com/nigels-com/glew/pull/478
---
 .../0005-CMakeLists.txt-fix-linking.patch     | 89 +++++++++++++++++++
 debian/patches/series                         |  1 +
 2 files changed, 90 insertions(+)
 create mode 100644 debian/patches/0005-CMakeLists.txt-fix-linking.patch

diff --git a/debian/patches/0005-CMakeLists.txt-fix-linking.patch b/debian/patches/0005-CMakeLists.txt-fix-linking.patch
new file mode 100644
index 0000000..c56f5d9
--- /dev/null
+++ b/debian/patches/0005-CMakeLists.txt-fix-linking.patch
@@ -0,0 +1,89 @@
+From dcd1d5686d061bdd3731bb11b5462baf50d36973 Mon Sep 17 00:00:00 2001
+From: Dimitry Ishenko <dimitry.ishenko@gmail.com>
+Date: Wed, 13 May 2026 16:03:15 -0400
+Subject: [PATCH] CMakeLists.txt: fix linking
+
+- Replaced legacy `LINK_PUBLIC` and `LINK_PRIVATE` with plain `PUBLIC`
+  and `PRIVATE` keywords. Ref:
+
+  https://cmake.org/cmake/help/latest/command/target_link_libraries.html#libraries-for-a-target-and-or-its-dependents-legacy
+
+- Changed linking from PUBLIC to PRIVATE to prevent GLEW dependencies
+  from spillng to the outside world (and being injected into the CMake
+  targets), which is causing build failures on Debian:
+
+  https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1136422
+
+- Fixed linking of glewinfo and visualinfo.
+---
+ build/cmake/CMakeLists.txt | 21 ++++++++++++---------
+ 1 file changed, 12 insertions(+), 9 deletions(-)
+
+diff --git a/build/cmake/CMakeLists.txt b/build/cmake/CMakeLists.txt
+index 7b7f8b4..c29d987 100644
+--- a/build/cmake/CMakeLists.txt
++++ b/build/cmake/CMakeLists.txt
+@@ -121,22 +121,22 @@ if (MSVC AND NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
+   target_compile_definitions (glew PRIVATE "GLEW_BUILD;VC_EXTRALEAN")
+   target_compile_definitions (glew_s PRIVATE "GLEW_STATIC;VC_EXTRALEAN")
+   if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i?86|x86|x86_32)$")
+-	  target_link_libraries (glew LINK_PRIVATE -BASE:0x62AA0000)
++	  target_link_libraries (glew PRIVATE -BASE:0x62AA0000)
+   endif()
+   # kill security checks which are dependent on stdlib
+   target_compile_options (glew PRIVATE -GS-)
+   target_compile_options (glew_s PRIVATE -GS-)
+   # remove stdlib dependency
+-  target_link_libraries (glew LINK_PRIVATE -nodefaultlib -noentry)
+-  target_link_libraries (glew LINK_PRIVATE libvcruntime.lib)
+-  target_link_libraries (glew LINK_PRIVATE msvcrt.lib )
++  target_link_libraries (glew PRIVATE -nodefaultlib -noentry)
++  target_link_libraries (glew PRIVATE libvcruntime.lib)
++  target_link_libraries (glew PRIVATE msvcrt.lib )
+   string(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
+ elseif (WIN32 AND ((CMAKE_C_COMPILER_ID MATCHES "GNU") OR (CMAKE_C_COMPILER_ID MATCHES "Clang")))
+   # remove stdlib dependency on windows with GCC and Clang (for similar reasons
+   # as to MSVC - to allow it to be used with any Windows compiler)
+   target_compile_options (glew PRIVATE -fno-builtin -fno-stack-protector)
+   target_compile_options (glew_s PRIVATE -fno-builtin -fno-stack-protector)
+-  target_link_libraries (glew LINK_PRIVATE -nostdlib)
++  target_link_libraries (glew PRIVATE -nostdlib)
+ endif ()
+ 
+ if (BUILD_FRAMEWORK)
+@@ -152,8 +152,8 @@ if (BUILD_FRAMEWORK)
+   )
+ endif()
+ 
+-target_link_libraries (glew LINK_PUBLIC ${GLEW_LIBRARIES})
+-target_link_libraries (glew_s ${GLEW_LIBRARIES})
++target_link_libraries (glew PRIVATE ${GLEW_LIBRARIES})
++target_link_libraries (glew_s PUBLIC ${GLEW_LIBRARIES})
+ 
+ target_compile_definitions(glew_s INTERFACE "GLEW_STATIC")
+ foreach(t glew glew_s)
+@@ -191,8 +191,11 @@ if (BUILD_UTILS)
+      target_link_libraries (glewinfo glew_s)
+   endif()
+   if (NOT WIN32)
+-    target_link_libraries(glewinfo ${X11_LIBRARIES})
++    target_link_libraries(glewinfo ${X11_LIBRARIES} ${GLEW_LIBRARIES})
+   endif ()
++  if (GLEW_EGL)
++    target_link_libraries(glewinfo ${OPENGL_egl_LIBRARY})
++  endif()
+ 
+   set (VISUALINFO_SRC_FILES ${GLEW_DIR}/src/visualinfo.c)
+   if (WIN32)
+@@ -205,7 +208,7 @@ if (BUILD_UTILS)
+      target_link_libraries (visualinfo glew_s)
+   endif()
+   if (NOT WIN32)
+-    target_link_libraries(visualinfo ${X11_LIBRARIES})
++    target_link_libraries(visualinfo ${X11_LIBRARIES} ${GLEW_LIBRARIES})
+   endif ()
+ 
+   install ( TARGETS glewinfo visualinfo
+-- 
+2.53.0
+
diff --git a/debian/patches/series b/debian/patches/series
index d37140f..68b76d7 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -2,3 +2,4 @@
 # 0002-Fix_pkgconfig_path.patch
 # 0003-Fix_glex-moved-header.patch
 0004-glew.pc.in-make-includedir-configurable.patch
+0005-CMakeLists.txt-fix-linking.patch
-- 
2.53.0

