Remove some unused members
[openal-soft.git] / CMakeLists.txt
blobf9a2c859629d596e22fd94ab98737a729afca7ff
1 # CMake build file list for OpenAL
3 cmake_minimum_required(VERSION 3.0.2)
5 if(APPLE)
6     # The workaround for try_compile failing with code signing
7     # since cmake-3.18.2, not required
8     set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
9         ${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES}
10         "CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED"
11         "CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED")
12     set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
13     set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
14 endif()
16 if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
17     # Fix compile failure with armv7 deployment target >= 11.0, xcode clang
18     # will report:
19     # error: invalid iOS deployment version '--target=armv7-apple-ios13.6',
20     # iOS 10 is the maximum deployment target for 32-bit targets
21     # If CMAKE_OSX_DEPLOYMENT_TARGET is not defined, cmake will choose latest
22     # deployment target
23     if("${CMAKE_OSX_ARCHITECTURES}" MATCHES ".*armv7.*")
24         if(NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET
25             OR NOT CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS "11.0")
26             message(STATUS "Forcing iOS deployment target to 10.0 for armv7")
27             set(CMAKE_OSX_DEPLOYMENT_TARGET "10.0" CACHE STRING "Minimum OS X deployment version"
28                 FORCE)
29         endif()
30     endif()
31 endif()
33 set(CMAKE_C_VISIBILITY_PRESET hidden)
34 set(CMAKE_CXX_VISIBILITY_PRESET hidden)
36 if(COMMAND CMAKE_POLICY)
37     cmake_policy(SET CMP0003 NEW)
38     cmake_policy(SET CMP0005 NEW)
39     if(POLICY CMP0020)
40         cmake_policy(SET CMP0020 NEW)
41     endif(POLICY CMP0020)
42     if(POLICY CMP0042)
43         cmake_policy(SET CMP0042 NEW)
44     endif(POLICY CMP0042)
45     if(POLICY CMP0054)
46         cmake_policy(SET CMP0054 NEW)
47     endif(POLICY CMP0054)
48     if(POLICY CMP0058)
49         cmake_policy(SET CMP0058 NEW)
50     endif(POLICY CMP0058)
51     if(POLICY CMP0063)
52         cmake_policy(SET CMP0063 NEW)
53     endif(POLICY CMP0063)
54     if(POLICY CMP0075)
55         cmake_policy(SET CMP0075 NEW)
56     endif(POLICY CMP0075)
57     if(POLICY CMP0092)
58         cmake_policy(SET CMP0092 NEW)
59     endif(POLICY CMP0092)
60     if(POLICY CMP0117)
61         cmake_policy(SET CMP0117 NEW)
62     endif(POLICY CMP0117)
63 endif(COMMAND CMAKE_POLICY)
65 project(OpenAL)
67 if(NOT CMAKE_BUILD_TYPE)
68     set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
69         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
70         FORCE)
71 endif()
72 if(NOT CMAKE_DEBUG_POSTFIX)
73     set(CMAKE_DEBUG_POSTFIX "" CACHE STRING
74         "Library postfix for debug builds. Normally left blank."
75         FORCE)
76 endif()
78 set(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
80 include(CheckFunctionExists)
81 include(CheckLibraryExists)
82 include(CheckIncludeFile)
83 include(CheckIncludeFiles)
84 include(CheckSymbolExists)
85 include(CheckCCompilerFlag)
86 include(CheckCXXCompilerFlag)
87 include(CheckCSourceCompiles)
88 include(CheckCXXSourceCompiles)
89 include(CheckStructHasMember)
90 include(CMakePackageConfigHelpers)
91 include(GNUInstallDirs)
93 find_package(PkgConfig)
96 option(ALSOFT_DLOPEN  "Check for the dlopen API for loading optional libs"  ON)
98 option(ALSOFT_WERROR  "Treat compile warnings as errors"      OFF)
100 option(ALSOFT_UTILS "Build utility programs"  ON)
101 option(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
103 option(ALSOFT_EXAMPLES  "Build example programs"  ON)
105 option(ALSOFT_INSTALL "Install main library" ON)
106 option(ALSOFT_INSTALL_CONFIG "Install alsoft.conf sample configuration file" ON)
107 option(ALSOFT_INSTALL_HRTF_DATA "Install HRTF data files" ON)
108 option(ALSOFT_INSTALL_AMBDEC_PRESETS "Install AmbDec preset files" ON)
109 option(ALSOFT_INSTALL_EXAMPLES "Install example programs (alplay, alstream, ...)" ON)
110 option(ALSOFT_INSTALL_UTILS "Install utility programs (openal-info, alsoft-config, ...)" ON)
111 option(ALSOFT_UPDATE_BUILD_VERSION "Update git build version info" ON)
113 option(ALSOFT_EAX "Enable legacy EAX extensions" ${WIN32})
115 option(ALSOFT_SEARCH_INSTALL_DATADIR "Search the installation data directory" OFF)
116 if(ALSOFT_SEARCH_INSTALL_DATADIR)
117     set(ALSOFT_INSTALL_DATADIR ${CMAKE_INSTALL_FULL_DATADIR})
118 endif()
120 if(DEFINED SHARE_INSTALL_DIR)
121     message(WARNING "SHARE_INSTALL_DIR is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
122     set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
123 endif()
125 if(DEFINED LIB_SUFFIX)
126     message(WARNING "LIB_SUFFIX is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
127 endif()
128 if(DEFINED ALSOFT_CONFIG)
129     message(WARNING "ALSOFT_CONFIG is deprecated. Use ALSOFT_INSTALL_CONFIG instead")
130 endif()
131 if(DEFINED ALSOFT_HRTF_DEFS)
132     message(WARNING "ALSOFT_HRTF_DEFS is deprecated. Use ALSOFT_INSTALL_HRTF_DATA instead")
133 endif()
134 if(DEFINED ALSOFT_AMBDEC_PRESETS)
135     message(WARNING "ALSOFT_AMBDEC_PRESETS is deprecated. Use ALSOFT_INSTALL_AMBDEC_PRESETS instead")
136 endif()
139 set(CPP_DEFS ) # C pre-processor, not C++
140 set(INC_PATHS )
141 set(C_FLAGS )
142 set(LINKER_FLAGS )
143 set(EXTRA_LIBS )
145 if(WIN32)
146     set(CPP_DEFS ${CPP_DEFS} _WIN32 NOMINMAX)
147     if(MINGW)
148         set(CPP_DEFS ${CPP_DEFS} __USE_MINGW_ANSI_STDIO)
149     endif()
151     option(ALSOFT_BUILD_ROUTER  "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)"  OFF)
152     if(MINGW)
153         option(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
154     endif()
155 elseif(APPLE)
156     option(ALSOFT_OSX_FRAMEWORK "Build as macOS framework" OFF)
157 endif()
160 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
161 if("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
162     set(INC_PATHS ${INC_PATHS} /usr/include)
163     set(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
164 endif()
166 # When the library is built for static linking, apps should define
167 # AL_LIBTYPE_STATIC when including the AL headers.
168 if(NOT LIBTYPE)
169     set(LIBTYPE SHARED)
170 endif()
172 set(LIB_MAJOR_VERSION "1")
173 set(LIB_MINOR_VERSION "22")
174 set(LIB_REVISION "2")
175 set(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
176 set(LIB_VERSION_NUM ${LIB_MAJOR_VERSION},${LIB_MINOR_VERSION},${LIB_REVISION},0)
178 set(EXPORT_DECL "")
181 # Require C++14
182 set(CMAKE_CXX_STANDARD 14)
183 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
185 # Prefer C11, but support C99 and C90 too.
186 set(CMAKE_C_STANDARD 11)
188 if(NOT WIN32)
189     # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
190     check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
191     if(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
192         set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
193         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
194         check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
195         if(NOT HAVE_POSIX_MEMALIGN_POSIX)
196             set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
197         else()
198             set(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
199         endif()
200     endif()
201     unset(OLD_REQUIRED_FLAGS)
202 endif()
204 # C99 has restrict, but C++ does not, so we can only utilize __restrict.
205 check_cxx_source_compiles("int *__restrict foo;
206 int main() { return 0; }" HAVE___RESTRICT)
207 if(HAVE___RESTRICT)
208     set(CPP_DEFS ${CPP_DEFS} RESTRICT=__restrict)
209 else()
210     set(CPP_DEFS ${CPP_DEFS} "RESTRICT=")
211 endif()
213 # Some systems may need libatomic for atomic functions to work
214 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
215 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
216 check_cxx_source_compiles("#include <atomic>
217 std::atomic<int> foo{0};
218 int main() { return foo.fetch_add(2); }"
219 HAVE_LIBATOMIC)
220 if(NOT HAVE_LIBATOMIC)
221     set(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
222 else()
223     set(EXTRA_LIBS atomic ${EXTRA_LIBS})
224 endif()
225 unset(OLD_REQUIRED_LIBRARIES)
227 if(ANDROID)
228     # Include liblog for Android logging
229     check_library_exists(log __android_log_print "" HAVE_LIBLOG)
230     if(HAVE_LIBLOG)
231         set(EXTRA_LIBS log ${EXTRA_LIBS})
232         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
233     endif()
234 endif()
236 if(MSVC)
237     set(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS)
238     check_cxx_compiler_flag(/permissive- HAVE_PERMISSIVE_SWITCH)
239     if(HAVE_PERMISSIVE_SWITCH)
240         set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
241     endif()
242     set(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4127 /wd4268 /wd4324 /wd5030 /wd5051)
244     if(NOT DXSDK_DIR)
245         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
246     else()
247         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
248     endif()
249     if(DXSDK_DIR)
250         message(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
251     endif()
253     option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
254     if(FORCE_STATIC_VCRT)
255         foreach(flag_var
256                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
257                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
258                 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
259                 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
260             if(${flag_var} MATCHES "/MD")
261                 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
262             endif()
263         endforeach(flag_var)
264     endif()
265 else()
266     set(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
267         -Wpedantic
268         $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
270     check_cxx_compiler_flag(-Wno-c++20-attribute-extensions HAVE_WNO_CXX20_ATTR_EXT)
271     if(HAVE_WNO_CXX20_ATTR_EXT)
272         set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:-Wno-c++20-attribute-extensions>)
273     endif()
275     if(ALSOFT_WERROR)
276         set(C_FLAGS ${C_FLAGS} -Werror)
277     endif()
279     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
280     # instead of NDEBUG)
281     foreach(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
282         if(${flag_var} MATCHES "-DNDEBUG")
283             string(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
284         endif()
285     endforeach()
287     check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
288     if(HAVE_FNO_MATH_ERRNO)
289         set(C_FLAGS ${C_FLAGS} -fno-math-errno)
290     endif()
292     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
293     if(ALSOFT_STATIC_LIBGCC)
294         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
295         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
296         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
297         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
298         unset(OLD_REQUIRED_LIBRARIES)
300         if(NOT HAVE_STATIC_LIBGCC_SWITCH)
301             message(FATAL_ERROR "Cannot static link libgcc")
302         endif()
303         set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
304     endif()
306     option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
307     if(ALSOFT_STATIC_STDCXX)
308         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
309         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
310         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
311         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
312         unset(OLD_REQUIRED_LIBRARIES)
314         if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
315             message(FATAL_ERROR "Cannot static link libstdc++")
316         endif()
317         set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
318     endif()
320     if(WIN32)
321         option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
322         if(ALSOFT_STATIC_WINPTHREAD)
323             set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
324             set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
325             check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
326             set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
327             unset(OLD_REQUIRED_LIBRARIES)
329             if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
330                 message(FATAL_ERROR "Cannot static link libwinpthread")
331             endif()
332             set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
333         endif()
334     endif()
335 endif()
337 # Set visibility/export options if available
338 if(WIN32)
339     if(NOT LIBTYPE STREQUAL "STATIC")
340         set(EXPORT_DECL "__declspec(dllexport)")
341     endif()
342 else()
343     set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
344     # Yes GCC, really don't accept visibility modes you don't support
345     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
347     check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
348                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
349     if(HAVE_GCC_PROTECTED_VISIBILITY)
350         if(NOT LIBTYPE STREQUAL "STATIC")
351             set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
352         endif()
353     else()
354         check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
355                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
356         if(HAVE_GCC_DEFAULT_VISIBILITY)
357             if(NOT LIBTYPE STREQUAL "STATIC")
358                 set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
359             endif()
360         endif()
361     endif()
363     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
364 endif()
367 set(SSE2_SWITCH "")
369 if(NOT MSVC)
370     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
371     # Yes GCC, really don't accept command line options you don't support
372     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
373     check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
374     if(HAVE_MSSE2_SWITCH)
375         set(SSE2_SWITCH "-msse2")
376     endif()
377     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
378     unset(OLD_REQUIRED_FLAGS)
379 endif()
381 check_include_file(xmmintrin.h HAVE_XMMINTRIN_H)
382 check_include_file(emmintrin.h HAVE_EMMINTRIN_H)
383 check_include_file(pmmintrin.h HAVE_PMMINTRIN_H)
384 check_include_file(smmintrin.h HAVE_SMMINTRIN_H)
385 check_include_file(arm_neon.h HAVE_ARM_NEON_H)
387 set(HAVE_SSE        0)
388 set(HAVE_SSE2       0)
389 set(HAVE_SSE3       0)
390 set(HAVE_SSE4_1     0)
391 set(HAVE_NEON       0)
393 # Check for SSE support
394 option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
395 if(HAVE_XMMINTRIN_H)
396     option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
397     if(ALSOFT_CPUEXT_SSE)
398         set(HAVE_SSE 1)
399     endif()
400 endif()
401 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
402     message(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
403 endif()
405 option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
406 if(HAVE_EMMINTRIN_H)
407     option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
408     if(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
409         set(HAVE_SSE2 1)
410     endif()
411 endif()
412 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
413     message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
414 endif()
416 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
417 if(HAVE_PMMINTRIN_H)
418     option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
419     if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
420         set(HAVE_SSE3 1)
421     endif()
422 endif()
423 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
424     message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
425 endif()
427 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
428 if(HAVE_SMMINTRIN_H)
429     option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
430     if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
431         set(HAVE_SSE4_1 1)
432     endif()
433 endif()
434 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
435     message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
436 endif()
438 # Check for ARM Neon support
439 option(ALSOFT_REQUIRE_NEON "Require ARM NEON support" OFF)
440 if(HAVE_ARM_NEON_H)
441     option(ALSOFT_CPUEXT_NEON "Enable ARM NEON support" ON)
442     if(ALSOFT_CPUEXT_NEON)
443         check_c_source_compiles("#include <arm_neon.h>
444             int main()
445             {
446                 int32x4_t ret4 = vdupq_n_s32(0);
447                 return vgetq_lane_s32(ret4, 0);
448             }" HAVE_NEON_INTRINSICS)
449         if(HAVE_NEON_INTRINSICS)
450             set(HAVE_NEON 1)
451         endif()
452     endif()
453 endif()
454 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
455     message(FATAL_ERROR "Failed to enabled required ARM NEON CPU extensions")
456 endif()
459 set(SSE_FLAGS )
460 set(FPMATH_SET "0")
461 if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND HAVE_SSE2)
462     option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
463     if(ALSOFT_ENABLE_SSE2_CODEGEN)
464         if(MSVC)
465             check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
466             if(HAVE_ARCH_SSE2)
467                 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
468                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
469                 set(FPMATH_SET 2)
470             endif()
471         elseif(SSE2_SWITCH)
472             check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
473             if(HAVE_MFPMATH_SSE_2)
474                 set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
475                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
476                 set(FPMATH_SET 2)
477             endif()
478             # SSE depends on a 16-byte aligned stack, and by default, GCC
479             # assumes the stack is suitably aligned. Older Linux code or other
480             # OSs don't guarantee this on 32-bit, so externally-callable
481             # functions need to ensure an aligned stack.
482             set(EXPORT_DECL "${EXPORT_DECL}__attribute__((force_align_arg_pointer))")
483         endif()
484     endif()
485 endif()
487 if(HAVE_SSE2)
488     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
489     foreach(flag_var ${SSE_FLAGS})
490         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
491     endforeach()
493     check_c_source_compiles("#include <emmintrin.h>
494         int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
496     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
497 endif()
500 check_include_file(malloc.h HAVE_MALLOC_H)
501 check_include_file(cpuid.h HAVE_CPUID_H)
502 check_include_file(intrin.h HAVE_INTRIN_H)
503 check_include_file(guiddef.h HAVE_GUIDDEF_H)
504 if(NOT HAVE_GUIDDEF_H)
505     check_include_file(initguid.h HAVE_INITGUID_H)
506 endif()
508 # Some systems need libm for some math functions to work
509 set(MATH_LIB )
510 check_library_exists(m pow "" HAVE_LIBM)
511 if(HAVE_LIBM)
512     set(MATH_LIB ${MATH_LIB} m)
513     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
514 endif()
516 # Some systems need to link with -lrt for clock_gettime as used by the common
517 # eaxmple functions.
518 set(RT_LIB )
519 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
520 if(HAVE_LIBRT)
521     set(RT_LIB rt)
522 endif()
524 # Check for the dlopen API (for dynamicly loading backend libs)
525 if(ALSOFT_DLOPEN)
526     check_include_file(dlfcn.h HAVE_DLFCN_H)
527     check_library_exists(dl dlopen "" HAVE_LIBDL)
528     if(HAVE_LIBDL)
529         set(EXTRA_LIBS dl ${EXTRA_LIBS})
530         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
531     endif()
532 endif()
534 # Check for a cpuid intrinsic
535 if(HAVE_CPUID_H)
536     check_c_source_compiles("#include <cpuid.h>
537         int main()
538         {
539             unsigned int eax, ebx, ecx, edx;
540             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
541         }" HAVE_GCC_GET_CPUID)
542 endif()
543 if(HAVE_INTRIN_H)
544     check_c_source_compiles("#include <intrin.h>
545         int main()
546         {
547             int regs[4];
548             __cpuid(regs, 0);
549             return regs[0];
550         }" HAVE_CPUID_INTRINSIC)
551 endif()
553 check_symbol_exists(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
554 check_symbol_exists(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
555 check_symbol_exists(proc_pidpath     libproc.h HAVE_PROC_PIDPATH)
557 if(NOT WIN32)
558     # We need pthreads outside of Windows, for semaphores. It's also used to
559     # set the priority and name of threads, when possible.
560     check_include_file(pthread.h HAVE_PTHREAD_H)
561     if(NOT HAVE_PTHREAD_H)
562         message(FATAL_ERROR "PThreads is required for non-Windows builds!")
563     endif()
565     check_c_compiler_flag(-pthread HAVE_PTHREAD)
566     if(HAVE_PTHREAD)
567         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
568         set(C_FLAGS ${C_FLAGS} -pthread)
569         set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
570     endif()
572     check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
574     # Some systems need pthread_np.h to get pthread_setname_np
575     check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
576     if(HAVE_PTHREAD_NP_H)
577         check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
578         if(NOT HAVE_PTHREAD_SETNAME_NP)
579             check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
580         endif()
581     else()
582         check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
583         if(NOT HAVE_PTHREAD_SETNAME_NP)
584             check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
585         endif()
586     endif()
587 endif()
589 check_symbol_exists(getopt unistd.h HAVE_GETOPT)
592 # Common sources used by both the OpenAL implementation library, the OpenAL
593 # router, and certain tools and examples.
594 set(COMMON_OBJS
595     common/albit.h
596     common/albyte.h
597     common/alcomplex.cpp
598     common/alcomplex.h
599     common/aldeque.h
600     common/alfstream.cpp
601     common/alfstream.h
602     common/almalloc.cpp
603     common/almalloc.h
604     common/alnumbers.h
605     common/alnumeric.h
606     common/aloptional.h
607     common/alspan.h
608     common/alstring.cpp
609     common/alstring.h
610     common/atomic.h
611     common/comptr.h
612     common/dynload.cpp
613     common/dynload.h
614     common/intrusive_ptr.h
615     common/opthelpers.h
616     common/phase_shifter.h
617     common/polyphase_resampler.cpp
618     common/polyphase_resampler.h
619     common/pragmadefs.h
620     common/ringbuffer.cpp
621     common/ringbuffer.h
622     common/strutils.cpp
623     common/strutils.h
624     common/threads.cpp
625     common/threads.h
626     common/vecmat.h
627     common/vector.h)
629 # Core library routines
630 set(CORE_OBJS
631     core/ambdec.cpp
632     core/ambdec.h
633     core/ambidefs.cpp
634     core/ambidefs.h
635     core/async_event.h
636     core/bformatdec.cpp
637     core/bformatdec.h
638     core/bs2b.cpp
639     core/bs2b.h
640     core/bsinc_defs.h
641     core/bsinc_tables.cpp
642     core/bsinc_tables.h
643     core/bufferline.h
644     core/buffer_storage.cpp
645     core/buffer_storage.h
646     core/context.cpp
647     core/context.h
648     core/converter.cpp
649     core/converter.h
650     core/cpu_caps.cpp
651     core/cpu_caps.h
652     core/devformat.cpp
653     core/devformat.h
654     core/device.cpp
655     core/device.h
656     core/effects/base.h
657     core/effectslot.cpp
658     core/effectslot.h
659     core/except.cpp
660     core/except.h
661     core/filters/biquad.h
662     core/filters/biquad.cpp
663     core/filters/nfc.cpp
664     core/filters/nfc.h
665     core/filters/splitter.cpp
666     core/filters/splitter.h
667     core/fmt_traits.cpp
668     core/fmt_traits.h
669     core/fpu_ctrl.cpp
670     core/fpu_ctrl.h
671     core/front_stablizer.h
672     core/helpers.cpp
673     core/helpers.h
674     core/hrtf.cpp
675     core/hrtf.h
676     core/logging.cpp
677     core/logging.h
678     core/mastering.cpp
679     core/mastering.h
680     core/mixer.cpp
681     core/mixer.h
682     core/resampler_limits.h
683     core/uhjfilter.cpp
684     core/uhjfilter.h
685     core/uiddefs.cpp
686     core/voice.cpp
687     core/voice.h
688     core/voice_change.h)
690 set(HAVE_RTKIT 0)
691 if(NOT WIN32)
692     option(ALSOFT_REQUIRE_RTKIT "Require RTKit/D-Bus support" FALSE)
693     find_package(DBus1 QUIET)
694     if(NOT DBus1_FOUND AND PkgConfig_FOUND)
695         pkg_check_modules(DBUS dbus-1)
696     endif()
697     if(DBus1_FOUND OR DBUS_FOUND)
698         option(ALSOFT_RTKIT "Enable RTKit support" ON)
699         if(ALSOFT_RTKIT)
700             set(HAVE_RTKIT 1)
701             set(CORE_OBJS ${CORE_OBJS} core/dbus_wrap.cpp core/dbus_wrap.h
702                 core/rtkit.cpp core/rtkit.h)
703             if(NOT DBus1_FOUND)
704                 set(INC_PATHS ${INC_PATHS} ${DBUS_INCLUDE_DIRS})
705                 set(CPP_DEFS ${CPP_DEFS} ${DBUS_CFLAGS_OTHER})
706                 if(NOT HAVE_DLFCN_H)
707                     set(EXTRA_LIBS ${EXTRA_LIBS} ${DBUS_LINK_LIBRARIES})
708                 endif()
709             elseif(HAVE_DLFCN_H)
710                 set(INC_PATHS ${INC_PATHS} ${DBus1_INCLUDE_DIRS})
711                 set(CPP_DEFS ${CPP_DEFS} ${DBus1_DEFINITIONS})
712             else()
713                 set(EXTRA_LIBS ${EXTRA_LIBS} ${DBus1_LIBRARIES})
714             endif()
715         endif()
716     else()
717         set(MISSING_VARS "")
718         if(NOT DBus1_INCLUDE_DIRS)
719             set(MISSING_VARS "${MISSING_VARS} DBus1_INCLUDE_DIRS")
720         endif()
721         if(NOT DBus1_LIBRARIES)
722             set(MISSING_VARS "${MISSING_VARS} DBus1_LIBRARIES")
723         endif()
724         message(STATUS "Could NOT find DBus1 (missing:${MISSING_VARS})")
725         unset(MISSING_VARS)
726     endif()
727 endif()
728 if(ALSOFT_REQUIRE_RTKIT AND NOT HAVE_RTKIT)
729     message(FATAL_ERROR "Failed to enabled required RTKit support")
730 endif()
732 # Default mixers, always available
733 set(CORE_OBJS ${CORE_OBJS}
734     core/mixer/defs.h
735     core/mixer/hrtfbase.h
736     core/mixer/hrtfdefs.h
737     core/mixer/mixer_c.cpp)
739 # AL and related routines
740 set(OPENAL_OBJS
741     al/auxeffectslot.cpp
742     al/auxeffectslot.h
743     al/buffer.cpp
744     al/buffer.h
745     al/effect.cpp
746     al/effect.h
747     al/effects/autowah.cpp
748     al/effects/chorus.cpp
749     al/effects/compressor.cpp
750     al/effects/convolution.cpp
751     al/effects/dedicated.cpp
752     al/effects/distortion.cpp
753     al/effects/echo.cpp
754         al/effects/effects.cpp
755     al/effects/effects.h
756     al/effects/equalizer.cpp
757     al/effects/fshifter.cpp
758     al/effects/modulator.cpp
759     al/effects/null.cpp
760     al/effects/pshifter.cpp
761     al/effects/reverb.cpp
762     al/effects/vmorpher.cpp
763     al/error.cpp
764     al/event.cpp
765     al/event.h
766     al/extension.cpp
767     al/filter.cpp
768     al/filter.h
769     al/listener.cpp
770     al/listener.h
771     al/source.cpp
772     al/source.h
773     al/state.cpp)
775 # ALC and related routines
776 set(ALC_OBJS
777     alc/alc.cpp
778     alc/alu.cpp
779     alc/alu.h
780     alc/alconfig.cpp
781     alc/alconfig.h
782     alc/context.cpp
783     alc/context.h
784     alc/device.cpp
785     alc/device.h
786     alc/effects/base.h
787     alc/effects/autowah.cpp
788     alc/effects/chorus.cpp
789     alc/effects/compressor.cpp
790     alc/effects/convolution.cpp
791     alc/effects/dedicated.cpp
792     alc/effects/distortion.cpp
793     alc/effects/echo.cpp
794     alc/effects/equalizer.cpp
795     alc/effects/fshifter.cpp
796     alc/effects/modulator.cpp
797     alc/effects/null.cpp
798     alc/effects/pshifter.cpp
799     alc/effects/reverb.cpp
800     alc/effects/vmorpher.cpp
801     alc/inprogext.h
802     alc/panning.cpp)
804 if (ALSOFT_EAX)
805     set(OPENAL_OBJS
806         ${OPENAL_OBJS}
807         al/eax/api.cpp
808         al/eax/api.h
809         al/eax/call.cpp
810         al/eax/call.h
811         al/eax/effect.h
812         al/eax/exception.cpp
813         al/eax/exception.h
814         al/eax/fx_slot_index.cpp
815         al/eax/fx_slot_index.h
816         al/eax/fx_slots.cpp
817         al/eax/fx_slots.h
818         al/eax/globals.cpp
819         al/eax/globals.h
820         al/eax/utils.cpp
821         al/eax/utils.h
822         al/eax/x_ram.h
824 endif ()
826 # Include SIMD mixers
827 set(CPU_EXTS "Default")
828 if(HAVE_SSE)
829     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse.cpp)
830     set(CPU_EXTS "${CPU_EXTS}, SSE")
831 endif()
832 if(HAVE_SSE2)
833     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse2.cpp)
834     set(CPU_EXTS "${CPU_EXTS}, SSE2")
835 endif()
836 if(HAVE_SSE3)
837     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse3.cpp)
838     set(CPU_EXTS "${CPU_EXTS}, SSE3")
839 endif()
840 if(HAVE_SSE4_1)
841     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse41.cpp)
842     set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
843 endif()
844 if(HAVE_NEON)
845     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_neon.cpp)
846     set(CPU_EXTS "${CPU_EXTS}, Neon")
847 endif()
850 set(HAVE_ALSA       0)
851 set(HAVE_OSS        0)
852 set(HAVE_PIPEWIRE   0)
853 set(HAVE_SOLARIS    0)
854 set(HAVE_SNDIO      0)
855 set(HAVE_DSOUND     0)
856 set(HAVE_WASAPI     0)
857 set(HAVE_WINMM      0)
858 set(HAVE_PORTAUDIO  0)
859 set(HAVE_PULSEAUDIO 0)
860 set(HAVE_COREAUDIO  0)
861 set(HAVE_OPENSL     0)
862 set(HAVE_OBOE       0)
863 set(HAVE_WAVE       0)
864 set(HAVE_SDL2       0)
866 if(WIN32 OR HAVE_DLFCN_H)
867     set(IS_LINKED "")
868     macro(ADD_BACKEND_LIBS _LIBS)
869     endmacro()
870 else()
871     set(IS_LINKED " (linked)")
872     macro(ADD_BACKEND_LIBS _LIBS)
873         set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
874     endmacro()
875 endif()
877 set(BACKENDS "")
878 set(ALC_OBJS  ${ALC_OBJS}
879     alc/backends/base.cpp
880     alc/backends/base.h
881     # Default backends, always available
882     alc/backends/loopback.cpp
883     alc/backends/loopback.h
884     alc/backends/null.cpp
885     alc/backends/null.h
888 # Check ALSA backend
889 option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
890 find_package(ALSA)
891 if(ALSA_FOUND)
892     option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
893     if(ALSOFT_BACKEND_ALSA)
894         set(HAVE_ALSA 1)
895         set(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
896         set(ALC_OBJS  ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
897         add_backend_libs(${ALSA_LIBRARIES})
898         set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
899     endif()
900 endif()
901 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
902     message(FATAL_ERROR "Failed to enabled required ALSA backend")
903 endif()
905 # Check OSS backend
906 option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
907 find_package(OSS)
908 if(OSS_FOUND)
909     option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
910     if(ALSOFT_BACKEND_OSS)
911         set(HAVE_OSS 1)
912         set(BACKENDS  "${BACKENDS} OSS,")
913         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
914         if(OSS_LIBRARIES)
915             set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
916         endif()
917         set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
918     endif()
919 endif()
920 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
921     message(FATAL_ERROR "Failed to enabled required OSS backend")
922 endif()
924 # Check PipeWire backend
925 option(ALSOFT_REQUIRE_PIPEWIRE "Require PipeWire backend" OFF)
926 if(PkgConfig_FOUND)
927     pkg_check_modules(PIPEWIRE libpipewire-0.3>=0.3.23)
928     if(PIPEWIRE_FOUND)
929         option(ALSOFT_BACKEND_PIPEWIRE "Enable PipeWire backend" ON)
930         if(ALSOFT_BACKEND_PIPEWIRE)
931             set(HAVE_PIPEWIRE 1)
932             set(BACKENDS  "${BACKENDS} PipeWire${IS_LINKED},")
933             set(ALC_OBJS  ${ALC_OBJS} alc/backends/pipewire.cpp alc/backends/pipewire.h)
934             add_backend_libs(${PIPEWIRE_LIBRARIES})
935             set(INC_PATHS ${INC_PATHS} ${PIPEWIRE_INCLUDE_DIRS})
936         endif()
937     endif()
938 endif()
939 if(ALSOFT_REQUIRE_PIPEWIRE AND NOT HAVE_PIPEWIRE)
940     message(FATAL_ERROR "Failed to enabled required PipeWire backend")
941 endif()
943 # Check Solaris backend
944 option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
945 find_package(AudioIO)
946 if(AUDIOIO_FOUND)
947     option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
948     if(ALSOFT_BACKEND_SOLARIS)
949         set(HAVE_SOLARIS 1)
950         set(BACKENDS  "${BACKENDS} Solaris,")
951         set(ALC_OBJS  ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
952         set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
953     endif()
954 endif()
955 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
956     message(FATAL_ERROR "Failed to enabled required Solaris backend")
957 endif()
959 # Check SndIO backend
960 option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
961 find_package(SoundIO)
962 if(SOUNDIO_FOUND)
963     option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
964     if(ALSOFT_BACKEND_SNDIO)
965         set(HAVE_SNDIO 1)
966         set(BACKENDS  "${BACKENDS} SndIO (linked),")
967         set(ALC_OBJS  ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
968         set(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
969         set(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
970     endif()
971 endif()
972 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
973     message(FATAL_ERROR "Failed to enabled required SndIO backend")
974 endif()
976 # Check Windows-only backends
977 option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
978 option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
979 option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
980 if(WIN32)
981     # Check MMSystem backend
982     option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
983     if(ALSOFT_BACKEND_WINMM)
984         set(HAVE_WINMM 1)
985         set(BACKENDS "${BACKENDS} WinMM,")
986         set(ALC_OBJS ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
987         # There doesn't seem to be good way to search for winmm.lib for MSVC.
988         # find_library doesn't find it without being told to look in a specific
989         # place in the WindowsSDK, but it links anyway. If there ends up being
990         # Windows targets without this, another means to detect it is needed.
991         set(EXTRA_LIBS winmm ${EXTRA_LIBS})
992     endif()
994     # Check DSound backend
995     check_include_file(dsound.h HAVE_DSOUND_H)
996     if(DXSDK_DIR)
997         find_path(DSOUND_INCLUDE_DIR NAMES "dsound.h"
998             PATHS "${DXSDK_DIR}" PATH_SUFFIXES include
999             DOC "The DirectSound include directory")
1000     endif()
1001     if(HAVE_DSOUND_H OR DSOUND_INCLUDE_DIR)
1002         option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
1003         if(ALSOFT_BACKEND_DSOUND)
1004             set(HAVE_DSOUND 1)
1005             set(BACKENDS "${BACKENDS} DirectSound,")
1006             set(ALC_OBJS ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
1008             if(NOT HAVE_DSOUND_H)
1009                 set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIR})
1010             endif()
1011         endif()
1012     endif()
1014     # Check for WASAPI backend
1015     check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1016     if(HAVE_MMDEVICEAPI_H)
1017         option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
1018         if(ALSOFT_BACKEND_WASAPI)
1019             set(HAVE_WASAPI 1)
1020             set(BACKENDS  "${BACKENDS} WASAPI,")
1021             set(ALC_OBJS  ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
1022         endif()
1023     endif()
1024 endif()
1025 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1026     message(FATAL_ERROR "Failed to enabled required WinMM backend")
1027 endif()
1028 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1029     message(FATAL_ERROR "Failed to enabled required DSound backend")
1030 endif()
1031 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
1032     message(FATAL_ERROR "Failed to enabled required WASAPI backend")
1033 endif()
1035 # Check PortAudio backend
1036 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1037 find_package(PortAudio)
1038 if(PORTAUDIO_FOUND)
1039     option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1040     if(ALSOFT_BACKEND_PORTAUDIO)
1041         set(HAVE_PORTAUDIO 1)
1042         set(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
1043         set(ALC_OBJS  ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
1044         add_backend_libs(${PORTAUDIO_LIBRARIES})
1045         set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
1046     endif()
1047 endif()
1048 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1049     message(FATAL_ERROR "Failed to enabled required PortAudio backend")
1050 endif()
1052 # Check PulseAudio backend
1053 option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1054 find_package(PulseAudio)
1055 if(PULSEAUDIO_FOUND)
1056     option(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1057     if(ALSOFT_BACKEND_PULSEAUDIO)
1058         set(HAVE_PULSEAUDIO 1)
1059         set(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
1060         set(ALC_OBJS  ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
1061         add_backend_libs(${PULSEAUDIO_LIBRARY})
1062         set(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIR})
1063     endif()
1064 endif()
1065 if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1066     message(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1067 endif()
1069 # Check JACK backend
1070 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1071 find_package(JACK)
1072 if(JACK_FOUND)
1073     option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1074     if(ALSOFT_BACKEND_JACK)
1075         set(HAVE_JACK 1)
1076         set(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1077         set(ALC_OBJS  ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
1078         add_backend_libs(${JACK_LIBRARIES})
1079         set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1080     endif()
1081 endif()
1082 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1083     message(FATAL_ERROR "Failed to enabled required JACK backend")
1084 endif()
1086 # Check CoreAudio backend
1087 option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1088 find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
1089 find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
1090 if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
1091     option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1092     if(ALSOFT_BACKEND_COREAUDIO)
1093         set(HAVE_COREAUDIO 1)
1094         set(ALC_OBJS  ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
1095         set(BACKENDS  "${BACKENDS} CoreAudio,")
1097         set(EXTRA_LIBS -Wl,-framework,CoreAudio ${EXTRA_LIBS})
1098         if(CMAKE_SYSTEM_NAME MATCHES "^(iOS|tvOS)$")
1099             find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
1100             if(COREFOUNDATION_FRAMEWORK)
1101                 set(EXTRA_LIBS -Wl,-framework,CoreFoundation ${EXTRA_LIBS})
1102             endif()
1103         else()
1104             set(EXTRA_LIBS -Wl,-framework,AudioUnit,-framework,ApplicationServices ${EXTRA_LIBS})
1105         endif()
1107         # Some versions of OSX may need the AudioToolbox framework. Add it if
1108         # it's found.
1109         find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
1110         if(AUDIOTOOLBOX_LIBRARY)
1111             set(EXTRA_LIBS -Wl,-framework,AudioToolbox ${EXTRA_LIBS})
1112         endif()
1114         set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
1115     endif()
1116 endif()
1117 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1118     message(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1119 endif()
1121 # Check for OpenSL (Android) backend
1122 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1123 find_package(OpenSL)
1124 if(OPENSL_FOUND)
1125     option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1126     if(ALSOFT_BACKEND_OPENSL)
1127         set(HAVE_OPENSL 1)
1128         set(ALC_OBJS  ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1129         set(BACKENDS  "${BACKENDS} OpenSL,")
1130         set(EXTRA_LIBS "OpenSL::OpenSLES" ${EXTRA_LIBS})
1131     endif()
1132 endif()
1133 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1134     message(FATAL_ERROR "Failed to enabled required OpenSL backend")
1135 endif()
1137 # Check for Oboe (Android) backend
1138 set(OBOE_TARGET )
1139 if(ANDROID)
1140     set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1141     if(OBOE_SOURCE)
1142         add_subdirectory(${OBOE_SOURCE} ./oboe)
1143         set(OBOE_TARGET oboe)
1144     else()
1145         find_package(oboe CONFIG)
1146         if(NOT TARGET oboe::oboe)
1147             find_package(Oboe)
1148         endif()
1149         if(TARGET oboe::oboe)
1150             set(OBOE_TARGET "oboe::oboe")
1151         endif()
1152     endif()
1153 endif()
1155 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1156 if(OBOE_TARGET)
1157     option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1158     if(ALSOFT_BACKEND_OBOE)
1159         set(HAVE_OBOE 1)
1160         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
1161         set(BACKENDS  "${BACKENDS} Oboe,")
1162         set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
1163     endif()
1164 endif()
1165 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1166     message(FATAL_ERROR "Failed to enabled required Oboe backend")
1167 endif()
1169 # Check for SDL2 backend
1170 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1171 find_package(SDL2 QUIET)
1172 if(SDL2_FOUND)
1173     # Off by default, since it adds a runtime dependency
1174     option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1175     if(ALSOFT_BACKEND_SDL2)
1176         set(HAVE_SDL2 1)
1177         set(ALC_OBJS  ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1178         set(BACKENDS  "${BACKENDS} SDL2,")
1179         set(EXTRA_LIBS ${EXTRA_LIBS} SDL2::SDL2)
1180     endif()
1181 else()
1182     message(STATUS "Could NOT find SDL2")
1183 endif()
1184 if(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1185     message(FATAL_ERROR "Failed to enabled required SDL2 backend")
1186 endif()
1188 # Optionally enable the Wave Writer backend
1189 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1190 if(ALSOFT_BACKEND_WAVE)
1191     set(HAVE_WAVE 1)
1192     set(ALC_OBJS  ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1193     set(BACKENDS  "${BACKENDS} WaveFile,")
1194 endif()
1196 # This is always available
1197 set(BACKENDS  "${BACKENDS} Null")
1200 find_package(Git)
1201 if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1202     # Get the current working branch and its latest abbreviated commit hash
1203     add_custom_command(OUTPUT "${OpenAL_BINARY_DIR}/version_witness.txt"
1204         BYPRODUCTS "${OpenAL_BINARY_DIR}/version.h"
1205         COMMAND ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1206             -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1207             -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1208         COMMAND ${CMAKE_COMMAND} -E touch "${OpenAL_BINARY_DIR}/version_witness.txt"
1209         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1210         MAIN_DEPENDENCY "${OpenAL_SOURCE_DIR}/version.h.in"
1211         DEPENDS "${OpenAL_SOURCE_DIR}/.git/index" "${OpenAL_SOURCE_DIR}/version.cmake"
1212         VERBATIM
1213     )
1215     add_custom_target(build_version DEPENDS "${OpenAL_BINARY_DIR}/version_witness.txt")
1216 else()
1217     set(GIT_BRANCH "UNKNOWN")
1218     set(GIT_COMMIT_HASH "unknown")
1219     configure_file(
1220         "${OpenAL_SOURCE_DIR}/version.h.in"
1221         "${OpenAL_BINARY_DIR}/version.h")
1222 endif()
1225 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1226 if(ALSOFT_EMBED_HRTF_DATA)
1227     macro(make_hrtf_header FILENAME VARNAME)
1228         set(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1229         set(outfile  "${OpenAL_BINARY_DIR}/${VARNAME}.txt")
1231         add_custom_command(OUTPUT "${outfile}"
1232             COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
1233                 -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1234             WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1235             DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1236             VERBATIM
1237         )
1238         set(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1239     endmacro()
1241     make_hrtf_header("Default HRTF.mhr" "default_hrtf")
1242 endif()
1245 if(ALSOFT_UTILS)
1246     find_package(MySOFA)
1247     if(NOT ALSOFT_NO_CONFIG_UTIL)
1248         find_package(Qt5Widgets QUIET)
1249         if(NOT Qt5Widgets_FOUND)
1250             message(STATUS "Could NOT find Qt5Widgets")
1251         endif()
1252     endif()
1253 endif()
1254 if(ALSOFT_UTILS OR ALSOFT_EXAMPLES)
1255     find_package(SndFile)
1256     if(SDL2_FOUND)
1257         find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1258     endif()
1259 endif()
1261 if(NOT WIN32)
1262     set(LIBNAME "openal")
1263 else()
1264     set(LIBNAME "OpenAL32")
1265 endif()
1267 # Needed for openal.pc.in
1268 set(prefix ${CMAKE_INSTALL_PREFIX})
1269 set(exec_prefix "\${prefix}")
1270 set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
1271 set(bindir "${CMAKE_INSTALL_FULL_BINDIR}")
1272 set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
1273 set(PACKAGE_VERSION "${LIB_VERSION}")
1274 set(PKG_CONFIG_CFLAGS )
1275 set(PKG_CONFIG_PRIVATE_LIBS )
1276 if(LIBTYPE STREQUAL "STATIC")
1277     set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1278     foreach(FLAG  ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1279         # If this is already a linker flag, or is a full path+file, add it
1280         # as-is. If it's an SDL2 target, add the link flag for it. Otherwise,
1281         # it's a name intended to be dressed as -lname.
1282         if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1283             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1284         elseif(FLAG MATCHES "^SDL2::SDL2")
1285             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -lSDL2")
1286         else()
1287             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1288         endif()
1289     endforeach()
1290 endif()
1292 # End configuration
1293 configure_file(
1294     "${OpenAL_SOURCE_DIR}/config.h.in"
1295     "${OpenAL_BINARY_DIR}/config.h")
1296 configure_file(
1297     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1298     "${OpenAL_BINARY_DIR}/openal.pc"
1299     @ONLY)
1302 add_library(common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1303 target_include_directories(common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include)
1304 target_compile_definitions(common PRIVATE ${CPP_DEFS})
1305 target_compile_options(common PRIVATE ${C_FLAGS})
1306 set_target_properties(common PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
1309 unset(HAS_ROUTER)
1310 set(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1312 # Build main library
1313 if(LIBTYPE STREQUAL "STATIC")
1314     add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS})
1315     target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
1316     target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1318     if(WIN32)
1319         # This option is for static linking OpenAL Soft into another project
1320         # that already defines the IDs. It is up to that project to ensure all
1321         # required IDs are defined.
1322         option(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
1323         if(ALSOFT_NO_UID_DEFS)
1324             target_compile_definitions(${IMPL_TARGET} PRIVATE AL_NO_UID_DEFS)
1325         endif()
1326     endif()
1327 else()
1328     set(RC_CONFIG resources/openal32.rc)
1329     if(WIN32 AND ALSOFT_BUILD_ROUTER)
1330         add_library(OpenAL SHARED
1331             resources/router.rc
1332             router/router.cpp
1333             router/router.h
1334             router/alc.cpp
1335             router/al.cpp
1336         )
1337         target_compile_definitions(OpenAL
1338             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}"
1339             "AL_API=${EXPORT_DECL}" ${CPP_DEFS})
1340         target_compile_options(OpenAL PRIVATE ${C_FLAGS})
1341         target_link_libraries(OpenAL PRIVATE common ${LINKER_FLAGS})
1342         target_include_directories(OpenAL
1343           PUBLIC
1344             $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1345             $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1346           PRIVATE
1347             ${OpenAL_SOURCE_DIR}/common
1348             ${OpenAL_BINARY_DIR}
1349         )
1350         set_target_properties(OpenAL PROPERTIES PREFIX "")
1351         set_target_properties(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1352         if(TARGET build_version)
1353             add_dependencies(OpenAL build_version)
1354         endif()
1355         set(HAS_ROUTER 1)
1357         set(LIBNAME "soft_oal")
1358         set(IMPL_TARGET soft_oal)
1359         set(RC_CONFIG resources/soft_oal.rc)
1360     endif()
1362     # !important: for osx framework public header works, the headers must be in
1363     # the project
1364     set(TARGET_PUBLIC_HEADERS include/AL/al.h include/AL/alc.h include/AL/alext.h include/AL/efx.h
1365         include/AL/efx-presets.h)
1366     add_library(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS} ${RC_CONFIG}
1367         ${TARGET_PUBLIC_HEADERS})
1368     if(WIN32)
1369         set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
1370     endif()
1371     target_link_libraries(${IMPL_TARGET} PRIVATE common ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1373     if(APPLE AND ALSOFT_OSX_FRAMEWORK)
1374         # Sets framework name to soft_oal to avoid ambiguity with the system OpenAL.framework
1375         set(LIBNAME "soft_oal")
1376         if(GIT_FOUND)
1377             EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD
1378                 TIMEOUT 5
1379                 OUTPUT_VARIABLE BUNDLE_VERSION
1380                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1381         else()
1382             set(BUNDLE_VERSION 1)
1383         endif()
1385         # Build: Fix rpath in iOS shared libraries
1386         # If this flag is not set, the final dylib binary ld path will be
1387         # /User/xxx/*/soft_oal.framework/soft_oal, which can't be loaded by iOS devices.
1388         # See also: https://github.com/libjpeg-turbo/libjpeg-turbo/commit/c80ddef7a4ce21ace9e3ca0fd190d320cc8cdaeb
1389         if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
1390             set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
1391         endif()
1393         set_target_properties(${IMPL_TARGET} PROPERTIES
1394             FRAMEWORK TRUE
1395             FRAMEWORK_VERSION C
1396             MACOSX_FRAMEWORK_NAME "${IMPL_TARGET}"
1397             MACOSX_FRAMEWORK_IDENTIFIER "org.openal-soft.openal"
1398             MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${LIB_VERSION}"
1399             MACOSX_FRAMEWORK_BUNDLE_VERSION "${BUNDLE_VERSION}"
1400             XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
1401             XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
1402             XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
1403             PUBLIC_HEADER "${TARGET_PUBLIC_HEADERS}"
1404             MACOSX_RPATH TRUE)
1405     endif()
1406 endif()
1408 target_include_directories(${IMPL_TARGET}
1409   PUBLIC
1410     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1411   INTERFACE
1412     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include/AL>
1413     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1414     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/AL>
1415   PRIVATE
1416     ${INC_PATHS}
1417     ${OpenAL_BINARY_DIR}
1418     ${OpenAL_SOURCE_DIR}
1419     ${OpenAL_SOURCE_DIR}/common
1422 set_target_properties(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1423     VERSION ${LIB_VERSION}
1424     SOVERSION ${LIB_MAJOR_VERSION}
1426 target_compile_definitions(${IMPL_TARGET}
1427     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}" "AL_API=${EXPORT_DECL}"
1428     ${CPP_DEFS})
1429 target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1431 if(TARGET build_version)
1432     add_dependencies(${IMPL_TARGET} build_version)
1433 endif()
1435 if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1436     find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
1437     if(NOT SED_EXECUTABLE OR NOT CMAKE_DLLTOOL)
1438         message(STATUS "")
1439         if(NOT SED_EXECUTABLE)
1440             message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1441         endif()
1442         if(NOT CMAKE_DLLTOOL)
1443             message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1444         endif()
1445     else()
1446         set_property(TARGET OpenAL APPEND_STRING PROPERTY
1447             LINK_FLAGS " -Wl,--output-def,OpenAL32.def")
1448         add_custom_command(TARGET OpenAL POST_BUILD
1449             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1450             COMMAND "${CMAKE_DLLTOOL}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1451             # Technically OpenAL32.def was created by the build, but cmake
1452             # doesn't recognize it due to -Wl,--output-def,OpenAL32.def being
1453             # manually specified. But declaring the file here allows it to be
1454             # properly cleaned, e.g. during make clean.
1455             BYPRODUCTS OpenAL32.def OpenAL32.lib
1456             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1457             VERBATIM
1458         )
1459     endif()
1460 endif()
1462 if(HAS_ROUTER)
1463     message(STATUS "")
1464     message(STATUS "Building DLL router")
1465 endif()
1467 message(STATUS "")
1468 message(STATUS "Building OpenAL with support for the following backends:")
1469 message(STATUS "   ${BACKENDS}")
1470 message(STATUS "")
1471 message(STATUS "Building with support for CPU extensions:")
1472 message(STATUS "    ${CPU_EXTS}")
1473 message(STATUS "")
1474 if(FPMATH_SET)
1475     message(STATUS "Building with SSE${FPMATH_SET} codegen")
1476     message(STATUS "")
1477 endif()
1479 if(ALSOFT_EAX)
1480     message(STATUS "Building with legacy EAX extension support")
1481     message(STATUS "")
1482 endif()
1484 if(ALSOFT_EMBED_HRTF_DATA)
1485     message(STATUS "Embedding HRTF datasets")
1486     message(STATUS "")
1487 endif()
1489 # An alias for sub-project builds
1490 add_library(OpenAL::OpenAL ALIAS OpenAL)
1492 # Install main library
1493 if(ALSOFT_INSTALL)
1494     configure_package_config_file(OpenALConfig.cmake.in OpenALConfig.cmake
1495         INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL)
1496     install(TARGETS OpenAL EXPORT OpenAL
1497         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1498         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1499         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1500         FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
1501         INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1502     export(TARGETS OpenAL
1503         NAMESPACE OpenAL::
1504         FILE OpenALTargets.cmake)
1505     install(EXPORT OpenAL
1506         DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1507         NAMESPACE OpenAL::
1508         FILE OpenALTargets.cmake)
1509     install(DIRECTORY include/AL
1510         DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1511     install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1512         DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1513     install(FILES "${OpenAL_BINARY_DIR}/OpenALConfig.cmake"
1514         DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL")
1515     if(TARGET soft_oal)
1516         install(TARGETS soft_oal
1517             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1518     endif()
1519     message(STATUS "Installing library and headers")
1520 else()
1521     message(STATUS "NOT installing library and headers")
1522 endif()
1524 if(ALSOFT_INSTALL_CONFIG)
1525     install(FILES alsoftrc.sample
1526         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1527     message(STATUS "Installing sample configuration")
1528 endif()
1530 if(ALSOFT_INSTALL_HRTF_DATA)
1531     install(DIRECTORY hrtf
1532         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1533     message(STATUS "Installing HRTF data files")
1534 endif()
1536 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1537     install(DIRECTORY presets
1538         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1539     message(STATUS "Installing AmbDec presets")
1540 endif()
1541 message(STATUS "")
1543 set(UNICODE_FLAG )
1544 if(MINGW)
1545     set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1546 endif()
1547 set(EXTRA_INSTALLS )
1548 if(ALSOFT_UTILS)
1549     add_executable(openal-info utils/openal-info.c)
1550     target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1551     target_compile_options(openal-info PRIVATE ${C_FLAGS})
1552     target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
1553     if(ALSOFT_INSTALL_EXAMPLES)
1554         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
1555     endif()
1557     if(SNDFILE_FOUND)
1558         add_executable(uhjdecoder utils/uhjdecoder.cpp)
1559         target_compile_definitions(uhjdecoder PRIVATE ${CPP_DEFS})
1560         target_include_directories(uhjdecoder
1561             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1562         target_compile_options(uhjdecoder PRIVATE ${C_FLAGS})
1563         target_link_libraries(uhjdecoder PUBLIC common
1564             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1566         add_executable(uhjencoder utils/uhjencoder.cpp)
1567         target_compile_definitions(uhjencoder PRIVATE ${CPP_DEFS})
1568         target_include_directories(uhjencoder
1569             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1570         target_compile_options(uhjencoder PRIVATE ${C_FLAGS})
1571         target_link_libraries(uhjencoder PUBLIC common
1572             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1573     endif()
1575     if(MYSOFA_FOUND)
1576         set(SOFA_SUPPORT_SRCS
1577             utils/sofa-support.cpp
1578             utils/sofa-support.h)
1579         add_library(sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
1580         target_compile_definitions(sofa-support PRIVATE ${CPP_DEFS})
1581         target_include_directories(sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
1582         target_compile_options(sofa-support PRIVATE ${C_FLAGS})
1583         target_link_libraries(sofa-support PUBLIC common MySOFA::MySOFA PRIVATE ${LINKER_FLAGS})
1585         set(MAKEMHR_SRCS
1586             utils/makemhr/loaddef.cpp
1587             utils/makemhr/loaddef.h
1588             utils/makemhr/loadsofa.cpp
1589             utils/makemhr/loadsofa.h
1590             utils/makemhr/makemhr.cpp
1591             utils/makemhr/makemhr.h)
1592         if(NOT HAVE_GETOPT)
1593             set(MAKEMHR_SRCS  ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1594         endif()
1595         add_executable(makemhr ${MAKEMHR_SRCS})
1596         target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1597         target_include_directories(makemhr
1598             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
1599         target_compile_options(makemhr PRIVATE ${C_FLAGS})
1600         target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1601         if(ALSOFT_INSTALL_EXAMPLES)
1602             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
1603         endif()
1605         set(SOFAINFO_SRCS  utils/sofa-info.cpp)
1606         add_executable(sofa-info ${SOFAINFO_SRCS})
1607         target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1608         target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
1609         target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1610         target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1611     endif()
1612     message(STATUS "Building utility programs")
1614     if(NOT ALSOFT_NO_CONFIG_UTIL)
1615         add_subdirectory(utils/alsoft-config)
1616     endif()
1617     message(STATUS "")
1618 endif()
1621 # Add a static library with common functions used by multiple example targets
1622 add_library(ex-common STATIC EXCLUDE_FROM_ALL
1623     examples/common/alhelpers.c
1624     examples/common/alhelpers.h)
1625 target_compile_definitions(ex-common PUBLIC ${CPP_DEFS})
1626 target_include_directories(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
1627 target_compile_options(ex-common PUBLIC ${C_FLAGS})
1628 target_link_libraries(ex-common PUBLIC OpenAL PRIVATE ${RT_LIB})
1630 if(ALSOFT_EXAMPLES)
1631     add_executable(altonegen examples/altonegen.c)
1632     target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common ${UNICODE_FLAG})
1634     add_executable(alrecord examples/alrecord.c)
1635     target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} ex-common ${UNICODE_FLAG})
1637     if(ALSOFT_INSTALL_EXAMPLES)
1638         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord)
1639     endif()
1641     message(STATUS "Building example programs")
1643     if(SNDFILE_FOUND)
1644         add_executable(alplay examples/alplay.c)
1645         target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1646             ${UNICODE_FLAG})
1648         add_executable(alstream examples/alstream.c)
1649         target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1650             ${UNICODE_FLAG})
1652         add_executable(alreverb examples/alreverb.c)
1653         target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1654             ${UNICODE_FLAG})
1656         add_executable(almultireverb examples/almultireverb.c)
1657         target_link_libraries(almultireverb
1658             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1660         add_executable(allatency examples/allatency.c)
1661         target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1662             ${UNICODE_FLAG})
1664         add_executable(alhrtf examples/alhrtf.c)
1665         target_link_libraries(alhrtf
1666             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1668         add_executable(alstreamcb examples/alstreamcb.cpp)
1669         target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1670             ${UNICODE_FLAG})
1672         add_executable(alconvolve examples/alconvolve.c)
1673         target_link_libraries(alconvolve PRIVATE ${LINKER_FLAGS} common SndFile::SndFile ex-common
1674             ${UNICODE_FLAG})
1676         if(ALSOFT_INSTALL_EXAMPLES)
1677             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1678                 alhrtf)
1679         endif()
1681         message(STATUS "Building SndFile example programs")
1682     endif()
1684     if(SDL2_FOUND)
1685         add_executable(alloopback examples/alloopback.c)
1686         target_link_libraries(alloopback
1687             PRIVATE ${LINKER_FLAGS} SDL2::SDL2 ex-common ${MATH_LIB})
1689         if(ALSOFT_INSTALL_EXAMPLES)
1690             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
1691         endif()
1693         message(STATUS "Building SDL example programs")
1695         set(FFVER_OK FALSE)
1696         if(FFMPEG_FOUND)
1697             set(FFVER_OK TRUE)
1698             if(AVFORMAT_VERSION VERSION_LESS "59.27.100")
1699                 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 59.27.100)")
1700                 set(FFVER_OK FALSE)
1701             endif()
1702             if(AVCODEC_VERSION VERSION_LESS "59.37.100")
1703                 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 59.37.100)")
1704                 set(FFVER_OK FALSE)
1705             endif()
1706             if(AVUTIL_VERSION VERSION_LESS "57.28.100")
1707                 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 57.28.100)")
1708                 set(FFVER_OK FALSE)
1709             endif()
1710             if(SWSCALE_VERSION VERSION_LESS "6.7.100")
1711                 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 6.7.100)")
1712                 set(FFVER_OK FALSE)
1713             endif()
1714             if(SWRESAMPLE_VERSION VERSION_LESS "4.7.100")
1715                 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 4.7.100)")
1716                 set(FFVER_OK FALSE)
1717             endif()
1718         endif()
1719         if(FFVER_OK)
1720             add_executable(alffplay examples/alffplay.cpp)
1721             target_include_directories(alffplay PRIVATE ${FFMPEG_INCLUDE_DIRS})
1722             target_link_libraries(alffplay
1723                 PRIVATE ${LINKER_FLAGS} SDL2::SDL2 ${FFMPEG_LIBRARIES} ex-common)
1725             if(ALSOFT_INSTALL_EXAMPLES)
1726                 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
1727             endif()
1728             message(STATUS "Building SDL+FFmpeg example programs")
1729         endif()
1730     endif()
1731     message(STATUS "")
1732 endif()
1734 if(EXTRA_INSTALLS)
1735     install(TARGETS ${EXTRA_INSTALLS}
1736         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1737         BUNDLE  DESTINATION ${CMAKE_INSTALL_BINDIR}
1738         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1739         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1740 endif()