forked from FNA-XNA/FAudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
387 lines (350 loc) · 11.7 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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# CMake Project for FAudio
# Written by @NeroBurner
cmake_minimum_required(VERSION 2.8.12)
project(FAudio C)
# Options
option(BUILD_UTILS "Build utils/ folder" OFF)
option(BUILD_TESTS "Build tests/ folder for unit tests to be executed on the host against FAudio" OFF)
option(BUILD_SDL3 "Build against SDL 3.0" OFF)
if(WIN32)
option(PLATFORM_WIN32 "Enable native Win32 platform instead of SDL" OFF)
endif()
option(XNASONG "Build with XNA_Song.c" ON)
option(LOG_ASSERTIONS "Bind FAudio_assert to log, instead of platform's assert" OFF)
option(FORCE_ENABLE_DEBUGCONFIGURATION "Enable DebugConfiguration in all build types" OFF)
option(DUMP_VOICES "Dump voices to RIFF WAVE files" OFF)
option(BUILD_SHARED_LIBS "Build shared library" ON)
if(WIN32)
option(INSTALL_MINGW_DEPENDENCIES "Add dependent libraries to MinGW install target" OFF)
endif()
# C99 Requirement
if(${CMAKE_VERSION} VERSION_LESS "3.1.3")
message(WARNING "Your CMake version is too old, set -std=c99 yourself!")
else()
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_EXTENSIONS OFF)
endif()
# Version
SET(LIB_MAJOR_VERSION "0")
SET(LIB_MINOR_VERSION "24")
SET(LIB_REVISION "10")
SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
# Build Type
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
# By default, we use Release
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE
STRING "Choose the type of build." FORCE
)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
STRINGS "Debug" "Release" "RelWithDebInfo"
)
endif()
# Add our repository's module path to CMake's module path list
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
# Platform Flags
if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
elseif(WIN32)
# "FAudio.dll", not "libFAudio.dll"
set(CMAKE_SHARED_LIBRARY_PREFIX "")
endif()
# Helper function for finding/installing MinGW libs
if(INSTALL_MINGW_DEPENDENCIES)
include(cmake/install_shared_libs.cmake)
endif()
set(target FAudio-shared)
if(NOT BUILD_SHARED_LIBS)
set(target FAudio-static)
endif()
# Source lists
add_library(${target}
# Public Headers
include/F3DAudio.h
include/FACT3D.h
include/FACT.h
include/FAPOBase.h
include/FAPOFX.h
include/FAPO.h
include/FAudioFX.h
include/FAudio.h
# Internal Headers
src/FACT_internal.h
src/FAudio_internal.h
src/stb.h
src/stb_vorbis.h
src/qoa_decoder.h
# Source Files
src/F3DAudio.c
src/FACT3D.c
src/FACT.c
src/FACT_internal.c
src/FAPOBase.c
src/FAPOFX.c
src/FAPOFX_echo.c
src/FAPOFX_eq.c
src/FAPOFX_masteringlimiter.c
src/FAPOFX_reverb.c
src/FAudio.c
src/FAudioFX_reverb.c
src/FAudioFX_volumemeter.c
src/FAudio_internal.c
src/FAudio_internal_simd.c
src/FAudio_operationset.c
src/FAudio_platform_sdl2.c
src/FAudio_platform_sdl3.c
src/FAudio_platform_win32.c
# Optional source files
src/XNA_Song.c
)
if(PLATFORM_WIN32)
target_link_libraries(${target} PRIVATE dxguid uuid winmm ole32 advapi32 user32 mfplat mfreadwrite mfuuid propsys)
target_compile_definitions(${target} PUBLIC FAUDIO_WIN32_PLATFORM)
target_compile_definitions(${target} PRIVATE HAVE_WMADEC=1)
set(PLATFORM_CFLAGS "-DFAUDIO_WIN32_PLATFORM")
set(XNASONG OFF)
else()
if(BUILD_SDL3)
target_compile_definitions(${target} PUBLIC FAUDIO_SDL3_PLATFORM)
set(PLATFORM_CFLAGS "-DFAUDIO_SDL3_PLATFORM")
else()
set(PLATFORM_CFLAGS)
endif()
endif()
# Only disable DebugConfiguration in release builds
if(NOT FORCE_ENABLE_DEBUGCONFIGURATION)
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Release>:FAUDIO_DISABLE_DEBUGCONFIGURATION>)
endif()
# FAudio_assert Customization
if(LOG_ASSERTIONS)
target_compile_definitions(${target} PUBLIC FAUDIO_LOG_ASSERTIONS)
endif()
# FAudio folders as includes, for other targets to consume
target_include_directories(${target} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
# MinGW builds should statically link libgcc
if(MINGW)
target_link_libraries(${target} PRIVATE -static-libgcc)
endif()
# Soname
set_target_properties(${target} PROPERTIES OUTPUT_NAME "FAudio"
VERSION ${LIB_VERSION}
SOVERSION ${LIB_MAJOR_VERSION}
)
# XNA_Song Support
if(NOT XNASONG)
target_compile_definitions(${target} PRIVATE DISABLE_XNASONG)
endif()
# Dump source voices to RIFF WAVE files
if(DUMP_VOICES)
target_compile_definitions(${target} PRIVATE FAUDIO_DUMP_VOICES)
endif()
# SDL Dependency
if (PLATFORM_WIN32)
message(STATUS "not using SDL")
elseif (BUILD_SDL3)
if (DEFINED SDL3_INCLUDE_DIRS AND DEFINED SDL3_LIBRARIES)
message(STATUS "using pre-defined SDL3 variables SDL3_INCLUDE_DIRS and SDL3_LIBRARIES")
target_include_directories(${target} PUBLIC "$<BUILD_INTERFACE:${SDL3_INCLUDE_DIRS}>")
target_link_libraries(${target} PUBLIC ${SDL3_LIBRARIES})
if(INSTALL_MINGW_DEPENDENCIES)
install_shared_libs(${SDL3_LIBRARIES} DESTINATION bin NO_INSTALL_SYMLINKS)
endif()
else()
# Only try to autodetect if both SDL3 variables aren't explicitly set
find_package(SDL3 CONFIG)
if (TARGET SDL3::SDL3)
message(STATUS "using TARGET SDL3::SDL3")
target_link_libraries(${target} PUBLIC SDL3::SDL3)
if(INSTALL_MINGW_DEPENDENCIES)
install_shared_libs(TARGETS SDL3::SDL3 DESTINATION bin NO_INSTALL_SYMLINKS REQUIRED)
endif()
elseif (TARGET SDL3)
message(STATUS "using TARGET SDL3")
target_link_libraries(${target} PUBLIC SDL3)
if(INSTALL_MINGW_DEPENDENCIES)
install_shared_libs(TARGETS SDL3 DESTINATION bin NO_INSTALL_SYMLINKS REQUIRED)
endif()
else()
message(STATUS "no TARGET SDL3::SDL3, or SDL3, using variables")
target_include_directories(${target} PUBLIC "$<BUILD_INTERFACE:${SDL3_INCLUDE_DIRS}>")
target_link_libraries(${target} PUBLIC ${SDL3_LIBRARIES})
if(INSTALL_MINGW_DEPENDENCIES)
install_shared_libs(${SDL3_LIBRARIES} DESTINATION bin NO_INSTALL_SYMLINKS)
endif()
endif()
endif()
elseif (DEFINED SDL2_INCLUDE_DIRS AND DEFINED SDL2_LIBRARIES)
message(STATUS "using pre-defined SDL2 variables SDL2_INCLUDE_DIRS and SDL2_LIBRARIES")
target_include_directories(${target} PUBLIC "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>")
target_link_libraries(${target} PUBLIC ${SDL2_LIBRARIES})
if(INSTALL_MINGW_DEPENDENCIES)
install_shared_libs(${SDL2_LIBRARIES} DESTINATION bin NO_INSTALL_SYMLINKS)
endif()
else()
# Only try to autodetect if both SDL2 variables aren't explicitly set
find_package(SDL2 CONFIG)
if (TARGET SDL2::SDL2)
message(STATUS "using TARGET SDL2::SDL2")
target_link_libraries(${target} PUBLIC SDL2::SDL2)
if(INSTALL_MINGW_DEPENDENCIES)
install_shared_libs(TARGETS SDL2::SDL2 DESTINATION bin NO_INSTALL_SYMLINKS REQUIRED)
endif()
elseif (TARGET SDL2)
message(STATUS "using TARGET SDL2")
target_link_libraries(${target} PUBLIC SDL2)
if(INSTALL_MINGW_DEPENDENCIES)
install_shared_libs(TARGETS SDL2 DESTINATION bin NO_INSTALL_SYMLINKS REQUIRED)
endif()
else()
message(STATUS "no TARGET SDL2::SDL2, or SDL2, using variables")
target_include_directories(${target} PUBLIC "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>")
target_link_libraries(${target} PUBLIC ${SDL2_LIBRARIES})
if(INSTALL_MINGW_DEPENDENCIES)
install_shared_libs(${SDL2_LIBRARIES} DESTINATION bin NO_INSTALL_SYMLINKS)
endif()
endif()
endif()
# utils/ Folder
if(BUILD_UTILS)
enable_language(CXX)
# Shared ImGui Framework
add_library(uicommon STATIC
utils/uicommon/FAudioUI_main.cpp
utils/uicommon/imconfig.h
utils/uicommon/imgui.cpp
utils/uicommon/imgui_demo.cpp
utils/uicommon/imgui_draw.cpp
utils/uicommon/imgui_widgets.cpp
utils/uicommon/imgui.h
utils/uicommon/imgui_internal.h
utils/uicommon/imstb_rectpack.h
utils/uicommon/imstb_textedit.h
utils/uicommon/imstb_truetype.h
)
target_link_libraries(uicommon PUBLIC ${target})
# Shared WAV Resources
add_library(wavs STATIC utils/wavcommon/wavs.cpp)
target_compile_definitions(wavs PUBLIC
RESOURCE_PATH="${CMAKE_SOURCE_DIR}/utils/wavcommon/resources"
)
# These tools do NOT use uicommon
add_executable(testparse utils/testparse/testparse.c)
target_link_libraries(testparse PRIVATE ${target})
add_executable(testxwma utils/testxwma/testxwma.cpp)
target_link_libraries(testxwma PRIVATE ${target})
add_executable(showriffheader utils/showriffheader/showriffheader.cpp)
target_link_libraries(showriffheader PRIVATE ${target})
# These tools use uicommon, but NOT wavs
add_executable(facttool utils/facttool/facttool.cpp)
target_link_libraries(facttool PRIVATE uicommon)
add_executable(testfilter
utils/testfilter/audio.cpp
utils/testfilter/audio_faudio.cpp
utils/testfilter/audio.h
utils/testfilter/audio_player.h
utils/testfilter/audio_xaudio.cpp
utils/testfilter/oscillator.cpp
utils/testfilter/oscillator.h
utils/testfilter/testfilter.cpp
)
target_link_libraries(testfilter PRIVATE uicommon)
# These tools use both uicommon and wavs
add_executable(testreverb
utils/testreverb/audio.cpp
utils/testreverb/audio_faudio.cpp
utils/testreverb/audio.h
utils/testreverb/audio_xaudio.cpp
utils/testreverb/testreverb.cpp
)
target_link_libraries(testreverb PRIVATE uicommon wavs)
add_executable(testvolumemeter
utils/testvolumemeter/audio.cpp
utils/testvolumemeter/audio_faudio.cpp
utils/testvolumemeter/audio.h
utils/testvolumemeter/testvolumemeter.cpp
)
target_link_libraries(testvolumemeter PRIVATE uicommon wavs)
add_executable(voicepool
utils/voicepool/voicepool.cpp
)
target_link_libraries(voicepool PRIVATE uicommon wavs)
endif()
# define install directories
# on mingw-w64 cross compilation $CMAKE_INSTALL_LIBDIR is set to an absolute
# path. Work around that by hard coding the directories on windows
if(WIN32)
set(FAudio_INSTALL_INCLUDEDIR include)
set(FAudio_INSTALL_BINDIR bin)
set(FAudio_INSTALL_LIBDIR lib)
else()
include(GNUInstallDirs)
set(FAudio_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR})
set(FAudio_INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR})
set(FAudio_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
endif()
# tests/ Folder
if(BUILD_TESTS)
add_executable(faudio_tests tests/xaudio2.c)
target_compile_definitions(faudio_tests PRIVATE _DEFAULT_SOURCE _BSD_SOURCE)
target_link_libraries(faudio_tests PRIVATE ${target})
endif()
# Installation
# Public Headers...
install(
DIRECTORY include/
DESTINATION ${FAudio_INSTALL_INCLUDEDIR}
)
# Libraries...
set(export ${PROJECT_NAME}-targets-shared)
if(NOT BUILD_SHARED_LIBS)
set(export ${PROJECT_NAME}-targets-static)
endif()
install(
TARGETS ${target}
EXPORT ${export}
INCLUDES DESTINATION ${FAudio_INSTALL_INCLUDEDIR}
RUNTIME DESTINATION ${FAudio_INSTALL_BINDIR}
LIBRARY DESTINATION ${FAudio_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${FAudio_INSTALL_LIBDIR}
)
# Generate a pkgconfig file
include(cmake/JoinPaths.cmake)
join_paths(FAUDIO_PKGCONF_LIBDIR "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
join_paths(FAUDIO_PKGCONF_INCLUDEDIR "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
if(NOT PLATFORM_WIN32)
if(BUILD_SDL3)
set(PC_REQUIRES_PRIVATE "Requires.private: sdl3")
else()
set(PC_REQUIRES_PRIVATE "Requires.private: sdl2")
endif()
endif()
configure_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}.pc.in"
${PROJECT_BINARY_DIR}/generated/${PROJECT_NAME}.pc
@ONLY
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}.pc
DESTINATION ${FAudio_INSTALL_LIBDIR}/pkgconfig
)
# Generate cmake-config file, install CMake files
include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${FAudio_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}Config.cmake
DESTINATION ${FAudio_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
install(
EXPORT ${export}
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${FAudio_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)