Accumulate delays as samples before calculating nanoseconds
[openal-soft.git] / CMakeLists.txt
blob7d09547c33247832019b94d1e00d82a8673fcd55
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 check_cxx_source_compiles("int *__restrict foo;
173 int main() { return 0; }" HAVE___RESTRICT)
174 if(HAVE___RESTRICT)
175     set(CPP_DEFS ${CPP_DEFS} RESTRICT=__restrict)
176 else()
177     set(CPP_DEFS ${CPP_DEFS} "RESTRICT=")
178 endif()
180 # Some systems may need libatomic for atomic functions to work
181 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
182 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
183 check_cxx_source_compiles("#include <atomic>
184 std::atomic<int> foo{0};
185 int main() { return foo.fetch_add(2); }"
186 HAVE_LIBATOMIC)
187 if(NOT HAVE_LIBATOMIC)
188     set(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
189 else()
190     set(EXTRA_LIBS atomic ${EXTRA_LIBS})
191 endif()
192 unset(OLD_REQUIRED_LIBRARIES)
194 # Include liblog for Android logging
195 check_library_exists(log __android_log_print "" HAVE_LIBLOG)
196 if(HAVE_LIBLOG)
197     set(EXTRA_LIBS log ${EXTRA_LIBS})
198     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
199 endif()
201 if(MSVC)
202     set(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS NOMINMAX)
203     check_cxx_compiler_flag(/permissive- HAVE_PERMISSIVE_SWITCH)
204     if(HAVE_PERMISSIVE_SWITCH)
205         set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
206     endif()
207     set(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4268 /wd4324 /wd5030)
209     if(NOT DXSDK_DIR)
210         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
211     else()
212         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
213     endif()
214     if(DXSDK_DIR)
215         message(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
216     endif()
218     option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
219     if(FORCE_STATIC_VCRT)
220         foreach(flag_var
221                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
222                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
223                 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
224                 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
225             if(${flag_var} MATCHES "/MD")
226                 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
227             endif()
228         endforeach(flag_var)
229     endif()
230 else()
231     set(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
232         -Wpedantic
233         $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
235     if(ALSOFT_WERROR)
236         set(C_FLAGS ${C_FLAGS} -Werror)
237     endif()
239     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
240     # instead of NDEBUG)
241     foreach(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
242         if(${flag_var} MATCHES "-DNDEBUG")
243             string(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
244         endif()
245     endforeach()
247     check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
248     if(HAVE_FNO_MATH_ERRNO)
249         set(C_FLAGS ${C_FLAGS} -fno-math-errno)
250     endif()
252     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
253     if(ALSOFT_STATIC_LIBGCC)
254         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
255         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
256         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
257         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
258         unset(OLD_REQUIRED_LIBRARIES)
260         if(NOT HAVE_STATIC_LIBGCC_SWITCH)
261             message(FATAL_ERROR "Cannot static link libgcc")
262         endif()
263         set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
264     endif()
266     option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
267     if(ALSOFT_STATIC_STDCXX)
268         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
269         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
270         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
271         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
272         unset(OLD_REQUIRED_LIBRARIES)
274         if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
275             message(FATAL_ERROR "Cannot static link libstdc++")
276         endif()
277         set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
278     endif()
280     if(WIN32)
281         option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
282         if(ALSOFT_STATIC_WINPTHREAD)
283             set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
284             set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
285             check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
286             set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
287             unset(OLD_REQUIRED_LIBRARIES)
289             if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
290                 message(FATAL_ERROR "Cannot static link libwinpthread")
291             endif()
292             set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
293         endif()
294     endif()
295 endif()
297 # Set visibility/export options if available
298 if(WIN32)
299     if(NOT LIBTYPE STREQUAL "STATIC")
300         set(EXPORT_DECL "__declspec(dllexport)")
301     endif()
302 else()
303     set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
304     # Yes GCC, really don't accept visibility modes you don't support
305     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
307     check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
308                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
309     if(HAVE_GCC_PROTECTED_VISIBILITY)
310         if(NOT LIBTYPE STREQUAL "STATIC")
311             set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
312         endif()
313     else()
314         check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
315                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
316         if(HAVE_GCC_DEFAULT_VISIBILITY)
317             if(NOT LIBTYPE STREQUAL "STATIC")
318                 set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
319             endif()
320         endif()
321     endif()
323     if(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
324         check_c_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
325         if(HAVE_VISIBILITY_HIDDEN_SWITCH)
326             set(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
327         endif()
328     endif()
330     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
331 endif()
334 set(SSE2_SWITCH "")
335 set(SSE3_SWITCH "")
336 set(SSE4_1_SWITCH "")
337 set(FPU_NEON_SWITCH "")
339 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
340 if(NOT MSVC)
341     # Yes GCC, really don't accept command line options you don't support
342     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
343 endif()
344 check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
345 if(HAVE_MSSE2_SWITCH)
346     set(SSE2_SWITCH "-msse2")
347     check_c_compiler_flag(-msse3 HAVE_MSSE3_SWITCH)
348     if(HAVE_MSSE3_SWITCH)
349         set(SSE3_SWITCH "-msse3")
350         check_c_compiler_flag(-msse4.1 HAVE_MSSE4_1_SWITCH)
351         if(HAVE_MSSE4_1_SWITCH)
352             set(SSE4_1_SWITCH "-msse4.1")
353         endif()
354     endif()
355 endif()
356 check_c_compiler_flag(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
357 if(HAVE_MFPU_NEON_SWITCH)
358     set(FPU_NEON_SWITCH "-mfpu=neon")
359 endif()
360 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
361 unset(OLD_REQUIRED_FLAGS)
363 check_include_file(xmmintrin.h HAVE_XMMINTRIN_H ${SSE2_SWITCH})
364 check_include_file(emmintrin.h HAVE_EMMINTRIN_H ${SSE2_SWITCH})
365 check_include_file(pmmintrin.h HAVE_PMMINTRIN_H ${SSE3_SWITCH})
366 check_include_file(smmintrin.h HAVE_SMMINTRIN_H ${SSE4_1_SWITCH})
367 check_include_file(arm_neon.h HAVE_ARM_NEON_H ${FPU_NEON_SWITCH})
369 set(SSE_FLAGS )
370 set(FPMATH_SET "0")
371 if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND (SSE2_SWITCH OR MSVC))
372     option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
373     if(ALSOFT_ENABLE_SSE2_CODEGEN)
374         if(SSE2_SWITCH)
375             check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
376             if(HAVE_MFPMATH_SSE_2)
377                 set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
378                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
379                 set(FPMATH_SET 2)
380             endif()
381             # SSE depends on a 16-byte aligned stack, and by default, GCC
382             # assumes the stack is suitably aligned. Older Linux code or other
383             # OSs don't guarantee this on 32-bit, so externally-callable
384             # functions need to ensure an aligned stack.
385             set(EXPORT_DECL "${EXPORT_DECL} __attribute__((force_align_arg_pointer))")
386         elseif(MSVC)
387             check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
388             if(HAVE_ARCH_SSE2)
389                 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
390                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
391                 set(FPMATH_SET 2)
392             endif()
393         endif()
394     endif()
395 endif()
397 if(HAVE_EMMINTRIN_H)
398     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
399     foreach(flag_var ${SSE_FLAGS})
400         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
401     endforeach()
403     check_c_source_compiles("#include <emmintrin.h>
404                              int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
406     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
407 endif()
410 check_include_file(malloc.h HAVE_MALLOC_H)
411 check_include_file(cpuid.h HAVE_CPUID_H)
412 check_include_file(intrin.h HAVE_INTRIN_H)
413 check_include_file(guiddef.h HAVE_GUIDDEF_H)
414 if(NOT HAVE_GUIDDEF_H)
415     check_include_file(initguid.h HAVE_INITGUID_H)
416 endif()
418 # Some systems need libm for some math functions to work
419 set(MATH_LIB )
420 check_library_exists(m pow "" HAVE_LIBM)
421 if(HAVE_LIBM)
422     set(MATH_LIB ${MATH_LIB} m)
423     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
424 endif()
426 # Some systems need to link with -lrt for clock_gettime as used by the common
427 # eaxmple functions.
428 set(RT_LIB )
429 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
430 if(HAVE_LIBRT)
431     set(RT_LIB rt)
432 endif()
434 # Check for the dlopen API (for dynamicly loading backend libs)
435 if(ALSOFT_DLOPEN)
436     check_include_file(dlfcn.h HAVE_DLFCN_H)
437     check_library_exists(dl dlopen "" HAVE_LIBDL)
438     if(HAVE_LIBDL)
439         set(EXTRA_LIBS dl ${EXTRA_LIBS})
440         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
441     endif()
442 endif()
444 # Check for a cpuid intrinsic
445 if(HAVE_CPUID_H)
446     check_c_source_compiles("#include <cpuid.h>
447         int main()
448         {
449             unsigned int eax, ebx, ecx, edx;
450             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
451         }" HAVE_GCC_GET_CPUID)
452 endif()
453 if(HAVE_INTRIN_H)
454     check_c_source_compiles("#include <intrin.h>
455         int main()
456         {
457             int regs[4];
458             __cpuid(regs, 0);
459             return regs[0];
460         }" HAVE_CPUID_INTRINSIC)
461 endif()
463 check_cxx_source_compiles("#include <cstdlib>
464 int main()
466     void *ptr{std::aligned_alloc(alignof(int), sizeof(int))};
467     std::free(ptr);
468     return 0;
469 }" HAVE_STD_ALIGNED_ALLOC)
470 check_symbol_exists(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
471 check_symbol_exists(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
472 check_symbol_exists(proc_pidpath     libproc.h HAVE_PROC_PIDPATH)
474 if(NOT WIN32)
475     # We need pthreads outside of Windows, for semaphores. It's also used to
476     # set the priority and name of threads, when possible.
477     check_include_file(pthread.h HAVE_PTHREAD_H)
478     if(NOT HAVE_PTHREAD_H)
479         message(FATAL_ERROR "PThreads is required for non-Windows builds!")
480     endif()
482     check_c_compiler_flag(-pthread HAVE_PTHREAD)
483     if(HAVE_PTHREAD)
484         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
485         set(C_FLAGS ${C_FLAGS} -pthread)
486         set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
487     endif()
489     check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
491     # Some systems need pthread_np.h to get pthread_setname_np
492     check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
493     if(HAVE_PTHREAD_NP_H)
494         check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
495         if(NOT HAVE_PTHREAD_SETNAME_NP)
496             check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
497         else()
498             check_c_source_compiles("
499 #include <pthread.h>
500 #include <pthread_np.h>
501 int main()
503     pthread_setname_np(\"testname\");
504     return 0;
506                 PTHREAD_SETNAME_NP_ONE_PARAM
507             )
508             check_c_source_compiles("
509 #include <pthread.h>
510 #include <pthread_np.h>
511 int main()
513     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
514     return 0;
516                 PTHREAD_SETNAME_NP_THREE_PARAMS
517             )
518         endif()
519     else()
520         check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
521         if(NOT HAVE_PTHREAD_SETNAME_NP)
522             check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
523         else()
524             check_c_source_compiles("
525 #include <pthread.h>
526 int main()
528     pthread_setname_np(\"testname\");
529     return 0;
531                 PTHREAD_SETNAME_NP_ONE_PARAM
532             )
533             check_c_source_compiles("
534 #include <pthread.h>
535 int main()
537     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
538     return 0;
540                 PTHREAD_SETNAME_NP_THREE_PARAMS
541             )
542         endif()
543     endif()
544 endif()
546 check_symbol_exists(getopt unistd.h HAVE_GETOPT)
549 # Common sources used by both the OpenAL implementation library and potentially
550 # the OpenAL router.
551 set(COMMON_OBJS
552     common/albyte.h
553     common/alcomplex.cpp
554     common/alcomplex.h
555     common/alexcpt.cpp
556     common/alexcpt.h
557     common/alfstream.cpp
558     common/alfstream.h
559     common/almalloc.cpp
560     common/almalloc.h
561     common/alnumeric.h
562     common/aloptional.h
563     common/alspan.h
564     common/alstring.cpp
565     common/alstring.h
566     common/atomic.h
567     common/dynload.cpp
568     common/dynload.h
569     common/endiantest.h
570     common/intrusive_ptr.h
571     common/math_defs.h
572     common/opthelpers.h
573     common/polyphase_resampler.cpp
574     common/polyphase_resampler.h
575     common/pragmadefs.h
576     common/strutils.cpp
577     common/strutils.h
578     common/threads.cpp
579     common/threads.h
580     common/vecmat.h
581     common/vector.h
583 set(OPENAL_OBJS
584     al/auxeffectslot.cpp
585     al/auxeffectslot.h
586     al/buffer.cpp
587     al/buffer.h
588     al/effect.cpp
589     al/effect.h
590     al/error.cpp
591     al/event.cpp
592     al/event.h
593     al/extension.cpp
594     al/filter.cpp
595     al/filter.h
596     al/listener.cpp
597     al/listener.h
598     al/source.cpp
599     al/source.h
600     al/state.cpp
602 set(ALC_OBJS
603     alc/alc.cpp
604     alc/alcmain.h
605     alc/alu.cpp
606     alc/alu.h
607     alc/alconfig.cpp
608     alc/alconfig.h
609     alc/alcontext.h
610     alc/ambdec.cpp
611     alc/ambdec.h
612     alc/ambidefs.h
613     alc/bformatdec.cpp
614     alc/bformatdec.h
615     alc/bs2b.cpp
616     alc/bs2b.h
617     alc/bsinc_defs.h
618     alc/bsinc_tables.cpp
619     alc/bsinc_tables.h
620     alc/bufferline.h
621     alc/buffer_storage.cpp
622     alc/buffer_storage.h
623     alc/compat.h
624     alc/converter.cpp
625     alc/converter.h
626     alc/cpu_caps.cpp
627     alc/cpu_caps.h
628     alc/devformat.h
629     alc/effects/base.h
630     alc/effects/autowah.cpp
631     alc/effects/chorus.cpp
632     alc/effects/compressor.cpp
633     alc/effects/convolution.cpp
634     alc/effects/dedicated.cpp
635     alc/effects/distortion.cpp
636     alc/effects/echo.cpp
637     alc/effects/equalizer.cpp
638     alc/effects/fshifter.cpp
639     alc/effects/modulator.cpp
640     alc/effects/null.cpp
641     alc/effects/pshifter.cpp
642     alc/effects/reverb.cpp
643     alc/effects/vmorpher.cpp
644     alc/filters/biquad.h
645     alc/filters/biquad.cpp
646     alc/filters/nfc.cpp
647     alc/filters/nfc.h
648     alc/filters/splitter.cpp
649     alc/filters/splitter.h
650     alc/fmt_traits.cpp
651     alc/fmt_traits.h
652     alc/fpu_ctrl.cpp
653     alc/fpu_ctrl.h
654     alc/front_stablizer.h
655     alc/helpers.cpp
656     alc/hrtf.cpp
657     alc/hrtf.h
658     alc/inprogext.h
659     alc/logging.h
660     alc/mastering.cpp
661     alc/mastering.h
662     alc/panning.cpp
663     alc/ringbuffer.cpp
664     alc/ringbuffer.h
665     alc/uhjfilter.cpp
666     alc/uhjfilter.h
667     alc/uiddefs.cpp
668     alc/voice.cpp
669     alc/voice.h
670     alc/mixer/defs.h
671     alc/mixer/hrtfbase.h
672     alc/mixer/mixer_c.cpp
676 set(CPU_EXTS "Default")
677 set(HAVE_SSE        0)
678 set(HAVE_SSE2       0)
679 set(HAVE_SSE3       0)
680 set(HAVE_SSE4_1     0)
681 set(HAVE_NEON       0)
683 # Check for SSE+SSE2 support
684 option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
685 option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
686 if(HAVE_XMMINTRIN_H AND HAVE_EMMINTRIN_H)
687     option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
688     option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
689     if(ALSOFT_CPUEXT_SSE AND ALSOFT_CPUEXT_SSE2)
690         set(HAVE_SSE 1)
691         set(HAVE_SSE2 1)
692         set(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse.cpp alc/mixer/mixer_sse2.cpp)
693         if(SSE2_SWITCH)
694             set_source_files_properties(alc/mixer/mixer_sse.cpp alc/mixer/mixer_sse2.cpp
695                 PROPERTIES COMPILE_FLAGS "${SSE2_SWITCH}")
696         endif()
697         set(CPU_EXTS "${CPU_EXTS}, SSE, SSE2")
698     endif()
699 endif()
700 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
701     message(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
702 endif()
703 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
704     message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
705 endif()
707 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
708 if(HAVE_EMMINTRIN_H)
709     option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
710     if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
711         set(HAVE_SSE3 1)
712         set(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse3.cpp)
713         if(SSE2_SWITCH)
714             set_source_files_properties(alc/mixer/mixer_sse3.cpp PROPERTIES
715                 COMPILE_FLAGS "${SSE3_SWITCH}")
716         endif()
717         set(CPU_EXTS "${CPU_EXTS}, SSE3")
718     endif()
719 endif()
720 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
721     message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
722 endif()
724 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
725 if(HAVE_SMMINTRIN_H)
726     option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
727     if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
728         set(HAVE_SSE4_1 1)
729         set(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse41.cpp)
730         if(SSE4_1_SWITCH)
731             set_source_files_properties(alc/mixer/mixer_sse41.cpp PROPERTIES
732                 COMPILE_FLAGS "${SSE4_1_SWITCH}")
733         endif()
734         set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
735     endif()
736 endif()
737 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
738     message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
739 endif()
741 # Check for ARM Neon support
742 option(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
743 if(HAVE_ARM_NEON_H)
744     option(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
745     if(ALSOFT_CPUEXT_NEON)
746         set(HAVE_NEON 1)
747         set(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_neon.cpp)
748         if(FPU_NEON_SWITCH)
749             set_source_files_properties(alc/mixer/mixer_neon.cpp PROPERTIES
750                 COMPILE_FLAGS "${FPU_NEON_SWITCH}")
751         endif()
752         set(CPU_EXTS "${CPU_EXTS}, Neon")
753     endif()
754 endif()
755 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
756     message(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
757 endif()
760 set(HAVE_ALSA       0)
761 set(HAVE_OSS        0)
762 set(HAVE_SOLARIS    0)
763 set(HAVE_SNDIO      0)
764 set(HAVE_DSOUND     0)
765 set(HAVE_WASAPI     0)
766 set(HAVE_WINMM      0)
767 set(HAVE_PORTAUDIO  0)
768 set(HAVE_PULSEAUDIO 0)
769 set(HAVE_COREAUDIO  0)
770 set(HAVE_OPENSL     0)
771 set(HAVE_OBOE       0)
772 set(HAVE_WAVE       0)
773 set(HAVE_SDL2       0)
775 if(WIN32 OR HAVE_DLFCN_H)
776     set(IS_LINKED "")
777     macro(ADD_BACKEND_LIBS _LIBS)
778     endmacro()
779 else()
780     set(IS_LINKED " (linked)")
781     macro(ADD_BACKEND_LIBS _LIBS)
782         set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
783     endmacro()
784 endif()
786 set(BACKENDS "")
787 set(ALC_OBJS  ${ALC_OBJS}
788     alc/backends/base.cpp
789     alc/backends/base.h
790     # Default backends, always available
791     alc/backends/loopback.cpp
792     alc/backends/loopback.h
793     alc/backends/null.cpp
794     alc/backends/null.h
797 # Check ALSA backend
798 option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
799 find_package(ALSA)
800 if(ALSA_FOUND)
801     option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
802     if(ALSOFT_BACKEND_ALSA)
803         set(HAVE_ALSA 1)
804         set(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
805         set(ALC_OBJS  ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
806         add_backend_libs(${ALSA_LIBRARIES})
807         set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
808     endif()
809 endif()
810 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
811     message(FATAL_ERROR "Failed to enabled required ALSA backend")
812 endif()
814 # Check OSS backend
815 option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
816 find_package(OSS)
817 if(OSS_FOUND)
818     option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
819     if(ALSOFT_BACKEND_OSS)
820         set(HAVE_OSS 1)
821         set(BACKENDS  "${BACKENDS} OSS,")
822         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
823         if(OSS_LIBRARIES)
824             set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
825         endif()
826         set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
827     endif()
828 endif()
829 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
830     message(FATAL_ERROR "Failed to enabled required OSS backend")
831 endif()
833 # Check Solaris backend
834 option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
835 find_package(AudioIO)
836 if(AUDIOIO_FOUND)
837     option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
838     if(ALSOFT_BACKEND_SOLARIS)
839         set(HAVE_SOLARIS 1)
840         set(BACKENDS  "${BACKENDS} Solaris,")
841         set(ALC_OBJS  ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
842         set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
843     endif()
844 endif()
845 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
846     message(FATAL_ERROR "Failed to enabled required Solaris backend")
847 endif()
849 # Check SndIO backend
850 option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
851 find_package(SoundIO)
852 if(SOUNDIO_FOUND)
853     option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
854     if(ALSOFT_BACKEND_SNDIO)
855         set(HAVE_SNDIO 1)
856         set(BACKENDS  "${BACKENDS} SndIO (linked),")
857         set(ALC_OBJS  ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
858         set(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
859         set(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
860     endif()
861 endif()
862 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
863     message(FATAL_ERROR "Failed to enabled required SndIO backend")
864 endif()
866 # Check Windows-only backends
867 option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
868 option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
869 option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
870 if(WIN32)
871     set(WINSDK_LIB_DIRS )
872     set(WINSDK_INCLUDE_DIRS )
873     find_package(WindowsSDK)
874     if(WINDOWSSDK_FOUND)
875         get_windowssdk_library_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_LIB_DIRS)
876         get_windowssdk_include_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_INCLUDE_DIRS)
877     endif()
879     # Check MMSystem backend
880     check_include_files("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
881     find_library(WINMM_LIBRARY NAMES winmm
882         PATHS ${WINSDK_LIB_DIRS})
883     if(HAVE_MMSYSTEM_H AND WINMM_LIBRARY)
884         option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
885         if(ALSOFT_BACKEND_WINMM)
886             set(HAVE_WINMM 1)
887             set(BACKENDS  "${BACKENDS} WinMM,")
888             set(ALC_OBJS  ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
889             set(EXTRA_LIBS ${WINMM_LIBRARY} ${EXTRA_LIBS})
890         endif()
891     endif()
893     # Check DSound backend
894     find_package(DSound)
895     if(DSOUND_FOUND)
896         option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
897         if(ALSOFT_BACKEND_DSOUND)
898             set(HAVE_DSOUND 1)
899             set(BACKENDS  "${BACKENDS} DirectSound${IS_LINKED},")
900             set(ALC_OBJS  ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
901             add_backend_libs(${DSOUND_LIBRARIES})
902             set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIRS})
903         endif()
904     endif()
906     # Check for WASAPI backend
907     check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
908     if(HAVE_MMDEVICEAPI_H)
909         option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
910         if(ALSOFT_BACKEND_WASAPI)
911             set(HAVE_WASAPI 1)
912             set(BACKENDS  "${BACKENDS} WASAPI,")
913             set(ALC_OBJS  ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
914         endif()
915     endif()
916 endif()
917 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
918     message(FATAL_ERROR "Failed to enabled required WinMM backend")
919 endif()
920 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
921     message(FATAL_ERROR "Failed to enabled required DSound backend")
922 endif()
923 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
924     message(FATAL_ERROR "Failed to enabled required WASAPI backend")
925 endif()
927 # Check PortAudio backend
928 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
929 find_package(PortAudio)
930 if(PORTAUDIO_FOUND)
931     option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
932     if(ALSOFT_BACKEND_PORTAUDIO)
933         set(HAVE_PORTAUDIO 1)
934         set(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
935         set(ALC_OBJS  ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
936         add_backend_libs(${PORTAUDIO_LIBRARIES})
937         set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
938     endif()
939 endif()
940 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
941     message(FATAL_ERROR "Failed to enabled required PortAudio backend")
942 endif()
944 # Check PulseAudio backend
945 option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
946 find_package(PulseAudio)
947 if(PULSEAUDIO_FOUND)
948     option(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
949     if(ALSOFT_BACKEND_PULSEAUDIO)
950         set(HAVE_PULSEAUDIO 1)
951         set(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
952         set(ALC_OBJS  ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
953         add_backend_libs(${PULSEAUDIO_LIBRARIES})
954         set(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
955     endif()
956 endif()
957 if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
958     message(FATAL_ERROR "Failed to enabled required PulseAudio backend")
959 endif()
961 # Check JACK backend
962 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
963 find_package(JACK)
964 if(JACK_FOUND)
965     option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
966     if(ALSOFT_BACKEND_JACK)
967         set(HAVE_JACK 1)
968         set(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
969         set(ALC_OBJS  ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
970         add_backend_libs(${JACK_LIBRARIES})
971         set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
972     endif()
973 endif()
974 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
975     message(FATAL_ERROR "Failed to enabled required JACK backend")
976 endif()
978 # Check CoreAudio backend
979 option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
980 find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
981 find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
982 if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
983     option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
984     if(ALSOFT_BACKEND_COREAUDIO)
985         set(HAVE_COREAUDIO 1)
986         set(ALC_OBJS  ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
987         set(BACKENDS  "${BACKENDS} CoreAudio,")
988         if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
989             find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
990             set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${COREFOUNDATION_FRAMEWORK} ${EXTRA_LIBS})
991         else()
992             set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} /System/Library/Frameworks/AudioUnit.framework
993                 /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
994         endif()
996         # Some versions of OSX may need the AudioToolbox framework. Add it if
997         # it's found.
998         find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
999         if(AUDIOTOOLBOX_LIBRARY)
1000             set(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1001         endif()
1003         set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
1004     endif()
1005 endif()
1006 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1007     message(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1008 endif()
1010 # Check for OpenSL (Android) backend
1011 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1012 find_package(OpenSL)
1013 if(OPENSL_FOUND)
1014     option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1015     if(ALSOFT_BACKEND_OPENSL)
1016         set(HAVE_OPENSL 1)
1017         set(ALC_OBJS  ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1018         set(BACKENDS  "${BACKENDS} OpenSL,")
1019         set(EXTRA_LIBS ${OPENSL_LIBRARIES} ${EXTRA_LIBS})
1020         set(INC_PATHS ${INC_PATHS} ${OPENSL_INCLUDE_DIRS})
1021     endif()
1022 endif()
1023 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1024     message(FATAL_ERROR "Failed to enabled required OpenSL backend")
1025 endif()
1027 # Check for Oboe (Android) backend
1028 set(OBOE_TARGET )
1029 if(ANDROID)
1030     set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1031     if(OBOE_SOURCE)
1032         # Force Oboe to build with hidden symbols. Don't want to be exporting
1033         # them from OpenAL.
1034         set(OLD_CXX_FLAGS ${CMAKE_CXX_FLAGS})
1035         check_cxx_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
1036         if(HAVE_VISIBILITY_HIDDEN_SWITCH)
1037             set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
1038         endif()
1039         add_subdirectory(${OBOE_SOURCE} ./oboe)
1040         set(CMAKE_CXX_FLAGS ${OLD_CXX_FLAGS})
1041         unset(OLD_CXX_FLAGS)
1043         set(OBOE_TARGET oboe)
1044     else()
1045         find_package(Oboe)
1046         if(OBOE_FOUND)
1047             set(OBOE_TARGET "oboe::oboe")
1048         endif()
1049     endif()
1050 endif()
1052 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1053 if(OBOE_TARGET)
1054     option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1055     if(ALSOFT_BACKEND_OBOE)
1056         set(HAVE_OBOE 1)
1057         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
1058         set(BACKENDS  "${BACKENDS} Oboe,")
1059         set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
1060     endif()
1061 endif()
1062 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1063     message(FATAL_ERROR "Failed to enabled required Oboe backend")
1064 endif()
1066 # Check for SDL2 backend
1067 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1068 find_package(SDL2)
1069 if(SDL2_FOUND)
1070     # Off by default, since it adds a runtime dependency
1071     option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1072     if(ALSOFT_BACKEND_SDL2)
1073         set(HAVE_SDL2 1)
1074         set(ALC_OBJS  ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1075         set(BACKENDS  "${BACKENDS} SDL2,")
1076         set(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
1077         set(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
1078     endif()
1079 endif()
1080 if(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1081     message(FATAL_ERROR "Failed to enabled required SDL2 backend")
1082 endif()
1084 # Optionally enable the Wave Writer backend
1085 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1086 if(ALSOFT_BACKEND_WAVE)
1087     set(HAVE_WAVE 1)
1088     set(ALC_OBJS  ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1089     set(BACKENDS  "${BACKENDS} WaveFile,")
1090 endif()
1092 # This is always available
1093 set(BACKENDS  "${BACKENDS} Null")
1096 find_package(Git)
1097 if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1098     # Get the current working branch and its latest abbreviated commit hash
1099     add_custom_target(build_version
1100         ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1101             -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1102             -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1103         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1104         VERBATIM
1105     )
1106 else()
1107     set(GIT_BRANCH "UNKNOWN")
1108     set(GIT_COMMIT_HASH "unknown")
1109     configure_file(
1110         "${OpenAL_SOURCE_DIR}/version.h.in"
1111         "${OpenAL_BINARY_DIR}/version.h")
1112 endif()
1115 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1116 if(ALSOFT_EMBED_HRTF_DATA)
1117     macro(make_hrtf_header FILENAME VARNAME)
1118         set(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1119         set(outfile  "${OpenAL_BINARY_DIR}/${VARNAME}.h")
1121         add_custom_command(OUTPUT "${outfile}"
1122             COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
1123                 -D "VARIABLE_NAME=${VARNAME}" -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1124             WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1125             DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1126             VERBATIM
1127         )
1128         set(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1129     endmacro()
1131     make_hrtf_header("Default HRTF.mhr" "hrtf_default")
1132 endif()
1135 if(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1136     find_package(Qt5Widgets)
1137 endif()
1138 if(ALSOFT_EXAMPLES)
1139     find_package(SndFile)
1140     find_package(SDL2)
1141     if(SDL2_FOUND)
1142         find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1143     endif()
1144 endif()
1146 if(NOT WIN32)
1147     set(LIBNAME "openal")
1148 else()
1149     set(LIBNAME "OpenAL32")
1150 endif()
1152 # Needed for openal.pc.in
1153 set(prefix ${CMAKE_INSTALL_PREFIX})
1154 set(exec_prefix "\${prefix}")
1155 set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1156 set(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1157 set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1158 set(PACKAGE_VERSION "${LIB_VERSION}")
1159 set(PKG_CONFIG_CFLAGS )
1160 set(PKG_CONFIG_PRIVATE_LIBS )
1161 if(LIBTYPE STREQUAL "STATIC")
1162     set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1163     foreach(FLAG  ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1164         # If this is already a linker flag, or is a full path+file, add it
1165         # as-is. Otherwise, it's a name intended to be dressed as -lname.
1166         if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1167             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1168         else()
1169             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1170         endif()
1171     endforeach()
1172 endif()
1174 # End configuration
1175 configure_file(
1176     "${OpenAL_SOURCE_DIR}/config.h.in"
1177     "${OpenAL_BINARY_DIR}/config.h")
1178 configure_file(
1179     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1180     "${OpenAL_BINARY_DIR}/openal.pc"
1181     @ONLY)
1184 add_library(common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1185 target_include_directories(common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include)
1186 target_compile_definitions(common PRIVATE ${CPP_DEFS})
1187 target_compile_options(common PRIVATE ${C_FLAGS})
1188 set_target_properties(common PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
1191 unset(HAS_ROUTER)
1192 set(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1194 # Build main library
1195 if(LIBTYPE STREQUAL "STATIC")
1196     add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1197     target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
1198     target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1199     if(WIN32)
1200         # This option is for static linking OpenAL Soft into another project
1201         # that already defines the IDs. It is up to that project to ensure all
1202         # required IDs are defined.
1203         option(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
1204         if(ALSOFT_NO_UID_DEFS)
1205             target_compile_definitions(${IMPL_TARGET} PRIVATE AL_NO_UID_DEFS)
1206         endif()
1207     endif()
1208 else()
1209     set(RC_CONFIG resources/openal32.rc)
1210     if(WIN32 AND ALSOFT_BUILD_ROUTER)
1211         add_library(OpenAL SHARED
1212             resources/router.rc
1213             router/router.cpp
1214             router/router.h
1215             router/alc.cpp
1216             router/al.cpp
1217         )
1218         target_compile_definitions(OpenAL
1219             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1220         target_compile_options(OpenAL PRIVATE ${C_FLAGS})
1221         target_link_libraries(OpenAL PRIVATE common ${LINKER_FLAGS})
1222         target_include_directories(OpenAL
1223           PUBLIC
1224             $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1225             $<INSTALL_INTERFACE:include>
1226           PRIVATE
1227             ${OpenAL_SOURCE_DIR}/common
1228             ${OpenAL_BINARY_DIR}
1229         )
1230         set_target_properties(OpenAL PROPERTIES PREFIX "")
1231         set_target_properties(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1232         if(TARGET build_version)
1233             add_dependencies(OpenAL build_version)
1234         endif()
1235         set(HAS_ROUTER 1)
1237         set(LIBNAME "soft_oal")
1238         set(IMPL_TARGET soft_oal)
1239         set(RC_CONFIG resources/soft_oal.rc)
1240     endif()
1242     # !important: for osx framework public header works, the headers must be in
1243     # the project
1244     set(TARGET_PUBLIC_HEADERS include/AL/al.h include/AL/alc.h include/AL/alext.h include/AL/efx.h)
1245     add_library(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${RC_CONFIG}
1246         ${TARGET_PUBLIC_HEADERS})
1247     if(WIN32)
1248         set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
1249     endif()
1250     target_link_libraries(${IMPL_TARGET} PRIVATE common ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1252     if(APPLE AND ALSOFT_OSX_FRAMEWORK)
1253         # Sets framework name to soft_oal to avoid ambiguity with the system OpenAL.framework
1254         set(LIBNAME "soft_oal")
1255         if(GIT_FOUND)
1256             EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list --count head
1257                 TIMEOUT 5
1258                 OUTPUT_VARIABLE BUNDLE_VERSION
1259                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1260         else()
1261             set(BUNDLE_VERSION 1)
1262         endif()
1264         # Build: Fix rpath in iOS shared libraries
1265         # If this flag is not set, the final dylib binary ld path will be
1266         # /User/xxx/*/soft_oal.framework/soft_oal, which can't be loaded by iOS devices.
1267         # See also: https://github.com/libjpeg-turbo/libjpeg-turbo/commit/c80ddef7a4ce21ace9e3ca0fd190d320cc8cdaeb
1268         if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
1269             set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
1270         endif()
1272         set_target_properties(${IMPL_TARGET} PROPERTIES
1273             FRAMEWORK TRUE
1274             FRAMEWORK_VERSION C
1275             MACOSX_FRAMEWORK_NAME "${IMPL_TARGET}"
1276             MACOSX_FRAMEWORK_IDENTIFIER "org.openal-soft.openal"
1277             MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${LIB_VERSION}
1278             MACOSX_FRAMEWORK_BUNDLE_VERSION ${BUNDLE_VERSION}
1279             XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
1280             XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
1281             XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
1282             PUBLIC_HEADER "${TARGET_PUBLIC_HEADERS}"
1283             MACOSX_RPATH TRUE)
1284     endif()
1285 endif()
1287 target_include_directories(${IMPL_TARGET}
1288   PUBLIC
1289     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1290     $<INSTALL_INTERFACE:include>
1291   PRIVATE
1292     ${INC_PATHS}
1293     ${OpenAL_BINARY_DIR}
1294     ${OpenAL_SOURCE_DIR}
1295     ${OpenAL_SOURCE_DIR}/alc
1296     ${OpenAL_SOURCE_DIR}/common
1299 set_target_properties(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1300     VERSION ${LIB_VERSION}
1301     SOVERSION ${LIB_MAJOR_VERSION}
1303 target_compile_definitions(${IMPL_TARGET}
1304     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1305 target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1307 if(TARGET build_version)
1308     add_dependencies(${IMPL_TARGET} build_version)
1309 endif()
1311 if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1312     find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
1313     if(NOT SED_EXECUTABLE OR NOT CMAKE_DLLTOOL)
1314         message(STATUS "")
1315         if(NOT SED_EXECUTABLE)
1316             message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1317         endif()
1318         if(NOT CMAKE_DLLTOOL)
1319             message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1320         endif()
1321     else()
1322         set_property(TARGET OpenAL APPEND_STRING PROPERTY
1323             LINK_FLAGS " -Wl,--output-def,OpenAL32.def")
1324         add_custom_command(TARGET OpenAL POST_BUILD
1325             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1326             COMMAND "${CMAKE_DLLTOOL}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1327             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1328             VERBATIM
1329         )
1330     endif()
1331 endif()
1333 if(HAS_ROUTER)
1334     message(STATUS "")
1335     message(STATUS "Building DLL router")
1336 endif()
1338 message(STATUS "
1339 Building OpenAL with support for the following backends:
1340     ${BACKENDS}
1342 Building with support for CPU extensions:
1343     ${CPU_EXTS}
1345 if(FPMATH_SET)
1346     message(STATUS "Building with SSE${FPMATH_SET} codegen
1348 endif()
1350 if(ALSOFT_EMBED_HRTF_DATA)
1351     message(STATUS "Embedding HRTF datasets
1353 endif()
1355 # Install main library
1356 if(ALSOFT_INSTALL)
1357     install(TARGETS OpenAL EXPORT OpenAL
1358         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1359         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1360         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1361         FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
1362         INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1363     export(TARGETS OpenAL
1364         NAMESPACE OpenAL::
1365         FILE OpenALConfig.cmake)
1366     install(EXPORT OpenAL
1367         DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1368         NAMESPACE OpenAL::
1369         FILE OpenALConfig.cmake)
1370     install(DIRECTORY include/AL
1371         DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1372     install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1373         DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1374     if(TARGET soft_oal)
1375         install(TARGETS soft_oal
1376             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1377     endif()
1378     message(STATUS "Installing library and headers")
1379 else()
1380     message(STATUS "NOT installing library and headers")
1381 endif()
1383 if(ALSOFT_INSTALL_CONFIG)
1384     install(FILES alsoftrc.sample
1385         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1386     message(STATUS "Installing sample configuration")
1387 endif()
1389 if(ALSOFT_INSTALL_HRTF_DATA)
1390     install(DIRECTORY hrtf
1391         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1392     message(STATUS "Installing HRTF data files")
1393 endif()
1395 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1396     install(DIRECTORY presets
1397         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1398     message(STATUS "Installing AmbDec presets")
1399 endif()
1400 message(STATUS "")
1402 set(UNICODE_FLAG )
1403 if(MINGW)
1404     set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1405 endif()
1406 set(EXTRA_INSTALLS )
1407 if(ALSOFT_UTILS)
1408     add_executable(openal-info utils/openal-info.c)
1409     target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1410     target_compile_options(openal-info PRIVATE ${C_FLAGS})
1411     target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
1412     if(ALSOFT_INSTALL_EXAMPLES)
1413         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
1414     endif()
1416     find_package(MySOFA)
1417     if(MYSOFA_FOUND)
1418         set(SOFA_SUPPORT_SRCS
1419             utils/sofa-support.cpp
1420             utils/sofa-support.h)
1421         add_library(sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
1422         target_compile_definitions(sofa-support PRIVATE ${CPP_DEFS})
1423         target_include_directories(sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
1424         target_compile_options(sofa-support PRIVATE ${C_FLAGS})
1425         target_link_libraries(sofa-support PUBLIC common MySOFA::MySOFA PRIVATE ${LINKER_FLAGS})
1427         set(MAKEMHR_SRCS
1428             utils/makemhr/loaddef.cpp
1429             utils/makemhr/loaddef.h
1430             utils/makemhr/loadsofa.cpp
1431             utils/makemhr/loadsofa.h
1432             utils/makemhr/makemhr.cpp
1433             utils/makemhr/makemhr.h)
1434         if(NOT HAVE_GETOPT)
1435             set(MAKEMHR_SRCS  ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1436         endif()
1437         add_executable(makemhr ${MAKEMHR_SRCS})
1438         target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1439         target_include_directories(makemhr
1440             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
1441         target_compile_options(makemhr PRIVATE ${C_FLAGS})
1442         target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1443         if(ALSOFT_INSTALL_EXAMPLES)
1444             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
1445         endif()
1447         set(SOFAINFO_SRCS  utils/sofa-info.cpp)
1448         add_executable(sofa-info ${SOFAINFO_SRCS})
1449         target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1450         target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
1451         target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1452         target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1453     endif()
1454     message(STATUS "Building utility programs")
1456     if(NOT ALSOFT_NO_CONFIG_UTIL)
1457         add_subdirectory(utils/alsoft-config)
1458     endif()
1459     message(STATUS "")
1460 endif()
1463 # Add a static library with common functions used by multiple example targets
1464 add_library(ex-common STATIC EXCLUDE_FROM_ALL
1465     examples/common/alhelpers.c
1466     examples/common/alhelpers.h)
1467 target_compile_definitions(ex-common PUBLIC ${CPP_DEFS})
1468 target_include_directories(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
1469 target_compile_options(ex-common PUBLIC ${C_FLAGS})
1470 target_link_libraries(ex-common PUBLIC OpenAL PRIVATE ${RT_LIB})
1472 if(ALSOFT_EXAMPLES)
1473     add_executable(altonegen examples/altonegen.c)
1474     target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common ${UNICODE_FLAG})
1476     add_executable(alrecord examples/alrecord.c)
1477     target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} ex-common ${UNICODE_FLAG})
1479     if(ALSOFT_INSTALL_EXAMPLES)
1480         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord)
1481     endif()
1483     message(STATUS "Building example programs")
1485     if(SNDFILE_FOUND)
1486         add_executable(alplay examples/alplay.c)
1487         target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1488             ${UNICODE_FLAG})
1490         add_executable(alstream examples/alstream.c)
1491         target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1492             ${UNICODE_FLAG})
1494         add_executable(alreverb examples/alreverb.c)
1495         target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1496             ${UNICODE_FLAG})
1498         add_executable(almultireverb examples/almultireverb.c)
1499         target_link_libraries(almultireverb
1500             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1502         add_executable(allatency examples/allatency.c)
1503         target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1504             ${UNICODE_FLAG})
1506         add_executable(alhrtf examples/alhrtf.c)
1507         target_link_libraries(alhrtf
1508             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1510         add_executable(alstreamcb examples/alstreamcb.cpp)
1511         target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1512             ${UNICODE_FLAG})
1514         add_executable(alconvolve examples/alconvolve.c)
1515         target_link_libraries(alconvolve PRIVATE ${LINKER_FLAGS} common SndFile::SndFile ex-common
1516             ${UNICODE_FLAG})
1518         if(ALSOFT_INSTALL_EXAMPLES)
1519             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1520                 alhrtf)
1521         endif()
1523         message(STATUS "Building SndFile example programs")
1524     endif()
1526     if(SDL2_FOUND)
1527         add_executable(alloopback examples/alloopback.c)
1528         target_include_directories(alloopback PRIVATE ${SDL2_INCLUDE_DIR})
1529         target_link_libraries(alloopback
1530             PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ex-common ${MATH_LIB})
1532         if(ALSOFT_INSTALL_EXAMPLES)
1533             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
1534         endif()
1536         message(STATUS "Building SDL example programs")
1538         set(FFVER_OK FALSE)
1539         if(FFMPEG_FOUND)
1540             set(FFVER_OK TRUE)
1541             if(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1542                 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1543                 set(FFVER_OK FALSE)
1544             endif()
1545             if(AVCODEC_VERSION VERSION_LESS "57.64.101")
1546                 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1547                 set(FFVER_OK FALSE)
1548             endif()
1549             if(AVUTIL_VERSION VERSION_LESS "55.34.101")
1550                 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1551                 set(FFVER_OK FALSE)
1552             endif()
1553             if(SWSCALE_VERSION VERSION_LESS "4.2.100")
1554                 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1555                 set(FFVER_OK FALSE)
1556             endif()
1557             if(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1558                 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1559                 set(FFVER_OK FALSE)
1560             endif()
1561         endif()
1562         if(FFVER_OK)
1563             add_executable(alffplay examples/alffplay.cpp)
1564             target_include_directories(alffplay
1565                 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1566             target_link_libraries(alffplay
1567                 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common)
1569             if(ALSOFT_INSTALL_EXAMPLES)
1570                 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
1571             endif()
1572             message(STATUS "Building SDL+FFmpeg example programs")
1573         endif()
1574     endif()
1575     message(STATUS "")
1576 endif()
1578 if(EXTRA_INSTALLS)
1579     install(TARGETS ${EXTRA_INSTALLS}
1580         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1581         BUNDLE  DESTINATION ${CMAKE_INSTALL_BINDIR}
1582         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1583         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1584 endif()