Skip to content

Commit

Permalink
rewrite CMake libao find module
Browse files Browse the repository at this point in the history
- It now exports actual CMake targets.
- It searches all of the system's default paths. (no more hardcoding)
  • Loading branch information
ValleyBell committed Mar 19, 2019
1 parent ec2e40f commit 8b3d7d9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 24 deletions.
7 changes: 2 additions & 5 deletions audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
project(vgm-audio)
cmake_minimum_required(VERSION 2.8)

set(CMAKE_MODULE_PATH ${vgm-audio_SOURCE_DIR}/cmake)

set(AUDIO_DEFS)
set(AUDIO_FILES
AudioStream.c
Expand Down Expand Up @@ -40,7 +38,6 @@ else()
find_package(ALSA QUIET)
find_package(PulseAudio QUIET)
endif()

find_package(LibAO QUIET)

option(AUDIODRV_WAVEWRITE "Audio Driver: Wave Writer" ON)
Expand Down Expand Up @@ -114,10 +111,10 @@ if(AUDIODRV_PULSE)
endif()

if(AUDIODRV_LIBAO)
find_package(LibAO REQUIRED)
set(AUDIO_DEFS ${AUDIO_DEFS} " AUDDRV_LIBAO")
set(AUDIO_FILES ${AUDIO_FILES} AudDrv_libao.c)
set(AUDIO_INCLUDES ${AUDIO_INCLUDES} ${LIBAO_INCLUDE_DIR})
set(AUDIO_LIBS ${AUDIO_LIBS} ${LIBAO_LIBRARIES})
set(AUDIO_LIBS ${AUDIO_LIBS} libao::libao)
endif()


Expand Down
19 changes: 0 additions & 19 deletions audio/cmake/FindLibAO.cmake

This file was deleted.

58 changes: 58 additions & 0 deletions libs/cmake_modules/FindLibAO.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

#[=======================================================================[.rst:
FindLibAO
--------

Find the libao cross-platform audio output library

IMPORTED Targets
^^^^^^^^^^^^^^^^

This module defines :prop_tgt:`IMPORTED` target ``libao::libao``, if
libao has been found.

Result Variables
^^^^^^^^^^^^^^^^

This module defines the following variables:

``LIBAO_FOUND``
True if LIBAO_INCLUDE_DIR & LIBAO_LIBRARY are found

``LIBAO_LIBRARIES``
List of libraries when using libao.

``LIBAO_INCLUDE_DIRS``
Where to find the libao headers.

Cache variables
^^^^^^^^^^^^^^^

The following cache variables may also be set:

``LIBAO_INCLUDE_DIR``
the libao include directory

``LIBAO_LIBRARY``
the absolute path of the libao library
#]=======================================================================]

find_path(LIBAO_INCLUDE_DIR NAMES ao/ao.h DOC "The libao include directory")
find_library(LIBAO_LIBRARY NAMES ao DOC "The libao library")

mark_as_advanced(LIBAO_INCLUDE_DIR LIBAO_LIBRARY)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibAO REQUIRED_VARS LIBAO_LIBRARY LIBAO_INCLUDE_DIR)

if(LIBAO_FOUND)
set(LIBAO_INCLUDE_DIRS "${LIBAO_INCLUDE_DIR}")
set(LIBAO_LIBRARIES "${LIBAO_LIBRARY}")
if(NOT TARGET libao::libao)
add_library(libao::libao UNKNOWN IMPORTED)
set_target_properties(libao::libao PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBAO_INCLUDE_DIRS}")
set_target_properties(libao::libao PROPERTIES IMPORTED_LOCATION "${LIBAO_LIBRARY}")
endif()
endif()

0 comments on commit 8b3d7d9

Please sign in to comment.