FindOpenAL.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #
  7. #
  8. #
  9. # Locate OpenAL This module defines OPENAL_LIBRARY OPENAL_FOUND, if
  10. # false, do not try to link to OpenAL OPENAL_INCLUDE_DIR, where to find
  11. # the headers
  12. #
  13. # $OPENALDIR is an environment variable that would correspond to the
  14. # ./configure --prefix=$OPENALDIR used in building OpenAL.
  15. #
  16. # Created by Eric Wing. This was influenced by the FindSDL.cmake
  17. # module.
  18. # This makes the presumption that you are include al.h like
  19. # #include "al.h"
  20. # and not
  21. # #include <AL/al.h>
  22. # The reason for this is that the latter is not entirely portable.
  23. # Windows/Creative Labs does not by default put their headers in AL/ and
  24. # OS X uses the convention <OpenAL/al.h>.
  25. #
  26. # For Windows, Creative Labs seems to have added a registry key for their
  27. # OpenAL 1.1 installer. I have added that key to the list of search paths,
  28. # however, the key looks like it could be a little fragile depending on
  29. # if they decide to change the 1.00.0000 number for bug fix releases.
  30. # Also, they seem to have laid down groundwork for multiple library platforms
  31. # which puts the library in an extra subdirectory. Currently there is only
  32. # Win32 and I have hardcoded that here. This may need to be adjusted as
  33. # platforms are introduced.
  34. # The OpenAL 1.0 installer doesn't seem to have a useful key I can use.
  35. # I do not know if the Nvidia OpenAL SDK has a registry key.
  36. #
  37. # For OS X, remember that OpenAL was added by Apple in 10.4 (Tiger).
  38. # To support the framework, I originally wrote special framework detection
  39. # code in this module which I have now removed with CMake's introduction
  40. # of native support for frameworks.
  41. # In addition, OpenAL is open source, and it is possible to compile on Panther.
  42. # Furthermore, due to bugs in the initial OpenAL release, and the
  43. # transition to OpenAL 1.1, it is common to need to override the built-in
  44. # framework.
  45. # Per my request, CMake should search for frameworks first in
  46. # the following order:
  47. # ~/Library/Frameworks/OpenAL.framework/Headers
  48. # /Library/Frameworks/OpenAL.framework/Headers
  49. # /System/Library/Frameworks/OpenAL.framework/Headers
  50. #
  51. # On OS X, this will prefer the Framework version (if found) over others.
  52. # People will have to manually change the cache values of
  53. # OPENAL_LIBRARY to override this selection or set the CMake environment
  54. # CMAKE_INCLUDE_PATH to modify the search paths.
  55. find_path(OPENAL_INCLUDE_DIR al.h
  56. HINTS
  57. ENV OPENALDIR
  58. PATH_SUFFIXES include/AL include/OpenAL include
  59. PATHS
  60. ~/Library/Frameworks
  61. /Library/Frameworks
  62. /sw # Fink
  63. /opt/local # DarwinPorts
  64. /opt/csw # Blastwave
  65. /opt
  66. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]
  67. )
  68. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  69. set(_OpenAL_ARCH_DIR libs/Win64)
  70. else()
  71. set(_OpenAL_ARCH_DIR libs/Win32)
  72. endif()
  73. find_library(OPENAL_LIBRARY
  74. NAMES OpenAL al openal OpenAL32
  75. HINTS
  76. ENV OPENALDIR
  77. PATH_SUFFIXES lib64 lib libs64 libs ${_OpenAL_ARCH_DIR}
  78. PATHS
  79. ~/Library/Frameworks
  80. /Library/Frameworks
  81. /sw
  82. /opt/local
  83. /opt/csw
  84. /opt
  85. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]
  86. )
  87. unset(_OpenAL_ARCH_DIR)
  88. include(FindPackageHandleStandardArgs)
  89. FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenAL DEFAULT_MSG OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
  90. if(OPENAL_FOUND)
  91. if(NOT TARGET OpenAL::OpenAL)
  92. add_library(OpenAL::OpenAL UNKNOWN IMPORTED)
  93. if(OPENAL_LIBRARY MATCHES "/([^/]+)\\.framework$")
  94. set(_al_fw "${OPENAL_LIBRARY}/${CMAKE_MATCH_1}")
  95. if(EXISTS "${_al_fw}.tbd")
  96. set(_al_fw "${_al_fw}.tbd")
  97. endif()
  98. set_target_properties(OpenAL::OpenAL PROPERTIES
  99. IMPORTED_LOCATION "${_al_fw}")
  100. else()
  101. set_target_properties(OpenAL::OpenAL PROPERTIES
  102. IMPORTED_LOCATION "${OPENAL_LIBRARY}")
  103. endif()
  104. set_target_properties(OpenAL::OpenAL PROPERTIES
  105. INTERFACE_INCLUDE_DIRECTORIES ${OPENAL_INCLUDE_DIR}
  106. )
  107. endif()
  108. endif()
  109. mark_as_advanced(OPENAL_LIBRARY OPENAL_INCLUDE_DIR)