build: fix finding SDL2 on vcpkg (again)

Sometimes vcpkg calls the SDL2 library SDL2-static for static toolchains
and sometimes it doesn't, change FindSDL2.cmake to search some possible
library names in order of priority.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2022-11-27 19:31:52 +00:00
parent 1a687e564b
commit 5807376fba
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
1 changed files with 19 additions and 7 deletions

View File

@ -109,19 +109,31 @@ if(SDL2_STATIC)
endif()
endif()
unset(lib_suffix)
unset(lib_suffixes)
if(MSVC)
if(VCPKG_TARGET_TRIPLET MATCHES "-static$")
set(lib_suffix "${lib_suffix}-static")
list(APPEND lib_suffixes -static)
endif()
if(CMAKE_BUILD_TYPE MATCHES "^(Debug|RelWithDebInfo)$")
set(lib_suffix "${lib_suffix}d")
list(APPEND lib_suffixes d)
endif()
endif()
# Calculate combination of possible name+suffixes.
unset(names)
set(lib_name SDL2)
set(current ${lib_name})
foreach(suffix ${lib_suffixes})
list(APPEND names "${current}${suffix}" "${lib_name}${suffix}")
set(current "${current}${suffix}")
endforeach()
# Fallback to name by itself.
list(APPEND names ${lib_name})
FIND_LIBRARY(SDL2_LIBRARY_TEMP
NAMES SDL2${lib_suffix}
NAMES ${names}
HINTS $ENV{SDL2DIR}
PATH_SUFFIXES lib64 lib lib/x64 lib/x86
PATHS ${SDL2_SEARCH_PATHS}