diff options
author | Patric Stout <truebrain@openttd.org> | 2021-02-27 00:34:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-27 00:34:41 +0100 |
commit | dc7ba33b515c83ec0ebd9cb1789fd20294dee4ec (patch) | |
tree | a7e35407b06388a628b565b8f16de785a77bbea8 /CMakeLists.txt | |
parent | d068d61f3c412b4e146d5665c17bcbc01acffa1e (diff) | |
download | openttd-dc7ba33b515c83ec0ebd9cb1789fd20294dee4ec.tar.xz |
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.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 74692d970..8482be6ed 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) |