1 # Locates the SDL_sound library
3 # This module depends on SDL being found and
4 # must be called AFTER FindSDL.cmake is called.
7 # SDL_SOUND_INCLUDE_DIR, where to find SDL_sound.h
8 # SDL_SOUND_FOUND, if false, do not try to link to SDL
9 # SDL_SOUND_LIBRARIES, this contains the list of libraries that you need
10 # to link against. This is a read-only variable and is marked INTERNAL.
11 # SDL_SOUND_EXTRAS, this is an optional variable for you to add your own
12 # flags to SDL_SOUND_LIBRARIES. This is prepended to SDL_SOUND_LIBRARIES.
13 # This is available mostly for cases this module failed to anticipate for
14 # and you must add additional flags. This is marked as ADVANCED.
17 # This module also defines (but you shouldn't need to use directly)
18 # SDL_SOUND_LIBRARY, the name of just the SDL_sound library you would link
19 # against. Use SDL_SOUND_LIBRARIES for you link instructions and not this one.
20 # And might define the following as needed
29 # Typically, you should not use these variables directly, and you should use
30 # SDL_SOUND_LIBRARIES which contains SDL_SOUND_LIBRARY and the other audio libraries
31 # (if needed) to successfully compile on your system .
33 # Created by Eric Wing.
34 # This module is a bit more complicated than the other FindSDL* family modules.
35 # The reason is that SDL_sound can be compiled in a large variety of different ways
36 # which are independent of platform. SDL_sound may dynamically link against other 3rd
37 # party libraries to get additional codec support, such as Ogg Vorbis, SMPEG, ModPlug,
38 # MikMod, FLAC, Speex, and potentially others.
39 # Under some circumstances which I don't fully understand,
40 # there seems to be a requirement
41 # that dependent libraries of libraries you use must also be explicitly
42 # linked against in order to successfully compile. SDL_sound does not currently
43 # have any system in place to know how it was compiled.
44 # So this CMake module does the hard work in trying to discover which 3rd party
45 # libraries are required for building (if any).
46 # This module uses a brute force approach to create a test program that uses SDL_sound,
47 # and then tries to build it. If the build fails, it parses the error output for
48 # known symbol names to figure out which libraries are needed.
50 # Responds to the $SDLDIR and $SDLSOUNDDIR environmental variable that would
51 # correspond to the ./configure --prefix=$SDLDIR used in building SDL.
53 # On OSX, this will prefer the Framework version (if found) over others.
54 # People will have to manually change the cache values of
55 # SDL_LIBRARY to override this selectionor set the CMake environment
56 # CMAKE_INCLUDE_PATH to modify the search paths.
59 #=============================================================================
60 # Copyright 2005-2009 Kitware, Inc.
62 # Distributed under the OSI-approved BSD License (the "License");
63 # see accompanying file Copyright.txt for details.
65 # This software is distributed WITHOUT ANY WARRANTY; without even the
66 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
67 # See the License for more information.
68 #=============================================================================
69 # (To distribute this file outside of CMake, substitute the full
70 # License text for the above reference.)
72 SET(SDL_SOUND_EXTRAS "" CACHE STRING "SDL_sound extra flags")
73 MARK_AS_ADVANCED(SDL_SOUND_EXTRAS)
76 FIND_PATH(SDL_SOUND_INCLUDE_DIR SDL_sound.h
78 $ENV{SDLSOUNDDIR}/include
83 /usr/local/include/SDL
85 /usr/local/include/SDL12
86 /usr/local/include/SDL11 # FreeBSD ports
89 /sw/include/SDL # Fink
91 /opt/local/include/SDL # DarwinPorts
93 /opt/csw/include/SDL # Blastwave
99 FIND_LIBRARY(SDL_SOUND_LIBRARY
102 $ENV{SDLSOUNDDIR}/lib
113 IF(SDL_FOUND AND SDL_SOUND_INCLUDE_DIR AND SDL_SOUND_LIBRARY)
115 # CMake is giving me problems using TRY_COMPILE with the CMAKE_FLAGS
116 # for the :STRING syntax if I have multiple values contained in a
117 # single variable. This is a problem for the SDL_LIBRARY variable
118 # because it does just that. When I feed this variable to the command,
119 # only the first value gets the appropriate modifier (e.g. -I) and
120 # the rest get dropped.
121 # To get multiple single variables to work, I must separate them with a "\;"
122 # I could go back and modify the FindSDL.cmake module, but that's kind of painful.
123 # The solution would be to try something like:
124 # SET(SDL_TRY_COMPILE_LIBRARY_LIST "${SDL_TRY_COMPILE_LIBRARY_LIST}\;${CMAKE_THREAD_LIBS_INIT}")
125 # Instead, it was suggested on the mailing list to write a temporary CMakeLists.txt
126 # with a temporary test project and invoke that with TRY_COMPILE.
127 # See message thread "Figuring out dependencies for a library in order to build"
131 # ${CMAKE_BINARY_DIR}
132 # ${PROJECT_SOURCE_DIR}/DetermineSoundLibs.c
134 # -DINCLUDE_DIRECTORIES:STRING=${SDL_INCLUDE_DIR}\;${SDL_SOUND_INCLUDE_DIR}
135 # -DLINK_LIBRARIES:STRING=${SDL_SOUND_LIBRARY}\;${SDL_LIBRARY}
136 # OUTPUT_VARIABLE MY_OUTPUT
139 # To minimize external dependencies, create a sdlsound test program
140 # which will be used to figure out if additional link dependencies are
141 # required for the link phase.
142 FILE(WRITE ${PROJECT_BINARY_DIR}/CMakeTmp/DetermineSoundLibs.c
143 "#include \"SDL_sound.h\"
145 int main(int argc, char* argv[])
147 Sound_AudioInfo desired;
148 Sound_Sample* sample;
153 /* This doesn't actually have to work, but Init() is a no-op
154 * for some of the decoders, so this should force more symbols
157 sample = Sound_NewSampleFromFile(argv[1], &desired, 4096);
166 # TARGET_LINK_LIBRARIES(DetermineSoundLibs "${SDL_SOUND_LIBRARY} ${SDL_LIBRARY})
167 # causes problems when SDL_LIBRARY looks like
168 # /Library/Frameworks/SDL.framework;-framework Cocoa
169 # The ;-framework Cocoa seems to be confusing CMake once the OS X
170 # framework support was added. I was told that breaking up the list
171 # would fix the problem.
173 FOREACH(lib ${SDL_SOUND_LIBRARY} ${SDL_LIBRARY})
174 SET(TMP_TRY_LIBS "${TMP_TRY_LIBS} \"${lib}\"")
177 # MESSAGE("TMP_TRY_LIBS ${TMP_TRY_LIBS}")
179 # Write the CMakeLists.txt and test project
180 # Weird, this is still sketchy. If I don't quote the variables
181 # in the TARGET_LINK_LIBRARIES, I seem to loose everything
182 # in the SDL_LIBRARY string after the "-framework".
183 # But if I quote the stuff in INCLUDE_DIRECTORIES, it doesn't work.
184 FILE(WRITE ${PROJECT_BINARY_DIR}/CMakeTmp/CMakeLists.txt
185 "PROJECT(DetermineSoundLibs)
186 INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
187 ADD_EXECUTABLE(DetermineSoundLibs DetermineSoundLibs.c)
188 TARGET_LINK_LIBRARIES(DetermineSoundLibs ${TMP_TRY_LIBS})"
193 ${PROJECT_BINARY_DIR}/CMakeTmp
194 ${PROJECT_BINARY_DIR}/CMakeTmp
196 OUTPUT_VARIABLE MY_OUTPUT
199 # MESSAGE("${MY_RESULT}")
200 # MESSAGE(${MY_OUTPUT})
204 # I expect that MPGLIB, VOC, WAV, AIFF, and SHN are compiled in statically.
205 # I think Timidity is also compiled in statically.
206 # I've never had to explcitly link against Quicktime, so I'll skip that for now.
208 SET(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARY})
211 IF("${MY_OUTPUT}" MATCHES "MikMod_")
212 FIND_LIBRARY(MIKMOD_LIBRARY
213 NAMES libmikmod-coreaudio mikmod
217 $ENV{SDLSOUNDDIR}/lib
227 SET(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${MIKMOD_LIBRARY})
228 ENDIF(MIKMOD_LIBRARY)
229 ENDIF("${MY_OUTPUT}" MATCHES "MikMod_")
232 IF("${MY_OUTPUT}" MATCHES "MODPLUG_")
233 FIND_LIBRARY(MODPLUG_LIBRARY
238 $ENV{SDLSOUNDDIR}/lib
248 SET(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${MODPLUG_LIBRARY})
249 ENDIF(MODPLUG_LIBRARY)
250 ENDIF("${MY_OUTPUT}" MATCHES "MODPLUG_")
253 # Find Ogg and Vorbis
254 IF("${MY_OUTPUT}" MATCHES "ov_")
255 FIND_LIBRARY(VORBIS_LIBRARY
256 NAMES vorbis Vorbis VORBIS
262 $ENV{SDLSOUNDDIR}/lib
272 SET(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${VORBIS_LIBRARY})
273 ENDIF(VORBIS_LIBRARY)
275 FIND_LIBRARY(OGG_LIBRARY
282 $ENV{SDLSOUNDDIR}/lib
292 SET(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${OGG_LIBRARY})
294 ENDIF("${MY_OUTPUT}" MATCHES "ov_")
298 IF("${MY_OUTPUT}" MATCHES "SMPEG_")
299 FIND_LIBRARY(SMPEG_LIBRARY
300 NAMES smpeg SMPEG Smpeg SMpeg
304 $ENV{SDLSOUNDDIR}/lib
314 SET(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${SMPEG_LIBRARY})
316 ENDIF("${MY_OUTPUT}" MATCHES "SMPEG_")
320 IF("${MY_OUTPUT}" MATCHES "FLAC_")
321 FIND_LIBRARY(FLAC_LIBRARY
326 $ENV{SDLSOUNDDIR}/lib
336 SET(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${FLAC_LIBRARY})
338 ENDIF("${MY_OUTPUT}" MATCHES "FLAC_")
341 # Hmmm...Speex seems to depend on Ogg. This might be a problem if
342 # the TRY_COMPILE attempt gets blocked at SPEEX before it can pull
343 # in the Ogg symbols. I'm not sure if I should duplicate the ogg stuff
344 # above for here or if two ogg entries will screw up things.
345 IF("${MY_OUTPUT}" MATCHES "speex_")
346 FIND_LIBRARY(SPEEX_LIBRARY
351 $ENV{SDLSOUNDDIR}/lib
361 SET(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${SPEEX_LIBRARY})
364 # Find OGG (needed for Speex)
365 # We might have already found Ogg for Vorbis, so skip it if so.
367 FIND_LIBRARY(OGG_LIBRARY
376 $ENV{SDLSOUNDDIR}/lib
386 SET(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${OGG_LIBRARY})
388 ENDIF(NOT OGG_LIBRARY)
389 ENDIF("${MY_OUTPUT}" MATCHES "speex_")
392 SET(SDL_SOUND_LIBRARIES "${SDL_SOUND_EXTRAS} ${SDL_SOUND_LIBRARY}" CACHE INTERNAL "SDL_sound and dependent libraries")
395 SET(SDL_SOUND_LIBRARIES "${SDL_SOUND_EXTRAS} ${SDL_SOUND_LIBRARIES_TMP}" CACHE INTERNAL "SDL_sound and dependent libraries")
396 ENDIF(SDL_FOUND AND SDL_SOUND_INCLUDE_DIR AND SDL_SOUND_LIBRARY)
398 INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
400 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_SOUND
401 REQUIRED_VARS SDL_SOUND_LIBRARIES SDL_SOUND_INCLUDE_DIR)