FindOpenGL: Weird assumptions about OpenGL and EGL
I was building wxGTK 3.2 (which uses cmake) on NetBSD 9.2, and one of the libraries which it creates was erroneously not linked with libEGL. In an issue with the wxWidgets project at https://github.com/wxWidgets/wxWidgets/issues/22841 it was discovered that this is because of a problem with cmake. Cmake apparently makes all kinds of weird assumptions about GL and EGL that are simply not true, at least for NetBSD. The direct issue here is that it seems to think that libEGL only exists/is usable if you have libOpenGL, and not if you have libGL. Guess which one of those is present on NetBSD? Not the one that cmake expects.
I could fix the issue with this patch:
--- /usr/pkg/share/cmake-3.23/Modules/FindOpenGL.cmake 2022-05-25 15:42:51.000000000 +0200
+++ /tmp/FindOpenGL.cmake 2022-10-03 16:48:39.590200453 +0200
@@ -515,12 +515,7 @@
"${OPENGL_INCLUDE_DIR}")
endif()
- # ::EGL is a GLVND library, and thus Linux-only: we don't bother checking
- # for a framework version of this library.
- # Note we test for OpenGL::OpenGL as a target. When this module is updated to
- # support GLES, we would additionally want to check for the hypothetical GLES
- # target and enable EGL if either ::GLES or ::OpenGL is created.
- if(TARGET OpenGL::OpenGL AND OpenGL_EGL_FOUND AND NOT TARGET OpenGL::EGL)
+ if(TARGET OpenGL::GL AND OpenGL_EGL_FOUND AND NOT TARGET OpenGL::EGL)
if(IS_ABSOLUTE "${OPENGL_egl_LIBRARY}")
add_library(OpenGL::EGL UNKNOWN IMPORTED)
set_target_properties(OpenGL::EGL PROPERTIES IMPORTED_LOCATION
@@ -531,7 +526,7 @@
"${OPENGL_egl_LIBRARY}")
endif()
set_target_properties(OpenGL::EGL PROPERTIES INTERFACE_LINK_LIBRARIES
- OpenGL::OpenGL)
+ OpenGL::GL)
# Note that EGL's include directory is different from OpenGL/GLX's!
set_target_properties(OpenGL::EGL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${OPENGL_EGL_INCLUDE_DIR}")
I don't know why there is a dependency on libGL or libOpenGL anyway, since libEGL doesn't link with either of them:
$ ldd /usr/pkg/lib/libEGL.so.1.0.0
/usr/pkg/lib/libEGL.so.1.0.0:
-lgbm.1 => /usr/pkg/lib/libgbm.so.1
-ldrm.2 => /usr/pkg/lib/libdrm.so.2
-lpci.2 => /usr/lib/libpci.so.2
-lc.12 => /usr/lib/libc.so.12
-lexpat.2 => /usr/lib/libexpat.so.2
-lstdc++.7 => /usr/pkg/gcc8/x86_64--netbsd/lib/./libstdc++.so.7
-lm.0 => /usr/lib/libm.so.0
-lgcc_s.1 => /usr/lib/libgcc_s.so.1
-lpthread.1 => /usr/lib/libpthread.so.1
-lglapi.0 => /usr/pkg/lib/libglapi.so.0
-lX11-xcb.1 => /usr/X11R7/lib/libX11-xcb.so.1
-lX11.7 => /usr/X11R7/lib/libX11.so.7
-lxcb.2 => /usr/X11R7/lib/libxcb.so.2
-lXau.7 => /usr/X11R7/lib/libXau.so.7
-lXdmcp.7 => /usr/X11R7/lib/libXdmcp.so.7
-lxcb-dri2.0 => /usr/X11R7/lib/libxcb-dri2.so.0
-lxcb-xfixes.0 => /usr/X11R7/lib/libxcb-xfixes.so.0
-lxcb-dri3.0 => /usr/X11R7/lib/libxcb-dri3.so.0
-lxcb-present.0 => /usr/X11R7/lib/libxcb-present.so.0
-lxcb-sync.1 => /usr/X11R7/lib/libxcb-sync.so.1
-lxshmfence.1 => /usr/X11R7/lib/libxshmfence.so.1
-lrt.1 => /usr/lib/librt.so.1
Because of that I suspect that I could remove the whole set_target_properties(OpenGL::EGL PROPERTIES INTERFACE_LINK_LIBRARIES
thing, but since I'm not well versed in cmake I'm not sure.