FindALSA.cmake 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. FindALSA
  5. --------
  6. Find Advanced Linux Sound Architecture (ALSA)
  7. Find the alsa libraries (``asound``)
  8. IMPORTED Targets
  9. ^^^^^^^^^^^^^^^^
  10. This module defines :prop_tgt:`IMPORTED` target ``ALSA::ALSA``, if
  11. ALSA has been found.
  12. Result Variables
  13. ^^^^^^^^^^^^^^^^
  14. This module defines the following variables:
  15. ``ALSA_FOUND``
  16. True if ALSA_INCLUDE_DIR & ALSA_LIBRARY are found
  17. ``ALSA_LIBRARIES``
  18. List of libraries when using ALSA.
  19. ``ALSA_INCLUDE_DIRS``
  20. Where to find the ALSA headers.
  21. Cache variables
  22. ^^^^^^^^^^^^^^^
  23. The following cache variables may also be set:
  24. ``ALSA_INCLUDE_DIR``
  25. the ALSA include directory
  26. ``ALSA_LIBRARY``
  27. the absolute path of the asound library
  28. #]=======================================================================]
  29. find_path(ALSA_INCLUDE_DIR NAMES alsa/asoundlib.h
  30. DOC "The ALSA (asound) include directory"
  31. )
  32. find_library(ALSA_LIBRARY NAMES asound
  33. DOC "The ALSA (asound) library"
  34. )
  35. if(ALSA_INCLUDE_DIR AND EXISTS "${ALSA_INCLUDE_DIR}/alsa/version.h")
  36. file(STRINGS "${ALSA_INCLUDE_DIR}/alsa/version.h" alsa_version_str REGEX "^#define[\t ]+SND_LIB_VERSION_STR[\t ]+\".*\"")
  37. string(REGEX REPLACE "^.*SND_LIB_VERSION_STR[\t ]+\"([^\"]*)\".*$" "\\1" ALSA_VERSION_STRING "${alsa_version_str}")
  38. unset(alsa_version_str)
  39. endif()
  40. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  41. FIND_PACKAGE_HANDLE_STANDARD_ARGS(ALSA
  42. REQUIRED_VARS ALSA_LIBRARY ALSA_INCLUDE_DIR
  43. VERSION_VAR ALSA_VERSION_STRING)
  44. if(ALSA_FOUND)
  45. set( ALSA_LIBRARIES ${ALSA_LIBRARY} )
  46. set( ALSA_INCLUDE_DIRS ${ALSA_INCLUDE_DIR} )
  47. if(NOT TARGET ALSA::ALSA)
  48. add_library(ALSA::ALSA UNKNOWN IMPORTED)
  49. set_target_properties(ALSA::ALSA PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${ALSA_INCLUDE_DIRS}")
  50. set_property(TARGET ALSA::ALSA APPEND PROPERTY IMPORTED_LOCATION "${ALSA_LIBRARY}")
  51. endif()
  52. endif()
  53. mark_as_advanced(ALSA_INCLUDE_DIR ALSA_LIBRARY)