# \[GNU/Linux\] \[Debian 12\] CMake fails to find OpenGL when MESA has been built without GLX support

**URL:** https://discourse.cmake.org/t/gnu-linux-debian-12-cmake-fails-to-find-opengl-when-mesa-has-been-built-without-glx-support/10901
**Category:** Usage
**Tags:** os:linux
**Created:** [May 24, 2024, 2:36pm UTC](https://discourse.cmake.org/t/gnu-linux-debian-12-cmake-fails-to-find-opengl-when-mesa-has-been-built-without-glx-support/10901 "2024-05-24T14:36:40Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![vanfanel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/v/9fc348/32.png) [@vanfanel](https://discourse.cmake.org/u/vanfanel)
#### Post date: [May 24, 2024, 2:36pm UTC](https://discourse.cmake.org/t/gnu-linux-debian-12-cmake-fails-to-find-opengl-when-mesa-has-been-built-without-glx-support/10901/1 "2024-05-24T14:36:40Z")

</div>

Hello there!

CMake (version included in Debian 12 and also latest stable cmake version 3.29.3) fails to find OpenGL when doing `find_package(OpenGL REQUIRED)` if MESA is built without GLX support:  
This is the error I get:

> CMake Error at /usr/local/lib/python3.11/dist-packages/cmake/data/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:230 (message):  
> Could NOT find OpenGL (missing: OPENGL\_glx\_LIBRARY)  
> Call Stack (most recent call first):  
> /usr/local/lib/python3.11/dist-packages/cmake/data/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:600 (\_FPHSA\_FAILURE\_MESSAGE)  
> /usr/local/lib/python3.11/dist-packages/cmake/data/share/cmake-3.29/Modules/FindOpenGL.cmake:579 (FIND\_PACKAGE\_HANDLE\_STANDARD\_ARGS)  
> cmake/ncine\_imported\_targets.cmake:210 (find\_package)  
> CMakeLists.txt:73 (include)

According to this doc, CMake should find the GLVND OpenGL implementation without any problems using `find_package(OpenGL REQUIRED)` → [https://cmake.org/cmake/help/latest/policy/CMP0072.html](https://cmake.org/cmake/help/latest/policy/CMP0072.html)

This is how my MESA build is configured:

```auto
meson setup -Dbuildtype=release -Dglx=disabled -Dplatforms=wayland \
-Dvulkan-drivers=intel -Dgallium-drivers=iris,kmsro,zink -Dglvnd=enabled ..

```

GLVND is in fact found by CMake if I do:

```auto
FIND_LIBRARY(OpenGL_LIBRARY OpenGL)
SET(EXTRA_LIBS ${OpenGL_LIBRARY})

```

…and CMake also links properly against GLVND OpenGL implementation if I do this:

```auto
target_link_libraries(${NCINE_APP} PUBLIC ${OpenGL_LIBRARY})

```

Any idea on WHY `find_package(OpenGL REQUIRED)` fails???

Many, many projects I use tend to do that, and I have to manually modify their CMake files and hack-in a solution, but I am almost sure this is on CMake.

---

<div class="post-metadata">

### Author: ![vanfanel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/v/9fc348/32.png) [@vanfanel](https://discourse.cmake.org/u/vanfanel)
#### Post date: [May 24, 2024, 2:49pm UTC](https://discourse.cmake.org/t/gnu-linux-debian-12-cmake-fails-to-find-opengl-when-mesa-has-been-built-without-glx-support/10901/2 "2024-05-24T14:49:36Z")

</div>

Also, it seems that doing this works:

```auto
set(OPENGL_USE_OPENGL ON)
find_package(OpenGL REQUIRED)

```

It seems to be because of this:

> <https://github.com/Kitware/CMake/blob/47ba19f346d03123c59ee5a3fe36d32a43b96359/Modules/FindOpenGL.cmake#L455>

…but that contradicts CMake docs in that `set(OPENGL_USE_OPENGL ON)` shouldn’t be needed when GLVND is installed because GLVND whould be preferred instead of legacy GLX.
