-
Notifications
You must be signed in to change notification settings - Fork 442
/
Copy pathFindOpenAL.cmake
190 lines (172 loc) · 8.19 KB
/
FindOpenAL.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#.rst:
# Find OpenAL
# -----------
#
# Finds the OpenAL library. This module defines:
#
# OpenAL_FOUND - True if the OpenAL library is found
# OpenAL::OpenAL - OpenAL imported target
#
# Additionally these variables are defined for internal usage:
#
# OPENAL_LIBRARY - OpenAL library
# OPENAL_DLL_RELEASE - OpenAL release DLL on Windows, if found. Note that
# in case of the binary OpenAL Soft distribution it's named soft_oal.dll and
# you need to rename it to OpenAL32.dll to make it work.
# OPENAL_INCLUDE_DIR - Include dir
#
#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
# 2020, 2021, 2022, 2023, 2024, 2025
# Vladimír Vondruš <mosra@centrum.cz>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# OpenAL Soft installs cmake package config files which handles dependencies in
# case OpenAL Soft is built statically. Try to find first, quietly, so it
# doesn't print loud messages when it's not found, since that's okay. If the
# OpenAL target already exists, it means we're using it through a CMake
# subproject -- don't attempt to find the package in that case.
#
# In case of Emscripten we don't want any of this -- the library name and
# includes are implicit.
if(NOT CORRADE_TARGET_EMSCRIPTEN AND NOT TARGET OpenAL)
find_package(OpenAL CONFIG QUIET)
endif()
# If either an OpenAL Soft config file was found or we have a subproject, point
# OpenAL::OpenAL to that and exit -- nothing else to do here.
if(TARGET OpenAL OR TARGET OpenAL::OpenAL)
# OpenAL Soft config file already defines this one, so this is just for
# the subproject case.
if(NOT TARGET OpenAL::OpenAL)
# Aliases of (global) targets are only supported in CMake 3.11, so we
# work around it by this. This is easier than fetching all possible
# properties (which are impossible to track of) and then attempting to
# rebuild them into a new target.
add_library(OpenAL::OpenAL INTERFACE IMPORTED)
set_target_properties(OpenAL::OpenAL PROPERTIES INTERFACE_LINK_LIBRARIES OpenAL)
# The OpenAL target doesn't define any usable
# INTERFACE_INCLUDE_DIRECTORIES for some reason (apparently the
# $<BUILD_INTERFACE:> in there doesn't work or whatever), so let's do
# that ourselves.
#
# TODO this could be probably fixable by using target_link_libraries()
# instead of set_target_properties() because it evaluates generator
# expressions, but that needs CMake 3.10+, before that
# target_link_libraries() can't be called on INTERFACE targets.
get_target_property(_OPENAL_SOURCE_DIR OpenAL SOURCE_DIR)
set_target_properties(OpenAL::OpenAL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${_OPENAL_SOURCE_DIR}/include/AL)
# For the imported target get the DLL location
else()
if(CORRADE_TARGET_WINDOWS)
get_target_property(OPENAL_DLL_DEBUG OpenAL::OpenAL IMPORTED_LOCATION_DEBUG)
get_target_property(OPENAL_DLL_RELEASE OpenAL::OpenAL IMPORTED_LOCATION_RELEASE)
# Release not found, fall back to RelWithDebInfo
if(NOT OPENAL_DLL_RELEASE)
get_target_property(OPENAL_DLL_RELEASE OpenAL::OpenAL IMPORTED_LOCATION_RELWITHDEBINFO)
endif()
endif()
endif()
# Just to make FPHSA print some meaningful location, nothing else.
# Fortunately because of the INTERFACE_INCLUDE_DIRECTORIES workaround above
# we can have the same handling both in case of an imported target and a
# CMake subproject.
get_target_property(_OPENAL_INTERFACE_INCLUDE_DIRECTORIES OpenAL::OpenAL INTERFACE_INCLUDE_DIRECTORIES)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args("OpenAL" DEFAULT_MSG
_OPENAL_INTERFACE_INCLUDE_DIRECTORIES)
return()
endif()
# Under Emscripten, OpenAL is linked implicitly. With MINIMAL_RUNTIME you need
# to specify -lopenal. Simply set the library name to that.
if(CORRADE_TARGET_EMSCRIPTEN)
set(OPENAL_LIBRARY openal CACHE STRING "Path to a library." FORCE)
else()
# OpenAL Soft Windows binary distribution puts the library into a subdir,
# the legacy one from Creative uses the same. OpenAL Soft puts DLLs into
# bin/Win{32,64}/soft_oal.dll
if(WIN32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_OPENAL_LIBRARY_PATH_SUFFIX libs/Win64)
set(_OPENAL_DLL_PATH_SUFFIX bin/Win64)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(_OPENAL_LIBRARY_PATH_SUFFIX libs/Win32)
set(_OPENAL_DLL_PATH_SUFFIX bin/Win32)
endif()
endif()
find_library(OPENAL_LIBRARY
# Names same as in CMake's vanilla FindOpenAL
NAMES OpenAL al openal OpenAL32
# For binary OpenAL Soft distribution on Windows
PATH_SUFFIXES ${_OPENAL_LIBRARY_PATH_SUFFIX}
# The other PATHS from CMake's vanilla FindOpenAL seem to be a legacy
# cruft, skipping those. The Windows registry used by the vanilla
# FindOpenAL doesn't seem to be set anymore either.
)
endif()
# Include dir
find_path(OPENAL_INCLUDE_DIR NAMES al.h
# AL/ used by OpenAL Soft, OpenAL/ used by the macOS framework. The legacy
# Creative SDK puts al.h directly into include/, ffs.
PATH_SUFFIXES AL OpenAL
# As above, skipping the obsolete PATHS and registry in vanilla FindOpenAL
)
# (Static) macOS / iOS dependencies
if(CORRADE_TARGET_APPLE AND OPENAL_LIBRARY MATCHES "${CMAKE_STATIC_LIBRARY_SUFFIX}$")
find_library(_OPENAL_CoreAudio_LIBRARY CoreAudio)
mark_as_advanced(_OPENAL_CoreAudio_LIBRARY)
set(_OPENAL_FRAMEWORK_LIBRARIES ${_OPENAL_CoreAudio_LIBRARY})
set(_OPENAL_FRAMEWORK_LIBRARY_NAMES _OPENAL_CoreAudio_LIBRARY)
endif()
# OpenAL DLL on Windows
if(CORRADE_TARGET_WINDOWS)
# TODO: debug?
find_file(OPENAL_DLL_RELEASE
NAMES soft_oal.dll
PATH_SUFFIXES ${_OPENAL_DLL_PATH_SUFFIX})
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenAL DEFAULT_MSG
OPENAL_LIBRARY
${_OPENAL_FRAMEWORK_LIBRARY_NAMES}
OPENAL_INCLUDE_DIR)
if(NOT TARGET OpenAL::OpenAL)
# Work around BUGGY framework support on macOS. Do this also in case of
# Emscripten, since there we don't have a location either.
# http://public.kitware.com/pipermail/cmake/2016-April/063179.html
if((APPLE AND OPENAL_LIBRARY MATCHES "\\.framework$") OR CORRADE_TARGET_EMSCRIPTEN)
add_library(OpenAL::OpenAL INTERFACE IMPORTED)
set_property(TARGET OpenAL::OpenAL APPEND PROPERTY
INTERFACE_LINK_LIBRARIES ${OPENAL_LIBRARY})
else()
add_library(OpenAL::OpenAL UNKNOWN IMPORTED)
set_property(TARGET OpenAL::OpenAL PROPERTY
IMPORTED_LOCATION ${OPENAL_LIBRARY})
endif()
# Link frameworks on macOS / iOS if we have a static SDL
if(CORRADE_TARGET_APPLE AND OPENAL_LIBRARY MATCHES "${CMAKE_STATIC_LIBRARY_SUFFIX}$")
set_property(TARGET OpenAL::OpenAL APPEND PROPERTY
INTERFACE_LINK_LIBRARIES ${_OPENAL_FRAMEWORK_LIBRARIES})
endif()
set_target_properties(OpenAL::OpenAL PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${OPENAL_INCLUDE_DIR})
endif()
mark_as_advanced(OPENAL_LIBRARY OPENAL_INCLUDE_DIR)