-
Notifications
You must be signed in to change notification settings - Fork 13
/
CMakeLists.txt
323 lines (271 loc) · 8.98 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# Set minimum CMake required version for this project.
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
# Define a C++ project.
project(RtAudio LANGUAGES CXX)
#define data directory
option(DATAPATH "Path to data Directory" ON)
if(UNIX)
set(DATAPATH $ENV{HOME}/.lcc_audio/data)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDATADIR=${DATAPATH}")
# standards version
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Check for Jack (any OS)
find_library(JACK_LIB jack)
find_package(PkgConfig)
pkg_check_modules(jack jack)
if(JACK_LIB OR jack_FOUND)
set(HAVE_JACK TRUE)
endif()
# Check for Pulse (any OS)
pkg_check_modules(pulse libpulse-simple)
# Check for known non-Linux unix-likes
if(CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*")
message(STATUS "NetBSD detected, using OSS")
set(xBSD ON)
elseif(UNIX AND NOT APPLE)
set(LINUX ON)
endif()
# Necessary for Windows
if(MINGW)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
# Standard CMake options
option(BUILD_SHARED_LIBS "Build as shared library" OFF)
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;RelWithDebInfo;MinSizeRel")
endif()
if(WIN32)
set(CMAKE_DEBUG_POSTFIX d CACHE STRING "Postfix for debug version of library")
endif()
# API Options
option(RTAUDIO_API_DS "Build DirectSound API" OFF)
option(RTAUDIO_API_ASIO "Build ASIO API" OFF)
option(RTAUDIO_API_WASAPI "Build WASAPI API" ${WIN32})
option(RTAUDIO_API_OSS "Build OSS4 API" ${xBSD})
option(RTAUDIO_API_ALSA "Build ALSA API" ${LINUX})
option(RTAUDIO_API_PULSE "Build PulseAudio API" ${pulse_FOUND})
option(RTAUDIO_API_JACK "Build JACK audio server API" ${HAVE_JACK})
option(RTAUDIO_API_CORE "Build CoreAudio API" ${APPLE})
# Check for functions
include(CheckFunctionExists)
check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
if(HAVE_GETTIMEOFDAY)
add_definitions(-DHAVE_GETTIMEOFDAY)
endif()
# Add -Wall if possible
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif(CMAKE_COMPILER_IS_GNUCXX)
# Add debug flags
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-D__RTAUDIO_DEBUG__)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif(CMAKE_COMPILER_IS_GNUCXX)
endif()
# Init variables
set(rtaudio_SOURCES RtAudio.cpp RtAudio.h)
set(LINKLIBS)
set(PKGCONFIG_REQUIRES)
set(API_DEFS)
set(API_LIST)
# Tweak API-specific configuration.
# Jack
if(RTAUDIO_API_JACK AND jack_FOUND)
set(NEED_PTHREAD ON)
list(APPEND PKGCONFIG_REQUIRES "jack")
list(APPEND API_DEFS "-D__UNIX_JACK__")
list(APPEND API_LIST "jack")
if(jack_FOUND)
list(APPEND LINKLIBS ${jack_LIBRARIES})
list(APPEND INCDIRS ${jack_INCLUDEDIR})
else()
list(APPEND LINKLIBS ${JACK_LIB})
endif()
endif()
# ALSA
if(RTAUDIO_API_ALSA)
set(NEED_PTHREAD ON)
find_package(ALSA)
if(NOT ALSA_FOUND)
message(FATAL_ERROR "ALSA API requested but no ALSA dev libraries found")
endif()
list(APPEND INCDIRS ${ALSA_INCLUDE_DIR})
list(APPEND LINKLIBS ${ALSA_LIBRARY})
list(APPEND PKGCONFIG_REQUIRES "alsa")
list(APPEND API_DEFS "-D__LINUX_ALSA__")
list(APPEND API_LIST "alsa")
endif()
# OSS
if(RTAUDIO_OSS)
set(NEED_PTHREAD ON)
find_library(OSSAUDIO_LIB ossaudio)
if(OSSAUDIO_LIB)
list(APPEND LINKLIBS ossaudio)
# Note: not an error on some systems
endif()
list(APPEND API_DEFS "-D__LINUX_OSS__")
list(APPEND API_LIST "oss")
endif()
# Pulse
if(RTAUDIO_API_PULSE)
set(NEED_PTHREAD ON)
find_library(PULSE_LIB pulse)
find_library(PULSESIMPLE_LIB pulse-simple)
list(APPEND LINKLIBS ${PULSE_LIB} ${PULSESIMPLE_LIB})
list(APPEND PKGCONFIG_REQUIRES "libpulse-simple")
list(APPEND API_DEFS "-D__LINUX_PULSE__")
list(APPEND API_LIST "pulse")
endif()
# CoreAudio
if(RTAUDIO_API_CORE)
find_library(COREAUDIO_LIB CoreAudio)
find_library(COREFOUNDATION_LIB CoreFoundation)
list(APPEND LINKLIBS ${COREAUDIO_LIB} ${COREFOUNDATION_LIB})
list(APPEND API_DEFS "-D__MACOSX_CORE__")
list(APPEND API_LIST "core")
endif()
# ASIO
if(RTAUDIO_API_ASIO)
set(NEED_WIN32LIBS ON)
include_directories(include)
list(APPEND rtaudio_SOURCES
include/asio.cpp
include/asiodrivers.cpp
include/asiolist.cpp
include/iasiothiscallresolver.cpp)
list(APPEND API_DEFS "-D__WINDOWS_ASIO__")
list(APPEND API_LIST "asio")
endif()
# DSound
if(RTAUDIO_API_DS)
set(NEED_WIN32LIBS ON)
list(APPEND LINKLIBS dsound)
list(APPEND API_DEFS "-D__WINDOWS_DS__")
list(APPEND API_LIST "ds")
endif()
# WASAPI
if(RTAUDIO_API_WASAPI)
include_directories(include)
set(NEED_WIN32LIBS ON)
list(APPEND LINKLIBS ksuser mfplat mfuuid wmcodecdspuuid)
list(APPEND API_DEFS "-D__WINDOWS_WASAPI__")
list(APPEND API_LIST "wasapi")
endif()
# Windows libs
if(NEED_WIN32LIBS)
list(APPEND LINKLIBS winmm ole32)
endif()
# pthread
if(NEED_PTHREAD)
find_package(Threads REQUIRED
CMAKE_THREAD_PREFER_PTHREAD
THREADS_PREFER_PTHREAD_FLAG)
list(APPEND LINKLIBS Threads::Threads)
endif()
# Create library targets.
set(LIB_TARGETS)
# Use RTAUDIO_BUILD_SHARED_LIBS / RTAUDIO_BUILD_STATIC_LIBS if they
# are defined, otherwise default to standard BUILD_SHARED_LIBS.
if(DEFINED RTAUDIO_BUILD_SHARED_LIBS)
if(RTAUDIO_BUILD_SHARED_LIBS)
add_library(rtaudio SHARED ${rtaudio_SOURCES})
else()
add_library(rtaudio STATIC ${rtaudio_SOURCES})
set(RTAUDIO_IS_STATIC TRUE)
endif()
elseif(DEFINED RTAUDIO_BUILD_STATIC_LIBS)
if(RTAUDIO_BUILD_STATIC_LIBS)
add_library(rtaudio STATIC ${rtaudio_SOURCES})
set(RTAUDIO_IS_STATIC TRUE)
else()
add_library(rtaudio SHARED ${rtaudio_SOURCES})
endif()
else()
add_library(rtaudio ${rtaudio_SOURCES})
if(NOT BUILD_SHARED_LIBS)
set(RTAUDIO_IS_STATIC TRUE)
endif()
endif()
list(APPEND LIB_TARGETS rtaudio)
if(NOT DEFINED RTAUDIO_STATIC_MSVCRT)
set(RTAUDIO_STATIC_MSVCRT ${RTAUDIO_IS_STATIC})
endif()
# In MSVC, set MD/MT appropriately for a static library
# (From https://github.com/protocolbuffers/protobuf/blob/master/cmake/CMakeLists.txt)
if(MSVC AND RTAUDIO_STATIC_MSVCRT)
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
endif()
# Add headers destination for install rule.
set_property(TARGET rtaudio PROPERTY PUBLIC_HEADER RtAudio.h)
set_target_properties(rtaudio PROPERTIES
SOVERSION ${SO_VER}
VERSION ${FULL_VER})
# Set standard installation directories.
include(GNUInstallDirs)
# Set include paths, populate target interface.
target_include_directories(rtaudio
INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/rtaudio>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
${INCDIRS}
)
# Set compile-time definitions
target_compile_definitions(rtaudio PRIVATE ${API_DEFS})
target_compile_definitions(rtaudio PRIVATE RTAUDIO_EXPORT)
target_link_libraries(rtaudio ${LINKLIBS})
# Subdirs
include(CTest)
if(NOT DEFINED RTAUDIO_BUILD_TESTING OR RTAUDIO_BUILD_TESTING STREQUAL "")
set(RTAUDIO_BUILD_TESTING ${BUILD_TESTING})
endif()
# Message
string(REPLACE ";" " " apilist "${API_LIST}")
message(STATUS "Compiling with support for: ${apilist}")
# PkgConfig file
string(REPLACE ";" " " req "${PKGCONFIG_REQUIRES}")
string(REPLACE ";" " " api "${API_DEFS}")
set(prefix ${CMAKE_INSTALL_PREFIX})
# Store the package in the user registry.
export(PACKAGE RtAudio)
# Create CMake configuration export file.
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/RtAudioConfig.cmake.in "@PACKAGE_INIT@\n")
if(NEED_PTHREAD)
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/RtAudioConfig.cmake.in "find_package(Threads REQUIRED)\n")
endif()
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/RtAudioConfig.cmake.in "include(\${CMAKE_CURRENT_LIST_DIR}/RtAudioTargets.cmake)")
# Create uninstall target.
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake" IMMEDIATE @ONLY)
add_custom_target(
uninstall "${CMAKE_COMMAND}" -P
"${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")
include_directories(..)
if (WIN32)
include_directories(../include)
endif (WIN32)
list(GET LIB_TARGETS 0 LIBRTAUDIO)
add_executable(lcc_audio lcc_rtaudio.cpp)
target_link_libraries(lcc_audio ${LIBRTAUDIO} ${LINKLIBS})
#installs executable in /usr/local/bin in unix with correct executable permission
#for system-wide access
if (UNIX)
install(TARGETS lcc_audio
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
install(DIRECTORY data/ DESTINATION $ENV{HOME}/.lcc_audio/data
PATTERN "data/*"
PERMISSIONS OWNER_WRITE OWNER_READ GROUP_WRITE GROUP_READ WORLD_WRITE WORLD_READ)
endif (UNIX)
install(FILES ${CMAKE_BINARY_DIR}/lcc_audio DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)