Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove FindSDL2 find-module, use sdl2-config.cmake instead
This requires SDL >= 2.0.4. Since <https://bugzilla.libsdl.org/show_bug.cgi?id=2464> was fixed in SDL 2.0.4, SDL behaves as a CMake "config-file package", even if it was not itself built using CMake: it installs a sdl2-config.cmake file to ${libdir}/cmake/SDL2, which tells CMake where to find SDL's headers and library, analogous to a pkg-config .pc file. As a result, we no longer need to copy/paste a "find-module package" to be able to find a system copy of SDL >= 2.0.4 with find_package(SDL2). Find-module packages are now discouraged by the CMake developers, in favour of having upstream projects behave as config-file packages. This results in a small API change: FindSDL2 used to set SDL2_INCLUDE_DIR and SDL2_LIBRARY, but the standard behaviour for config-file packages is to set <name>_INCLUDE_DIRS and <name>_LIBRARIES. Use the CONFIG keyword to make sure we search in config-file package mode, and will not find a FindSDL2.cmake in some other directory that implements the old interface. In addition to deleting redundant code, this avoids some assumptions in FindSDL2 about the layout of a SDL installation. The current libsdl2-dev package in Debian breaks those assumptions; this is considered a bug and will hopefully be fixed soon, but it illustrates how fragile these assumptions can be. We can be more robust against different installation layouts by relying on SDL's own CMake integration. When linking to a copy of CMake in a non-standard location, users can now set the SDL2_DIR or CMAKE_PREFIX_PATH environment variable to point to it; previously, these users would have used the SDL2DIR environment variable. This continues to be unnecessary if using matching system-wide installations of CMake and SDL2, for example both from Debian. Mitigates: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=951087 Signed-off-by: Simon McVittie <smcv@debian.org>
- Loading branch information
5203023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smcv This doesn't work out of the box on Arch/Manjaro. (SDL 2.0.12) CMake 3.17.3
SDL2_INCLUDE_DIRS not set SDL2_LIBRARIES not set. Using SDL2::SDL2 works but this is not backwards compatible with most travis-ci versions of CMake.
What steps are required for making it detect the SDL2 installation with sdl2-config. There is no --help only vague usage.
SDL2_DIR is set to /usr/lib32or64/cmake/SDL2 and contains
SDL2Config.cmake SDL2ConfigVersion.cmake SDL2Targets-noconfig.cmake SDL2Targets.cmake
5203023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ensiform Is this the distro's CMake and the distro's SDL package, or your own build of one or both of them?
If
/usr/lib32or64/cmake
is in the distro's CMake's search path, I would have expected thatfind_package(SDL2 REQUIRED CONFIG)
should work without setting special environment variables.Upstream SDL2 seems to install different files depending whether it was built with Autotools or CMake. Debian uses an Autotools build, which installs
.../cmake/sdl2-config.cmake
; yours seems to be a CMake build, which installs.../cmake/SDL2Config.cmake
. However,find_package(SDL2)
should find either of those interchangeably, so it should still work.Maybe
SDL2Config.cmake
, and the files it includes, don't define the same variables assdl2-config.cmake
? If true, that seems like a bug, either in the packaging you're using or in SDL2 upstream.If I'm reading the documentation correctly, I think you're meant to set
SDL2_DIR
to/usr
? But I don't know whether it will understandlib32or64
unless your CMake has been specially patched to do so.Current best-practice seems to be "don't"; pkg-config or the CMake module is preferred now. I think you'd have to reinstate a
FindSDL2.cmake
cargo-culted from other projects, which is now discouraged, and revert some or all of the changes I made in #1033.5203023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the official distro SDL2.
SDL2_DIR is correctly set to /usr/lib32/cmake/SDL2 if 32bit and lib64 if 64.
SDL2Config is just a one liner to include the targets file mentioned above and it does not seem to do anything with those variables. I'm not at home to paste the whole thing at this moment.
SDL2config.cmake:
SDL2Targets.cmake:
5203023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Mac, it seems like the SDL2 config file was generated using Autotools. I don't think the CMake-generated SDL2 config defines the
SDL2_*
variables ironically...5203023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like a bug in SDL? When built with CMake, it generates a config-module with less information.
5203023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What OS are you using for the Travis-CI build? Still bionic?
Ideally SDL would document which parts of the config-modules are "API" and which are implementation details, but at the moment it isn't clear. Perhaps
SDL::SDL
is the part you're meant to use, I don't know... since it isn't documented, I was going by what worked (when built with Autotools, but apparently not when built with CMake).5203023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks as though SDL2::SDL2 is the part that is meant to be "API", but unfortunately that was only added to SDL Autotools builds in SDL 2.0.12.
If you need to stay backwards-compatible with SDL 2.0.8 (Ubuntu 18.04), perhaps try something like this:
and then continue to use
SDL2_INCLUDE_DIRS
andSDL2_LIBRARIES
.5203023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bionic is too new. 16 and 14 are preferred for most backwards compatibility with dedicated server hosts.
Note: I realize this repo's is set to bionic but it probably shouldn't be. However xenial has 3.12.4 in it's Travis updates unless using docker, then it's the ancient version.