FindOpenAL.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. IMPORTED Targets
  25. ^^^^^^^^^^^^^^^^
  26. .. versionadded:: 3.25
  27. This module defines the :prop_tgt:`IMPORTED` target:
  28. ``OpenAL::OpenAL``
  29. The OpenAL library, if found.
  30. Result Variables
  31. ^^^^^^^^^^^^^^^^
  32. This module defines the following variables:
  33. ``OPENAL_FOUND``
  34. If false, do not try to link to OpenAL
  35. ``OPENAL_INCLUDE_DIR``
  36. OpenAL include directory
  37. ``OPENAL_LIBRARY``
  38. Path to the OpenAL library
  39. ``OPENAL_VERSION_STRING``
  40. Human-readable string containing the version of OpenAL
  41. #]=======================================================================]
  42. # For Windows, Creative Labs seems to have added a registry key for their
  43. # OpenAL 1.1 installer. I have added that key to the list of search paths,
  44. # however, the key looks like it could be a little fragile depending on
  45. # if they decide to change the 1.00.0000 number for bug fix releases.
  46. # Also, they seem to have laid down groundwork for multiple library platforms
  47. # which puts the library in an extra subdirectory. Currently there is only
  48. # Win32 and I have hardcoded that here. This may need to be adjusted as
  49. # platforms are introduced.
  50. # The OpenAL 1.0 installer doesn't seem to have a useful key I can use.
  51. # I do not know if the Nvidia OpenAL SDK has a registry key.
  52. find_path(OPENAL_INCLUDE_DIR al.h
  53. HINTS
  54. ENV OPENALDIR
  55. PATHS
  56. ~/Library/Frameworks
  57. /Library/Frameworks
  58. /opt
  59. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]
  60. PATH_SUFFIXES include/AL include/OpenAL include AL OpenAL
  61. )
  62. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  63. set(_OpenAL_ARCH_DIR libs/Win64)
  64. else()
  65. set(_OpenAL_ARCH_DIR libs/Win32)
  66. endif()
  67. find_library(OPENAL_LIBRARY
  68. NAMES OpenAL al openal OpenAL32
  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 libx32 lib64 lib libs64 libs ${_OpenAL_ARCH_DIR}
  77. )
  78. unset(_OpenAL_ARCH_DIR)
  79. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  80. find_package_handle_standard_args(
  81. OpenAL
  82. REQUIRED_VARS OPENAL_LIBRARY OPENAL_INCLUDE_DIR
  83. VERSION_VAR OPENAL_VERSION_STRING
  84. )
  85. mark_as_advanced(OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
  86. if(OPENAL_INCLUDE_DIR AND OPENAL_LIBRARY)
  87. if(NOT TARGET OpenAL::OpenAL)
  88. if(EXISTS "${OPENAL_LIBRARY}")
  89. add_library(OpenAL::OpenAL UNKNOWN IMPORTED)
  90. set_target_properties(OpenAL::OpenAL PROPERTIES
  91. IMPORTED_LOCATION "${OPENAL_LIBRARY}")
  92. else()
  93. add_library(OpenAL::OpenAL INTERFACE IMPORTED)
  94. set_target_properties(OpenAL::OpenAL PROPERTIES
  95. IMPORTED_LIBNAME "${OPENAL_LIBRARY}")
  96. endif()
  97. set_target_properties(OpenAL::OpenAL PROPERTIES
  98. INTERFACE_INCLUDE_DIRECTORIES "${OPENAL_INCLUDE_DIR}")
  99. endif()
  100. endif()