Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/dep/cubeb/CMakeLists.txt
7642 views
1
# TODO
2
# - backend selection via command line, rather than simply detecting headers.
3
4
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
5
project(cubeb C CXX)
6
7
option(LAZY_LOAD_LIBS "Lazily load shared libraries" ON)
8
9
if(NOT CMAKE_BUILD_TYPE)
10
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
11
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
12
endif()
13
14
set(CMAKE_C_STANDARD 99)
15
set(CMAKE_CXX_STANDARD 17)
16
set(CMAKE_CXX_STANDARD_REQUIRED ON)
17
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
18
19
set(CMAKE_CXX_WARNING_LEVEL 4)
20
if(NOT MSVC)
21
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter")
22
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -fno-exceptions -fno-rtti")
23
else()
24
string(REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # Disable RTTI
25
string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # Disable Exceptions
26
endif()
27
28
add_library(cubeb
29
src/cubeb.c
30
src/cubeb_mixer.cpp
31
src/cubeb_resampler.cpp
32
src/cubeb_log.cpp
33
src/cubeb_strings.c
34
src/cubeb_utils.cpp
35
)
36
target_include_directories(cubeb
37
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>
38
)
39
40
add_library(speex OBJECT subprojects/speex/resample.c)
41
set_target_properties(speex PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
42
target_include_directories(speex INTERFACE subprojects)
43
target_compile_definitions(speex PUBLIC
44
OUTSIDE_SPEEX
45
FLOATING_POINT
46
EXPORT=
47
RANDOM_PREFIX=speex
48
)
49
add_library(speex_resampler_headers INTERFACE)
50
target_include_directories(speex_resampler_headers INTERFACE subprojects)
51
52
# $<BUILD_INTERFACE:> required because of https://gitlab.kitware.com/cmake/cmake/-/issues/15415
53
target_link_libraries(cubeb PRIVATE $<BUILD_INTERFACE:speex>)
54
55
include(CheckIncludeFiles)
56
57
# Threads needed by cubeb_log, _pulse, _alsa, _jack, _sndio, _oss and _sun
58
set(THREADS_PREFER_PTHREAD_FLAG ON)
59
find_package(Threads)
60
target_link_libraries(cubeb PRIVATE Threads::Threads)
61
62
if(LAZY_LOAD_LIBS)
63
if(NOT APPLE AND NOT WIN32) # Skip checks on MacOS because it takes ages in XCode.
64
check_include_files(pulse/pulseaudio.h USE_PULSE)
65
check_include_files(alsa/asoundlib.h USE_ALSA)
66
check_include_files(jack/jack.h USE_JACK)
67
check_include_files(sndio.h USE_SNDIO)
68
69
if(USE_PULSE OR USE_ALSA OR USE_JACK OR USE_SNDIO OR USE_AAUDIO)
70
target_link_libraries(cubeb PRIVATE ${CMAKE_DL_LIBS})
71
72
if(ANDROID)
73
target_compile_definitions(cubeb PRIVATE __ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__)
74
endif()
75
endif()
76
endif()
77
78
elseif(NOT APPLE AND NOT WIN32)
79
80
find_package(PkgConfig REQUIRED)
81
82
pkg_check_modules(libpulse IMPORTED_TARGET libpulse)
83
if(libpulse_FOUND)
84
set(USE_PULSE ON)
85
target_compile_definitions(cubeb PRIVATE DISABLE_LIBPULSE_DLOPEN)
86
target_link_libraries(cubeb PRIVATE PkgConfig::libpulse)
87
endif()
88
89
pkg_check_modules(alsa IMPORTED_TARGET alsa)
90
if(alsa_FOUND)
91
set(USE_ALSA ON)
92
target_compile_definitions(cubeb PRIVATE DISABLE_LIBASOUND_DLOPEN)
93
target_link_libraries(cubeb PRIVATE PkgConfig::alsa)
94
endif()
95
96
pkg_check_modules(jack IMPORTED_TARGET jack)
97
if(jack_FOUND)
98
set(USE_JACK ON)
99
target_compile_definitions(cubeb PRIVATE DISABLE_LIBJACK_DLOPEN)
100
target_link_libraries(cubeb PRIVATE PkgConfig::jack)
101
endif()
102
103
check_include_files(sndio.h USE_SNDIO)
104
if(USE_SNDIO)
105
target_compile_definitions(cubeb PRIVATE DISABLE_LIBSNDIO_DLOPEN)
106
target_link_libraries(cubeb PRIVATE sndio)
107
endif()
108
endif()
109
110
if(USE_PULSE)
111
target_sources(cubeb PRIVATE src/cubeb_pulse.c)
112
target_compile_definitions(cubeb PRIVATE USE_PULSE)
113
endif()
114
115
if(USE_ALSA)
116
target_sources(cubeb PRIVATE src/cubeb_alsa.c)
117
target_compile_definitions(cubeb PRIVATE USE_ALSA)
118
endif()
119
120
if(USE_JACK)
121
target_sources(cubeb PRIVATE src/cubeb_jack.cpp)
122
target_compile_definitions(cubeb PRIVATE USE_JACK)
123
endif()
124
125
if(USE_SNDIO)
126
target_sources(cubeb PRIVATE src/cubeb_sndio.c)
127
target_compile_definitions(cubeb PRIVATE USE_SNDIO)
128
endif()
129
130
if(APPLE)
131
check_include_files(AudioUnit/AudioUnit.h USE_AUDIOUNIT)
132
if(USE_AUDIOUNIT)
133
target_sources(cubeb PRIVATE
134
src/cubeb_audiounit.cpp
135
src/cubeb_osx_run_loop.cpp)
136
target_compile_definitions(cubeb PRIVATE USE_AUDIOUNIT)
137
target_link_libraries(cubeb PRIVATE "-framework AudioUnit" "-framework CoreAudio" "-framework CoreServices")
138
endif()
139
endif()
140
141
if(WIN32)
142
check_include_files(audioclient.h USE_WASAPI)
143
if(USE_WASAPI)
144
target_sources(cubeb PRIVATE
145
src/cubeb_wasapi.cpp)
146
target_compile_definitions(cubeb PRIVATE USE_WASAPI)
147
target_link_libraries(cubeb PRIVATE ole32 ksuser)
148
endif()
149
150
check_include_files("windows.h;mmsystem.h" USE_WINMM)
151
if(USE_WINMM)
152
target_sources(cubeb PRIVATE
153
src/cubeb_winmm.c)
154
target_compile_definitions(cubeb PRIVATE USE_WINMM)
155
target_link_libraries(cubeb PRIVATE winmm)
156
endif()
157
endif()
158
159
if(NOT WIN32 AND NOT APPLE)
160
check_include_files(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
161
if(HAVE_SYS_SOUNDCARD_H)
162
try_compile(USE_OSS "${PROJECT_BINARY_DIR}/compile_tests"
163
${PROJECT_SOURCE_DIR}/cmake/compile_tests/oss_is_v4.c)
164
if(USE_OSS)
165
# strlcpy is not available on BSD systems that use glibc,
166
# like Debian kfreebsd, so try using libbsd if available
167
include(CheckSymbolExists)
168
check_symbol_exists(strlcpy string.h HAVE_STRLCPY)
169
if(NOT HAVE_STRLCPY)
170
pkg_check_modules(libbsd-overlay IMPORTED_TARGET libbsd-overlay)
171
if(libbsd-overlay_FOUND)
172
target_link_libraries(cubeb PRIVATE PkgConfig::libbsd-overlay)
173
set(HAVE_STRLCPY true)
174
endif()
175
endif()
176
if (HAVE_STRLCPY)
177
target_sources(cubeb PRIVATE
178
src/cubeb_oss.c)
179
target_compile_definitions(cubeb PRIVATE USE_OSS)
180
endif()
181
endif()
182
endif()
183
endif()
184
185