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