FindSDL_sound¶
Finds the SDL_sound library, an abstract soundfile decoder for use in SDL (Simple DirectMedia Layer) applications.
Note
This module is specifically intended for SDL_sound version 1. Starting with
version 2.0.2, SDL_sound provides a CMake package configuration file when
built with CMake and should be found using find_package(SDL2_sound).
These newer versions provide Imported Targets that encapsulate usage
requirements. Refer to the upstream SDL_sound documentation for more
information.
Note
This module depends on SDL being found and must be called after the
find_package(SDL).
Depending on how the SDL_sound library is built, it may require additional dependent libraries to be found for this module to succeed. These dependencies may include MikMod, ModPlug, Ogg, Vorbis, SMPEG, FLAC, and Speex.
Result Variables¶
This module defines the following variables:
SDL_sound_FOUNDBoolean indicating whether the (requested version of) SDL_sound library is found. For backward compatibility, the
SDL_SOUND_FOUNDvariable is also set to the same value.SDL_SOUND_VERSION_STRINGThe human-readable string containing the version of SDL_sound found.
SDL_SOUND_LIBRARIESLibraries needed to link against to use the SDL_sound library.
Cache Variables¶
The following cache variables may also be set:
SDL_SOUND_INCLUDE_DIRThe directory containing the
SDL_sound.hand other headers needed to use the SDL_sound library.SDL_SOUND_LIBRARYThe name of just the SDL_sound library you would link against. Use
SDL_SOUND_LIBRARIESfor the link instructions and not this one.MIKMOD_LIBRARYThe path to the dependent MikMod library.
MODPLUG_LIBRARYThe path to the dependent ModPlug library (libmodplug).
OGG_LIBRARYThe path to the dependent Ogg library.
VORBIS_LIBRARYThe path to the dependent Vorbis library.
SMPEG_LIBRARYThe path to the dependent SMPEG library.
FLAC_LIBRARYThe path to the dependent FLAC library.
SPEEX_LIBRARYThe path to the dependent Speex library.
Hints¶
This module accepts the following variables:
SDLDIREnvironment variable that can be set to help locate an SDL library installed in a custom location. It should point to the installation destination that was used when configuring, building, and installing SDL library:
./configure --prefix=$SDLDIR.On macOS, setting this variable will prefer the Framework version (if found) over others. In this case, the cache value of
SDL_LIBRARYwould need to be manually changed to override this selection or set theCMAKE_INCLUDE_PATHvariable to modify the search paths.SDLSOUNDDIREnvironment variable that works the same as
SDLDIR.SDL_SOUND_EXTRASThis is an optional cache variable that can be used to add additional flags that are prepended to the
SDL_SOUND_LIBRARIESresult variable. This is available mostly for cases this module failed to anticipate for and additional flags must be added.
Examples¶
Finding SDL_sound library and creating an imported interface target for linking it to a project target:
find_package(SDL)
find_package(SDL_sound)
if(SDL_sound_FOUND AND NOT TARGET SDL::SDL_sound)
add_library(SDL::SDL_sound INTERFACE IMPORTED)
set_target_properties(
SDL::SDL_sound
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SDL_SOUND_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${SDL_SOUND_LIBRARIES}"
)
# Append the SDL dependency as imported target to be transitively linked:
set_property(
TARGET SDL::SDL_sound
APPEND
PROPERTY INTERFACE_LINK_LIBRARIES SDL::SDL
)
endif()
target_link_libraries(project_target PRIVATE SDL::SDL_sound)
When working with SDL_sound version 2, the upstream package provides the
SDL2_sound::SDL2_sound imported target directly. It can be used in a
project without using this module:
find_package(SDL2_sound)
target_link_libraries(project_target PRIVATE SDL2_sound::SDL2_sound)
See Also¶
The
FindSDLmodule to find the main SDL library.