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