FindSDL_sound — CMake 4.4.1 Documentation

# FindSDL_sound

Finds the SDL_sound library, an abstract soundfile decoder for use in SDL (Simple DirectMedia Layer) applications:

    find_package(SDL_sound [<version>] [...])

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_FOUND`

  Added in version 3.3.

  Boolean indicating whether the (requested version of) SDL_sound library was found.

`SDL_sound_VERSION`

  Added in version 4.2.

  The human-readable string containing the version of SDL_sound found.

`SDL_SOUND_LIBRARIES`

  Libraries needed to link against to use the SDL_sound library.

## Cache Variables

The following cache variables may also be set:

`SDL_SOUND_INCLUDE_DIR`

  The directory containing the `SDL_sound.h` and other headers needed to use the SDL_sound library.

`SDL_SOUND_LIBRARY`

  The name of just the SDL_sound library you would link against. Use `SDL_SOUND_LIBRARIES` for the link instructions and not this one.

`MIKMOD_LIBRARY`

  The path to the dependent MikMod library.

`MODPLUG_LIBRARY`

  The path to the dependent ModPlug library (libmodplug).

`OGG_LIBRARY`

  The path to the dependent Ogg library.

`VORBIS_LIBRARY`

  The path to the dependent Vorbis library.

`SMPEG_LIBRARY`

  The path to the dependent SMPEG library.

`FLAC_LIBRARY`

  The path to the dependent FLAC library.

`SPEEX_LIBRARY`

  The path to the dependent Speex library.

## Hints

This module accepts the following variables:

`SDLDIR`

  Environment 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_LIBRARY` would need to be manually changed to override this selection or set the `CMAKE_INCLUDE_PATH` variable to modify the search paths.

`SDLSOUNDDIR`

  Environment variable that works the same as `SDLDIR`.

`SDL_SOUND_EXTRAS`

  This is an optional cache variable that can be used to add additional flags that are prepended to the `SDL_SOUND_LIBRARIES` result variable. This is available mostly for cases this module failed to anticipate for and additional flags must be added.

## Deprecated Variables

The following variables are provided for backward compatibility:

`SDL_SOUND_FOUND`

  Deprecated since version 4.2: Use `SDL_sound_FOUND`, which has the same value.

  Boolean indicating whether the (requested version of) SDL_sound library was found.

`SDL_SOUND_VERSION_STRING`

  Deprecated since version 4.2: Use `SDL_sound_VERSION`, which has the same value.

  The human-readable string containing the version of SDL_sound found.

## 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 `FindSDL` module to find the main SDL library.