Bug 250739 - games/widelands: fails to build with libglvnd
Summary: games/widelands: fails to build with libglvnd
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Dmitry Marakasov
URL: https://reviews.freebsd.org/P450
Keywords: needs-patch
Depends on:
Blocks: 246767
  Show dependency treegraph
 
Reported: 2020-10-30 10:39 UTC by Jan Beich
Modified: 2020-10-31 08:57 UTC (History)
0 users

See Also:
amdmi3: maintainer-feedback+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Beich freebsd_committer 2020-10-30 10:39:00 UTC
Apply review D25020 then notice build fails (see URL for poudriere log). Replacing files/patch-CMakeLists.txt with USES=localbase:ldflags fixes the build.

-- Found OpenGL: /usr/local/lib/libOpenGL.so
[...]
FAILED: src/io/filesystem/test/test_io_filesystem 
ld: error: undefined symbol: glReadPixels
>>> referenced by screen.cc
>>>               screen.cc.o:(Screen::to_texture() const) in archive src/graphic/libgraphic_surface.a

ld: error: undefined symbol: glGenTextures
>>> referenced by texture.cc
>>>               texture.cc.o:(Texture::Texture(int, int)) in archive src/graphic/libgraphic_surface.a

ld: error: undefined symbol: glTexParameteri
>>> referenced by texture.cc
>>>               texture.cc.o:(Texture::Texture(int, int)) in archive src/graphic/libgraphic_surface.a

ld: error: undefined symbol: glTexParameteri
>>> referenced by texture.cc
>>>               texture.cc.o:(Texture::Texture(int, int)) in archive src/graphic/libgraphic_surface.a

ld: error: undefined symbol: glTexImage2D
>>> referenced by texture.cc
>>>               texture.cc.o:(Texture::Texture(int, int)) in archive src/graphic/libgraphic_surface.a

ld: error: undefined symbol: glGenTextures
>>> referenced by texture.cc
>>>               texture.cc.o:(Texture::init(unsigned short, unsigned short)) in archive src/graphic/libgraphic_surface.a
[...]

$ grep -i OPENGL.\*LIBRARY.\*so $(make -V BUILD_WRKSRC)/CMakeCache.txt
OPENGL_egl_LIBRARY:FILEPATH=/usr/local/lib/libEGL.so
OPENGL_glu_LIBRARY:FILEPATH=/usr/local/lib/libGLU.so
OPENGL_glx_LIBRARY:FILEPATH=/usr/local/lib/libGLX.so
OPENGL_opengl_LIBRARY:FILEPATH=/usr/local/lib/libOpenGL.so

$ pkg info -l libglvnd | grep '.so$' | xargs nm -A 2>&1 | fgrep 'T glReadPixels'
/usr/local/lib/libGL.so:0000000000072ac0 T glReadPixels
/usr/local/lib/libGLESv1_CM.so:0000000000006e40 T glReadPixels
/usr/local/lib/libGLESv2.so:000000000000e040 T glReadPixels
/usr/local/lib/libOpenGL.so:0000000000021620 T glReadPixels
Comment 1 Dmitry Marakasov freebsd_committer 2020-10-30 12:24:42 UTC
> Replacing files/patch-CMakeLists.txt with USES=localbase:ldflags fixes the build.

This doesn't seem like the correct solution

First, it degrades from the CMake's wonderful way of linking with precise library paths instead of bugprone -L/-l scheme back to the latter, and ignores all CMake machinery of correct opengl library detection, this is absolutely not acceptable.

You haven't provided any info on what glvnd is and how it is expected to work, but I've got some understanding from code and documentation of CMake's FindOpenGL.cmake (which has all the machinery for glvnd support), and it looks like the CMakeLists.txt patch in widelands should instead be fixed like this

-+  link_libraries(${OpenGL_GL_LIBRARY})
++  link_libraries(${OPENGL_opengl_LIBRARY})

(which should work for glvnd), or even better (which should work for both cases),

-+  link_libraries(${OpenGL_GL_LIBRARY})
++  link_libraries(OpenGL::GL)

I've just confirmed that the latter change works fine with the current mesa, so feel free to commit it along with adding glvnd support if it also works for you, or if that's confirmed I can commit it right away.

Note that linking with -lGL is not correct in either case, as it ignores glnvd completely. Also note that similar change of linking with OpenGL::GL may be needed for other CMake using ports, either to fix build or to use glvnd correctly.
Comment 2 Jan Beich freebsd_committer 2020-10-30 13:05:30 UTC
(In reply to Dmitry Marakasov from comment #1)
> You haven't provided any info on what glvnd is and how it is expected to work,

libglvnd wraps libGL and libEGL, allowing to switch between mesa-libs and nvidia-driver at runtime. After patching USE_GL=gl pulls libglvnd instead of mesa-libs.

See also https://gitlab.freedesktop.org/glvnd/libglvnd/-/blob/master/README.md#architecture

> -+  link_libraries(${OpenGL_GL_LIBRARY})
> ++  link_libraries(OpenGL::GL)

Works for me, see https://reviews.freebsd.org/P451
Comment 3 commit-hook freebsd_committer 2020-10-30 15:00:01 UTC
A commit references this bug:

Author: amdmi3
Date: Fri Oct 30 14:59:04 UTC 2020
New revision: 553695
URL: https://svnweb.freebsd.org/changeset/ports/553695

Log:
  Fix the way of linking with OpenGL, fixing compatibility with glvnd

  PR:		250739
  Reported by:	jbeich

Changes:
  head/games/widelands/files/patch-CMakeLists.txt
Comment 4 Dmitry Marakasov freebsd_committer 2020-10-30 15:00:50 UTC
> Works for me, see https://reviews.freebsd.org/P451

Great, I've committed the fix.

Out of curiocity, will we have to fix all the ports which still link with -lGL?
Comment 5 Jan Beich freebsd_committer 2020-10-30 16:28:40 UTC
(In reply to Dmitry Marakasov from comment #4)
While dogfooding libglvnd in poudriere I've fixed the few ports on-the-go. Finding and fixing the rest (mainly leaf ports) requires exp-run which got delayed.

https://freshbsd.org/search?committer=jbeich&q=libglvnd

For example, games/widelands and www/iridium were found while I was testing devel/icu consumers for review D27001.