/
FindSDL2Libs.cmake
93 lines (80 loc) · 3.07 KB
/
FindSDL2Libs.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
find_package (PkgConfig QUIET)
macro (target_link_sdl2 target vis)
if (TARGET SDL2)
if (MINGW)
target_link_libraries (${target} ${vis} mingw32) # for SDL_main handling
endif ()
target_link_libraries (${target} ${vis} SDL2)
endif ()
if (TARGET SDL2_mixer)
target_link_libraries (${target} ${vis} SDL2_mixer)
endif ()
endmacro ()
if (TARGET SDL2)
return ()
endif ()
if (PKG_CONFIG_FOUND AND NOT IOS)
if (NOT TARGET SDL2)
add_pkgconfig_interface_library (SDL2 OPTIONAL sdl2)
add_pkgconfig_interface_library (SDL2_ttf OPTIONAL SDL2_ttf)
add_pkgconfig_interface_library (SDL2_mixer OPTIONAL SDL2_mixer)
endif ()
elseif (WIN32)
# Try to locate SDL2 from the local system (assuming Windows).
set (_oldPath ${SDL2_LIBRARY})
file (GLOB _hints ${SDL2_DIR}/SDL2* $ENV{DENG_DEPEND_PATH}/SDL2*)
find_library (SDL2_LIBRARY SDL2
PATHS ${SDL2_DIR}
HINTS ${_hints} ENV DENG_DEPEND_PATH
PATH_SUFFIXES lib/${DE_ARCH} lib
)
mark_as_advanced (SDL2_LIBRARY)
if (NOT SDL2_LIBRARY)
message (FATAL_ERROR "SDL2 not found. Set the SDL2_DIR variable to help locate it.\n")
endif ()
if (NOT _oldPath STREQUAL SDL2_LIBRARY)
message (STATUS "Found SDL2: ${SDL2_LIBRARY}")
endif ()
# Define the target.
add_library (SDL2 INTERFACE)
target_link_libraries (SDL2 INTERFACE ${SDL2_LIBRARY})
# Deduce the include directory.
get_filename_component (_libDir ${SDL2_LIBRARY} DIRECTORY)
get_filename_component (_incDir ${_libDir}/../../include REALPATH)
target_include_directories (SDL2 INTERFACE ${_incDir})
deng_install_library (${_libDir}/SDL2.dll)
# Also attempt to locate SLD2_mixer.
set (_oldPath ${SDL_MIXER_LIBRARY})
file (GLOB _hints ${SDL2_DIR}/SDL2_mixer* ${SDL2_MIXER_DIR}/SDL2_mixer*
$ENV{DENG_DEPEND_PATH}/SDL2_mixer*
)
find_library (SDL2_MIXER_LIBRARY SDL2_mixer
PATHS ${SDL2_DIR} ${SDL2_MIXER_DIR}
HINTS ${_hints} ENV DENG_DEPEND_PATH
PATH_SUFFIXES lib/${DE_ARCH} lib
)
mark_as_advanced (SDL2_MIXER_LIBRARY)
if (NOT _oldPath STREQUAL SDL2_MIXER_LIBRARY)
message (STATUS "Found SDL2_mixer: ${SDL2_MIXER_LIBRARY}")
endif ()
# Define the target.
add_library (SDL2_mixer INTERFACE)
target_link_libraries (SDL2_mixer INTERFACE ${SDL2_MIXER_LIBRARY})
# Deduce the include directory.
get_filename_component (_libDir ${SDL2_MIXER_LIBRARY} DIRECTORY)
get_filename_component (_incDir ${_libDir}/../../include REALPATH)
target_include_directories (SDL2_mixer INTERFACE ${_incDir})
# There are multiple DLLs needed for deployment.
file (GLOB _mixLibs ${_libDir}/*.dll)
foreach (_lib IN LISTS _mixLibs)
deng_install_library (${_lib})
endforeach (_lib)
endif ()
if (NOT TARGET SDL2)
add_definitions (-DDE_NO_SDL=1)
message (STATUS "SDL2 disabled (not found).")
endif ()
if (NOT TARGET SDL2_mixer)
add_definitions (-DDE_DISABLE_SDLMIXER=1)
message (STATUS "SDL2_mixer disabled (not found).")
endif ()