cmake_modules/FindOggVorbis.cmake
author Simon McVittie <smcv@debian.org>
Mon, 12 Sep 2022 10:40:53 -0400
branch1.0.0
changeset 15859 7b1d6dfa3173
parent 8667 f93cc19d8b98
permissions -rw-r--r--
Remove FindSDL2 find-module, use sdl2-config.cmake instead This requires SDL >= 2.0.4. Since <https://bugzilla.libsdl.org/show_bug.cgi?id=2464> was fixed in SDL 2.0.4, SDL behaves as a CMake "config-file package", even if it was not itself built using CMake: it installs a sdl2-config.cmake file to ${libdir}/cmake/SDL2, which tells CMake where to find SDL's headers and library, analogous to a pkg-config .pc file. As a result, we no longer need to copy/paste a "find-module package" to be able to find a system copy of SDL >= 2.0.4 with find_package(SDL2). Find-module packages are now discouraged by the CMake developers, in favour of having upstream projects behave as config-file packages. This results in a small API change: FindSDL2 used to set SDL2_INCLUDE_DIR and SDL2_LIBRARY, but the standard behaviour for config-file packages is to set <name>_INCLUDE_DIRS and <name>_LIBRARIES. Use the CONFIG keyword to make sure we search in config-file package mode, and will not find a FindSDL2.cmake in some other directory that implements the old interface. In addition to deleting redundant code, this avoids some assumptions in FindSDL2 about the layout of a SDL installation. The current libsdl2-dev package in Debian breaks those assumptions; this is considered a bug and will hopefully be fixed soon, but it illustrates how fragile these assumptions can be. We can be more robust against different installation layouts by relying on SDL's own CMake integration. When linking to a copy of CMake in a non-standard location, users can now set the SDL2_DIR or CMAKE_PREFIX_PATH environment variable to point to it; previously, these users would have used the SDL2DIR environment variable. This continues to be unnecessary if using matching system-wide installations of CMake and SDL2, for example both from Debian.

# - Try to find the OggVorbis libraries
# Once done this will define
#
#  OGGVORBIS_FOUND       - system has both Ogg and Vorbis
#  OGGVORBIS_VERSION     - set either to 1 or 2
#  OGGVORBIS_INCLUDE_DIR - the OggVorbis include directory
#  OGGVORBIS_LIBRARIES   - the libraries needed to use OggVorbis
#
#  OGG_LIBRARY           - the Ogg library
#  OGG_INCLUDE_DIR       - the Ogg include directory
#  VORBIS_LIBRARY        - the Vorbis library
#  VORBIS_INCLUDE_DIR    - the Vorbis include directory
#  VORBISFILE_LIBRARY    - the VorbisFile library
#
# Copyright (c) 2006, Richard Laerkaeng <richard@goteborg.utfors.se>
# Copyright (c) 2013, Vittorio Giovara <vittorio.giovara@gmail.com>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

### sommer [SuperTux]
##  - Removed unused vorbisenc library
##  - reversed order of libraries, so that cmake 2.4.5 for Windows generates an MSYS Makefile that will link correctly

### koda [Hedgewars]
##  - split ogg and vorbis lookup
##  - special case for framework handling
##  - standard variables handling


include (CheckLibraryExists)
include (FindPackageHandleStandardArgs)

find_path(OGG_INCLUDE_DIR ogg.h PATH_SUFFIXES ogg)
find_path(VORBIS_INCLUDE_DIR vorbisfile.h PATH_SUFFIXES vorbis)

find_library(OGG_LIBRARY NAMES Ogg ogg)
find_library(VORBIS_LIBRARY NAMES Vorbis vorbis)
find_library(VORBISFILE_LIBRARY NAMES vorbisfile)

set(_CMAKE_REQUIRED_LIBRARIES_TMP ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${OGGVORBIS_LIBRARIES})
check_library_exists(${VORBIS_LIBRARY} vorbis_bitrate_addblock "" HAVE_LIBVORBISENC2)
set(CMAKE_REQUIRED_LIBRARIES ${_CMAKE_REQUIRED_LIBRARIES_TMP})

if(HAVE_LIBVORBISENC2)
    set(OGGVORBIS_VERSION 2)
else(HAVE_LIBVORBISENC2)
    set(OGGVORBIS_VERSION 1)
endif(HAVE_LIBVORBISENC2)

if(${OGG_LIBRARY} MATCHES ".framework" AND ${VORBIS_LIBRARY} MATCHES ".framework")
    set(VORBISFILE_LIBRARY "") #vorbisfile will appear as NOTFOUND and discarded
    set(fphsa_vorbis_list VORBIS_LIBRARY)
else()
    set(fphsa_vorbis_list VORBISFILE_LIBRARY VORBIS_LIBRARY)
endif()

find_package_handle_standard_args(OggVorbis DEFAULT_MSG ${fphsa_vorbis_list} OGG_LIBRARY
                                                        OGG_INCLUDE_DIR VORBIS_INCLUDE_DIR)
unset(fphsa_vorbis_list)

set(OGGVORBIS_LIBRARIES ${VORBISFILE_LIBRARY} ${VORBIS_LIBRARY} ${OGG_LIBRARY})
set(OGGVORBIS_INCLUDE_DIR ${VORBIS_INCLUDE_DIR} ${OGG_INCLUDE_DIR})

mark_as_advanced(OGGVORBIS_VERSION OGGVORBIS_INCLUDE_DIR OGGVORBIS_LIBRARIES
                 OGG_LIBRARY OGG_INCLUDE_DIR VORBIS_LIBRARY VORBIS_INCLUDE_DIR VORBISFILE_LIBRARY)