Changeset View
Changeset View
Standalone View
Standalone View
cmake/modules/FindPulseAudio.cmake
- This file was added.
1 | #.rst: | ||||
---|---|---|---|---|---|
2 | # FindPulseAudio | ||||
3 | # -------------- | ||||
4 | # | ||||
5 | # Try to locate the PulseAudio library. | ||||
6 | # If found, this will define the following variables: | ||||
7 | # | ||||
8 | # ``PulseAudio_FOUND`` | ||||
9 | # True if the system has the PulseAudio library of at least | ||||
10 | # the minimum version specified by either the version parameter | ||||
11 | # to find_package() or the variable PulseAudio_MINIMUM_VERSION | ||||
12 | # ``PulseAudio_INCLUDE_DIRS`` | ||||
13 | # The PulseAudio include directory | ||||
14 | # ``PulseAudio_LIBRARIES`` | ||||
15 | # The PulseAudio libraries for linking | ||||
16 | # ``PulseAudio_MAINLOOP_LIBRARY`` | ||||
17 | # The libraries needed to use PulseAudio Mainloop | ||||
18 | # ``PulseAudio_VERSION`` | ||||
19 | # The version of PulseAudio that was found | ||||
20 | # ``PulseAudio_INCLUDE_DIR`` | ||||
21 | # Deprecated, use ``PulseAudio_INCLUDE_DIRS`` | ||||
22 | # ``PulseAudio_LIBRARY`` | ||||
23 | # Deprecated, use ``PulseAudio_LIBRARIES`` | ||||
24 | # | ||||
25 | # If ``PulseAudio_FOUND`` is TRUE, it will also define the following | ||||
26 | # imported target: | ||||
27 | # | ||||
28 | # ``PulseAudio::PulseAudio`` | ||||
29 | # The PulseAudio library | ||||
30 | # | ||||
31 | # Since 5.41.0. | ||||
32 | | ||||
33 | #============================================================================= | ||||
34 | # Copyright (c) 2008, Matthias Kretz, <kretz@kde.org> | ||||
35 | # Copyright (c) 2009, Marcus Hufgard, <Marcus.Hufgard@hufgard.de> | ||||
36 | # | ||||
37 | # Redistribution and use in source and binary forms, with or without | ||||
38 | # modification, are permitted provided that the following conditions | ||||
39 | # are met: | ||||
40 | # | ||||
41 | # 1. Redistributions of source code must retain the copyright | ||||
42 | # notice, this list of conditions and the following disclaimer. | ||||
43 | # 2. Redistributions in binary form must reproduce the copyright | ||||
44 | # notice, this list of conditions and the following disclaimer in the | ||||
45 | # documentation and/or other materials provided with the distribution. | ||||
46 | # 3. The name of the author may not be used to endorse or promote products | ||||
47 | # derived from this software without specific prior written permission. | ||||
48 | # | ||||
49 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||||
50 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||||
51 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||||
52 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||||
53 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||||
54 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||||
55 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||||
56 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||
57 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||||
58 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
59 | #============================================================================= | ||||
60 | | ||||
61 | # Support PulseAudio_MINIMUM_VERSION for compatibility: | ||||
62 | if(NOT PulseAudio_FIND_VERSION) | ||||
63 | set(PulseAudio_FIND_VERSION "${PulseAudio_MINIMUM_VERSION}") | ||||
64 | endif() | ||||
65 | | ||||
66 | # the minimum version of PulseAudio we require | ||||
67 | if(NOT PulseAudio_FIND_VERSION) | ||||
68 | set(PulseAudio_FIND_VERSION "0.9.9") | ||||
69 | endif() | ||||
70 | | ||||
71 | find_package(PkgConfig) | ||||
72 | pkg_check_modules(PC_PulseAudio QUIET libpulse>=${PulseAudio_FIND_VERSION}) | ||||
73 | pkg_check_modules(PC_PulseAudio_MAINLOOP QUIET libpulse-mainloop-glib) | ||||
74 | | ||||
75 | find_path(PulseAudio_INCLUDE_DIRS pulse/pulseaudio.h | ||||
76 | HINTS | ||||
77 | ${PC_PulseAudio_INCLUDEDIR} | ||||
78 | ${PC_PulseAudio_INCLUDE_DIRS} | ||||
79 | ) | ||||
80 | | ||||
81 | find_library(PulseAudio_LIBRARIES NAMES pulse libpulse | ||||
82 | HINTS | ||||
83 | ${PC_PulseAudio_LIBDIR} | ||||
84 | ${PC_PulseAudio_LIBRARY_DIRS} | ||||
85 | ) | ||||
86 | | ||||
87 | find_library(PulseAudio_MAINLOOP_LIBRARY NAMES pulse-mainloop pulse-mainloop-glib libpulse-mainloop-glib | ||||
88 | HINTS | ||||
89 | ${PC_PulseAudio_LIBDIR} | ||||
90 | ${PC_PulseAudio_LIBRARY_DIRS} | ||||
91 | ) | ||||
92 | | ||||
93 | # Store the version number in the cache, so we don't have to search every time again: | ||||
94 | if (PulseAudio_INCLUDE_DIRS AND NOT PulseAudio_VERSION) | ||||
95 | | ||||
96 | # get PulseAudio's version from its version.h | ||||
97 | file(STRINGS "${PulseAudio_INCLUDE_DIRS}/pulse/version.h" pulse_version_h | ||||
98 | REGEX ".*pa_get_headers_version\\(\\).*") | ||||
99 | string(REGEX REPLACE ".*pa_get_headers_version\\(\\)\ \\(\"([0-9]+\\.[0-9]+\\.[0-9]+)[^\"]*\"\\).*" "\\1" | ||||
100 | _PulseAudio_VERSION "${pulse_version_h}") | ||||
101 | | ||||
102 | set(PulseAudio_VERSION "${_PulseAudio_VERSION}" CACHE STRING "Version number of PulseAudio" FORCE) | ||||
103 | endif() | ||||
104 | | ||||
105 | # Deprecated synonyms | ||||
106 | set(PulseAudio_INCLUDE_DIR "${PulseAudio_INCLUDE_DIRS}") | ||||
107 | set(PulseAudio_LIBRARY "${PulseAudio_LIBRARIES}") | ||||
108 | | ||||
109 | # Use the new extended syntax of find_package_handle_standard_args(), which also handles version checking: | ||||
110 | include(FindPackageHandleStandardArgs) | ||||
111 | find_package_handle_standard_args(PulseAudio REQUIRED_VARS PulseAudio_LIBRARIES PulseAudio_INCLUDE_DIRS | ||||
112 | VERSION_VAR PulseAudio_VERSION) | ||||
113 | | ||||
114 | if(PulseAudio_FOUND AND NOT TARGET PulseAudio::PulseAudio) | ||||
115 | add_library(PulseAudio::PulseAudio UNKNOWN IMPORTED) | ||||
116 | set_target_properties(PulseAudio::PulseAudio PROPERTIES | ||||
117 | IMPORTED_LOCATION "${PulseAudio_LIBRARIES}" | ||||
118 | INTERFACE_INCLUDE_DIRECTORIES "${PulseAudio_INCLUDE_DIRS}") | ||||
119 | endif() | ||||
120 | | ||||
121 | mark_as_advanced(PulseAudio_INCLUDE_DIRS PulseAudio_INCLUDE_DIR | ||||
122 | PulseAudio_LIBRARIES PulseAudio_LIBRARY | ||||
123 | PulseAudio_MAINLOOP_LIBRARY) | ||||
124 | set_package_properties(PulseAudio PROPERTIES | ||||
125 | URL "https://www.freedesktop.org/wiki/Software/PulseAudio" | ||||
126 | DESCRIPTION "Sound server, for sound stream routing and mixing") |