This fixes linking to SDL2::SDL2-static on systems where external libraries such as X11 are not in a standard location.
Pthread also needs special care.
When SDL is built with Wayland support on Linux, and Wayland libraries
are linked as dependencies instead of being loaded with dlopen(), its
dependencies will include libraries whose names contain a dash, like
`-lwayland-client` and `-ldecor-0`. Don't replace such libraries with
`-lwayland` and `-ldecor`: those don't exist and linking them will fail.
Signed-off-by: Simon McVittie <smcv@collabora.com>
It didn't work at all because shared libs defined in CMake with
add_library() need something like IMPORTED_IMPLIB (pointing to a .dll.a
or .lib for th DLLs) set to link on Windows.
But even with that it didn't work because the order of the libs is very
important: it must be -lmingw32 -lSDL2main -lSDL -mwindows - but
with normal add_library(SDL2::SDL2 SHARED IMPORTED) libs, SDL2 itself
is always linked first.
So I use an "INTERFACE" library (usually used for header-only libs), which
doesn't implicitly/automatically link anything so I can specify the whole
order of the linked libs.
(SDL2::SDL2-static is completely untested)
this makes it easier to create a portable sdl2-config.cmake that doesn't
hardcode its path (by replacing the hardcoded prefix with something
like "${CMAKE_CURRENT_LIST_DIR}/../../..")
A project being built entirely statically will call pkg-config with
--static, which utilises the Libs.private field. Conversely it will
not use --static when not being built entirely statically, even if
there is only a static build of SDL available. This will most likely
cause the build to fail due to underlinking unless we merge the Libs
fields.
This is what the Meson build system does when it generates pkg-config
files. This also also follows the behaviour of sdl2-config.
At the same time, the runtime linker flags are not applicable to
static-only builds so only add them for shared builds.