Simplify handling effect output for spatial effects
[openal-soft.git] / CMakeLists.txt
blobe20770bc2089968c8a9af3932f2b3ea7528bbfc7
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     check_cxx_compiler_flag(-Wno-c++20-attribute-extensions HAVE_WNO_CXX20_ATTR_EXT)
262     if(HAVE_WNO_CXX20_ATTR_EXT)
263         set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:-Wno-c++20-attribute-extensions>)
264     endif()
266     if(ALSOFT_WERROR)
267         set(C_FLAGS ${C_FLAGS} -Werror)
268     endif()
270     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
271     # instead of NDEBUG)
272     foreach(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
273         if(${flag_var} MATCHES "-DNDEBUG")
274             string(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
275         endif()
276     endforeach()
278     check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
279     if(HAVE_FNO_MATH_ERRNO)
280         set(C_FLAGS ${C_FLAGS} -fno-math-errno)
281     endif()
283     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
284     if(ALSOFT_STATIC_LIBGCC)
285         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
286         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
287         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
288         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
289         unset(OLD_REQUIRED_LIBRARIES)
291         if(NOT HAVE_STATIC_LIBGCC_SWITCH)
292             message(FATAL_ERROR "Cannot static link libgcc")
293         endif()
294         set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
295     endif()
297     option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
298     if(ALSOFT_STATIC_STDCXX)
299         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
300         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
301         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
302         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
303         unset(OLD_REQUIRED_LIBRARIES)
305         if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
306             message(FATAL_ERROR "Cannot static link libstdc++")
307         endif()
308         set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
309     endif()
311     if(WIN32)
312         option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
313         if(ALSOFT_STATIC_WINPTHREAD)
314             set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
315             set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
316             check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
317             set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
318             unset(OLD_REQUIRED_LIBRARIES)
320             if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
321                 message(FATAL_ERROR "Cannot static link libwinpthread")
322             endif()
323             set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
324         endif()
325     endif()
326 endif()
328 # Set visibility/export options if available
329 if(WIN32)
330     if(NOT LIBTYPE STREQUAL "STATIC")
331         set(EXPORT_DECL "__declspec(dllexport)")
332     endif()
333 else()
334     set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
335     # Yes GCC, really don't accept visibility modes you don't support
336     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
338     check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
339                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
340     if(HAVE_GCC_PROTECTED_VISIBILITY)
341         if(NOT LIBTYPE STREQUAL "STATIC")
342             set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
343         endif()
344     else()
345         check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
346                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
347         if(HAVE_GCC_DEFAULT_VISIBILITY)
348             if(NOT LIBTYPE STREQUAL "STATIC")
349                 set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
350             endif()
351         endif()
352     endif()
354     if(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
355         check_c_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
356         if(HAVE_VISIBILITY_HIDDEN_SWITCH)
357             set(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
358         endif()
359     endif()
361     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
362 endif()
365 set(SSE2_SWITCH "")
367 if(NOT MSVC)
368     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
369     # Yes GCC, really don't accept command line options you don't support
370     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
371     check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
372     if(HAVE_MSSE2_SWITCH)
373         set(SSE2_SWITCH "-msse2")
374     endif()
375     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
376     unset(OLD_REQUIRED_FLAGS)
377 endif()
379 check_include_file(xmmintrin.h HAVE_XMMINTRIN_H)
380 check_include_file(emmintrin.h HAVE_EMMINTRIN_H)
381 check_include_file(pmmintrin.h HAVE_PMMINTRIN_H)
382 check_include_file(smmintrin.h HAVE_SMMINTRIN_H)
383 check_include_file(arm_neon.h HAVE_ARM_NEON_H)
385 set(HAVE_SSE        0)
386 set(HAVE_SSE2       0)
387 set(HAVE_SSE3       0)
388 set(HAVE_SSE4_1     0)
389 set(HAVE_NEON       0)
391 # Check for SSE support
392 option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
393 if(HAVE_XMMINTRIN_H)
394     option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
395     if(ALSOFT_CPUEXT_SSE)
396         set(HAVE_SSE 1)
397     endif()
398 endif()
399 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
400     message(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
401 endif()
403 option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
404 if(HAVE_EMMINTRIN_H)
405     option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
406     if(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
407         set(HAVE_SSE2 1)
408     endif()
409 endif()
410 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
411     message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
412 endif()
414 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
415 if(HAVE_PMMINTRIN_H)
416     option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
417     if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
418         set(HAVE_SSE3 1)
419     endif()
420 endif()
421 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
422     message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
423 endif()
425 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
426 if(HAVE_SMMINTRIN_H)
427     option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
428     if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
429         set(HAVE_SSE4_1 1)
430     endif()
431 endif()
432 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
433     message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
434 endif()
436 # Check for ARM Neon support
437 option(ALSOFT_REQUIRE_NEON "Require ARM NEON support" OFF)
438 if(HAVE_ARM_NEON_H)
439     option(ALSOFT_CPUEXT_NEON "Enable ARM NEON support" ON)
440     if(ALSOFT_CPUEXT_NEON)
441         check_c_source_compiles("#include <arm_neon.h>
442             int main()
443             {
444                 int32x4_t ret4 = vdupq_n_s32(0);
445                 return vgetq_lane_s32(ret4, 0);
446             }" HAVE_NEON_INTRINSICS)
447         if(HAVE_NEON_INTRINSICS)
448             set(HAVE_NEON 1)
449         endif()
450     endif()
451 endif()
452 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
453     message(FATAL_ERROR "Failed to enabled required ARM NEON CPU extensions")
454 endif()
457 set(SSE_FLAGS )
458 set(FPMATH_SET "0")
459 if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND HAVE_SSE2)
460     option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
461     if(ALSOFT_ENABLE_SSE2_CODEGEN)
462         if(MSVC)
463             check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
464             if(HAVE_ARCH_SSE2)
465                 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
466                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
467                 set(FPMATH_SET 2)
468             endif()
469         elseif(SSE2_SWITCH)
470             check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
471             if(HAVE_MFPMATH_SSE_2)
472                 set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
473                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
474                 set(FPMATH_SET 2)
475             endif()
476             # SSE depends on a 16-byte aligned stack, and by default, GCC
477             # assumes the stack is suitably aligned. Older Linux code or other
478             # OSs don't guarantee this on 32-bit, so externally-callable
479             # functions need to ensure an aligned stack.
480             set(EXPORT_DECL "${EXPORT_DECL}__attribute__((force_align_arg_pointer))")
481         endif()
482     endif()
483 endif()
485 if(HAVE_SSE2)
486     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
487     foreach(flag_var ${SSE_FLAGS})
488         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
489     endforeach()
491     check_c_source_compiles("#include <emmintrin.h>
492         int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
494     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
495 endif()
498 check_include_file(malloc.h HAVE_MALLOC_H)
499 check_include_file(cpuid.h HAVE_CPUID_H)
500 check_include_file(intrin.h HAVE_INTRIN_H)
501 check_include_file(guiddef.h HAVE_GUIDDEF_H)
502 if(NOT HAVE_GUIDDEF_H)
503     check_include_file(initguid.h HAVE_INITGUID_H)
504 endif()
506 # Some systems need libm for some math functions to work
507 set(MATH_LIB )
508 check_library_exists(m pow "" HAVE_LIBM)
509 if(HAVE_LIBM)
510     set(MATH_LIB ${MATH_LIB} m)
511     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
512 endif()
514 # Some systems need to link with -lrt for clock_gettime as used by the common
515 # eaxmple functions.
516 set(RT_LIB )
517 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
518 if(HAVE_LIBRT)
519     set(RT_LIB rt)
520 endif()
522 # Check for the dlopen API (for dynamicly loading backend libs)
523 if(ALSOFT_DLOPEN)
524     check_include_file(dlfcn.h HAVE_DLFCN_H)
525     check_library_exists(dl dlopen "" HAVE_LIBDL)
526     if(HAVE_LIBDL)
527         set(EXTRA_LIBS dl ${EXTRA_LIBS})
528         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
529     endif()
530 endif()
532 # Check for a cpuid intrinsic
533 if(HAVE_CPUID_H)
534     check_c_source_compiles("#include <cpuid.h>
535         int main()
536         {
537             unsigned int eax, ebx, ecx, edx;
538             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
539         }" HAVE_GCC_GET_CPUID)
540 endif()
541 if(HAVE_INTRIN_H)
542     check_c_source_compiles("#include <intrin.h>
543         int main()
544         {
545             int regs[4];
546             __cpuid(regs, 0);
547             return regs[0];
548         }" HAVE_CPUID_INTRINSIC)
549 endif()
551 check_symbol_exists(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
552 check_symbol_exists(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
553 check_symbol_exists(proc_pidpath     libproc.h HAVE_PROC_PIDPATH)
555 if(NOT WIN32)
556     # We need pthreads outside of Windows, for semaphores. It's also used to
557     # set the priority and name of threads, when possible.
558     check_include_file(pthread.h HAVE_PTHREAD_H)
559     if(NOT HAVE_PTHREAD_H)
560         message(FATAL_ERROR "PThreads is required for non-Windows builds!")
561     endif()
563     check_c_compiler_flag(-pthread HAVE_PTHREAD)
564     if(HAVE_PTHREAD)
565         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
566         set(C_FLAGS ${C_FLAGS} -pthread)
567         set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
568     endif()
570     check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
572     # Some systems need pthread_np.h to get pthread_setname_np
573     check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
574     if(HAVE_PTHREAD_NP_H)
575         check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
576         if(NOT HAVE_PTHREAD_SETNAME_NP)
577             check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
578         endif()
579     else()
580         check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
581         if(NOT HAVE_PTHREAD_SETNAME_NP)
582             check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
583         endif()
584     endif()
585 endif()
587 check_symbol_exists(getopt unistd.h HAVE_GETOPT)
590 # Common sources used by both the OpenAL implementation library, the OpenAL
591 # router, and certain tools and examples.
592 set(COMMON_OBJS
593     common/albit.h
594     common/albyte.h
595     common/alcomplex.cpp
596     common/alcomplex.h
597     common/aldeque.h
598     common/alfstream.cpp
599     common/alfstream.h
600     common/almalloc.cpp
601     common/almalloc.h
602     common/alnumbers.h
603     common/alnumeric.h
604     common/aloptional.h
605     common/alspan.h
606     common/alstring.cpp
607     common/alstring.h
608     common/atomic.h
609     common/comptr.h
610     common/dynload.cpp
611     common/dynload.h
612     common/intrusive_ptr.h
613     common/opthelpers.h
614     common/phase_shifter.h
615     common/polyphase_resampler.cpp
616     common/polyphase_resampler.h
617     common/pragmadefs.h
618     common/ringbuffer.cpp
619     common/ringbuffer.h
620     common/strutils.cpp
621     common/strutils.h
622     common/threads.cpp
623     common/threads.h
624     common/vecmat.h
625     common/vector.h)
627 # Core library routines
628 set(CORE_OBJS
629     core/ambdec.cpp
630     core/ambdec.h
631     core/ambidefs.cpp
632     core/ambidefs.h
633     core/async_event.h
634     core/bformatdec.cpp
635     core/bformatdec.h
636     core/bs2b.cpp
637     core/bs2b.h
638     core/bsinc_defs.h
639     core/bsinc_tables.cpp
640     core/bsinc_tables.h
641     core/bufferline.h
642     core/buffer_storage.cpp
643     core/buffer_storage.h
644     core/context.cpp
645     core/context.h
646     core/converter.cpp
647     core/converter.h
648     core/cpu_caps.cpp
649     core/cpu_caps.h
650     core/devformat.cpp
651     core/devformat.h
652     core/device.cpp
653     core/device.h
654     core/effects/base.h
655     core/effectslot.cpp
656     core/effectslot.h
657     core/except.cpp
658     core/except.h
659     core/filters/biquad.h
660     core/filters/biquad.cpp
661     core/filters/nfc.cpp
662     core/filters/nfc.h
663     core/filters/splitter.cpp
664     core/filters/splitter.h
665     core/fmt_traits.cpp
666     core/fmt_traits.h
667     core/fpu_ctrl.cpp
668     core/fpu_ctrl.h
669     core/front_stablizer.h
670     core/helpers.cpp
671     core/helpers.h
672     core/hrtf.cpp
673     core/hrtf.h
674     core/logging.cpp
675     core/logging.h
676     core/mastering.cpp
677     core/mastering.h
678     core/mixer.cpp
679     core/mixer.h
680     core/resampler_limits.h
681     core/uhjfilter.cpp
682     core/uhjfilter.h
683     core/uiddefs.cpp
684     core/voice.cpp
685     core/voice.h
686     core/voice_change.h)
688 set(HAVE_RTKIT 0)
689 if(NOT WIN32)
690     option(ALSOFT_REQUIRE_RTKIT "Require RTKit/D-Bus support" FALSE)
691     find_package(DBus1 QUIET)
692     if(NOT DBus1_FOUND AND PkgConfig_FOUND)
693         pkg_check_modules(DBUS dbus-1)
694     endif()
695     if(DBus1_FOUND OR DBUS_FOUND)
696         option(ALSOFT_RTKIT "Enable RTKit support" ON)
697         if(ALSOFT_RTKIT)
698             set(HAVE_RTKIT 1)
699             set(CORE_OBJS ${CORE_OBJS} core/dbus_wrap.cpp core/dbus_wrap.h
700                 core/rtkit.cpp core/rtkit.h)
701             if(NOT DBus1_FOUND)
702                 set(INC_PATHS ${INC_PATHS} ${DBUS_INCLUDE_DIRS})
703                 set(CPP_DEFS ${CPP_DEFS} ${DBUS_CFLAGS_OTHER})
704                 if(NOT HAVE_DLFCN_H)
705                     set(EXTRA_LIBS ${EXTRA_LIBS} ${DBUS_LINK_LIBRARIES})
706                 endif()
707             elseif(HAVE_DLFCN_H)
708                 set(INC_PATHS ${INC_PATHS} ${DBus1_INCLUDE_DIRS})
709                 set(CPP_DEFS ${CPP_DEFS} ${DBus1_DEFINITIONS})
710             else()
711                 set(EXTRA_LIBS ${EXTRA_LIBS} ${DBus1_LIBRARIES})
712             endif()
713         endif()
714     else()
715         set(MISSING_VARS "")
716         if(NOT DBus1_INCLUDE_DIRS)
717             set(MISSING_VARS "${MISSING_VARS} DBus1_INCLUDE_DIRS")
718         endif()
719         if(NOT DBus1_LIBRARIES)
720             set(MISSING_VARS "${MISSING_VARS} DBus1_LIBRARIES")
721         endif()
722         message(STATUS "Could NOT find DBus1 (missing:${MISSING_VARS})")
723         unset(MISSING_VARS)
724     endif()
725 endif()
726 if(ALSOFT_REQUIRE_RTKIT AND NOT HAVE_RTKIT)
727     message(FATAL_ERROR "Failed to enabled required RTKit support")
728 endif()
730 # Default mixers, always available
731 set(CORE_OBJS ${CORE_OBJS}
732     core/mixer/defs.h
733     core/mixer/hrtfbase.h
734     core/mixer/hrtfdefs.h
735     core/mixer/mixer_c.cpp)
737 # AL and related routines
738 set(OPENAL_OBJS
739     al/auxeffectslot.cpp
740     al/auxeffectslot.h
741     al/buffer.cpp
742     al/buffer.h
743     al/effect.cpp
744     al/effect.h
745     al/effects/autowah.cpp
746     al/effects/chorus.cpp
747     al/effects/compressor.cpp
748     al/effects/convolution.cpp
749     al/effects/dedicated.cpp
750     al/effects/distortion.cpp
751     al/effects/echo.cpp
752         al/effects/effects.cpp
753     al/effects/effects.h
754     al/effects/equalizer.cpp
755     al/effects/fshifter.cpp
756     al/effects/modulator.cpp
757     al/effects/null.cpp
758     al/effects/pshifter.cpp
759     al/effects/reverb.cpp
760     al/effects/vmorpher.cpp
761     al/error.cpp
762     al/event.cpp
763     al/event.h
764     al/extension.cpp
765     al/filter.cpp
766     al/filter.h
767     al/listener.cpp
768     al/listener.h
769     al/source.cpp
770     al/source.h
771     al/state.cpp)
773 # ALC and related routines
774 set(ALC_OBJS
775     alc/alc.cpp
776     alc/alu.cpp
777     alc/alu.h
778     alc/alconfig.cpp
779     alc/alconfig.h
780     alc/context.cpp
781     alc/context.h
782     alc/device.cpp
783     alc/device.h
784     alc/effects/base.h
785     alc/effects/autowah.cpp
786     alc/effects/chorus.cpp
787     alc/effects/compressor.cpp
788     alc/effects/convolution.cpp
789     alc/effects/dedicated.cpp
790     alc/effects/distortion.cpp
791     alc/effects/echo.cpp
792     alc/effects/equalizer.cpp
793     alc/effects/fshifter.cpp
794     alc/effects/modulator.cpp
795     alc/effects/null.cpp
796     alc/effects/pshifter.cpp
797     alc/effects/reverb.cpp
798     alc/effects/vmorpher.cpp
799     alc/inprogext.h
800     alc/panning.cpp)
802 if (ALSOFT_EAX)
803     set(OPENAL_OBJS
804         ${OPENAL_OBJS}
805         al/eax/api.cpp
806         al/eax/api.h
807         al/eax/call.cpp
808         al/eax/call.h
809         al/eax/effect.h
810         al/eax/exception.cpp
811         al/eax/exception.h
812         al/eax/fx_slot_index.cpp
813         al/eax/fx_slot_index.h
814         al/eax/fx_slots.cpp
815         al/eax/fx_slots.h
816         al/eax/globals.cpp
817         al/eax/globals.h
818         al/eax/utils.cpp
819         al/eax/utils.h
820         al/eax/x_ram.h
822 endif ()
824 # Include SIMD mixers
825 set(CPU_EXTS "Default")
826 if(HAVE_SSE)
827     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse.cpp)
828     set(CPU_EXTS "${CPU_EXTS}, SSE")
829 endif()
830 if(HAVE_SSE2)
831     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse2.cpp)
832     set(CPU_EXTS "${CPU_EXTS}, SSE2")
833 endif()
834 if(HAVE_SSE3)
835     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse3.cpp)
836     set(CPU_EXTS "${CPU_EXTS}, SSE3")
837 endif()
838 if(HAVE_SSE4_1)
839     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse41.cpp)
840     set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
841 endif()
842 if(HAVE_NEON)
843     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_neon.cpp)
844     set(CPU_EXTS "${CPU_EXTS}, Neon")
845 endif()
848 set(HAVE_ALSA       0)
849 set(HAVE_OSS        0)
850 set(HAVE_PIPEWIRE   0)
851 set(HAVE_SOLARIS    0)
852 set(HAVE_SNDIO      0)
853 set(HAVE_DSOUND     0)
854 set(HAVE_WASAPI     0)
855 set(HAVE_WINMM      0)
856 set(HAVE_PORTAUDIO  0)
857 set(HAVE_PULSEAUDIO 0)
858 set(HAVE_COREAUDIO  0)
859 set(HAVE_OPENSL     0)
860 set(HAVE_OBOE       0)
861 set(HAVE_WAVE       0)
862 set(HAVE_SDL2       0)
864 if(WIN32 OR HAVE_DLFCN_H)
865     set(IS_LINKED "")
866     macro(ADD_BACKEND_LIBS _LIBS)
867     endmacro()
868 else()
869     set(IS_LINKED " (linked)")
870     macro(ADD_BACKEND_LIBS _LIBS)
871         set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
872     endmacro()
873 endif()
875 set(BACKENDS "")
876 set(ALC_OBJS  ${ALC_OBJS}
877     alc/backends/base.cpp
878     alc/backends/base.h
879     # Default backends, always available
880     alc/backends/loopback.cpp
881     alc/backends/loopback.h
882     alc/backends/null.cpp
883     alc/backends/null.h
886 # Check ALSA backend
887 option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
888 find_package(ALSA)
889 if(ALSA_FOUND)
890     option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
891     if(ALSOFT_BACKEND_ALSA)
892         set(HAVE_ALSA 1)
893         set(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
894         set(ALC_OBJS  ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
895         add_backend_libs(${ALSA_LIBRARIES})
896         set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
897     endif()
898 endif()
899 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
900     message(FATAL_ERROR "Failed to enabled required ALSA backend")
901 endif()
903 # Check OSS backend
904 option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
905 find_package(OSS)
906 if(OSS_FOUND)
907     option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
908     if(ALSOFT_BACKEND_OSS)
909         set(HAVE_OSS 1)
910         set(BACKENDS  "${BACKENDS} OSS,")
911         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
912         if(OSS_LIBRARIES)
913             set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
914         endif()
915         set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
916     endif()
917 endif()
918 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
919     message(FATAL_ERROR "Failed to enabled required OSS backend")
920 endif()
922 # Check PipeWire backend
923 option(ALSOFT_REQUIRE_PIPEWIRE "Require PipeWire backend" OFF)
924 if(PkgConfig_FOUND)
925     pkg_check_modules(PIPEWIRE libpipewire-0.3>=0.3.23)
926     if(PIPEWIRE_FOUND)
927         option(ALSOFT_BACKEND_PIPEWIRE "Enable PipeWire backend" ON)
928         if(ALSOFT_BACKEND_PIPEWIRE)
929             set(HAVE_PIPEWIRE 1)
930             set(BACKENDS  "${BACKENDS} PipeWire${IS_LINKED},")
931             set(ALC_OBJS  ${ALC_OBJS} alc/backends/pipewire.cpp alc/backends/pipewire.h)
932             add_backend_libs(${PIPEWIRE_LIBRARIES})
933             set(INC_PATHS ${INC_PATHS} ${PIPEWIRE_INCLUDE_DIRS})
934         endif()
935     endif()
936 endif()
937 if(ALSOFT_REQUIRE_PIPEWIRE AND NOT HAVE_PIPEWIRE)
938     message(FATAL_ERROR "Failed to enabled required PipeWire backend")
939 endif()
941 # Check Solaris backend
942 option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
943 find_package(AudioIO)
944 if(AUDIOIO_FOUND)
945     option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
946     if(ALSOFT_BACKEND_SOLARIS)
947         set(HAVE_SOLARIS 1)
948         set(BACKENDS  "${BACKENDS} Solaris,")
949         set(ALC_OBJS  ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
950         set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
951     endif()
952 endif()
953 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
954     message(FATAL_ERROR "Failed to enabled required Solaris backend")
955 endif()
957 # Check SndIO backend
958 option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
959 find_package(SoundIO)
960 if(SOUNDIO_FOUND)
961     option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
962     if(ALSOFT_BACKEND_SNDIO)
963         set(HAVE_SNDIO 1)
964         set(BACKENDS  "${BACKENDS} SndIO (linked),")
965         set(ALC_OBJS  ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
966         set(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
967         set(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
968     endif()
969 endif()
970 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
971     message(FATAL_ERROR "Failed to enabled required SndIO backend")
972 endif()
974 # Check Windows-only backends
975 option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
976 option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
977 option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
978 if(WIN32)
979     # Check MMSystem backend
980     option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
981     if(ALSOFT_BACKEND_WINMM)
982         set(HAVE_WINMM 1)
983         set(BACKENDS "${BACKENDS} WinMM,")
984         set(ALC_OBJS ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
985         # There doesn't seem to be good way to search for winmm.lib for MSVC.
986         # find_library doesn't find it without being told to look in a specific
987         # place in the WindowsSDK, but it links anyway. If there ends up being
988         # Windows targets without this, another means to detect it is needed.
989         set(EXTRA_LIBS winmm ${EXTRA_LIBS})
990     endif()
992     # Check DSound backend
993     check_include_file(dsound.h HAVE_DSOUND_H)
994     if(DXSDK_DIR)
995         find_path(DSOUND_INCLUDE_DIR NAMES "dsound.h"
996             PATHS "${DXSDK_DIR}" PATH_SUFFIXES include
997             DOC "The DirectSound include directory")
998     endif()
999     if(HAVE_DSOUND_H OR DSOUND_INCLUDE_DIR)
1000         option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
1001         if(ALSOFT_BACKEND_DSOUND)
1002             set(HAVE_DSOUND 1)
1003             set(BACKENDS "${BACKENDS} DirectSound,")
1004             set(ALC_OBJS ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
1006             if(NOT HAVE_DSOUND_H)
1007                 set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIR})
1008             endif()
1009         endif()
1010     endif()
1012     # Check for WASAPI backend
1013     check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1014     if(HAVE_MMDEVICEAPI_H)
1015         option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
1016         if(ALSOFT_BACKEND_WASAPI)
1017             set(HAVE_WASAPI 1)
1018             set(BACKENDS  "${BACKENDS} WASAPI,")
1019             set(ALC_OBJS  ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
1020         endif()
1021     endif()
1022 endif()
1023 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1024     message(FATAL_ERROR "Failed to enabled required WinMM backend")
1025 endif()
1026 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1027     message(FATAL_ERROR "Failed to enabled required DSound backend")
1028 endif()
1029 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
1030     message(FATAL_ERROR "Failed to enabled required WASAPI backend")
1031 endif()
1033 # Check PortAudio backend
1034 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1035 find_package(PortAudio)
1036 if(PORTAUDIO_FOUND)
1037     option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1038     if(ALSOFT_BACKEND_PORTAUDIO)
1039         set(HAVE_PORTAUDIO 1)
1040         set(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
1041         set(ALC_OBJS  ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
1042         add_backend_libs(${PORTAUDIO_LIBRARIES})
1043         set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
1044     endif()
1045 endif()
1046 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1047     message(FATAL_ERROR "Failed to enabled required PortAudio backend")
1048 endif()
1050 # Check PulseAudio backend
1051 option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1052 find_package(PulseAudio)
1053 if(PULSEAUDIO_FOUND)
1054     option(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1055     if(ALSOFT_BACKEND_PULSEAUDIO)
1056         set(HAVE_PULSEAUDIO 1)
1057         set(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
1058         set(ALC_OBJS  ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
1059         add_backend_libs(${PULSEAUDIO_LIBRARY})
1060         set(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIR})
1061     endif()
1062 endif()
1063 if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1064     message(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1065 endif()
1067 # Check JACK backend
1068 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1069 find_package(JACK)
1070 if(JACK_FOUND)
1071     option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1072     if(ALSOFT_BACKEND_JACK)
1073         set(HAVE_JACK 1)
1074         set(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1075         set(ALC_OBJS  ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
1076         add_backend_libs(${JACK_LIBRARIES})
1077         set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1078     endif()
1079 endif()
1080 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1081     message(FATAL_ERROR "Failed to enabled required JACK backend")
1082 endif()
1084 # Check CoreAudio backend
1085 option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1086 find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
1087 find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
1088 if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
1089     option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1090     if(ALSOFT_BACKEND_COREAUDIO)
1091         set(HAVE_COREAUDIO 1)
1092         set(ALC_OBJS  ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
1093         set(BACKENDS  "${BACKENDS} CoreAudio,")
1095         set(EXTRA_LIBS -Wl,-framework,CoreAudio ${EXTRA_LIBS})
1096         if(CMAKE_SYSTEM_NAME MATCHES "^(iOS|tvOS)$")
1097             find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
1098             if(COREFOUNDATION_FRAMEWORK)
1099                 set(EXTRA_LIBS -Wl,-framework,CoreFoundation ${EXTRA_LIBS})
1100             endif()
1101         else()
1102             set(EXTRA_LIBS -Wl,-framework,AudioUnit,-framework,ApplicationServices ${EXTRA_LIBS})
1103         endif()
1105         # Some versions of OSX may need the AudioToolbox framework. Add it if
1106         # it's found.
1107         find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
1108         if(AUDIOTOOLBOX_LIBRARY)
1109             set(EXTRA_LIBS -Wl,-framework,AudioToolbox ${EXTRA_LIBS})
1110         endif()
1112         set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
1113     endif()
1114 endif()
1115 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1116     message(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1117 endif()
1119 # Check for OpenSL (Android) backend
1120 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1121 find_package(OpenSL)
1122 if(OPENSL_FOUND)
1123     option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1124     if(ALSOFT_BACKEND_OPENSL)
1125         set(HAVE_OPENSL 1)
1126         set(ALC_OBJS  ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1127         set(BACKENDS  "${BACKENDS} OpenSL,")
1128         set(EXTRA_LIBS "OpenSL::OpenSLES" ${EXTRA_LIBS})
1129     endif()
1130 endif()
1131 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1132     message(FATAL_ERROR "Failed to enabled required OpenSL backend")
1133 endif()
1135 # Check for Oboe (Android) backend
1136 set(OBOE_TARGET )
1137 if(ANDROID)
1138     set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1139     if(OBOE_SOURCE)
1140         # Force Oboe to build with hidden symbols. Don't want to be exporting
1141         # them from OpenAL.
1142         set(OLD_CXX_FLAGS ${CMAKE_CXX_FLAGS})
1143         check_cxx_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
1144         if(HAVE_VISIBILITY_HIDDEN_SWITCH)
1145             set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
1146         endif()
1147         add_subdirectory(${OBOE_SOURCE} ./oboe)
1148         set(CMAKE_CXX_FLAGS ${OLD_CXX_FLAGS})
1149         unset(OLD_CXX_FLAGS)
1151         set(OBOE_TARGET oboe)
1152     else()
1153         find_package(oboe CONFIG)
1154         if(NOT TARGET oboe::oboe)
1155             find_package(Oboe)
1156         endif()
1157         if(TARGET oboe::oboe)
1158             set(OBOE_TARGET "oboe::oboe")
1159         endif()
1160     endif()
1161 endif()
1163 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1164 if(OBOE_TARGET)
1165     option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1166     if(ALSOFT_BACKEND_OBOE)
1167         set(HAVE_OBOE 1)
1168         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
1169         set(BACKENDS  "${BACKENDS} Oboe,")
1170         set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
1171     endif()
1172 endif()
1173 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1174     message(FATAL_ERROR "Failed to enabled required Oboe backend")
1175 endif()
1177 # Check for SDL2 backend
1178 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1179 find_package(SDL2 QUIET)
1180 if(SDL2_FOUND)
1181     # Off by default, since it adds a runtime dependency
1182     option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1183     if(ALSOFT_BACKEND_SDL2)
1184         set(HAVE_SDL2 1)
1185         set(ALC_OBJS  ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1186         set(BACKENDS  "${BACKENDS} SDL2,")
1187         set(EXTRA_LIBS ${EXTRA_LIBS} SDL2::SDL2)
1188     endif()
1189 else()
1190     message(STATUS "Could NOT find SDL2")
1191 endif()
1192 if(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1193     message(FATAL_ERROR "Failed to enabled required SDL2 backend")
1194 endif()
1196 # Optionally enable the Wave Writer backend
1197 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1198 if(ALSOFT_BACKEND_WAVE)
1199     set(HAVE_WAVE 1)
1200     set(ALC_OBJS  ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1201     set(BACKENDS  "${BACKENDS} WaveFile,")
1202 endif()
1204 # This is always available
1205 set(BACKENDS  "${BACKENDS} Null")
1208 find_package(Git)
1209 if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1210     # Get the current working branch and its latest abbreviated commit hash
1211     add_custom_target(build_version
1212         ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1213             -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1214             -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1215         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1216         VERBATIM
1217     )
1218 else()
1219     set(GIT_BRANCH "UNKNOWN")
1220     set(GIT_COMMIT_HASH "unknown")
1221     configure_file(
1222         "${OpenAL_SOURCE_DIR}/version.h.in"
1223         "${OpenAL_BINARY_DIR}/version.h")
1224 endif()
1227 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1228 if(ALSOFT_EMBED_HRTF_DATA)
1229     macro(make_hrtf_header FILENAME VARNAME)
1230         set(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1231         set(outfile  "${OpenAL_BINARY_DIR}/${VARNAME}.h")
1233         add_custom_command(OUTPUT "${outfile}"
1234             COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
1235                 -D "VARIABLE_NAME=${VARNAME}" -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1236             WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1237             DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1238             VERBATIM
1239         )
1240         set(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1241     endmacro()
1243     make_hrtf_header("Default HRTF.mhr" "hrtf_default")
1244 endif()
1247 if(ALSOFT_UTILS)
1248     find_package(MySOFA)
1249     if(NOT ALSOFT_NO_CONFIG_UTIL)
1250         find_package(Qt5Widgets QUIET)
1251         if(NOT Qt5Widgets_FOUND)
1252             message(STATUS "Could NOT find Qt5Widgets")
1253         endif()
1254     endif()
1255 endif()
1256 if(ALSOFT_UTILS OR ALSOFT_EXAMPLES)
1257     find_package(SndFile)
1258     if(SDL2_FOUND)
1259         find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1260     endif()
1261 endif()
1263 if(NOT WIN32)
1264     set(LIBNAME "openal")
1265 else()
1266     set(LIBNAME "OpenAL32")
1267 endif()
1269 # Needed for openal.pc.in
1270 set(prefix ${CMAKE_INSTALL_PREFIX})
1271 set(exec_prefix "\${prefix}")
1272 set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
1273 set(bindir "${CMAKE_INSTALL_FULL_BINDIR}")
1274 set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
1275 set(PACKAGE_VERSION "${LIB_VERSION}")
1276 set(PKG_CONFIG_CFLAGS )
1277 set(PKG_CONFIG_PRIVATE_LIBS )
1278 if(LIBTYPE STREQUAL "STATIC")
1279     set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1280     foreach(FLAG  ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1281         # If this is already a linker flag, or is a full path+file, add it
1282         # as-is. If it's an SDL2 target, add the link flag for it. Otherwise,
1283         # it's a name intended to be dressed as -lname.
1284         if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1285             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1286         elseif(FLAG MATCHES "^SDL2::SDL2")
1287             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -lSDL2")
1288         else()
1289             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1290         endif()
1291     endforeach()
1292 endif()
1294 # End configuration
1295 configure_file(
1296     "${OpenAL_SOURCE_DIR}/config.h.in"
1297     "${OpenAL_BINARY_DIR}/config.h")
1298 configure_file(
1299     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1300     "${OpenAL_BINARY_DIR}/openal.pc"
1301     @ONLY)
1304 add_library(common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1305 target_include_directories(common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include)
1306 target_compile_definitions(common PRIVATE ${CPP_DEFS})
1307 target_compile_options(common PRIVATE ${C_FLAGS})
1308 set_target_properties(common PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
1311 unset(HAS_ROUTER)
1312 set(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1314 # Build main library
1315 if(LIBTYPE STREQUAL "STATIC")
1316     add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS})
1317     target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
1318     target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1320     if(WIN32)
1321         # This option is for static linking OpenAL Soft into another project
1322         # that already defines the IDs. It is up to that project to ensure all
1323         # required IDs are defined.
1324         option(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
1325         if(ALSOFT_NO_UID_DEFS)
1326             target_compile_definitions(${IMPL_TARGET} PRIVATE AL_NO_UID_DEFS)
1327         endif()
1328     endif()
1329 else()
1330     set(RC_CONFIG resources/openal32.rc)
1331     if(WIN32 AND ALSOFT_BUILD_ROUTER)
1332         add_library(OpenAL SHARED
1333             resources/router.rc
1334             router/router.cpp
1335             router/router.h
1336             router/alc.cpp
1337             router/al.cpp
1338         )
1339         target_compile_definitions(OpenAL
1340             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}"
1341             "AL_API=${EXPORT_DECL}" ${CPP_DEFS})
1342         target_compile_options(OpenAL PRIVATE ${C_FLAGS})
1343         target_link_libraries(OpenAL PRIVATE common ${LINKER_FLAGS})
1344         target_include_directories(OpenAL
1345           PUBLIC
1346             $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1347             $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1348           PRIVATE
1349             ${OpenAL_SOURCE_DIR}/common
1350             ${OpenAL_BINARY_DIR}
1351         )
1352         set_target_properties(OpenAL PROPERTIES PREFIX "")
1353         set_target_properties(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1354         if(TARGET build_version)
1355             add_dependencies(OpenAL build_version)
1356         endif()
1357         set(HAS_ROUTER 1)
1359         set(LIBNAME "soft_oal")
1360         set(IMPL_TARGET soft_oal)
1361         set(RC_CONFIG resources/soft_oal.rc)
1362     endif()
1364     # !important: for osx framework public header works, the headers must be in
1365     # the project
1366     set(TARGET_PUBLIC_HEADERS include/AL/al.h include/AL/alc.h include/AL/alext.h include/AL/efx.h
1367         include/AL/efx-presets.h)
1368     add_library(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS} ${RC_CONFIG}
1369         ${TARGET_PUBLIC_HEADERS})
1370     if(WIN32)
1371         set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
1372     endif()
1373     target_link_libraries(${IMPL_TARGET} PRIVATE common ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1375     if(APPLE AND ALSOFT_OSX_FRAMEWORK)
1376         # Sets framework name to soft_oal to avoid ambiguity with the system OpenAL.framework
1377         set(LIBNAME "soft_oal")
1378         if(GIT_FOUND)
1379             EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD
1380                 TIMEOUT 5
1381                 OUTPUT_VARIABLE BUNDLE_VERSION
1382                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1383         else()
1384             set(BUNDLE_VERSION 1)
1385         endif()
1387         # Build: Fix rpath in iOS shared libraries
1388         # If this flag is not set, the final dylib binary ld path will be
1389         # /User/xxx/*/soft_oal.framework/soft_oal, which can't be loaded by iOS devices.
1390         # See also: https://github.com/libjpeg-turbo/libjpeg-turbo/commit/c80ddef7a4ce21ace9e3ca0fd190d320cc8cdaeb
1391         if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
1392             set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
1393         endif()
1395         set_target_properties(${IMPL_TARGET} PROPERTIES
1396             FRAMEWORK TRUE
1397             FRAMEWORK_VERSION C
1398             MACOSX_FRAMEWORK_NAME "${IMPL_TARGET}"
1399             MACOSX_FRAMEWORK_IDENTIFIER "org.openal-soft.openal"
1400             MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${LIB_VERSION}"
1401             MACOSX_FRAMEWORK_BUNDLE_VERSION "${BUNDLE_VERSION}"
1402             XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
1403             XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
1404             XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
1405             PUBLIC_HEADER "${TARGET_PUBLIC_HEADERS}"
1406             MACOSX_RPATH TRUE)
1407     endif()
1408 endif()
1410 target_include_directories(${IMPL_TARGET}
1411   PUBLIC
1412     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1413   INTERFACE
1414     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include/AL>
1415     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1416     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/AL>
1417   PRIVATE
1418     ${INC_PATHS}
1419     ${OpenAL_BINARY_DIR}
1420     ${OpenAL_SOURCE_DIR}
1421     ${OpenAL_SOURCE_DIR}/common
1424 set_target_properties(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1425     VERSION ${LIB_VERSION}
1426     SOVERSION ${LIB_MAJOR_VERSION}
1428 target_compile_definitions(${IMPL_TARGET}
1429     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}" "AL_API=${EXPORT_DECL}"
1430     ${CPP_DEFS})
1431 target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1433 if(TARGET build_version)
1434     add_dependencies(${IMPL_TARGET} build_version)
1435 endif()
1437 if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1438     find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
1439     if(NOT SED_EXECUTABLE OR NOT CMAKE_DLLTOOL)
1440         message(STATUS "")
1441         if(NOT SED_EXECUTABLE)
1442             message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1443         endif()
1444         if(NOT CMAKE_DLLTOOL)
1445             message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1446         endif()
1447     else()
1448         set_property(TARGET OpenAL APPEND_STRING PROPERTY
1449             LINK_FLAGS " -Wl,--output-def,OpenAL32.def")
1450         add_custom_command(TARGET OpenAL POST_BUILD
1451             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1452             COMMAND "${CMAKE_DLLTOOL}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1453             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1454             VERBATIM
1455         )
1456     endif()
1457 endif()
1459 if(HAS_ROUTER)
1460     message(STATUS "")
1461     message(STATUS "Building DLL router")
1462 endif()
1464 message(STATUS "")
1465 message(STATUS "Building OpenAL with support for the following backends:")
1466 message(STATUS "   ${BACKENDS}")
1467 message(STATUS "")
1468 message(STATUS "Building with support for CPU extensions:")
1469 message(STATUS "    ${CPU_EXTS}")
1470 message(STATUS "")
1471 if(FPMATH_SET)
1472     message(STATUS "Building with SSE${FPMATH_SET} codegen")
1473     message(STATUS "")
1474 endif()
1476 if(ALSOFT_EAX)
1477     message(STATUS "Building with legacy EAX extension support")
1478     message(STATUS "")
1479 endif()
1481 if(ALSOFT_EMBED_HRTF_DATA)
1482     message(STATUS "Embedding HRTF datasets")
1483     message(STATUS "")
1484 endif()
1486 # An alias for sub-project builds
1487 add_library(OpenAL::OpenAL ALIAS OpenAL)
1489 # Install main library
1490 if(ALSOFT_INSTALL)
1491     configure_package_config_file(OpenALConfig.cmake.in OpenALConfig.cmake
1492         INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL)
1493     install(TARGETS OpenAL EXPORT OpenAL
1494         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1495         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1496         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1497         FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
1498         INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1499     export(TARGETS OpenAL
1500         NAMESPACE OpenAL::
1501         FILE OpenALTargets.cmake)
1502     install(EXPORT OpenAL
1503         DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1504         NAMESPACE OpenAL::
1505         FILE OpenALTargets.cmake)
1506     install(DIRECTORY include/AL
1507         DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1508     install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1509         DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1510     install(FILES "${OpenAL_BINARY_DIR}/OpenALConfig.cmake"
1511         DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL")
1512     if(TARGET soft_oal)
1513         install(TARGETS soft_oal
1514             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1515     endif()
1516     message(STATUS "Installing library and headers")
1517 else()
1518     message(STATUS "NOT installing library and headers")
1519 endif()
1521 if(ALSOFT_INSTALL_CONFIG)
1522     install(FILES alsoftrc.sample
1523         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1524     message(STATUS "Installing sample configuration")
1525 endif()
1527 if(ALSOFT_INSTALL_HRTF_DATA)
1528     install(DIRECTORY hrtf
1529         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1530     message(STATUS "Installing HRTF data files")
1531 endif()
1533 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1534     install(DIRECTORY presets
1535         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1536     message(STATUS "Installing AmbDec presets")
1537 endif()
1538 message(STATUS "")
1540 set(UNICODE_FLAG )
1541 if(MINGW)
1542     set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1543 endif()
1544 set(EXTRA_INSTALLS )
1545 if(ALSOFT_UTILS)
1546     add_executable(openal-info utils/openal-info.c)
1547     target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1548     target_compile_options(openal-info PRIVATE ${C_FLAGS})
1549     target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
1550     if(ALSOFT_INSTALL_EXAMPLES)
1551         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
1552     endif()
1554     if(SNDFILE_FOUND)
1555         add_executable(uhjdecoder utils/uhjdecoder.cpp)
1556         target_compile_definitions(uhjdecoder PRIVATE ${CPP_DEFS})
1557         target_include_directories(uhjdecoder
1558             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1559         target_compile_options(uhjdecoder PRIVATE ${C_FLAGS})
1560         target_link_libraries(uhjdecoder PUBLIC common
1561             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1563         add_executable(uhjencoder utils/uhjencoder.cpp)
1564         target_compile_definitions(uhjencoder PRIVATE ${CPP_DEFS})
1565         target_include_directories(uhjencoder
1566             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1567         target_compile_options(uhjencoder PRIVATE ${C_FLAGS})
1568         target_link_libraries(uhjencoder PUBLIC common
1569             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1570     endif()
1572     if(MYSOFA_FOUND)
1573         set(SOFA_SUPPORT_SRCS
1574             utils/sofa-support.cpp
1575             utils/sofa-support.h)
1576         add_library(sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
1577         target_compile_definitions(sofa-support PRIVATE ${CPP_DEFS})
1578         target_include_directories(sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
1579         target_compile_options(sofa-support PRIVATE ${C_FLAGS})
1580         target_link_libraries(sofa-support PUBLIC common MySOFA::MySOFA PRIVATE ${LINKER_FLAGS})
1582         set(MAKEMHR_SRCS
1583             utils/makemhr/loaddef.cpp
1584             utils/makemhr/loaddef.h
1585             utils/makemhr/loadsofa.cpp
1586             utils/makemhr/loadsofa.h
1587             utils/makemhr/makemhr.cpp
1588             utils/makemhr/makemhr.h)
1589         if(NOT HAVE_GETOPT)
1590             set(MAKEMHR_SRCS  ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1591         endif()
1592         add_executable(makemhr ${MAKEMHR_SRCS})
1593         target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1594         target_include_directories(makemhr
1595             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
1596         target_compile_options(makemhr PRIVATE ${C_FLAGS})
1597         target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1598         if(ALSOFT_INSTALL_EXAMPLES)
1599             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
1600         endif()
1602         set(SOFAINFO_SRCS  utils/sofa-info.cpp)
1603         add_executable(sofa-info ${SOFAINFO_SRCS})
1604         target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1605         target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
1606         target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1607         target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1608     endif()
1609     message(STATUS "Building utility programs")
1611     if(NOT ALSOFT_NO_CONFIG_UTIL)
1612         add_subdirectory(utils/alsoft-config)
1613     endif()
1614     message(STATUS "")
1615 endif()
1618 # Add a static library with common functions used by multiple example targets
1619 add_library(ex-common STATIC EXCLUDE_FROM_ALL
1620     examples/common/alhelpers.c
1621     examples/common/alhelpers.h)
1622 target_compile_definitions(ex-common PUBLIC ${CPP_DEFS})
1623 target_include_directories(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
1624 target_compile_options(ex-common PUBLIC ${C_FLAGS})
1625 target_link_libraries(ex-common PUBLIC OpenAL PRIVATE ${RT_LIB})
1627 if(ALSOFT_EXAMPLES)
1628     add_executable(altonegen examples/altonegen.c)
1629     target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common ${UNICODE_FLAG})
1631     add_executable(alrecord examples/alrecord.c)
1632     target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} ex-common ${UNICODE_FLAG})
1634     if(ALSOFT_INSTALL_EXAMPLES)
1635         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord)
1636     endif()
1638     message(STATUS "Building example programs")
1640     if(SNDFILE_FOUND)
1641         add_executable(alplay examples/alplay.c)
1642         target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1643             ${UNICODE_FLAG})
1645         add_executable(alstream examples/alstream.c)
1646         target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1647             ${UNICODE_FLAG})
1649         add_executable(alreverb examples/alreverb.c)
1650         target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1651             ${UNICODE_FLAG})
1653         add_executable(almultireverb examples/almultireverb.c)
1654         target_link_libraries(almultireverb
1655             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1657         add_executable(allatency examples/allatency.c)
1658         target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1659             ${UNICODE_FLAG})
1661         add_executable(alhrtf examples/alhrtf.c)
1662         target_link_libraries(alhrtf
1663             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1665         add_executable(alstreamcb examples/alstreamcb.cpp)
1666         target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1667             ${UNICODE_FLAG})
1669         add_executable(alconvolve examples/alconvolve.c)
1670         target_link_libraries(alconvolve PRIVATE ${LINKER_FLAGS} common SndFile::SndFile ex-common
1671             ${UNICODE_FLAG})
1673         if(ALSOFT_INSTALL_EXAMPLES)
1674             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1675                 alhrtf)
1676         endif()
1678         message(STATUS "Building SndFile example programs")
1679     endif()
1681     if(SDL2_FOUND)
1682         add_executable(alloopback examples/alloopback.c)
1683         target_link_libraries(alloopback
1684             PRIVATE ${LINKER_FLAGS} SDL2::SDL2 ex-common ${MATH_LIB})
1686         if(ALSOFT_INSTALL_EXAMPLES)
1687             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
1688         endif()
1690         message(STATUS "Building SDL example programs")
1692         set(FFVER_OK FALSE)
1693         if(FFMPEG_FOUND)
1694             set(FFVER_OK TRUE)
1695             if(AVFORMAT_VERSION VERSION_LESS "59.27.100")
1696                 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 59.27.100)")
1697                 set(FFVER_OK FALSE)
1698             endif()
1699             if(AVCODEC_VERSION VERSION_LESS "59.37.100")
1700                 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 59.37.100)")
1701                 set(FFVER_OK FALSE)
1702             endif()
1703             if(AVUTIL_VERSION VERSION_LESS "57.28.100")
1704                 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 57.28.100)")
1705                 set(FFVER_OK FALSE)
1706             endif()
1707             if(SWSCALE_VERSION VERSION_LESS "6.7.100")
1708                 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 6.7.100)")
1709                 set(FFVER_OK FALSE)
1710             endif()
1711             if(SWRESAMPLE_VERSION VERSION_LESS "4.7.100")
1712                 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 4.7.100)")
1713                 set(FFVER_OK FALSE)
1714             endif()
1715         endif()
1716         if(FFVER_OK)
1717             add_executable(alffplay examples/alffplay.cpp)
1718             target_include_directories(alffplay PRIVATE ${FFMPEG_INCLUDE_DIRS})
1719             target_link_libraries(alffplay
1720                 PRIVATE ${LINKER_FLAGS} SDL2::SDL2 ${FFMPEG_LIBRARIES} ex-common)
1722             if(ALSOFT_INSTALL_EXAMPLES)
1723                 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
1724             endif()
1725             message(STATUS "Building SDL+FFmpeg example programs")
1726         endif()
1727     endif()
1728     message(STATUS "")
1729 endif()
1731 if(EXTRA_INSTALLS)
1732     install(TARGETS ${EXTRA_INSTALLS}
1733         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1734         BUNDLE  DESTINATION ${CMAKE_INSTALL_BINDIR}
1735         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1736         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1737 endif()