diff --git a/CMakeLists.txt b/CMakeLists.txt
index 77f369489d..e38befe435 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -148,6 +148,14 @@ set_package_properties(epoxy PROPERTIES DESCRIPTION "libepoxy"
PURPOSE "OpenGL dispatch library"
)
+set(HAVE_DL_LIBRARY FALSE)
+if(epoxy_HAS_GLX)
+ find_library(DL_LIBRARY dl)
+ if(DL_LIBRARY)
+ set(HAVE_DL_LIBRARY TRUE)
+ endif()
+endif()
+
find_package(Wayland 1.2 REQUIRED COMPONENTS Cursor OPTIONAL_COMPONENTS Egl)
set_package_properties(Wayland PROPERTIES
TYPE REQUIRED
@@ -573,11 +581,6 @@ target_link_libraries(kwin ${kwinLibs})
generate_export_header(kwin EXPORT_FILE_NAME kwin_export.h)
target_link_libraries(kwin kwinglutils ${epoxy_LIBRARY})
-# -ldl used by OpenGL code
-find_library(DL_LIBRARY dl)
-if (DL_LIBRARY)
-target_link_libraries(kwin ${DL_LIBRARY})
-endif()
kf5_add_kdeinit_executable(kwin_x11 main_x11.cpp)
target_link_libraries(kdeinit_kwin_x11 kwin KF5::Crash)
diff --git a/libkwineffects/kwinconfig.h.cmake b/libkwineffects/kwinconfig.h.cmake
index 0ac607e7c7..4718cf0aaf 100644
--- a/libkwineffects/kwinconfig.h.cmake
+++ b/libkwineffects/kwinconfig.h.cmake
@@ -21,5 +21,6 @@
#cmakedefine01 HAVE_EPOXY_GLX
+#cmakedefine01 HAVE_DL_LIBRARY
#endif
diff --git a/plugins/platforms/x11/standalone/CMakeLists.txt b/plugins/platforms/x11/standalone/CMakeLists.txt
index e7f8c56648..98daa12208 100644
--- a/plugins/platforms/x11/standalone/CMakeLists.txt
+++ b/plugins/platforms/x11/standalone/CMakeLists.txt
@@ -21,6 +21,10 @@ if(X11_Xinput_FOUND)
target_link_libraries(KWinX11Platform ${X11_Xinput_LIB})
endif()
+if(HAVE_DL_LIBRARY)
+ target_link_libraries(KWinX11Platform ${DL_LIBRARY})
+endif()
+
install(
TARGETS
KWinX11Platform
diff --git a/plugins/platforms/x11/standalone/glxbackend.cpp b/plugins/platforms/x11/standalone/glxbackend.cpp
index 59599acd64..fc988eca26 100644
--- a/plugins/platforms/x11/standalone/glxbackend.cpp
+++ b/plugins/platforms/x11/standalone/glxbackend.cpp
@@ -43,7 +43,9 @@ along with this program. If not, see .
#include
#include
+#if HAVE_DL_LIBRARY
#include
+#endif
#ifndef XCB_GLX_BUFFER_SWAP_COMPLETE
#define XCB_GLX_BUFFER_SWAP_COMPLETE 1
@@ -159,8 +161,10 @@ static glXFuncPtr getProcAddress(const char* name)
#if HAVE_EPOXY_GLX
ret = glXGetProcAddress((const GLubyte*) name);
#endif
+#if HAVE_DL_LIBRARY
if (ret == nullptr)
ret = (glXFuncPtr) dlsym(RTLD_DEFAULT, name);
+#endif
return ret;
}
glXSwapIntervalMESA_func glXSwapIntervalMESA;