4 # Finds the PulseAudio library
6 # This will define the following targets:
8 # ${APP_NAME_LC}::PulseAudio - The PulseAudio library
9 # ${APP_NAME_LC}::PulseAudioSimple - The PulseAudio simple library
10 # ${APP_NAME_LC}::PulseAudioMainloop - The PulseAudio mainloop library
12 if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
14 find_package(PkgConfig)
16 if(PulseAudio_FIND_VERSION)
17 if(PulseAudio_FIND_VERSION_EXACT)
18 set(PulseAudio_FIND_SPEC "=${PulseAudio_FIND_VERSION_COMPLETE}")
20 set(PulseAudio_FIND_SPEC ">=${PulseAudio_FIND_VERSION_COMPLETE}")
24 pkg_check_modules(PC_PULSEAUDIO libpulse${PulseAudio_FIND_SPEC} QUIET)
25 pkg_check_modules(PC_PULSEAUDIO_MAINLOOP libpulse-mainloop-glib${PulseAudio_FIND_SPEC} QUIET)
26 pkg_check_modules(PC_PULSEAUDIO_SIMPLE libpulse-simple${PulseAudio_FIND_SPEC} QUIET)
29 find_path(PULSEAUDIO_INCLUDE_DIR NAMES pulse/pulseaudio.h pulse/simple.h
30 HINTS ${PC_PULSEAUDIO_INCLUDEDIR} ${PC_PULSEAUDIO_INCLUDE_DIRS})
32 find_library(PULSEAUDIO_LIBRARY NAMES pulse libpulse
33 HINTS ${PC_PULSEAUDIO_LIBDIR} ${PC_PULSEAUDIO_LIBRARY_DIRS})
35 find_library(PULSEAUDIO_SIMPLE_LIBRARY NAMES pulse-simple libpulse-simple
36 HINTS ${PC_PULSEAUDIO_LIBDIR} ${PC_PULSEAUDIO_LIBRARY_DIRS})
38 find_library(PULSEAUDIO_MAINLOOP_LIBRARY NAMES pulse-mainloop pulse-mainloop-glib libpulse-mainloop-glib
39 HINTS ${PC_PULSEAUDIO_LIBDIR} ${PC_PULSEAUDIO_LIBRARY_DIRS})
41 if(PC_PULSEAUDIO_VERSION)
42 set(PULSEAUDIO_VERSION_STRING ${PC_PULSEAUDIO_VERSION})
43 elseif(PULSEAUDIO_INCLUDE_DIR AND EXISTS "${PULSEAUDIO_INCLUDE_DIR}/pulse/version.h")
44 file(STRINGS "${PULSEAUDIO_INCLUDE_DIR}/pulse/version.h" pulseaudio_version_str REGEX "^#define[\t ]+pa_get_headers_version\\(\\)[\t ]+\\(\".*\"\\).*")
45 string(REGEX REPLACE "^#define[\t ]+pa_get_headers_version\\(\\)[\t ]+\\(\"([^\"]+)\"\\).*" "\\1" PULSEAUDIO_VERSION_STRING "${pulseaudio_version_str}")
46 unset(pulseaudio_version_str)
49 include(FindPackageHandleStandardArgs)
50 find_package_handle_standard_args(PulseAudio
51 REQUIRED_VARS PULSEAUDIO_LIBRARY PULSEAUDIO_MAINLOOP_LIBRARY PULSEAUDIO_SIMPLE_LIBRARY PULSEAUDIO_INCLUDE_DIR
52 VERSION_VAR PULSEAUDIO_VERSION_STRING)
55 list(APPEND AUDIO_BACKENDS_LIST "pulseaudio")
56 set(AUDIO_BACKENDS_LIST ${AUDIO_BACKENDS_LIST} PARENT_SCOPE)
58 add_library(${APP_NAME_LC}::PulseAudioSimple UNKNOWN IMPORTED)
59 set_target_properties(${APP_NAME_LC}::PulseAudioSimple PROPERTIES
60 IMPORTED_LOCATION "${PULSEAUDIO_SIMPLE_LIBRARY}")
62 add_library(${APP_NAME_LC}::PulseAudioMainloop UNKNOWN IMPORTED)
63 set_target_properties(${APP_NAME_LC}::PulseAudioMainloop PROPERTIES
64 IMPORTED_LOCATION "${PULSEAUDIO_MAINLOOP_LIBRARY}")
66 add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} UNKNOWN IMPORTED)
67 set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
68 IMPORTED_LOCATION "${PULSEAUDIO_LIBRARY}"
69 INTERFACE_INCLUDE_DIRECTORIES "${PULSEAUDIO_INCLUDE_DIR}"
70 INTERFACE_COMPILE_DEFINITIONS HAS_PULSEAUDIO
71 INTERFACE_LINK_LIBRARIES "${APP_NAME_LC}::PulseAudioMainloop;${APP_NAME_LC}::PulseAudioSimple")