FindOpenAL.cmake 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindOpenAL
  5. ----------
  6. Finds the Open Audio Library (OpenAL):
  7. .. code-block:: cmake
  8. find_package(OpenAL [<version>] [...])
  9. OpenAL is a cross-platform 3D audio API designed for efficient rendering of
  10. multichannel three-dimensional positional audio. It is commonly used in games
  11. and multimedia applications to provide immersive and spatialized sound.
  12. Projects using this module should include the OpenAL header file using
  13. ``#include <al.h>``, and **not** ``#include <AL/al.h>``. The reason for this is
  14. that the latter is not portable. For example, Windows/Creative Labs does not by
  15. default put OpenAL headers in ``AL/`` and macOS uses the convention of
  16. ``<OpenAL/al.h>``.
  17. Imported Targets
  18. ^^^^^^^^^^^^^^^^
  19. This module provides the following :ref:`Imported Targets`:
  20. ``OpenAL::OpenAL``
  21. .. versionadded:: 3.25
  22. Target encapsulating the OpenAL library usage requirements, available only if
  23. the OpenAL library is found.
  24. Result Variables
  25. ^^^^^^^^^^^^^^^^
  26. This module defines the following variables:
  27. ``OpenAL_FOUND``
  28. .. versionadded:: 3.3
  29. Boolean indicating whether (the requested version of) OpenAL was found.
  30. ``OPENAL_VERSION_STRING``
  31. Human-readable string containing the version of OpenAL found.
  32. Cache Variables
  33. ^^^^^^^^^^^^^^^
  34. The following cache variables may also be set:
  35. ``OPENAL_INCLUDE_DIR``
  36. The include directory containing headers needed to use the OpenAL library.
  37. ``OPENAL_LIBRARY``
  38. The path to the OpenAL library.
  39. Deprecated Variables
  40. ^^^^^^^^^^^^^^^^^^^^
  41. The following variables are provided for backward compatibility:
  42. ``OPENAL_FOUND``
  43. .. deprecated:: 4.2
  44. Use ``OpenAL_FOUND``, which has the same value.
  45. Boolean indicating whether (the requested version of) OpenAL was found.
  46. Hints
  47. ^^^^^
  48. This module accepts the following variables:
  49. ``OPENALDIR``
  50. Environment variable which can be used to set the installation prefix of
  51. OpenAL to be found in non-standard locations.
  52. OpenAL is searched in the following order:
  53. 1. By default on macOS, system framework is searched first:
  54. ``/System/Library/Frameworks``, whose priority can be changed by setting
  55. the :variable:`CMAKE_FIND_FRAMEWORK` variable.
  56. 2. Environment variable ``ENV{OPENALDIR}``.
  57. 3. System paths.
  58. 4. User-compiled framework: ``~/Library/Frameworks``.
  59. 5. Manually compiled framework: ``/Library/Frameworks``.
  60. 6. Add-on package: ``/opt``.
  61. Examples
  62. ^^^^^^^^
  63. Finding the OpenAL library and linking it to a project target:
  64. .. code-block:: cmake
  65. find_package(OpenAL)
  66. target_link_libraries(project_target PRIVATE OpenAL::OpenAL)
  67. #]=======================================================================]
  68. # For Windows, Creative Labs seems to have added a registry key for their
  69. # OpenAL 1.1 installer. I have added that key to the list of search paths,
  70. # however, the key looks like it could be a little fragile depending on
  71. # if they decide to change the 1.00.0000 number for bug fix releases.
  72. # Also, they seem to have laid down groundwork for multiple library platforms
  73. # which puts the library in an extra subdirectory. Currently there is only
  74. # Win32 and I have hardcoded that here. This may need to be adjusted as
  75. # platforms are introduced.
  76. # The OpenAL 1.0 installer doesn't seem to have a useful key I can use.
  77. # I do not know if the Nvidia OpenAL SDK has a registry key.
  78. find_path(OPENAL_INCLUDE_DIR al.h
  79. HINTS
  80. ENV OPENALDIR
  81. PATHS
  82. ~/Library/Frameworks
  83. /Library/Frameworks
  84. /opt
  85. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]
  86. PATH_SUFFIXES include/AL include/OpenAL include AL OpenAL
  87. )
  88. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  89. set(_OpenAL_ARCH_DIR libs/Win64)
  90. else()
  91. set(_OpenAL_ARCH_DIR libs/Win32)
  92. endif()
  93. find_library(OPENAL_LIBRARY
  94. NAMES OpenAL al openal OpenAL32
  95. HINTS
  96. ENV OPENALDIR
  97. PATHS
  98. ~/Library/Frameworks
  99. /Library/Frameworks
  100. /opt
  101. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]
  102. PATH_SUFFIXES libx32 lib64 lib libs64 libs ${_OpenAL_ARCH_DIR}
  103. )
  104. unset(_OpenAL_ARCH_DIR)
  105. include(FindPackageHandleStandardArgs)
  106. find_package_handle_standard_args(
  107. OpenAL
  108. REQUIRED_VARS OPENAL_LIBRARY OPENAL_INCLUDE_DIR
  109. VERSION_VAR OPENAL_VERSION_STRING
  110. )
  111. mark_as_advanced(OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
  112. if(OpenAL_FOUND AND NOT TARGET OpenAL::OpenAL)
  113. add_library(OpenAL::OpenAL UNKNOWN IMPORTED)
  114. set_target_properties(OpenAL::OpenAL PROPERTIES
  115. IMPORTED_LOCATION "${OPENAL_LIBRARY}")
  116. set_target_properties(OpenAL::OpenAL PROPERTIES
  117. INTERFACE_INCLUDE_DIRECTORIES "${OPENAL_INCLUDE_DIR}")
  118. endif()