Initial implementation of the convolution effect
[openal-soft.git] / CMakeLists.txt
blobf77f5a24f9efbe959d9e7082dc5ac0cf8f590a2a
1 # CMake build file list for OpenAL
3 cmake_minimum_required(VERSION 3.0.2)
5 # The workaround for try_compile failing with code signing
6 # since cmake-3.18.2, not required
7 set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
8     "CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED"
9     "CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED")
10 set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
11 set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
13 # Fix compile failure with armv7 deployment target >= 11.0, xcode clang will
14 # report:
15 # error: invalid iOS deployment version '--target=armv7-apple-ios13.6',
16 # iOS 10 is the maximum deployment target for 32-bit targets
17 # If CMAKE_OSX_DEPLOYMENT_TARGET is not defined, cmake will choose latest
18 # deployment target
19 if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
20     if("${CMAKE_OSX_ARCHITECTURES}" MATCHES ".*armv7.*")
21         if(NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET
22             OR NOT CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS "11.0")
23             message(STATUS "Forcing iOS deployment target to 10.0 for armv7")
24             set(CMAKE_OSX_DEPLOYMENT_TARGET "10.0" CACHE STRING "Minimum OS X deployment version"
25                 FORCE)
26         endif()
27     endif()
28 endif()
30 project(OpenAL)
32 if(COMMAND CMAKE_POLICY)
33     cmake_policy(SET CMP0003 NEW)
34     cmake_policy(SET CMP0005 NEW)
35     if(POLICY CMP0020)
36         cmake_policy(SET CMP0020 NEW)
37     endif(POLICY CMP0020)
38     if(POLICY CMP0042)
39         cmake_policy(SET CMP0042 NEW)
40     endif(POLICY CMP0042)
41     if(POLICY CMP0054)
42         cmake_policy(SET CMP0054 NEW)
43     endif(POLICY CMP0054)
44     if(POLICY CMP0075)
45         cmake_policy(SET CMP0075 NEW)
46     endif(POLICY CMP0075)
47 endif(COMMAND CMAKE_POLICY)
49 if(NOT CMAKE_BUILD_TYPE)
50     set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
51         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
52         FORCE)
53 endif()
54 if(NOT CMAKE_DEBUG_POSTFIX)
55     set(CMAKE_DEBUG_POSTFIX "" CACHE STRING
56         "Library postfix for debug builds. Normally left blank."
57         FORCE)
58 endif()
60 set(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
62 include(CheckFunctionExists)
63 include(CheckLibraryExists)
64 include(CheckIncludeFile)
65 include(CheckIncludeFiles)
66 include(CheckSymbolExists)
67 include(CheckCCompilerFlag)
68 include(CheckCXXCompilerFlag)
69 include(CheckCSourceCompiles)
70 include(CheckCXXSourceCompiles)
71 include(CheckStructHasMember)
72 include(GNUInstallDirs)
75 option(ALSOFT_DLOPEN  "Check for the dlopen API for loading optional libs"  ON)
77 option(ALSOFT_WERROR  "Treat compile warnings as errors"      OFF)
79 option(ALSOFT_UTILS "Build utility programs"  ON)
80 option(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
82 option(ALSOFT_EXAMPLES  "Build example programs"  ON)
84 option(ALSOFT_INSTALL "Install main library" ON)
85 option(ALSOFT_INSTALL_CONFIG "Install alsoft.conf sample configuration file" ON)
86 option(ALSOFT_INSTALL_HRTF_DATA "Install HRTF data files" ON)
87 option(ALSOFT_INSTALL_AMBDEC_PRESETS "Install AmbDec preset files" ON)
88 option(ALSOFT_INSTALL_EXAMPLES "Install example programs (alplay, alstream, ...)" ON)
89 option(ALSOFT_INSTALL_UTILS "Install utility programs (openal-info, alsoft-config, ...)" ON)
90 option(ALSOFT_UPDATE_BUILD_VERSION "Update git build version info" ON)
92 if(DEFINED SHARE_INSTALL_DIR)
93     message(WARNING "SHARE_INSTALL_DIR is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
94     set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
95 endif()
97 if(DEFINED LIB_SUFFIX)
98     message(WARNING "LIB_SUFFIX is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
99 endif()
100 if(DEFINED ALSOFT_CONFIG)
101     message(WARNING "ALSOFT_CONFIG is deprecated. Use ALSOFT_INSTALL_CONFIG instead")
102 endif()
103 if(DEFINED ALSOFT_HRTF_DEFS)
104     message(WARNING "ALSOFT_HRTF_DEFS is deprecated. Use ALSOFT_INSTALL_HRTF_DATA instead")
105 endif()
106 if(DEFINED ALSOFT_AMBDEC_PRESETS)
107     message(WARNING "ALSOFT_AMBDEC_PRESETS is deprecated. Use ALSOFT_INSTALL_AMBDEC_PRESETS instead")
108 endif()
111 set(CPP_DEFS ) # C pre-processor, not C++
112 set(INC_PATHS )
113 set(C_FLAGS )
114 set(LINKER_FLAGS )
115 set(EXTRA_LIBS )
117 if(WIN32)
118     set(CPP_DEFS ${CPP_DEFS} _WIN32)
120     option(ALSOFT_BUILD_ROUTER  "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)"  OFF)
121     if(MINGW)
122         option(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
123     endif()
124 elseif(APPLE)
125     option(ALSOFT_OSX_FRAMEWORK "Build as macOS framework" OFF)
126 endif()
129 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
130 if("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
131     set(INC_PATHS ${INC_PATHS} /usr/include)
132     set(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
133 endif()
135 if(NOT LIBTYPE)
136     set(LIBTYPE SHARED)
137 endif()
139 set(LIB_MAJOR_VERSION "1")
140 set(LIB_MINOR_VERSION "20")
141 set(LIB_REVISION "1")
142 set(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
143 set(LIB_VERSION_NUM ${LIB_MAJOR_VERSION},${LIB_MINOR_VERSION},${LIB_REVISION},0)
145 set(EXPORT_DECL "")
148 # Require C++14
149 set(CMAKE_CXX_STANDARD 14)
150 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
152 # Prefer C11, but support C99 and C90 too.
153 set(CMAKE_C_STANDARD 11)
155 if(NOT WIN32)
156     # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
157     check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
158     if(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
159         set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
160         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
161         check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
162         if(NOT HAVE_POSIX_MEMALIGN_POSIX)
163             set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
164         else()
165             set(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
166         endif()
167     endif()
168     unset(OLD_REQUIRED_FLAGS)
169 endif()
171 # C99 has restrict, but C++ does not, so we can only utilize __restrict.
172 set(RESTRICT_DECL )
173 check_cxx_source_compiles("int *__restrict foo;
174 int main() { return 0; }" HAVE___RESTRICT)
175 if(HAVE___RESTRICT)
176     set(RESTRICT_DECL "__restrict")
177 endif()
179 # Some systems may need libatomic for atomic functions to work
180 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
181 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
182 check_cxx_source_compiles("#include <atomic>
183 std::atomic<int> foo{0};
184 int main() { return foo.fetch_add(2); }"
185 HAVE_LIBATOMIC)
186 if(NOT HAVE_LIBATOMIC)
187     set(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
188 else()
189     set(EXTRA_LIBS atomic ${EXTRA_LIBS})
190 endif()
191 unset(OLD_REQUIRED_LIBRARIES)
193 # Include liblog for Android logging
194 check_library_exists(log __android_log_print "" HAVE_LIBLOG)
195 if(HAVE_LIBLOG)
196     set(EXTRA_LIBS log ${EXTRA_LIBS})
197     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
198 endif()
200 if(MSVC)
201     set(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS NOMINMAX)
202     check_cxx_compiler_flag(/permissive- HAVE_PERMISSIVE_SWITCH)
203     if(HAVE_PERMISSIVE_SWITCH)
204         set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
205     endif()
206     set(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4268 /wd4324 /wd5030)
208     if(NOT DXSDK_DIR)
209         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
210     else()
211         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
212     endif()
213     if(DXSDK_DIR)
214         message(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
215     endif()
217     option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
218     if(FORCE_STATIC_VCRT)
219         foreach(flag_var
220                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
221                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
222                 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
223                 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
224             if(${flag_var} MATCHES "/MD")
225                 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
226             endif()
227         endforeach(flag_var)
228     endif()
229 else()
230     set(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
231         -Wpedantic
232         $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
234     if(ALSOFT_WERROR)
235         set(C_FLAGS ${C_FLAGS} -Werror)
236     endif()
238     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
239     # instead of NDEBUG)
240     foreach(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
241         if(${flag_var} MATCHES "-DNDEBUG")
242             string(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
243         endif()
244     endforeach()
246     check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
247     if(HAVE_FNO_MATH_ERRNO)
248         set(C_FLAGS ${C_FLAGS} -fno-math-errno)
249     endif()
251     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
252     if(ALSOFT_STATIC_LIBGCC)
253         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
254         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
255         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
256         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
257         unset(OLD_REQUIRED_LIBRARIES)
259         if(NOT HAVE_STATIC_LIBGCC_SWITCH)
260             message(FATAL_ERROR "Cannot static link libgcc")
261         endif()
262         set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
263     endif()
265     option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
266     if(ALSOFT_STATIC_STDCXX)
267         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
268         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
269         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
270         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
271         unset(OLD_REQUIRED_LIBRARIES)
273         if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
274             message(FATAL_ERROR "Cannot static link libstdc++")
275         endif()
276         set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
277     endif()
279     if(WIN32)
280         option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
281         if(ALSOFT_STATIC_WINPTHREAD)
282             set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
283             set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
284             check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
285             set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
286             unset(OLD_REQUIRED_LIBRARIES)
288             if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
289                 message(FATAL_ERROR "Cannot static link libwinpthread")
290             endif()
291             set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
292         endif()
293     endif()
294 endif()
296 # Set visibility/export options if available
297 if(WIN32)
298     if(NOT LIBTYPE STREQUAL "STATIC")
299         set(EXPORT_DECL "__declspec(dllexport)")
300     endif()
301 else()
302     set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
303     # Yes GCC, really don't accept visibility modes you don't support
304     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
306     check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
307                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
308     if(HAVE_GCC_PROTECTED_VISIBILITY)
309         if(NOT LIBTYPE STREQUAL "STATIC")
310             set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
311         endif()
312     else()
313         check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
314                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
315         if(HAVE_GCC_DEFAULT_VISIBILITY)
316             if(NOT LIBTYPE STREQUAL "STATIC")
317                 set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
318             endif()
319         endif()
320     endif()
322     if(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
323         check_c_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
324         if(HAVE_VISIBILITY_HIDDEN_SWITCH)
325             set(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
326         endif()
327     endif()
329     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
330 endif()
333 set(SSE2_SWITCH "")
334 set(SSE3_SWITCH "")
335 set(SSE4_1_SWITCH "")
336 set(FPU_NEON_SWITCH "")
338 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
339 if(NOT MSVC)
340     # Yes GCC, really don't accept command line options you don't support
341     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
342 endif()
343 check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
344 if(HAVE_MSSE2_SWITCH)
345     set(SSE2_SWITCH "-msse2")
346     check_c_compiler_flag(-msse3 HAVE_MSSE3_SWITCH)
347     if(HAVE_MSSE3_SWITCH)
348         set(SSE3_SWITCH "-msse3")
349         check_c_compiler_flag(-msse4.1 HAVE_MSSE4_1_SWITCH)
350         if(HAVE_MSSE4_1_SWITCH)
351             set(SSE4_1_SWITCH "-msse4.1")
352         endif()
353     endif()
354 endif()
355 check_c_compiler_flag(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
356 if(HAVE_MFPU_NEON_SWITCH)
357     set(FPU_NEON_SWITCH "-mfpu=neon")
358 endif()
359 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
360 unset(OLD_REQUIRED_FLAGS)
362 check_include_file(xmmintrin.h HAVE_XMMINTRIN_H ${SSE2_SWITCH})
363 check_include_file(emmintrin.h HAVE_EMMINTRIN_H ${SSE2_SWITCH})
364 check_include_file(pmmintrin.h HAVE_PMMINTRIN_H ${SSE3_SWITCH})
365 check_include_file(smmintrin.h HAVE_SMMINTRIN_H ${SSE4_1_SWITCH})
366 check_include_file(arm_neon.h HAVE_ARM_NEON_H ${FPU_NEON_SWITCH})
368 set(SSE_FLAGS )
369 set(FPMATH_SET "0")
370 if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND (SSE2_SWITCH OR MSVC))
371     option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
372     if(ALSOFT_ENABLE_SSE2_CODEGEN)
373         if(SSE2_SWITCH)
374             check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
375             if(HAVE_MFPMATH_SSE_2)
376                 set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
377                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
378                 set(FPMATH_SET 2)
379             endif()
380             # SSE depends on a 16-byte aligned stack, and by default, GCC
381             # assumes the stack is suitably aligned. Older Linux code or other
382             # OSs don't guarantee this on 32-bit, so externally-callable
383             # functions need to ensure an aligned stack.
384             set(EXPORT_DECL "${EXPORT_DECL} __attribute__((force_align_arg_pointer))")
385         elseif(MSVC)
386             check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
387             if(HAVE_ARCH_SSE2)
388                 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
389                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
390                 set(FPMATH_SET 2)
391             endif()
392         endif()
393     endif()
394 endif()
396 if(HAVE_EMMINTRIN_H)
397     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
398     foreach(flag_var ${SSE_FLAGS})
399         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
400     endforeach()
402     check_c_source_compiles("#include <emmintrin.h>
403                              int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
405     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
406 endif()
409 check_include_file(malloc.h HAVE_MALLOC_H)
410 check_include_file(cpuid.h HAVE_CPUID_H)
411 check_include_file(intrin.h HAVE_INTRIN_H)
412 check_include_file(guiddef.h HAVE_GUIDDEF_H)
413 if(NOT HAVE_GUIDDEF_H)
414     check_include_file(initguid.h HAVE_INITGUID_H)
415 endif()
417 # Some systems need libm for some math functions to work
418 set(MATH_LIB )
419 check_library_exists(m pow "" HAVE_LIBM)
420 if(HAVE_LIBM)
421     set(MATH_LIB ${MATH_LIB} m)
422     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
423 endif()
425 # Some systems need to link with -lrt for clock_gettime as used by the common
426 # eaxmple functions.
427 set(RT_LIB )
428 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
429 if(HAVE_LIBRT)
430     set(RT_LIB rt)
431 endif()
433 # Check for the dlopen API (for dynamicly loading backend libs)
434 if(ALSOFT_DLOPEN)
435     check_include_file(dlfcn.h HAVE_DLFCN_H)
436     check_library_exists(dl dlopen "" HAVE_LIBDL)
437     if(HAVE_LIBDL)
438         set(EXTRA_LIBS dl ${EXTRA_LIBS})
439         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
440     endif()
441 endif()
443 # Check for a cpuid intrinsic
444 if(HAVE_CPUID_H)
445     check_c_source_compiles("#include <cpuid.h>
446         int main()
447         {
448             unsigned int eax, ebx, ecx, edx;
449             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
450         }" HAVE_GCC_GET_CPUID)
451 endif()
452 if(HAVE_INTRIN_H)
453     check_c_source_compiles("#include <intrin.h>
454         int main()
455         {
456             int regs[4];
457             __cpuid(regs, 0);
458             return regs[0];
459         }" HAVE_CPUID_INTRINSIC)
460 endif()
462 check_cxx_source_compiles("#include <cstdlib>
463 int main()
465     void *ptr{std::aligned_alloc(alignof(int), sizeof(int))};
466     std::free(ptr);
467     return 0;
468 }" HAVE_STD_ALIGNED_ALLOC)
469 check_symbol_exists(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
470 check_symbol_exists(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
471 check_symbol_exists(proc_pidpath     libproc.h HAVE_PROC_PIDPATH)
473 if(NOT WIN32)
474     # We need pthreads outside of Windows, for semaphores. It's also used to
475     # set the priority and name of threads, when possible.
476     check_include_file(pthread.h HAVE_PTHREAD_H)
477     if(NOT HAVE_PTHREAD_H)
478         message(FATAL_ERROR "PThreads is required for non-Windows builds!")
479     endif()
481     check_c_compiler_flag(-pthread HAVE_PTHREAD)
482     if(HAVE_PTHREAD)
483         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
484         set(C_FLAGS ${C_FLAGS} -pthread)
485         set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
486     endif()
488     check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
490     # Some systems need pthread_np.h to get pthread_setname_np
491     check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
492     if(HAVE_PTHREAD_NP_H)
493         check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
494         if(NOT HAVE_PTHREAD_SETNAME_NP)
495             check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
496         else()
497             check_c_source_compiles("
498 #include <pthread.h>
499 #include <pthread_np.h>
500 int main()
502     pthread_setname_np(\"testname\");
503     return 0;
505                 PTHREAD_SETNAME_NP_ONE_PARAM
506             )
507             check_c_source_compiles("
508 #include <pthread.h>
509 #include <pthread_np.h>
510 int main()
512     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
513     return 0;
515                 PTHREAD_SETNAME_NP_THREE_PARAMS
516             )
517         endif()
518     else()
519         check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
520         if(NOT HAVE_PTHREAD_SETNAME_NP)
521             check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
522         else()
523             check_c_source_compiles("
524 #include <pthread.h>
525 int main()
527     pthread_setname_np(\"testname\");
528     return 0;
530                 PTHREAD_SETNAME_NP_ONE_PARAM
531             )
532             check_c_source_compiles("
533 #include <pthread.h>
534 int main()
536     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
537     return 0;
539                 PTHREAD_SETNAME_NP_THREE_PARAMS
540             )
541         endif()
542     endif()
543 endif()
545 check_symbol_exists(getopt unistd.h HAVE_GETOPT)
548 # Common sources used by both the OpenAL implementation library and potentially
549 # the OpenAL router.
550 set(COMMON_OBJS
551     common/albyte.h
552     common/alcomplex.cpp
553     common/alcomplex.h
554     common/alexcpt.cpp
555     common/alexcpt.h
556     common/alfstream.cpp
557     common/alfstream.h
558     common/almalloc.cpp
559     common/almalloc.h
560     common/alnumeric.h
561     common/aloptional.h
562     common/alspan.h
563     common/alstring.cpp
564     common/alstring.h
565     common/atomic.h
566     common/dynload.cpp
567     common/dynload.h
568     common/endiantest.h
569     common/intrusive_ptr.h
570     common/math_defs.h
571     common/opthelpers.h
572     common/polyphase_resampler.cpp
573     common/polyphase_resampler.h
574     common/pragmadefs.h
575     common/strutils.cpp
576     common/strutils.h
577     common/threads.cpp
578     common/threads.h
579     common/vecmat.h
580     common/vector.h
582 set(OPENAL_OBJS
583     al/auxeffectslot.cpp
584     al/auxeffectslot.h
585     al/buffer.cpp
586     al/buffer.h
587     al/effect.cpp
588     al/effect.h
589     al/error.cpp
590     al/event.cpp
591     al/event.h
592     al/extension.cpp
593     al/filter.cpp
594     al/filter.h
595     al/listener.cpp
596     al/listener.h
597     al/source.cpp
598     al/source.h
599     al/state.cpp
601 set(ALC_OBJS
602     alc/alc.cpp
603     alc/alcmain.h
604     alc/alu.cpp
605     alc/alu.h
606     alc/alconfig.cpp
607     alc/alconfig.h
608     alc/alcontext.h
609     alc/ambdec.cpp
610     alc/ambdec.h
611     alc/ambidefs.h
612     alc/bformatdec.cpp
613     alc/bformatdec.h
614     alc/bs2b.cpp
615     alc/bs2b.h
616     alc/bsinc_defs.h
617     alc/bsinc_tables.cpp
618     alc/bsinc_tables.h
619     alc/bufferline.h
620     alc/buffer_formats.cpp
621     alc/buffer_formats.h
622     alc/compat.h
623     alc/converter.cpp
624     alc/converter.h
625     alc/cpu_caps.cpp
626     alc/cpu_caps.h
627     alc/devformat.h
628     alc/effects/base.h
629     alc/effects/autowah.cpp
630     alc/effects/chorus.cpp
631     alc/effects/compressor.cpp
632     alc/effects/convolution.cpp
633     alc/effects/dedicated.cpp
634     alc/effects/distortion.cpp
635     alc/effects/echo.cpp
636     alc/effects/equalizer.cpp
637     alc/effects/fshifter.cpp
638     alc/effects/modulator.cpp
639     alc/effects/null.cpp
640     alc/effects/pshifter.cpp
641     alc/effects/reverb.cpp
642     alc/effects/vmorpher.cpp
643     alc/filters/biquad.h
644     alc/filters/biquad.cpp
645     alc/filters/nfc.cpp
646     alc/filters/nfc.h
647     alc/filters/splitter.cpp
648     alc/filters/splitter.h
649     alc/fpu_ctrl.cpp
650     alc/fpu_ctrl.h
651     alc/front_stablizer.h
652     alc/helpers.cpp
653     alc/hrtf.cpp
654     alc/hrtf.h
655     alc/inprogext.h
656     alc/logging.h
657     alc/mastering.cpp
658     alc/mastering.h
659     alc/panning.cpp
660     alc/ringbuffer.cpp
661     alc/ringbuffer.h
662     alc/uhjfilter.cpp
663     alc/uhjfilter.h
664     alc/uiddefs.cpp
665     alc/voice.cpp
666     alc/voice.h
667     alc/mixer/defs.h
668     alc/mixer/hrtfbase.h
669     alc/mixer/mixer_c.cpp
673 set(CPU_EXTS "Default")
674 set(HAVE_SSE        0)
675 set(HAVE_SSE2       0)
676 set(HAVE_SSE3       0)
677 set(HAVE_SSE4_1     0)
678 set(HAVE_NEON       0)
680 # Check for SSE+SSE2 support
681 option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
682 option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
683 if(HAVE_XMMINTRIN_H AND HAVE_EMMINTRIN_H)
684     option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
685     option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
686     if(ALSOFT_CPUEXT_SSE AND ALSOFT_CPUEXT_SSE2)
687         set(HAVE_SSE 1)
688         set(HAVE_SSE2 1)
689         set(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse.cpp alc/mixer/mixer_sse2.cpp)
690         if(SSE2_SWITCH)
691             set_source_files_properties(alc/mixer/mixer_sse.cpp alc/mixer/mixer_sse2.cpp
692                 PROPERTIES COMPILE_FLAGS "${SSE2_SWITCH}")
693         endif()
694         set(CPU_EXTS "${CPU_EXTS}, SSE, SSE2")
695     endif()
696 endif()
697 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
698     message(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
699 endif()
700 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
701     message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
702 endif()
704 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
705 if(HAVE_EMMINTRIN_H)
706     option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
707     if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
708         set(HAVE_SSE3 1)
709         set(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse3.cpp)
710         if(SSE2_SWITCH)
711             set_source_files_properties(alc/mixer/mixer_sse3.cpp PROPERTIES
712                 COMPILE_FLAGS "${SSE3_SWITCH}")
713         endif()
714         set(CPU_EXTS "${CPU_EXTS}, SSE3")
715     endif()
716 endif()
717 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
718     message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
719 endif()
721 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
722 if(HAVE_SMMINTRIN_H)
723     option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
724     if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
725         set(HAVE_SSE4_1 1)
726         set(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse41.cpp)
727         if(SSE4_1_SWITCH)
728             set_source_files_properties(alc/mixer/mixer_sse41.cpp PROPERTIES
729                 COMPILE_FLAGS "${SSE4_1_SWITCH}")
730         endif()
731         set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
732     endif()
733 endif()
734 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
735     message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
736 endif()
738 # Check for ARM Neon support
739 option(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
740 if(HAVE_ARM_NEON_H)
741     option(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
742     if(ALSOFT_CPUEXT_NEON)
743         set(HAVE_NEON 1)
744         set(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_neon.cpp)
745         if(FPU_NEON_SWITCH)
746             set_source_files_properties(alc/mixer/mixer_neon.cpp PROPERTIES
747                 COMPILE_FLAGS "${FPU_NEON_SWITCH}")
748         endif()
749         set(CPU_EXTS "${CPU_EXTS}, Neon")
750     endif()
751 endif()
752 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
753     message(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
754 endif()
757 set(HAVE_ALSA       0)
758 set(HAVE_OSS        0)
759 set(HAVE_SOLARIS    0)
760 set(HAVE_SNDIO      0)
761 set(HAVE_DSOUND     0)
762 set(HAVE_WASAPI     0)
763 set(HAVE_WINMM      0)
764 set(HAVE_PORTAUDIO  0)
765 set(HAVE_PULSEAUDIO 0)
766 set(HAVE_COREAUDIO  0)
767 set(HAVE_OPENSL     0)
768 set(HAVE_OBOE       0)
769 set(HAVE_WAVE       0)
770 set(HAVE_SDL2       0)
772 if(WIN32 OR HAVE_DLFCN_H)
773     set(IS_LINKED "")
774     macro(ADD_BACKEND_LIBS _LIBS)
775     endmacro()
776 else()
777     set(IS_LINKED " (linked)")
778     macro(ADD_BACKEND_LIBS _LIBS)
779         set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
780     endmacro()
781 endif()
783 set(BACKENDS "")
784 set(ALC_OBJS  ${ALC_OBJS}
785     alc/backends/base.cpp
786     alc/backends/base.h
787     # Default backends, always available
788     alc/backends/loopback.cpp
789     alc/backends/loopback.h
790     alc/backends/null.cpp
791     alc/backends/null.h
794 # Check ALSA backend
795 option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
796 find_package(ALSA)
797 if(ALSA_FOUND)
798     option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
799     if(ALSOFT_BACKEND_ALSA)
800         set(HAVE_ALSA 1)
801         set(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
802         set(ALC_OBJS  ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
803         add_backend_libs(${ALSA_LIBRARIES})
804         set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
805     endif()
806 endif()
807 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
808     message(FATAL_ERROR "Failed to enabled required ALSA backend")
809 endif()
811 # Check OSS backend
812 option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
813 find_package(OSS)
814 if(OSS_FOUND)
815     option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
816     if(ALSOFT_BACKEND_OSS)
817         set(HAVE_OSS 1)
818         set(BACKENDS  "${BACKENDS} OSS,")
819         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
820         if(OSS_LIBRARIES)
821             set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
822         endif()
823         set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
824     endif()
825 endif()
826 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
827     message(FATAL_ERROR "Failed to enabled required OSS backend")
828 endif()
830 # Check Solaris backend
831 option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
832 find_package(AudioIO)
833 if(AUDIOIO_FOUND)
834     option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
835     if(ALSOFT_BACKEND_SOLARIS)
836         set(HAVE_SOLARIS 1)
837         set(BACKENDS  "${BACKENDS} Solaris,")
838         set(ALC_OBJS  ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
839         set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
840     endif()
841 endif()
842 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
843     message(FATAL_ERROR "Failed to enabled required Solaris backend")
844 endif()
846 # Check SndIO backend
847 option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
848 find_package(SoundIO)
849 if(SOUNDIO_FOUND)
850     option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
851     if(ALSOFT_BACKEND_SNDIO)
852         set(HAVE_SNDIO 1)
853         set(BACKENDS  "${BACKENDS} SndIO (linked),")
854         set(ALC_OBJS  ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
855         set(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
856         set(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
857     endif()
858 endif()
859 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
860     message(FATAL_ERROR "Failed to enabled required SndIO backend")
861 endif()
863 # Check Windows-only backends
864 option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
865 option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
866 option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
867 if(WIN32)
868     set(WINSDK_LIB_DIRS )
869     set(WINSDK_INCLUDE_DIRS )
870     find_package(WindowsSDK)
871     if(WINDOWSSDK_FOUND)
872         get_windowssdk_library_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_LIB_DIRS)
873         get_windowssdk_include_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_INCLUDE_DIRS)
874     endif()
876     # Check MMSystem backend
877     check_include_files("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
878     find_library(WINMM_LIBRARY NAMES winmm
879         PATHS ${WINSDK_LIB_DIRS})
880     if(HAVE_MMSYSTEM_H AND WINMM_LIBRARY)
881         option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
882         if(ALSOFT_BACKEND_WINMM)
883             set(HAVE_WINMM 1)
884             set(BACKENDS  "${BACKENDS} WinMM,")
885             set(ALC_OBJS  ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
886             set(EXTRA_LIBS ${WINMM_LIBRARY} ${EXTRA_LIBS})
887         endif()
888     endif()
890     # Check DSound backend
891     find_package(DSound)
892     if(DSOUND_FOUND)
893         option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
894         if(ALSOFT_BACKEND_DSOUND)
895             set(HAVE_DSOUND 1)
896             set(BACKENDS  "${BACKENDS} DirectSound${IS_LINKED},")
897             set(ALC_OBJS  ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
898             add_backend_libs(${DSOUND_LIBRARIES})
899             set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIRS})
900         endif()
901     endif()
903     # Check for WASAPI backend
904     check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
905     if(HAVE_MMDEVICEAPI_H)
906         option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
907         if(ALSOFT_BACKEND_WASAPI)
908             set(HAVE_WASAPI 1)
909             set(BACKENDS  "${BACKENDS} WASAPI,")
910             set(ALC_OBJS  ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
911         endif()
912     endif()
913 endif()
914 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
915     message(FATAL_ERROR "Failed to enabled required WinMM backend")
916 endif()
917 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
918     message(FATAL_ERROR "Failed to enabled required DSound backend")
919 endif()
920 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
921     message(FATAL_ERROR "Failed to enabled required WASAPI backend")
922 endif()
924 # Check PortAudio backend
925 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
926 find_package(PortAudio)
927 if(PORTAUDIO_FOUND)
928     option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
929     if(ALSOFT_BACKEND_PORTAUDIO)
930         set(HAVE_PORTAUDIO 1)
931         set(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
932         set(ALC_OBJS  ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
933         add_backend_libs(${PORTAUDIO_LIBRARIES})
934         set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
935     endif()
936 endif()
937 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
938     message(FATAL_ERROR "Failed to enabled required PortAudio backend")
939 endif()
941 # Check PulseAudio backend
942 option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
943 find_package(PulseAudio)
944 if(PULSEAUDIO_FOUND)
945     option(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
946     if(ALSOFT_BACKEND_PULSEAUDIO)
947         set(HAVE_PULSEAUDIO 1)
948         set(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
949         set(ALC_OBJS  ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
950         add_backend_libs(${PULSEAUDIO_LIBRARIES})
951         set(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
952     endif()
953 endif()
954 if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
955     message(FATAL_ERROR "Failed to enabled required PulseAudio backend")
956 endif()
958 # Check JACK backend
959 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
960 find_package(JACK)
961 if(JACK_FOUND)
962     option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
963     if(ALSOFT_BACKEND_JACK)
964         set(HAVE_JACK 1)
965         set(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
966         set(ALC_OBJS  ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
967         add_backend_libs(${JACK_LIBRARIES})
968         set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
969     endif()
970 endif()
971 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
972     message(FATAL_ERROR "Failed to enabled required JACK backend")
973 endif()
975 # Check CoreAudio backend
976 option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
977 find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
978 find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
979 if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
980     option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
981     if(ALSOFT_BACKEND_COREAUDIO)
982         set(HAVE_COREAUDIO 1)
983         set(ALC_OBJS  ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
984         set(BACKENDS  "${BACKENDS} CoreAudio,")
985         if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
986             find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
987             set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${COREFOUNDATION_FRAMEWORK} ${EXTRA_LIBS})
988         else()
989             set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} /System/Library/Frameworks/AudioUnit.framework
990                 /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
991         endif()
993         # Some versions of OSX may need the AudioToolbox framework. Add it if
994         # it's found.
995         find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
996         if(AUDIOTOOLBOX_LIBRARY)
997             set(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
998         endif()
1000         set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
1001     endif()
1002 endif()
1003 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1004     message(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1005 endif()
1007 # Check for OpenSL (Android) backend
1008 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1009 find_package(OpenSL)
1010 if(OPENSL_FOUND)
1011     option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1012     if(ALSOFT_BACKEND_OPENSL)
1013         set(HAVE_OPENSL 1)
1014         set(ALC_OBJS  ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1015         set(BACKENDS  "${BACKENDS} OpenSL,")
1016         set(EXTRA_LIBS ${OPENSL_LIBRARIES} ${EXTRA_LIBS})
1017         set(INC_PATHS ${INC_PATHS} ${OPENSL_INCLUDE_DIRS})
1018     endif()
1019 endif()
1020 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1021     message(FATAL_ERROR "Failed to enabled required OpenSL backend")
1022 endif()
1024 # Check for Oboe (Android) backend
1025 set(OBOE_TARGET )
1026 if(ANDROID)
1027     set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1028     if(OBOE_SOURCE)
1029         # Force Oboe to build with hidden symbols. Don't want to be exporting
1030         # them from OpenAL.
1031         set(OLD_CXX_FLAGS ${CMAKE_CXX_FLAGS})
1032         check_cxx_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
1033         if(HAVE_VISIBILITY_HIDDEN_SWITCH)
1034             set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
1035         endif()
1036         add_subdirectory(${OBOE_SOURCE} ./oboe)
1037         set(CMAKE_CXX_FLAGS ${OLD_CXX_FLAGS})
1038         unset(OLD_CXX_FLAGS)
1040         set(OBOE_TARGET oboe)
1041     else()
1042         find_package(Oboe)
1043         if(OBOE_FOUND)
1044             set(OBOE_TARGET "oboe::oboe")
1045         endif()
1046     endif()
1047 endif()
1049 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1050 if(OBOE_TARGET)
1051     option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1052     if(ALSOFT_BACKEND_OBOE)
1053         set(HAVE_OBOE 1)
1054         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
1055         set(BACKENDS  "${BACKENDS} Oboe,")
1056         set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
1057     endif()
1058 endif()
1059 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1060     message(FATAL_ERROR "Failed to enabled required Oboe backend")
1061 endif()
1063 # Check for SDL2 backend
1064 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1065 find_package(SDL2)
1066 if(SDL2_FOUND)
1067     # Off by default, since it adds a runtime dependency
1068     option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1069     if(ALSOFT_BACKEND_SDL2)
1070         set(HAVE_SDL2 1)
1071         set(ALC_OBJS  ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1072         set(BACKENDS  "${BACKENDS} SDL2,")
1073         set(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
1074         set(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
1075     endif()
1076 endif()
1077 if(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1078     message(FATAL_ERROR "Failed to enabled required SDL2 backend")
1079 endif()
1081 # Optionally enable the Wave Writer backend
1082 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1083 if(ALSOFT_BACKEND_WAVE)
1084     set(HAVE_WAVE 1)
1085     set(ALC_OBJS  ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1086     set(BACKENDS  "${BACKENDS} WaveFile,")
1087 endif()
1089 # This is always available
1090 set(BACKENDS  "${BACKENDS} Null")
1093 find_package(Git)
1094 if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1095     # Get the current working branch and its latest abbreviated commit hash
1096     add_custom_target(build_version
1097         ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1098             -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1099             -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1100         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1101         VERBATIM
1102     )
1103 else()
1104     set(GIT_BRANCH "UNKNOWN")
1105     set(GIT_COMMIT_HASH "unknown")
1106     configure_file(
1107         "${OpenAL_SOURCE_DIR}/version.h.in"
1108         "${OpenAL_BINARY_DIR}/version.h")
1109 endif()
1112 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1113 if(ALSOFT_EMBED_HRTF_DATA)
1114     macro(make_hrtf_header FILENAME VARNAME)
1115         set(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1116         set(outfile  "${OpenAL_BINARY_DIR}/${VARNAME}.h")
1118         add_custom_command(OUTPUT "${outfile}"
1119             COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
1120                 -D "VARIABLE_NAME=${VARNAME}" -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1121             WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1122             DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1123             VERBATIM
1124         )
1125         set(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1126     endmacro()
1128     make_hrtf_header("Default HRTF.mhr" "hrtf_default")
1129 endif()
1132 if(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1133     find_package(Qt5Widgets)
1134 endif()
1135 if(ALSOFT_EXAMPLES)
1136     find_package(SndFile)
1137     find_package(SDL2)
1138     if(SDL2_FOUND)
1139         find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1140     endif()
1141 endif()
1143 if(NOT WIN32)
1144     set(LIBNAME "openal")
1145 else()
1146     set(LIBNAME "OpenAL32")
1147 endif()
1149 # Needed for openal.pc.in
1150 set(prefix ${CMAKE_INSTALL_PREFIX})
1151 set(exec_prefix "\${prefix}")
1152 set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1153 set(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1154 set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1155 set(PACKAGE_VERSION "${LIB_VERSION}")
1156 set(PKG_CONFIG_CFLAGS )
1157 set(PKG_CONFIG_PRIVATE_LIBS )
1158 if(LIBTYPE STREQUAL "STATIC")
1159     set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1160     foreach(FLAG  ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1161         # If this is already a linker flag, or is a full path+file, add it
1162         # as-is. Otherwise, it's a name intended to be dressed as -lname.
1163         if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1164             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1165         else()
1166             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1167         endif()
1168     endforeach()
1169 endif()
1171 # End configuration
1172 configure_file(
1173     "${OpenAL_SOURCE_DIR}/config.h.in"
1174     "${OpenAL_BINARY_DIR}/config.h")
1175 configure_file(
1176     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1177     "${OpenAL_BINARY_DIR}/openal.pc"
1178     @ONLY)
1181 add_library(common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1182 target_include_directories(common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include)
1183 target_compile_definitions(common PRIVATE ${CPP_DEFS})
1184 target_compile_options(common PRIVATE ${C_FLAGS})
1185 set_target_properties(common PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
1188 unset(HAS_ROUTER)
1189 set(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1191 # Build main library
1192 if(LIBTYPE STREQUAL "STATIC")
1193     add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1194     target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
1195     target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1196     if(WIN32)
1197         # This option is for static linking OpenAL Soft into another project
1198         # that already defines the IDs. It is up to that project to ensure all
1199         # required IDs are defined.
1200         option(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
1201         if(ALSOFT_NO_UID_DEFS)
1202             target_compile_definitions(${IMPL_TARGET} PRIVATE AL_NO_UID_DEFS)
1203         endif()
1204     endif()
1205 else()
1206     set(RC_CONFIG resources/openal32.rc)
1207     if(WIN32 AND ALSOFT_BUILD_ROUTER)
1208         add_library(OpenAL SHARED
1209             resources/router.rc
1210             router/router.cpp
1211             router/router.h
1212             router/alc.cpp
1213             router/al.cpp
1214         )
1215         target_compile_definitions(OpenAL
1216             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1217         target_compile_options(OpenAL PRIVATE ${C_FLAGS})
1218         target_link_libraries(OpenAL PRIVATE common ${LINKER_FLAGS})
1219         target_include_directories(OpenAL
1220           PUBLIC
1221             $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1222             $<INSTALL_INTERFACE:include>
1223           PRIVATE
1224             ${OpenAL_SOURCE_DIR}/common
1225             ${OpenAL_BINARY_DIR}
1226         )
1227         set_target_properties(OpenAL PROPERTIES PREFIX "")
1228         set_target_properties(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1229         if(TARGET build_version)
1230             add_dependencies(OpenAL build_version)
1231         endif()
1232         set(HAS_ROUTER 1)
1234         set(LIBNAME "soft_oal")
1235         set(IMPL_TARGET soft_oal)
1236         set(RC_CONFIG resources/soft_oal.rc)
1237     endif()
1239     # !important: for osx framework public header works, the headers must be in
1240     # the project
1241     set(TARGET_PUBLIC_HEADERS include/AL/al.h include/AL/alc.h include/AL/alext.h include/AL/efx.h)
1242     add_library(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${RC_CONFIG}
1243         ${TARGET_PUBLIC_HEADERS})
1244     if(WIN32)
1245         set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
1246     endif()
1247     target_link_libraries(${IMPL_TARGET} PRIVATE common ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1249     if(APPLE AND ALSOFT_OSX_FRAMEWORK)
1250         # Sets framework name to soft_oal to avoid ambiguity with the system OpenAL.framework
1251         set(LIBNAME "soft_oal")
1252         if(GIT_FOUND)
1253             EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list --count head
1254                 TIMEOUT 5
1255                 OUTPUT_VARIABLE BUNDLE_VERSION
1256                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1257         else()
1258             set(BUNDLE_VERSION 1)
1259         endif()
1261         # Build: Fix rpath in iOS shared libraries
1262         # If this flag is not set, the final dylib binary ld path will be
1263         # /User/xxx/*/soft_oal.framework/soft_oal, which can't be loaded by iOS devices.
1264         # See also: https://github.com/libjpeg-turbo/libjpeg-turbo/commit/c80ddef7a4ce21ace9e3ca0fd190d320cc8cdaeb
1265         if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
1266             set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
1267         endif()
1269         set_target_properties(${IMPL_TARGET} PROPERTIES
1270             FRAMEWORK TRUE
1271             FRAMEWORK_VERSION C
1272             MACOSX_FRAMEWORK_NAME "${IMPL_TARGET}"
1273             MACOSX_FRAMEWORK_IDENTIFIER "org.openal-soft.openal"
1274             MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${LIB_VERSION}
1275             MACOSX_FRAMEWORK_BUNDLE_VERSION ${BUNDLE_VERSION}
1276             XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
1277             XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
1278             XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
1279             PUBLIC_HEADER "${TARGET_PUBLIC_HEADERS}"
1280             MACOSX_RPATH TRUE)
1281     endif()
1282 endif()
1284 target_include_directories(${IMPL_TARGET}
1285   PUBLIC
1286     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1287     $<INSTALL_INTERFACE:include>
1288   PRIVATE
1289     ${INC_PATHS}
1290     ${OpenAL_BINARY_DIR}
1291     ${OpenAL_SOURCE_DIR}
1292     ${OpenAL_SOURCE_DIR}/alc
1293     ${OpenAL_SOURCE_DIR}/common
1296 set_target_properties(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1297     VERSION ${LIB_VERSION}
1298     SOVERSION ${LIB_MAJOR_VERSION}
1300 target_compile_definitions(${IMPL_TARGET}
1301     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1302 target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1304 if(TARGET build_version)
1305     add_dependencies(${IMPL_TARGET} build_version)
1306 endif()
1308 if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1309     find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
1310     if(NOT SED_EXECUTABLE OR NOT CMAKE_DLLTOOL)
1311         message(STATUS "")
1312         if(NOT SED_EXECUTABLE)
1313             message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1314         endif()
1315         if(NOT CMAKE_DLLTOOL)
1316             message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1317         endif()
1318     else()
1319         set_property(TARGET OpenAL APPEND_STRING PROPERTY
1320             LINK_FLAGS " -Wl,--output-def,OpenAL32.def")
1321         add_custom_command(TARGET OpenAL POST_BUILD
1322             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1323             COMMAND "${CMAKE_DLLTOOL}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1324             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1325             VERBATIM
1326         )
1327     endif()
1328 endif()
1330 if(HAS_ROUTER)
1331     message(STATUS "")
1332     message(STATUS "Building DLL router")
1333 endif()
1335 message(STATUS "
1336 Building OpenAL with support for the following backends:
1337     ${BACKENDS}
1339 Building with support for CPU extensions:
1340     ${CPU_EXTS}
1342 if(FPMATH_SET)
1343     message(STATUS "Building with SSE${FPMATH_SET} codegen
1345 endif()
1347 if(ALSOFT_EMBED_HRTF_DATA)
1348     message(STATUS "Embedding HRTF datasets
1350 endif()
1352 # Install main library
1353 if(ALSOFT_INSTALL)
1354     install(TARGETS OpenAL EXPORT OpenAL
1355         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1356         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1357         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1358         FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
1359         INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1360     export(TARGETS OpenAL
1361         NAMESPACE OpenAL::
1362         FILE OpenALConfig.cmake)
1363     install(EXPORT OpenAL
1364         DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1365         NAMESPACE OpenAL::
1366         FILE OpenALConfig.cmake)
1367     install(DIRECTORY include/AL
1368         DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1369     install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1370         DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1371     if(TARGET soft_oal)
1372         install(TARGETS soft_oal
1373             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1374     endif()
1375     message(STATUS "Installing library and headers")
1376 else()
1377     message(STATUS "NOT installing library and headers")
1378 endif()
1380 if(ALSOFT_INSTALL_CONFIG)
1381     install(FILES alsoftrc.sample
1382         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1383     message(STATUS "Installing sample configuration")
1384 endif()
1386 if(ALSOFT_INSTALL_HRTF_DATA)
1387     install(DIRECTORY hrtf
1388         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1389     message(STATUS "Installing HRTF data files")
1390 endif()
1392 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1393     install(DIRECTORY presets
1394         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1395     message(STATUS "Installing AmbDec presets")
1396 endif()
1397 message(STATUS "")
1399 set(UNICODE_FLAG )
1400 if(MINGW)
1401     set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1402 endif()
1403 set(EXTRA_INSTALLS )
1404 if(ALSOFT_UTILS)
1405     add_executable(openal-info utils/openal-info.c)
1406     target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1407     target_compile_options(openal-info PRIVATE ${C_FLAGS})
1408     target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
1409     if(ALSOFT_INSTALL_EXAMPLES)
1410         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
1411     endif()
1413     find_package(MySOFA)
1414     if(MYSOFA_FOUND)
1415         set(SOFA_SUPPORT_SRCS
1416             utils/sofa-support.cpp
1417             utils/sofa-support.h)
1418         add_library(sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
1419         target_compile_definitions(sofa-support PRIVATE ${CPP_DEFS})
1420         target_include_directories(sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
1421         target_compile_options(sofa-support PRIVATE ${C_FLAGS})
1422         target_link_libraries(sofa-support PUBLIC common MySOFA::MySOFA PRIVATE ${LINKER_FLAGS})
1424         set(MAKEMHR_SRCS
1425             utils/makemhr/loaddef.cpp
1426             utils/makemhr/loaddef.h
1427             utils/makemhr/loadsofa.cpp
1428             utils/makemhr/loadsofa.h
1429             utils/makemhr/makemhr.cpp
1430             utils/makemhr/makemhr.h)
1431         if(NOT HAVE_GETOPT)
1432             set(MAKEMHR_SRCS  ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1433         endif()
1434         add_executable(makemhr ${MAKEMHR_SRCS})
1435         target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1436         target_include_directories(makemhr
1437             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
1438         target_compile_options(makemhr PRIVATE ${C_FLAGS})
1439         target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1440         if(ALSOFT_INSTALL_EXAMPLES)
1441             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
1442         endif()
1444         set(SOFAINFO_SRCS  utils/sofa-info.cpp)
1445         add_executable(sofa-info ${SOFAINFO_SRCS})
1446         target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1447         target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
1448         target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1449         target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1450     endif()
1451     message(STATUS "Building utility programs")
1453     if(NOT ALSOFT_NO_CONFIG_UTIL)
1454         add_subdirectory(utils/alsoft-config)
1455     endif()
1456     message(STATUS "")
1457 endif()
1460 # Add a static library with common functions used by multiple example targets
1461 add_library(ex-common STATIC EXCLUDE_FROM_ALL
1462     examples/common/alhelpers.c
1463     examples/common/alhelpers.h)
1464 target_compile_definitions(ex-common PUBLIC ${CPP_DEFS})
1465 target_include_directories(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
1466 target_compile_options(ex-common PUBLIC ${C_FLAGS})
1467 target_link_libraries(ex-common PUBLIC OpenAL PRIVATE ${RT_LIB})
1469 if(ALSOFT_EXAMPLES)
1470     add_executable(altonegen examples/altonegen.c)
1471     target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common ${UNICODE_FLAG})
1473     add_executable(alrecord examples/alrecord.c)
1474     target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} ex-common ${UNICODE_FLAG})
1476     if(ALSOFT_INSTALL_EXAMPLES)
1477         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord)
1478     endif()
1480     message(STATUS "Building example programs")
1482     if(SNDFILE_FOUND)
1483         add_executable(alplay examples/alplay.c)
1484         target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1485             ${UNICODE_FLAG})
1487         add_executable(alstream examples/alstream.c)
1488         target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1489             ${UNICODE_FLAG})
1491         add_executable(alreverb examples/alreverb.c)
1492         target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1493             ${UNICODE_FLAG})
1495         add_executable(almultireverb examples/almultireverb.c)
1496         target_link_libraries(almultireverb
1497             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1499         add_executable(allatency examples/allatency.c)
1500         target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1501             ${UNICODE_FLAG})
1503         add_executable(alhrtf examples/alhrtf.c)
1504         target_link_libraries(alhrtf
1505             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1507         add_executable(alstreamcb examples/alstreamcb.cpp)
1508         target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1509             ${UNICODE_FLAG})
1511         if(ALSOFT_INSTALL_EXAMPLES)
1512             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1513                 alhrtf)
1514         endif()
1516         message(STATUS "Building SndFile example programs")
1517     endif()
1519     if(SDL2_FOUND)
1520         add_executable(alloopback examples/alloopback.c)
1521         target_include_directories(alloopback PRIVATE ${SDL2_INCLUDE_DIR})
1522         target_link_libraries(alloopback
1523             PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ex-common ${MATH_LIB})
1525         if(ALSOFT_INSTALL_EXAMPLES)
1526             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
1527         endif()
1529         message(STATUS "Building SDL example programs")
1531         set(FFVER_OK FALSE)
1532         if(FFMPEG_FOUND)
1533             set(FFVER_OK TRUE)
1534             if(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1535                 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1536                 set(FFVER_OK FALSE)
1537             endif()
1538             if(AVCODEC_VERSION VERSION_LESS "57.64.101")
1539                 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1540                 set(FFVER_OK FALSE)
1541             endif()
1542             if(AVUTIL_VERSION VERSION_LESS "55.34.101")
1543                 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1544                 set(FFVER_OK FALSE)
1545             endif()
1546             if(SWSCALE_VERSION VERSION_LESS "4.2.100")
1547                 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1548                 set(FFVER_OK FALSE)
1549             endif()
1550             if(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1551                 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1552                 set(FFVER_OK FALSE)
1553             endif()
1554         endif()
1555         if(FFVER_OK)
1556             add_executable(alffplay examples/alffplay.cpp)
1557             target_include_directories(alffplay
1558                 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1559             target_link_libraries(alffplay
1560                 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common)
1562             if(ALSOFT_INSTALL_EXAMPLES)
1563                 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
1564             endif()
1565             message(STATUS "Building SDL+FFmpeg example programs")
1566         endif()
1567     endif()
1568     message(STATUS "")
1569 endif()
1571 if(EXTRA_INSTALLS)
1572     install(TARGETS ${EXTRA_INSTALLS}
1573         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1574         BUNDLE  DESTINATION ${CMAKE_INSTALL_BINDIR}
1575         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1576         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1577 endif()