From dc7ba33b515c83ec0ebd9cb1789fd20294dee4ec Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 27 Feb 2021 00:34:41 +0100 Subject: [PATCH] Fix: don't link to OpenGL with SDL2 as backend; SDL2 dynamically loads it (#8745) Although for developers this doesn't change anything, for our linux-generic binary it changes everything. Without this, the OpenGL dynamic library is dragged in as dependency, and as it depends on X11, that will be dragged in too. This is not something we prefer to have, as that won't run on as many machines as it could. SDL2 doesn't depend on OpenGL directly, as it tries to load it in on runtime. If found, it would work in exactly the same way as if we would link to OpenGL ourselves. As such, this is the best of both worlds: our linux-generics have less linked dependencies, and developers won't notice any difference. As a side-effect, if someone uses linux-generic on a machine that does not have any OpenGL package installed, it will gracefully fall back to the default backend of SDL instead. --- CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 74692d970e..8482be6ede 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -249,7 +249,16 @@ if(NOT OPTION_DEDICATED) link_package(Fontconfig TARGET Fontconfig::Fontconfig) link_package(ICU_lx) link_package(ICU_i18n) - link_package(OpenGL TARGET OpenGL::GL) + + if(SDL2_FOUND AND OPENGL_FOUND AND UNIX) + # SDL2 dynamically loads OpenGL if needed, so do not link to OpenGL when + # on Linux. For Windows, we need to link to OpenGL as we also have a win32 + # driver using it. + add_definitions(-DWITH_OPENGL) + message(STATUS "OpenGL found -- -DWITH_OPENGL -- (via SDL2)") + else() + link_package(OpenGL TARGET OpenGL::GL) + endif() endif() if(APPLE)