forked from ddiakopoulos/libnyquist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
305 lines (241 loc) · 9.94 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
cmake_minimum_required(VERSION 3.13)
set(LIBNYQUIST_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
set(CMAKE_MODULE_PATH ${LIBNYQUIST_ROOT}/cmake)
include(CXXhelpers)
include(GNUInstallDirs)
if (CMAKE_OSX_ARCHITECTURES)
if(CMAKE_OSX_SYSROOT MATCHES ".*iphoneos.*")
# RtAudio is not portable to ios currently
option(LIBNYQUIST_BUILD_EXAMPLE "Build example application" OFF)
else()
option(LIBNYQUIST_BUILD_EXAMPLE "Build example application" ON)
endif()
else()
option(LIBNYQUIST_BUILD_EXAMPLE "Build example application" ON)
endif()
#-------------------------------------------------------------------------------
# libopus
if (BUILD_LIBOPUS)
project(libopus)
file(GLOB third_opus_src
"${LIBNYQUIST_ROOT}/third_party/opus/celt/*.c"
"${LIBNYQUIST_ROOT}/third_party/opus/opusfile/src/*.c"
"${LIBNYQUIST_ROOT}/third_party/opus/silk/*.c"
"${LIBNYQUIST_ROOT}/third_party/opus/silk/float/*.c"
)
set(lib_opus_src
"${LIBNYQUIST_ROOT}/third_party/opus/libopus/src/analysis.c"
"${LIBNYQUIST_ROOT}/third_party/opus/libopus/src/mlp_data.c"
"${LIBNYQUIST_ROOT}/third_party/opus/libopus/src/mlp.c"
"${LIBNYQUIST_ROOT}/third_party/opus/libopus/src/opus_decoder.c"
"${LIBNYQUIST_ROOT}/third_party/opus/libopus/src/opus_multistream_decoder.c"
"${LIBNYQUIST_ROOT}/third_party/opus/libopus/src/opus_multistream_encoder.c"
"${LIBNYQUIST_ROOT}/third_party/opus/libopus/src/opus.c"
"${LIBNYQUIST_ROOT}/third_party/opus/libopus/src/repacketizer.c"
)
add_library(libopus STATIC ${third_opus_src} ${lib_opus_src})
set_cxx_version(libopus)
_set_compile_options(libopus)
if (WIN32)
_disable_warning(4244)
_disable_warning(4018)
endif()
target_include_directories(libopus SYSTEM PRIVATE
${LIBNYQUIST_ROOT}/third_party/libogg/include
${LIBNYQUIST_ROOT}/third_party/opus/celt
${LIBNYQUIST_ROOT}/third_party/opus/libopus/include
${LIBNYQUIST_ROOT}/third_party/opus/opusfile/include
${LIBNYQUIST_ROOT}/third_party/opus/opusfile/src/include
${LIBNYQUIST_ROOT}/third_party/opus/silk
${LIBNYQUIST_ROOT}/third_party/opus/silk/float)
if (MSVC_IDE)
# hack to get around the "Debug" and "Release" directories cmake tries to add on Windows
#set_target_properties(libnyquist PROPERTIES PREFIX "../")
set_target_properties(libopus PROPERTIES IMPORT_PREFIX "../")
endif()
target_compile_definitions(libopus PRIVATE OPUS_BUILD)
target_compile_definitions(libopus PRIVATE USE_ALLOCA)
set_target_properties(libopus
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
set_target_properties(libopus PROPERTIES OUTPUT_NAME_DEBUG libopus_d)
install (TARGETS libopus
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin)
install (TARGETS libopus DESTINATION lib)
# folders
source_group(src FILES ${third_opus_src})
endif()
#-------------------------------------------------------------------------------
# libwavpack
if (BUILD_LIBWAVPACK)
project(libwavpack)
if(MSVC)
# Disable warning C4996 regarding fopen(), strcpy(), etc.
_add_define("_CRT_SECURE_NO_WARNINGS")
# Disable warning C4996 regarding unchecked iterators for std::transform,
# std::copy, std::equal, et al.
_add_define("_SCL_SECURE_NO_WARNINGS")
# Make sure WinDef.h does not define min and max macros which
# will conflict with std::min() and std::max().
_add_define("NOMINMAX")
endif()
add_definitions(${_NQR_CXX_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${_NQR_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
file(GLOB third_wavpack_src "${LIBNYQUIST_ROOT}/third_party/wavpack/src/*.c")
add_library(libwavpack STATIC ${third_wavpack_src})
set_cxx_version(libwavpack)
_set_compile_options(libwavpack)
if (WIN32)
_disable_warning(181)
_disable_warning(111)
_disable_warning(4267)
_disable_warning(4996)
_disable_warning(4244)
_disable_warning(4701)
_disable_warning(4702)
_disable_warning(4133)
_disable_warning(4100)
_disable_warning(4127)
_disable_warning(4206)
_disable_warning(4312)
_disable_warning(4505)
_disable_warning(4365)
_disable_warning(4005)
_disable_warning(4013)
_disable_warning(4334)
_disable_warning(4703)
endif()
target_include_directories(libwavpack SYSTEM PRIVATE ${LIBNYQUIST_ROOT}/third_party/wavpack/include)
if (MSVC_IDE)
set_target_properties(libwavpack PROPERTIES IMPORT_PREFIX "../")
endif()
set_target_properties(libwavpack
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
set_target_properties(libwavpack PROPERTIES OUTPUT_NAME_DEBUG libwavpack_d)
install(TARGETS libwavpack
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin)
install (TARGETS libwavpack DESTINATION lib)
endif()
#-------------------------------------------------------------------------------
# libnyquist static library
project(libnyquist)
file(GLOB nyquist_include "${LIBNYQUIST_ROOT}/include/libnyquist/*")
file(GLOB nyquist_src "${LIBNYQUIST_ROOT}/src/*")
file(GLOB wavpack_src "${LIBNYQUIST_ROOT}/third_party/wavpack/src/*.c")
add_library(libnyquist STATIC
${nyquist_include}
${nyquist_src}
${wavpack_src}
)
set_cxx_version(libnyquist)
_set_compile_options(libnyquist)
if (WIN32)
_disable_warning(4244)
_disable_warning(4018)
endif()
target_include_directories(libnyquist SYSTEM
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${LIBNYQUIST_ROOT}/include>
PRIVATE
${LIBNYQUIST_ROOT}/include/libnyquist
${LIBNYQUIST_ROOT}/third_party
${LIBNYQUIST_ROOT}/third_party/FLAC/src/include
${LIBNYQUIST_ROOT}/third_party/libogg/include
${LIBNYQUIST_ROOT}/third_party/libvorbis/include
${LIBNYQUIST_ROOT}/third_party/libvorbis/src
${LIBNYQUIST_ROOT}/third_party/musepack/include
${LIBNYQUIST_ROOT}/third_party/opus/celt
${LIBNYQUIST_ROOT}/third_party/opus/libopus/include
${LIBNYQUIST_ROOT}/third_party/opus/opusfile/include
${LIBNYQUIST_ROOT}/third_party/opus/opusfile/src/include
${LIBNYQUIST_ROOT}/third_party/opus/silk
${LIBNYQUIST_ROOT}/third_party/opus/silk/float
${LIBNYQUIST_ROOT}/third_party/wavpack/include
${LIBNYQUIST_ROOT}/src
)
if (MSVC_IDE)
# hack to get around the "Debug" and "Release" directories cmake tries to add on Windows
#set_target_properties(libnyquist PROPERTIES PREFIX "../")
set_target_properties(libnyquist PROPERTIES IMPORT_PREFIX "../")
endif()
set_target_properties(libnyquist PROPERTIES OUTPUT_NAME_DEBUG libnyquist_d)
set_target_properties(libnyquist
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_INSTALL_LIBDIR}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_INSTALL_BINDIR}"
)
#target_link_libraries(libnyquist PRIVATE libwavpack)
add_library(libnyquist::libnyquist ALIAS libnyquist)
# todo, install the headers
# export the targets for use when libnyquist is included as a subproject
export(TARGETS libnyquist
NAMESPACE libnyquist::
FILE "${CMAKE_CURRENT_BINARY_DIR}/libnyquistConfig.cmake"
)
# folders
source_group(src FILES ${nyquist_src})
#-------------------------------------------------------------------------------
# libnyquist-examples
if(LIBNYQUIST_BUILD_EXAMPLE)
set(NQR_EXAMPLE_APP_NAME "libnyquist-examples")
set(
EXAMPLE_SOURCES
${LIBNYQUIST_ROOT}/examples/src/Main.cpp
${LIBNYQUIST_ROOT}/examples/src/AudioDevice.cpp
${LIBNYQUIST_ROOT}/examples/src/AudioDevice.h
${LIBNYQUIST_ROOT}/examples/src/RingBuffer.h
${LIBNYQUIST_ROOT}/third_party/rtaudio/RtAudio.cpp
${LIBNYQUIST_ROOT}/third_party/rtaudio/RtAudio.h
)
add_executable(${NQR_EXAMPLE_APP_NAME} ${EXAMPLE_SOURCES})
if(WIN32)
target_compile_definitions(${NQR_EXAMPLE_APP_NAME} PRIVATE __WINDOWS_WASAPI__)
elseif(APPLE)
target_compile_definitions(${NQR_EXAMPLE_APP_NAME} PRIVATE __MACOSX_CORE__)
elseif(LIBNYQUIST_JACK)
target_compile_definitions(${NQR_EXAMPLE_APP_NAME} PRIVATE __UNIX_JACK__)
target_link_libraries(${NQR_EXAMPLE_APP_NAME} PRIVATE jack pthread)
elseif(LIBNYQUIST_PULSE)
find_library(PULSESIMPLE_LIB pulse-simple)
target_compile_definitions(${NQR_EXAMPLE_APP_NAME} PRIVATE __LINUX_PULSE__)
target_link_libraries(${NQR_EXAMPLE_APP_NAME} PRIVATE pulse ${PULSESIMPLE_LIB} pthread)
elseif(LIBNYQUIST_ASOUND)
target_compile_definitions(${NQR_EXAMPLE_APP_NAME} PRIVATE __LINUX_ALSA__)
target_link_libraries(${NQR_EXAMPLE_APP_NAME} PRIVATE asound pthread)
else()
message(FATAL_ERROR "On Linux, one of LIBNYQUIST_JACK, LIBNYQUIST_PULSE, or LIBNYQUIST_ASOUND must be set.")
endif()
target_include_directories(${NQR_EXAMPLE_APP_NAME} SYSTEM PRIVATE
${LIBNYQUIST_ROOT}/examples/src
${LIBNYQUIST_ROOT}/third_party
)
target_link_libraries(${NQR_EXAMPLE_APP_NAME} PRIVATE libnyquist)
set_target_properties(${NQR_EXAMPLE_APP_NAME}
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
if(APPLE)
target_link_libraries(${NQR_EXAMPLE_APP_NAME} PRIVATE
"-framework AudioToolbox"
"-framework AudioUnit"
"-framework Accelerate"
"-framework CoreAudio"
"-framework Cocoa"
)
ENDIF(APPLE)
endif()