FindOpenAL.cmake 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 [...])
  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 OpenAL was found.
  30. Cache Variables
  31. ^^^^^^^^^^^^^^^
  32. The following cache variables may also be set:
  33. ``OPENAL_INCLUDE_DIR``
  34. The include directory containing headers needed to use the OpenAL library.
  35. ``OPENAL_LIBRARY``
  36. The path to the OpenAL library.
  37. Hints
  38. ^^^^^
  39. This module accepts the following variables:
  40. ``OPENALDIR``
  41. Environment variable which can be used to set the installation prefix of
  42. OpenAL to be found in non-standard locations.
  43. OpenAL is searched in the following order:
  44. 1. By default on macOS, system framework is searched first:
  45. ``/System/Library/Frameworks``, whose priority can be changed by setting
  46. the :variable:`CMAKE_FIND_FRAMEWORK` variable.
  47. 2. Environment variable ``ENV{OPENALDIR}``.
  48. 3. System paths.
  49. 4. User-compiled framework: ``~/Library/Frameworks``.
  50. 5. Manually compiled framework: ``/Library/Frameworks``.
  51. 6. Add-on package: ``/opt``.
  52. Deprecated Variables
  53. ^^^^^^^^^^^^^^^^^^^^
  54. The following variables are provided for backward compatibility:
  55. ``OPENAL_FOUND``
  56. .. deprecated:: 4.2
  57. Use ``OpenAL_FOUND``, which has the same value.
  58. Boolean indicating whether OpenAL was found.
  59. Examples
  60. ^^^^^^^^
  61. Finding the OpenAL library and linking it to a project target:
  62. .. code-block:: cmake
  63. find_package(OpenAL)
  64. target_link_libraries(project_target PRIVATE OpenAL::OpenAL)
  65. #]=======================================================================]
  66. # For Windows, Creative Labs seems to have added a registry key for their
  67. # OpenAL 1.1 installer. I have added that key to the list of search paths,
  68. # however, the key looks like it could be a little fragile depending on
  69. # if they decide to change the 1.00.0000 number for bug fix releases.
  70. # Also, they seem to have laid down groundwork for multiple library platforms
  71. # which puts the library in an extra subdirectory. Currently there is only
  72. # Win32 and I have hardcoded that here. This may need to be adjusted as
  73. # platforms are introduced.
  74. # The OpenAL 1.0 installer doesn't seem to have a useful key I can use.
  75. # I do not know if the Nvidia OpenAL SDK has a registry key.
  76. find_path(OPENAL_INCLUDE_DIR al.h
  77. HINTS
  78. ENV OPENALDIR
  79. PATHS
  80. ~/Library/Frameworks
  81. /Library/Frameworks
  82. /opt
  83. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]
  84. PATH_SUFFIXES include/AL include/OpenAL include AL OpenAL
  85. )
  86. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  87. set(_OpenAL_ARCH_DIR libs/Win64)
  88. else()
  89. set(_OpenAL_ARCH_DIR libs/Win32)
  90. endif()
  91. find_library(OPENAL_LIBRARY
  92. NAMES OpenAL al openal OpenAL32
  93. HINTS
  94. ENV OPENALDIR
  95. PATHS
  96. ~/Library/Frameworks
  97. /Library/Frameworks
  98. /opt
  99. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]
  100. PATH_SUFFIXES libx32 lib64 lib libs64 libs ${_OpenAL_ARCH_DIR}
  101. )
  102. unset(_OpenAL_ARCH_DIR)
  103. include(FindPackageHandleStandardArgs)
  104. find_package_handle_standard_args(
  105. OpenAL
  106. REQUIRED_VARS OPENAL_LIBRARY OPENAL_INCLUDE_DIR
  107. )
  108. mark_as_advanced(OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
  109. if(OpenAL_FOUND AND NOT TARGET OpenAL::OpenAL)
  110. add_library(OpenAL::OpenAL UNKNOWN IMPORTED)
  111. set_target_properties(OpenAL::OpenAL PROPERTIES
  112. IMPORTED_LOCATION "${OPENAL_LIBRARY}")
  113. set_target_properties(OpenAL::OpenAL PROPERTIES
  114. INTERFACE_INCLUDE_DIRECTORIES "${OPENAL_INCLUDE_DIR}")
  115. endif()