FindOpenAL.cmake 3.2 KB

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