Skip to content

Commit

Permalink
modules: make FindSDL2.cmake also find debug libraries.
Browse files Browse the repository at this point in the history
Fixes an issue with SDL2d.dll not being copied to the output directory
with vcpkg.
  • Loading branch information
Squareys authored and mosra committed Jun 16, 2018
1 parent 00c0aa4 commit 52b7c26
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions modules/FindSDL2.cmake
Expand Up @@ -10,6 +10,8 @@
# Additionally these variables are defined for internal usage:
#
# SDL2_LIBRARY - SDL2 library
# SDL2_LIBRARY_DEBUG - SDL2 debug library
# SDL2_LIBRARY_RELEASE - SDL2 release library
# SDL2_INCLUDE_DIR - Root include dir
#

Expand Down Expand Up @@ -50,16 +52,23 @@ else()
set(_SDL_LIBRARY_PATH_SUFFIX lib/x86)
endif()

find_library(SDL2_LIBRARY
find_library(SDL2_LIBRARY_RELEASE
# Compiling SDL2 from scratch on macOS creates dead libSDL2.so symlink
# which CMake somehow prefers before the SDL2-2.0.dylib file. Making
# the dylib first so it is preferred.
# the dylib first so it is preferred. Not sure how this maps to debug
# config though :/
NAMES SDL2-2.0 SDL2
PATH_SUFFIXES ${_SDL_LIBRARY_PATH_SUFFIX})
find_library(SDL2_LIBRARY_DEBUG
NAMES SDL2d
PATH_SUFFIXES ${_SDL_LIBRARY_PATH_SUFFIX})
set(SDL2_LIBRARY_NEEDED SDL2_LIBRARY)
set(_SDL2_PATH_SUFFIXES SDL2)
endif()

include(SelectLibraryConfigurations)
select_library_configurations(SDL2)

# Include dir
find_path(SDL2_INCLUDE_DIR
# We must search file which is present only in SDL2 and not in SDL1.
Expand Down Expand Up @@ -120,10 +129,19 @@ if(NOT TARGET SDL2::SDL2)

# Work around BUGGY framework support on macOS
# https://cmake.org/Bug/view.php?id=14105
if(CORRADE_TARGET_APPLE AND ${SDL2_LIBRARY} MATCHES "\\.framework$")
set_property(TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION ${SDL2_LIBRARY}/SDL2)
if(CORRADE_TARGET_APPLE AND SDL2_LIBRARY_RELEASE MATCHES "\\.framework$")
set_property(TARGET SDL2::SDL2 APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_property(TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION_RELEASE ${SDL2_LIBRARY_RELEASE}/SDL2)
else()
set_property(TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION ${SDL2_LIBRARY})
if(SDL2_LIBRARY_RELEASE)
set_property(TARGET SDL2::SDL2 APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_property(TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION_RELEASE ${SDL2_LIBRARY_RELEASE})
endif()

if(SDL2_LIBRARY_DEBUG)
set_property(TARGET SDL2::SDL2 APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_property(TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION_DEBUG ${SDL2_LIBRARY_DEBUG})
endif()
endif()

# Link additional `dl` and `pthread` libraries required by a static
Expand Down

0 comments on commit 52b7c26

Please sign in to comment.