Debian Codegraph @

prboom2/cmake/FindSDL2_mixer.cmake

raw
1 #[=======================================================================[.rst:
2 FindSDL2_mixer
3 -------
4
5 Finds the SDL2_mixer library.
6
7 Imported Targets
8 ^^^^^^^^^^^^^^^^
9
10 This module provides either of the following imported targets, if found:
11
12 ``SDL2_mixer::SDL2_mixer``
13 The shared SDL2_mixer library
14 ``SDL2_mixer::SDL2_mixer-static``
15 The static SDL2_mixer library
16
17 Result Variables
18 ^^^^^^^^^^^^^^^^
19
20 This will define the following variables:
21
22 ``SDL2_mixer_FOUND``
23 True if the system has the SDL2_mixer library.
24 ``SDL2_mixer_INCLUDE_DIRS``
25 Include directories needed to use SDL2_mixer.
26 ``SDL2_mixer_LIBRARIES``
27 Libraries needed to link to SDL2_mixer.
28
29 Cache Variables
30 ^^^^^^^^^^^^^^^
31
32 The following cache variables may also be set:
33
34 ``SDL2_mixer_INCLUDE_DIR``
35 The directory containing ``SDL2_mixer.h``.
36 ``SDL2_mixer_DLL_RELEASE``
37 The path to the SDL2_mixer Windows runtime (release config).
38 ``SDL2_mixer_DLL_DEBUG``
39 The path to the SDL2_mixer Windows runtime (debug config).
40 ``SDL2_mixer_LIBRARY_RELEASE``
41 The path to the SDL2_mixer library (release config).
42 ``SDL2_mixer_LIBRARY_DEBUG``
43 The path to the SDL2_mixer library (debug config).
44
45 #]=======================================================================]
46
47 find_package(PkgConfig QUIET)
48 pkg_check_modules(PC_SDL2_mixer IMPORTED_TARGET SDL2_mixer)
49
50 if(PC_SDL2_mixer_FOUND)
51 if(NOT TARGET SDL2_mixer::SDL2_mixer)
52 add_library(SDL2_mixer::SDL2_mixer ALIAS PkgConfig::PC_SDL2_mixer)
53 endif()
54 set(SDL2_mixer_FOUND TRUE)
55 set(SDL2_mixer_VERSION ${PC_SDL2_mixer_VERSION})
56 return()
57 endif()
58
59 find_path(
60 SDL2_mixer_INCLUDE_DIR
61 NAMES SDL_mixer.h
62 PATH_SUFFIXES SDL2
63 )
64
65 find_file(
66 SDL2_mixer_DLL_RELEASE
67 NAMES SDL2_mixer.dll
68 PATH_SUFFIXES bin
69 )
70
71 find_file(
72 SDL2_mixer_DLL_DEBUG
73 NAMES SDL2_mixerd.dll
74 PATH_SUFFIXES bin
75 )
76
77 include(SelectDllConfigurations)
78 select_dll_configurations(SDL2_mixer)
79
80 find_library(
81 SDL2_mixer_LIBRARY_RELEASE
82 NAMES SDL2_mixer SDL2_mixer-static
83 )
84
85 find_library(
86 SDL2_mixer_LIBRARY_DEBUG
87 NAMES SDL2_mixerd SDL2_mixer-staticd
88 )
89
90 include(SelectLibraryConfigurations)
91 select_library_configurations(SDL2_mixer)
92
93 if(SDL2_mixer_DLL OR SDL2_mixer_LIBRARY MATCHES ".so|.dylib")
94 set(_sdl2_mixer_library_type SHARED)
95 else()
96 set(_sdl2_mixer_library_type STATIC)
97 endif()
98
99 if(_SDL2_mixer_library_type STREQUAL "STATIC")
100 set(SDL2_mixer_LINK_LIBRARIES "" CACHE STRING "Additional libraries to link to SDL2_mixer.")
101 set(SDL2_mixer_LINK_DIRECTORIES "" CACHE PATH "Additional directories to search libraries in for SDL2_mixer.")
102 if(NOT SDL2_mixer_LINK_LIBRARIES)
103 message(WARNING
104 "pkg-config is unavailable and SDL2_mixer seems to be static, link failures are to be expected.\n"
105 "Set `SDL2_mixer_LINK_LIBRARIES` to a list of libraries SDL2_mixer depends on.\n"
106 "Set `SDL2_mixer_LINK_DIRECTORIES` to a list of directories to search for libraries in."
107 )
108 endif()
109 endif()
110
111 include(FindPackageHandleStandardArgs)
112 find_package_handle_standard_args(
113 SDL2_mixer
114 REQUIRED_VARS "SDL2_mixer_LIBRARY" "SDL2_mixer_INCLUDE_DIR")
115
116 if(SDL2_mixer_FOUND)
117 if(_sdl2_mixer_library_type STREQUAL "SHARED")
118 set(_sdl2_mixer_target_name SDL2_mixer::SDL2_mixer)
119 else()
120 set(_sdl2_mixer_target_name SDL2_mixer::SDL2_mixer-static)
121 endif()
122 if(NOT TARGET ${_sdl2_mixer_target_name})
123 add_library(${_sdl2_mixer_target_name} ${_sdl2_mixer_library_type} IMPORTED)
124 set_target_properties(
125 ${_sdl2_mixer_target_name}
126 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${SDL2_mixer_INCLUDE_DIR}"
127 INTERFACE_LINK_LIBRARIES "${SDL2_mixer_LINK_LIBRARIES}"
128 INTERFACE_LINK_DIRECTORIES "${SDL2_mixer_LINK_DIRECTORIES}"
129 )
130 endif()
131
132 if(SDL2_mixer_DLL)
133 set_target_properties(
134 ${_sdl2_mixer_target_name}
135 PROPERTIES IMPORTED_LOCATION "${SDL2_mixer_DLL}"
136 IMPORTED_IMPLIB "${SDL2_mixer_LIBRARY}"
137 )
138 else()
139 set_target_properties(
140 ${_sdl2_mixer_target_name}
141 PROPERTIES IMPORTED_LOCATION "${SDL2_mixer_LIBRARY}"
142 )
143 endif()
144
145 if(SDL2_mixer_LIBRARY_RELEASE)
146 set_property(
147 TARGET ${_sdl2_mixer_target_name}
148 APPEND
149 PROPERTY IMPORTED_CONFIGURATIONS RELEASE
150 )
151 if(SDL2_mixer_DLL_RELEASE)
152 set_target_properties(
153 ${_sdl2_mixer_target_name}
154 PROPERTIES IMPORTED_LOCATION_RELEASE "${SDL2_mixer_DLL_RELEASE}"
155 IMPORTED_IMPLIB_RELEASE "${SDL2_mixer_LIBRARY_RELEASE}"
156 )
157 else()
158 set_target_properties(
159 ${_sdl2_mixer_target_name}
160 PROPERTIES IMPORTED_LOCATION_RELEASE "${SDL2_mixer_LIBRARY_RELEASE}"
161 )
162 endif()
163 endif()
164 if(SDL2_mixer_LIBRARY_DEBUG)
165 set_property(
166 TARGET ${_sdl2_mixer_target_name}
167 APPEND
168 PROPERTY IMPORTED_CONFIGURATIONS DEBUG
169 )
170 if(SDL2_mixer_DLL_DEBUG)
171 set_target_properties(
172 ${_sdl2_mixer_target_name}
173 PROPERTIES IMPORTED_LOCATION_DEBUG "${SDL2_mixer_DLL_DEBUG}"
174 IMPORTED_IMPLIB_DEBUG "${SDL2_mixer_LIBRARY_DEBUG}"
175 )
176 else()
177 set_target_properties(
178 ${_sdl2_mixer_target_name}
179 PROPERTIES IMPORTED_LOCATION_DEBUG "${SDL2_mixer_LIBRARY_DEBUG}"
180 )
181 endif()
182 endif()
183
184 set(SDL2_mixer_LIBRARIES ${_sdl2_mixer_target_name})
185 set(SDL2_mixer_INCLUDE_DIRS "${SDL2_mixer_INCLUDE_DIR}")
186 endif()
187
188 mark_as_advanced(
189 SDL2_mixer_INCLUDE_DIR
190 )