Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Modules / FindOpenAL.cmake
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
3
4 #[=======================================================================[.rst:
5 FindOpenAL
6 ----------
7
8 Finds Open Audio Library (OpenAL).
9
10 Projects using this module should use ``#include "al.h"`` to include the OpenAL
11 header file, **not** ``#include <AL/al.h>``.  The reason for this is that the
12 latter is not entirely portable.  Windows/Creative Labs does not by default put
13 their headers in ``AL/`` and macOS uses the convention ``<OpenAL/al.h>``.
14
15 Hints
16 ^^^^^
17
18 Environment variable ``$OPENALDIR`` can be used to set the prefix of OpenAL
19 installation to be found.
20
21 By default on macOS, system framework is search first.  In other words,
22 OpenAL is searched in the following order:
23
24 1. System framework: ``/System/Library/Frameworks``, whose priority can be
25    changed via setting the :variable:`CMAKE_FIND_FRAMEWORK` variable.
26 2. Environment variable ``$OPENALDIR``.
27 3. System paths.
28 4. User-compiled framework: ``~/Library/Frameworks``.
29 5. Manually compiled framework: ``/Library/Frameworks``.
30 6. Add-on package: ``/opt``.
31
32 IMPORTED Targets
33 ^^^^^^^^^^^^^^^^
34
35 .. versionadded:: 3.25
36
37 This module defines the :prop_tgt:`IMPORTED` target:
38
39 ``OpenAL::OpenAL``
40   The OpenAL library, if found.
41
42 Result Variables
43 ^^^^^^^^^^^^^^^^
44
45 This module defines the following variables:
46
47 ``OPENAL_FOUND``
48   If false, do not try to link to OpenAL
49 ``OPENAL_INCLUDE_DIR``
50   OpenAL include directory
51 ``OPENAL_LIBRARY``
52   Path to the OpenAL library
53 ``OPENAL_VERSION_STRING``
54   Human-readable string containing the version of OpenAL
55 #]=======================================================================]
56
57 # For Windows, Creative Labs seems to have added a registry key for their
58 # OpenAL 1.1 installer. I have added that key to the list of search paths,
59 # however, the key looks like it could be a little fragile depending on
60 # if they decide to change the 1.00.0000 number for bug fix releases.
61 # Also, they seem to have laid down groundwork for multiple library platforms
62 # which puts the library in an extra subdirectory. Currently there is only
63 # Win32 and I have hardcoded that here. This may need to be adjusted as
64 # platforms are introduced.
65 # The OpenAL 1.0 installer doesn't seem to have a useful key I can use.
66 # I do not know if the Nvidia OpenAL SDK has a registry key.
67
68 find_path(OPENAL_INCLUDE_DIR al.h
69   HINTS
70     ENV OPENALDIR
71   PATHS
72     ~/Library/Frameworks
73     /Library/Frameworks
74     /opt
75     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]
76   PATH_SUFFIXES include/AL include/OpenAL include AL OpenAL
77   )
78
79 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
80   set(_OpenAL_ARCH_DIR libs/Win64)
81 else()
82   set(_OpenAL_ARCH_DIR libs/Win32)
83 endif()
84
85 find_library(OPENAL_LIBRARY
86   NAMES OpenAL al openal OpenAL32
87   HINTS
88     ENV OPENALDIR
89   PATHS
90     ~/Library/Frameworks
91     /Library/Frameworks
92     /opt
93     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]
94   PATH_SUFFIXES libx32 lib64 lib libs64 libs ${_OpenAL_ARCH_DIR}
95   )
96
97 unset(_OpenAL_ARCH_DIR)
98
99 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
100 find_package_handle_standard_args(
101   OpenAL
102   REQUIRED_VARS OPENAL_LIBRARY OPENAL_INCLUDE_DIR
103   VERSION_VAR OPENAL_VERSION_STRING
104   )
105
106 mark_as_advanced(OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
107
108 if(OPENAL_INCLUDE_DIR AND OPENAL_LIBRARY)
109   if(NOT TARGET OpenAL::OpenAL)
110     if(EXISTS "${OPENAL_LIBRARY}")
111       add_library(OpenAL::OpenAL UNKNOWN IMPORTED)
112       set_target_properties(OpenAL::OpenAL PROPERTIES
113         IMPORTED_LOCATION "${OPENAL_LIBRARY}")
114     else()
115       add_library(OpenAL::OpenAL INTERFACE IMPORTED)
116       set_target_properties(OpenAL::OpenAL PROPERTIES
117         IMPORTED_LIBNAME "${OPENAL_LIBRARY}")
118     endif()
119     set_target_properties(OpenAL::OpenAL PROPERTIES
120       INTERFACE_INCLUDE_DIRECTORIES "${OPENAL_INCLUDE_DIR}")
121   endif()
122 endif()