Don't rely on terminate in a catch block giving a useful message
[openal-soft.git] / CMakeLists.txt
blob6cfb6988899b13943e5eec5334778a7d46757952
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     else()
287         set(C_FLAGS ${C_FLAGS} -Werror=undef)
288     endif()
290     check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
291     if(HAVE_FNO_MATH_ERRNO)
292         set(C_FLAGS ${C_FLAGS} -fno-math-errno)
293     endif()
295     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
296     if(ALSOFT_STATIC_LIBGCC)
297         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
298         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
299         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
300         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
301         unset(OLD_REQUIRED_LIBRARIES)
303         if(NOT HAVE_STATIC_LIBGCC_SWITCH)
304             message(FATAL_ERROR "Cannot static link libgcc")
305         endif()
306         set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
307     endif()
309     option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
310     if(ALSOFT_STATIC_STDCXX)
311         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
312         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-static-libstdc++")
313         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
314         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
315         unset(OLD_REQUIRED_LIBRARIES)
317         if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
318             message(FATAL_ERROR "Cannot static link libstdc++")
319         endif()
320         set(LINKER_FLAGS ${LINKER_FLAGS} "-static-libstdc++")
321     endif()
323     if(WIN32)
324         option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
325         if(ALSOFT_STATIC_WINPTHREAD)
326             set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
327             set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,-lwinpthread,--pop-state")
328             check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
329             set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
330             unset(OLD_REQUIRED_LIBRARIES)
332             if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
333                 message(FATAL_ERROR "Cannot static link libwinpthread")
334             endif()
335             set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,-lwinpthread,--pop-state")
336         endif()
337     endif()
338 endif()
340 # Set visibility/export options if available
341 if(NOT LIBTYPE STREQUAL "STATIC")
342     if(WIN32)
343         set(EXPORT_DECL "__declspec(dllexport)")
344     else()
345         set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
346         # Yes GCC, really don't accept visibility modes you don't support
347         set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
349         check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
350                                 int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
351         if(HAVE_GCC_PROTECTED_VISIBILITY)
352             set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
353         else()
354             check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
355                                     int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
356             if(HAVE_GCC_DEFAULT_VISIBILITY)
357                 set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
358             endif()
359         endif()
360         if(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
361             set(CMAKE_C_VISIBILITY_PRESET hidden)
362             set(CMAKE_CXX_VISIBILITY_PRESET hidden)
363         endif()
365         set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
366     endif()
367 endif()
370 set(SSE2_SWITCH "")
372 if(NOT MSVC)
373     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
374     # Yes GCC, really don't accept command line options you don't support
375     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
376     check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
377     if(HAVE_MSSE2_SWITCH)
378         set(SSE2_SWITCH "-msse2")
379     endif()
380     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
381     unset(OLD_REQUIRED_FLAGS)
382 endif()
384 check_include_file(xmmintrin.h HAVE_XMMINTRIN_H)
385 check_include_file(emmintrin.h HAVE_EMMINTRIN_H)
386 check_include_file(pmmintrin.h HAVE_PMMINTRIN_H)
387 check_include_file(smmintrin.h HAVE_SMMINTRIN_H)
388 check_include_file(arm_neon.h HAVE_ARM_NEON_H)
390 set(HAVE_SSE        0)
391 set(HAVE_SSE2       0)
392 set(HAVE_SSE3       0)
393 set(HAVE_SSE4_1     0)
394 set(HAVE_NEON       0)
396 # Check for SSE support
397 option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
398 option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
399 if(ALSOFT_CPUEXT_SSE AND HAVE_XMMINTRIN_H)
400     set(HAVE_SSE 1)
401 endif()
402 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
403     message(FATAL_ERROR "Failed to enable required SSE CPU extensions")
404 endif()
406 option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
407 option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
408 if(ALSOFT_CPUEXT_SSE2 AND HAVE_SSE AND HAVE_EMMINTRIN_H)
409     set(HAVE_SSE2 1)
410 endif()
411 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
412     message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
413 endif()
415 option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
416 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
417 if(ALSOFT_CPUEXT_SSE3 AND HAVE_SSE2 AND HAVE_PMMINTRIN_H)
418     set(HAVE_SSE3 1)
419 endif()
420 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
421     message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
422 endif()
424 option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
425 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
426 if(ALSOFT_CPUEXT_SSE4_1 AND HAVE_SSE3 AND HAVE_SMMINTRIN_H)
427     set(HAVE_SSE4_1 1)
428 endif()
429 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
430     message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
431 endif()
433 # Check for ARM Neon support
434 option(ALSOFT_CPUEXT_NEON "Enable ARM NEON support" ON)
435 option(ALSOFT_REQUIRE_NEON "Require ARM NEON support" OFF)
436 if(ALSOFT_CPUEXT_NEON AND HAVE_ARM_NEON_H)
437     check_c_source_compiles("#include <arm_neon.h>
438         int main()
439         {
440             int32x4_t ret4 = vdupq_n_s32(0);
441             return vgetq_lane_s32(ret4, 0);
442         }" HAVE_NEON_INTRINSICS)
443     if(HAVE_NEON_INTRINSICS)
444         set(HAVE_NEON 1)
445     endif()
446 endif()
447 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
448     message(FATAL_ERROR "Failed to enable required ARM NEON CPU extensions")
449 endif()
452 set(ALSOFT_FORCE_ALIGN )
453 set(SSE_FLAGS )
454 set(FPMATH_SET "0")
455 if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND HAVE_SSE2)
456     option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
457     if(ALSOFT_ENABLE_SSE2_CODEGEN)
458         if(MSVC)
459             check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
460             if(HAVE_ARCH_SSE2)
461                 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
462                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
463                 set(FPMATH_SET 2)
464             endif()
465         elseif(SSE2_SWITCH)
466             check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
467             if(HAVE_MFPMATH_SSE_2)
468                 set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
469                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
470                 set(FPMATH_SET 2)
471             endif()
472             # SSE depends on a 16-byte aligned stack, and by default, GCC
473             # assumes the stack is suitably aligned. Older Linux code or other
474             # OSs don't guarantee this on 32-bit, so externally-callable
475             # functions need to ensure an aligned stack.
476             set(EXPORT_DECL "${EXPORT_DECL}__attribute__((force_align_arg_pointer))")
477             set(ALSOFT_FORCE_ALIGN "__attribute__((force_align_arg_pointer))")
478         endif()
479     endif()
480 endif()
482 if(HAVE_SSE2)
483     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
484     foreach(flag_var ${SSE_FLAGS})
485         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
486     endforeach()
488     check_c_source_compiles("#include <emmintrin.h>
489         int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
491     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
492 endif()
495 check_include_file(cpuid.h HAVE_CPUID_H)
496 check_include_file(intrin.h HAVE_INTRIN_H)
497 check_include_file(guiddef.h HAVE_GUIDDEF_H)
499 # Some systems need libm for some math functions to work
500 set(MATH_LIB )
501 check_library_exists(m pow "" HAVE_LIBM)
502 if(HAVE_LIBM)
503     set(MATH_LIB ${MATH_LIB} m)
504     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
505 endif()
507 # Some systems need to link with -lrt for clock_gettime as used by the common
508 # eaxmple functions.
509 set(RT_LIB )
510 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
511 if(HAVE_LIBRT)
512     set(RT_LIB rt)
513 endif()
515 # Check for the dlopen API (for dynamically loading backend libs)
516 if(ALSOFT_DLOPEN)
517     check_include_file(dlfcn.h HAVE_DLFCN_H)
518     check_library_exists(dl dlopen "" HAVE_LIBDL)
519     if(HAVE_LIBDL)
520         set(EXTRA_LIBS dl ${EXTRA_LIBS})
521         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
522     endif()
523 endif()
525 # Check for a cpuid intrinsic
526 if(HAVE_CPUID_H)
527     check_c_source_compiles("#include <cpuid.h>
528         int main()
529         {
530             unsigned int eax, ebx, ecx, edx;
531             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
532         }" HAVE_GCC_GET_CPUID)
533 endif()
534 if(HAVE_INTRIN_H)
535     check_c_source_compiles("#include <intrin.h>
536         int main()
537         {
538             int regs[4];
539             __cpuid(regs, 0);
540             return regs[0];
541         }" HAVE_CPUID_INTRINSIC)
542 endif()
544 check_symbol_exists(proc_pidpath     libproc.h HAVE_PROC_PIDPATH)
546 if(NOT WIN32)
547     # We need pthreads outside of Windows, for semaphores. It's also used to
548     # set the priority and name of threads, when possible.
549     check_include_file(pthread.h HAVE_PTHREAD_H)
550     if(NOT HAVE_PTHREAD_H)
551         message(FATAL_ERROR "PThreads is required for non-Windows builds!")
552     endif()
554     check_c_compiler_flag(-pthread HAVE_PTHREAD)
555     if(HAVE_PTHREAD)
556         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
557         set(C_FLAGS ${C_FLAGS} -pthread)
558         set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
559     endif()
561     check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
563     # Some systems need pthread_np.h to get pthread_setname_np
564     check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
565     if(HAVE_PTHREAD_NP_H)
566         check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
567         if(NOT HAVE_PTHREAD_SETNAME_NP)
568             check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
569         endif()
570     else()
571         check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
572         if(NOT HAVE_PTHREAD_SETNAME_NP)
573             check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
574         endif()
575     endif()
576 endif()
579 # Common sources used by both the OpenAL implementation library, the OpenAL
580 # router, and certain tools and examples.
581 set(COMMON_OBJS
582     common/alassert.cpp
583     common/alassert.h
584     common/albit.h
585     common/alcomplex.cpp
586     common/alcomplex.h
587     common/almalloc.h
588     common/alnumbers.h
589     common/alnumeric.h
590     common/alsem.cpp
591     common/alsem.h
592     common/alspan.h
593     common/alstring.cpp
594     common/alstring.h
595     common/althrd_setname.cpp
596     common/althrd_setname.h
597     common/althreads.h
598     common/altraits.h
599     common/atomic.h
600     common/comptr.h
601     common/dynload.cpp
602     common/dynload.h
603     common/flexarray.h
604     common/intrusive_ptr.h
605     common/opthelpers.h
606     common/pffft.cpp
607     common/pffft.h
608     common/phase_shifter.h
609     common/polyphase_resampler.cpp
610     common/polyphase_resampler.h
611     common/pragmadefs.h
612     common/ringbuffer.cpp
613     common/ringbuffer.h
614     common/strutils.cpp
615     common/strutils.h
616     common/vecmat.h
617     common/vector.h)
619 # Core library routines
620 set(CORE_OBJS
621     core/ambdec.cpp
622     core/ambdec.h
623     core/ambidefs.cpp
624     core/ambidefs.h
625     core/async_event.h
626     core/bformatdec.cpp
627     core/bformatdec.h
628     core/bs2b.cpp
629     core/bs2b.h
630     core/bsinc_defs.h
631     core/bsinc_tables.cpp
632     core/bsinc_tables.h
633     core/bufferline.h
634     core/buffer_storage.cpp
635     core/buffer_storage.h
636     core/context.cpp
637     core/context.h
638     core/converter.cpp
639     core/converter.h
640     core/cpu_caps.cpp
641     core/cpu_caps.h
642     core/cubic_defs.h
643     core/cubic_tables.cpp
644     core/cubic_tables.h
645     core/devformat.cpp
646     core/devformat.h
647     core/device.cpp
648     core/device.h
649     core/effects/base.h
650     core/effectslot.cpp
651     core/effectslot.h
652     core/except.cpp
653     core/except.h
654     core/filters/biquad.h
655     core/filters/biquad.cpp
656     core/filters/nfc.cpp
657     core/filters/nfc.h
658     core/filters/splitter.cpp
659     core/filters/splitter.h
660     core/fmt_traits.cpp
661     core/fmt_traits.h
662     core/fpu_ctrl.cpp
663     core/fpu_ctrl.h
664     core/front_stablizer.h
665     core/helpers.cpp
666     core/helpers.h
667     core/hrtf.cpp
668     core/hrtf.h
669     core/logging.cpp
670     core/logging.h
671     core/mastering.cpp
672     core/mastering.h
673     core/mixer.cpp
674     core/mixer.h
675     core/resampler_limits.h
676     core/storage_formats.cpp
677     core/storage_formats.h
678     core/uhjfilter.cpp
679     core/uhjfilter.h
680     core/uiddefs.cpp
681     core/voice.cpp
682     core/voice.h
683     core/voice_change.h)
685 set(HAVE_RTKIT 0)
686 if(NOT WIN32)
687     option(ALSOFT_RTKIT "Enable RTKit support" ON)
688     option(ALSOFT_REQUIRE_RTKIT "Require RTKit/D-Bus support" FALSE)
689     if(ALSOFT_RTKIT)
690         find_package(DBus1 QUIET)
691         if(NOT DBus1_FOUND AND PkgConfig_FOUND)
692             pkg_check_modules(DBUS dbus-1)
693         endif()
694         if(DBus1_FOUND OR DBUS_FOUND)
695             set(HAVE_RTKIT 1)
696             set(CORE_OBJS ${CORE_OBJS} core/dbus_wrap.cpp core/dbus_wrap.h
697                 core/rtkit.cpp core/rtkit.h)
698             if(NOT DBus1_FOUND)
699                 set(INC_PATHS ${INC_PATHS} ${DBUS_INCLUDE_DIRS})
700                 set(CPP_DEFS ${CPP_DEFS} ${DBUS_CFLAGS_OTHER})
701                 if(NOT HAVE_DLFCN_H)
702                     set(EXTRA_LIBS ${EXTRA_LIBS} ${DBUS_LINK_LIBRARIES})
703                 endif()
704             elseif(HAVE_DLFCN_H)
705                 set(INC_PATHS ${INC_PATHS} ${DBus1_INCLUDE_DIRS})
706                 set(CPP_DEFS ${CPP_DEFS} ${DBus1_DEFINITIONS})
707             else()
708                 set(EXTRA_LIBS ${EXTRA_LIBS} ${DBus1_LIBRARIES})
709             endif()
710         endif()
711     else()
712         set(MISSING_VARS "")
713         if(NOT DBus1_INCLUDE_DIRS)
714             set(MISSING_VARS "${MISSING_VARS} DBus1_INCLUDE_DIRS")
715         endif()
716         if(NOT DBus1_LIBRARIES)
717             set(MISSING_VARS "${MISSING_VARS} DBus1_LIBRARIES")
718         endif()
719         message(STATUS "Could NOT find DBus1 (missing:${MISSING_VARS})")
720         unset(MISSING_VARS)
721     endif()
722 endif()
723 if(ALSOFT_REQUIRE_RTKIT AND NOT HAVE_RTKIT)
724     message(FATAL_ERROR "Failed to enable required RTKit support")
725 endif()
727 # Default mixers, always available
728 set(CORE_OBJS ${CORE_OBJS}
729     core/mixer/defs.h
730     core/mixer/hrtfbase.h
731     core/mixer/hrtfdefs.h
732     core/mixer/mixer_c.cpp)
734 # AL and related routines
735 set(OPENAL_OBJS
736     al/auxeffectslot.cpp
737     al/auxeffectslot.h
738     al/buffer.cpp
739     al/buffer.h
740     al/debug.cpp
741     al/debug.h
742     al/direct_defs.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/error.h
763     al/event.cpp
764     al/event.h
765     al/extension.cpp
766     al/filter.cpp
767     al/filter.h
768     al/listener.cpp
769     al/listener.h
770     al/source.cpp
771     al/source.h
772     al/state.cpp)
774 # ALC and related routines
775 set(ALC_OBJS
776     alc/alc.cpp
777     alc/alu.cpp
778     alc/alu.h
779     alc/alconfig.cpp
780     alc/alconfig.h
781     alc/context.cpp
782     alc/context.h
783     alc/device.cpp
784     alc/device.h
785     alc/effects/base.h
786     alc/effects/autowah.cpp
787     alc/effects/chorus.cpp
788     alc/effects/compressor.cpp
789     alc/effects/convolution.cpp
790     alc/effects/dedicated.cpp
791     alc/effects/distortion.cpp
792     alc/effects/echo.cpp
793     alc/effects/equalizer.cpp
794     alc/effects/fshifter.cpp
795     alc/effects/modulator.cpp
796     alc/effects/null.cpp
797     alc/effects/pshifter.cpp
798     alc/effects/reverb.cpp
799     alc/effects/vmorpher.cpp
800     alc/events.cpp
801     alc/events.h
802     alc/export_list.h
803     alc/inprogext.h
804     alc/panning.cpp)
806 if(ALSOFT_EAX)
807     set(OPENAL_OBJS
808         ${OPENAL_OBJS}
809         al/eax/api.cpp
810         al/eax/api.h
811         al/eax/call.cpp
812         al/eax/call.h
813         al/eax/effect.h
814         al/eax/exception.cpp
815         al/eax/exception.h
816         al/eax/fx_slot_index.cpp
817         al/eax/fx_slot_index.h
818         al/eax/fx_slots.cpp
819         al/eax/fx_slots.h
820         al/eax/globals.h
821         al/eax/utils.cpp
822         al/eax/utils.h
823         al/eax/x_ram.h
824     )
825 endif()
827 # Include SIMD mixers
828 set(CPU_EXTS "Default")
829 if(HAVE_SSE)
830     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse.cpp)
831     set(CPU_EXTS "${CPU_EXTS}, SSE")
832 endif()
833 if(HAVE_SSE2)
834     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse2.cpp)
835     set(CPU_EXTS "${CPU_EXTS}, SSE2")
836 endif()
837 if(HAVE_SSE3)
838     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse3.cpp)
839     set(CPU_EXTS "${CPU_EXTS}, SSE3")
840 endif()
841 if(HAVE_SSE4_1)
842     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse41.cpp)
843     set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
844 endif()
845 if(HAVE_NEON)
846     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_neon.cpp)
847     set(CPU_EXTS "${CPU_EXTS}, Neon")
848 endif()
851 set(HAVE_ALSA       0)
852 set(HAVE_OSS        0)
853 set(HAVE_PIPEWIRE   0)
854 set(HAVE_SOLARIS    0)
855 set(HAVE_SNDIO      0)
856 set(HAVE_DSOUND     0)
857 set(HAVE_WASAPI     0)
858 set(HAVE_WINMM      0)
859 set(HAVE_PORTAUDIO  0)
860 set(HAVE_PULSEAUDIO 0)
861 set(HAVE_COREAUDIO  0)
862 set(HAVE_OPENSL     0)
863 set(HAVE_OBOE       0)
864 set(HAVE_OTHERIO    0)
865 set(HAVE_WAVE       0)
866 set(HAVE_SDL2       0)
868 if(WIN32 OR HAVE_DLFCN_H)
869     set(IS_LINKED "")
870     macro(ADD_BACKEND_LIBS _LIBS)
871     endmacro()
872 else()
873     set(IS_LINKED " (linked)")
874     macro(ADD_BACKEND_LIBS _LIBS)
875         set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
876     endmacro()
877 endif()
879 set(BACKENDS "")
880 set(ALC_OBJS  ${ALC_OBJS}
881     alc/backends/base.cpp
882     alc/backends/base.h
883     # Default backends, always available
884     alc/backends/loopback.cpp
885     alc/backends/loopback.h
886     alc/backends/null.cpp
887     alc/backends/null.h
890 # Check PipeWire backend
891 option(ALSOFT_BACKEND_PIPEWIRE "Enable PipeWire backend" ON)
892 option(ALSOFT_REQUIRE_PIPEWIRE "Require PipeWire backend" OFF)
893 if(ALSOFT_BACKEND_PIPEWIRE AND PkgConfig_FOUND)
894     pkg_check_modules(PIPEWIRE libpipewire-0.3>=0.3.23)
895     if(PIPEWIRE_FOUND)
896         set(HAVE_PIPEWIRE 1)
897         set(BACKENDS  "${BACKENDS} PipeWire${IS_LINKED},")
898         set(ALC_OBJS  ${ALC_OBJS} alc/backends/pipewire.cpp alc/backends/pipewire.h)
899         add_backend_libs(${PIPEWIRE_LIBRARIES})
900         set(INC_PATHS ${INC_PATHS} ${PIPEWIRE_INCLUDE_DIRS})
901     endif()
902 endif()
903 if(ALSOFT_REQUIRE_PIPEWIRE AND NOT HAVE_PIPEWIRE)
904     message(FATAL_ERROR "Failed to enable required PipeWire backend")
905 endif()
907 # Check PulseAudio backend
908 option(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
909 option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
910 if(ALSOFT_BACKEND_PULSEAUDIO)
911     find_package(PulseAudio)
912     if(PULSEAUDIO_FOUND)
913         set(HAVE_PULSEAUDIO 1)
914         set(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
915         set(ALC_OBJS  ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
916         add_backend_libs(${PULSEAUDIO_LIBRARY})
917         set(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIR})
918     endif()
919 endif()
920 if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
921     message(FATAL_ERROR "Failed to enable required PulseAudio backend")
922 endif()
924 if(NOT WIN32)
925     # Check ALSA backend
926     option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
927     option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
928     if(ALSOFT_BACKEND_ALSA)
929         find_package(ALSA)
930         if(ALSA_FOUND)
931             set(HAVE_ALSA 1)
932             set(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
933             set(ALC_OBJS  ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
934             add_backend_libs(${ALSA_LIBRARIES})
935             set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
936         endif()
937     endif()
939     # Check OSS backend
940     option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
941     option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
942     if(ALSOFT_BACKEND_OSS)
943         find_package(OSS)
944         if(OSS_FOUND)
945             set(HAVE_OSS 1)
946             set(BACKENDS  "${BACKENDS} OSS,")
947             set(ALC_OBJS  ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
948             if(OSS_LIBRARIES)
949                 set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
950             endif()
951             set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
952         endif()
953     endif()
955     # Check Solaris backend
956     option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
957     option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
958     if(ALSOFT_BACKEND_SOLARIS)
959         find_package(AudioIO)
960         if(AUDIOIO_FOUND)
961             set(HAVE_SOLARIS 1)
962             set(BACKENDS  "${BACKENDS} Solaris,")
963             set(ALC_OBJS  ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
964             set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
965         endif()
966     endif()
968     # Check SndIO backend (disabled by default on non-BSDs)
969     if(BSD)
970         option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
971     else()
972         option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" OFF)
973     endif()
974     option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
975     if(ALSOFT_BACKEND_SNDIO)
976         find_package(SndIO)
977         if(SNDIO_FOUND)
978             set(HAVE_SNDIO 1)
979             set(BACKENDS  "${BACKENDS} SndIO (linked),")
980             set(ALC_OBJS  ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
981             set(EXTRA_LIBS ${SNDIO_LIBRARIES} ${EXTRA_LIBS})
982             set(INC_PATHS ${INC_PATHS} ${SNDIO_INCLUDE_DIRS})
983         endif()
984     endif()
985 endif()
986 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
987     message(FATAL_ERROR "Failed to enable required ALSA backend")
988 endif()
989 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
990     message(FATAL_ERROR "Failed to enable required OSS backend")
991 endif()
992 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
993     message(FATAL_ERROR "Failed to enable required Solaris backend")
994 endif()
995 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
996     message(FATAL_ERROR "Failed to enable required SndIO backend")
997 endif()
999 # Check Windows-only backends
1000 if(WIN32)
1001     if (NOT ALSOFT_UWP)
1002         # Check MMSystem backend
1003         option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
1004         option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
1005         if(ALSOFT_BACKEND_WINMM)
1006             set(HAVE_WINMM 1)
1007             set(BACKENDS "${BACKENDS} WinMM,")
1008             set(ALC_OBJS ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
1009             # There doesn't seem to be good way to search for winmm.lib for MSVC.
1010             # find_library doesn't find it without being told to look in a specific
1011             # place in the WindowsSDK, but it links anyway. If there ends up being
1012             # Windows targets without this, another means to detect it is needed.
1013             set(EXTRA_LIBS winmm ${EXTRA_LIBS})
1014         endif()
1016         # Check DSound backend
1017         option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
1018         option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
1019         if(ALSOFT_BACKEND_DSOUND)
1020             check_include_file(dsound.h HAVE_DSOUND_H)
1021             if(DXSDK_DIR)
1022                 find_path(DSOUND_INCLUDE_DIR NAMES "dsound.h"
1023                     PATHS "${DXSDK_DIR}" PATH_SUFFIXES include
1024                     DOC "The DirectSound include directory")
1025             endif()
1026             if(HAVE_DSOUND_H OR DSOUND_INCLUDE_DIR)
1027                 set(HAVE_DSOUND 1)
1028                 set(BACKENDS "${BACKENDS} DirectSound,")
1029                 set(ALC_OBJS ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
1031                 if(NOT HAVE_DSOUND_H)
1032                     set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIR})
1033                 endif()
1034             endif()
1035         endif()
1036     endif()
1038     # Check for WASAPI backend
1039     option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
1040     option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
1041     if(ALSOFT_BACKEND_WASAPI)
1042         check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1043         if(HAVE_MMDEVICEAPI_H)
1044             set(HAVE_WASAPI 1)
1045             set(BACKENDS  "${BACKENDS} WASAPI,")
1046             set(ALC_OBJS  ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
1048             if(NOT ALSOFT_UWP)
1049                 set(EXTRA_LIBS avrt ${EXTRA_LIBS})
1050             endif()
1051         endif()
1052     endif()
1054     option(ALSOFT_BACKEND_OTHERIO "Enable OtherIO backend" OFF)
1055     option(ALSOFT_REQUIRE_OTHERIO "Require OtherIO backend" OFF)
1056     if(ALSOFT_BACKEND_OTHERIO)
1057         set(HAVE_OTHERIO 1)
1058         set(BACKENDS  "${BACKENDS} OtherIO,")
1059         set(ALC_OBJS  ${ALC_OBJS} alc/backends/otherio.cpp alc/backends/otherio.h)
1060     endif()
1061 endif()
1062 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1063     message(FATAL_ERROR "Failed to enable required WinMM backend")
1064 endif()
1065 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1066     message(FATAL_ERROR "Failed to enable required DSound backend")
1067 endif()
1068 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
1069     message(FATAL_ERROR "Failed to enable required WASAPI backend")
1070 endif()
1071 if(ALSOFT_REQUIRE_OTHERIO AND NOT HAVE_OTHERIO)
1072     message(FATAL_ERROR "Failed to enable required OtherIO backend")
1073 endif()
1075 # Check JACK backend
1076 option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1077 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1078 if(ALSOFT_BACKEND_JACK)
1079     find_package(JACK)
1080     if(JACK_FOUND)
1081         set(HAVE_JACK 1)
1082         set(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1083         set(ALC_OBJS  ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
1084         add_backend_libs(${JACK_LIBRARIES})
1085         set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1086     endif()
1087 endif()
1088 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1089     message(FATAL_ERROR "Failed to enable required JACK backend")
1090 endif()
1092 # Check CoreAudio backend
1093 option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1094 option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1095 if(ALSOFT_BACKEND_COREAUDIO)
1096     find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
1097     find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
1098     if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
1099         set(HAVE_COREAUDIO 1)
1100         set(ALC_OBJS  ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
1101         set(BACKENDS  "${BACKENDS} CoreAudio,")
1103         set(EXTRA_LIBS -Wl,-framework,CoreAudio ${EXTRA_LIBS})
1104         if(CMAKE_SYSTEM_NAME MATCHES "^(iOS|tvOS)$")
1105             find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
1106             if(COREFOUNDATION_FRAMEWORK)
1107                 set(EXTRA_LIBS -Wl,-framework,CoreFoundation ${EXTRA_LIBS})
1108             endif()
1109         else()
1110             set(EXTRA_LIBS -Wl,-framework,AudioUnit,-framework,ApplicationServices ${EXTRA_LIBS})
1111         endif()
1113         # Some versions of OSX may need the AudioToolbox framework. Add it if
1114         # it's found.
1115         find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
1116         if(AUDIOTOOLBOX_LIBRARY)
1117             set(EXTRA_LIBS -Wl,-framework,AudioToolbox ${EXTRA_LIBS})
1118         endif()
1120         set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
1121     endif()
1122 endif()
1123 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1124     message(FATAL_ERROR "Failed to enable required CoreAudio backend")
1125 endif()
1127 # Check for Oboe (Android) backend
1128 option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1129 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1130 if(ALSOFT_BACKEND_OBOE)
1131     set(OBOE_TARGET )
1132     if(ANDROID)
1133         set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1134         if(OBOE_SOURCE)
1135             add_subdirectory(${OBOE_SOURCE} ./oboe EXCLUDE_FROM_ALL)
1136             set(OBOE_TARGET oboe)
1137         else()
1138             find_package(oboe CONFIG)
1139             if(NOT TARGET oboe::oboe)
1140                 find_package(Oboe)
1141             endif()
1142             if(TARGET oboe::oboe)
1143                 set(OBOE_TARGET "oboe::oboe")
1144             endif()
1145         endif()
1146     endif()
1148     if(OBOE_TARGET)
1149         set(HAVE_OBOE 1)
1150         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
1151         set(BACKENDS  "${BACKENDS} Oboe,")
1152         set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
1153     endif()
1154 endif()
1155 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1156     message(FATAL_ERROR "Failed to enable required Oboe backend")
1157 endif()
1159 # Check for OpenSL (Android) backend
1160 option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1161 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1162 if(ALSOFT_BACKEND_OPENSL)
1163     find_package(OpenSL)
1164     if(OPENSL_FOUND)
1165         set(HAVE_OPENSL 1)
1166         set(ALC_OBJS  ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1167         set(BACKENDS  "${BACKENDS} OpenSL,")
1168         set(EXTRA_LIBS ${OPENSL_LIBRARIES} ${EXTRA_LIBS})
1169         set(INC_PATHS ${INC_PATHS} ${OPENSL_INCLUDE_DIRS})
1170     endif()
1171 endif()
1172 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1173     message(FATAL_ERROR "Failed to enable required OpenSL backend")
1174 endif()
1176 # Check PortAudio backend
1177 option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1178 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1179 if(ALSOFT_BACKEND_PORTAUDIO)
1180     find_package(PortAudio)
1181     if(PORTAUDIO_FOUND)
1182         set(HAVE_PORTAUDIO 1)
1183         set(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
1184         set(ALC_OBJS  ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
1185         add_backend_libs(${PORTAUDIO_LIBRARIES})
1186         set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
1187     endif()
1188 endif()
1189 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1190     message(FATAL_ERROR "Failed to enable required PortAudio backend")
1191 endif()
1193 # Check for SDL2 backend
1194 # Off by default, since it adds a runtime dependency
1195 option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1196 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1197 if(ALSOFT_BACKEND_SDL2)
1198     if(SDL2_FOUND)
1199         set(HAVE_SDL2 1)
1200         set(ALC_OBJS  ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1201         set(BACKENDS  "${BACKENDS} SDL2,")
1202         set(EXTRA_LIBS ${EXTRA_LIBS} SDL2::SDL2)
1203     else()
1204         message(STATUS "Could NOT find SDL2")
1205     endif()
1206 endif()
1207 if(ALSOFT_REQUIRE_SDL2 AND NOT HAVE_SDL2)
1208     message(FATAL_ERROR "Failed to enable required SDL2 backend")
1209 endif()
1211 # Optionally enable the Wave Writer backend
1212 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1213 if(ALSOFT_BACKEND_WAVE)
1214     set(HAVE_WAVE 1)
1215     set(ALC_OBJS  ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1216     set(BACKENDS  "${BACKENDS} WaveFile,")
1217 endif()
1219 # This is always available
1220 set(BACKENDS  "${BACKENDS} Null")
1223 find_package(Git)
1224 if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1225     set(GIT_DIR "${OpenAL_SOURCE_DIR}/.git")
1227     # Check if this is a submodule, if it is then find the .git directory
1228     if(NOT IS_DIRECTORY "${OpenAL_SOURCE_DIR}/.git")
1229         file(READ ${GIT_DIR} submodule)
1230         string(REGEX REPLACE "gitdir: (.*)$" "\\1" GIT_DIR_RELATIVE ${submodule})
1231         string(STRIP ${GIT_DIR_RELATIVE} GIT_DIR_RELATIVE)
1232         get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
1233         get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
1234     endif()
1236     # Get the current working branch and its latest abbreviated commit hash
1237     add_custom_command(OUTPUT "${OpenAL_BINARY_DIR}/version_witness.txt"
1238         BYPRODUCTS "${OpenAL_BINARY_DIR}/version.h"
1239         COMMAND ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1240             -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1241             -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1242         COMMAND ${CMAKE_COMMAND} -E touch "${OpenAL_BINARY_DIR}/version_witness.txt"
1243         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1244         MAIN_DEPENDENCY "${OpenAL_SOURCE_DIR}/version.h.in"
1245         DEPENDS "${GIT_DIR}/index" "${OpenAL_SOURCE_DIR}/version.cmake"
1246         VERBATIM
1247     )
1249     add_custom_target(alsoft.build_version DEPENDS "${OpenAL_BINARY_DIR}/version_witness.txt")
1250 else()
1251     set(GIT_BRANCH "UNKNOWN")
1252     set(GIT_COMMIT_HASH "unknown")
1253     configure_file(
1254         "${OpenAL_SOURCE_DIR}/version.h.in"
1255         "${OpenAL_BINARY_DIR}/version.h")
1256 endif()
1259 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1260 if(ALSOFT_EMBED_HRTF_DATA)
1261     macro(make_hrtf_header FILENAME VARNAME)
1262         set(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1263         set(outfile  "${OpenAL_BINARY_DIR}/${VARNAME}.txt")
1265         add_custom_command(OUTPUT "${outfile}"
1266             COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
1267                 -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1268             WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1269             DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1270             VERBATIM
1271         )
1272         set(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1273     endmacro()
1275     make_hrtf_header("Default HRTF.mhr" "default_hrtf")
1276 endif()
1279 if(ALSOFT_UTILS)
1280     find_package(MySOFA)
1281     if(NOT ALSOFT_NO_CONFIG_UTIL)
1282         find_package(Qt5Widgets QUIET)
1283         if(NOT Qt5Widgets_FOUND)
1284             message(STATUS "Could NOT find Qt5Widgets")
1285         endif()
1286     endif()
1287 endif()
1288 if(ALSOFT_UTILS OR ALSOFT_EXAMPLES)
1289     find_package(SndFile)
1290     if(SDL2_FOUND)
1291         find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1292     endif()
1293 endif()
1295 if(NOT WIN32)
1296     set(LIBNAME "openal")
1297 else()
1298     set(LIBNAME "OpenAL32")
1299 endif()
1301 # Needed for openal.pc.in
1302 set(prefix ${CMAKE_INSTALL_PREFIX})
1303 set(exec_prefix "\${prefix}")
1304 set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
1305 set(bindir "${CMAKE_INSTALL_FULL_BINDIR}")
1306 set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
1307 set(PACKAGE_VERSION "${LIB_VERSION}")
1308 set(PKG_CONFIG_CFLAGS )
1309 set(PKG_CONFIG_PRIVATE_LIBS )
1310 if(LIBTYPE STREQUAL "STATIC")
1311     set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1312     foreach(FLAG  ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1313         # If this is already a linker flag, or is a full path+file, add it
1314         # as-is. If it's an SDL2 target, add the link flag for it. Otherwise,
1315         # it's a name intended to be dressed as -lname.
1316         if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1317             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1318         elseif(FLAG MATCHES "^SDL2::SDL2")
1319             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -lSDL2")
1320         else()
1321             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1322         endif()
1323     endforeach()
1324 endif()
1326 # End configuration
1327 configure_file(
1328     "${OpenAL_SOURCE_DIR}/config.h.in"
1329     "${OpenAL_BINARY_DIR}/config.h")
1330 configure_file(
1331     "${OpenAL_SOURCE_DIR}/config_backends.h.in"
1332     "${OpenAL_BINARY_DIR}/config_backends.h")
1333 configure_file(
1334     "${OpenAL_SOURCE_DIR}/config_simd.h.in"
1335     "${OpenAL_BINARY_DIR}/config_simd.h")
1336 configure_file(
1337     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1338     "${OpenAL_BINARY_DIR}/openal.pc"
1339     @ONLY)
1342 add_library(alsoft.common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1343 target_include_directories(alsoft.common PRIVATE ${OpenAL_SOURCE_DIR}/include
1344     PUBLIC ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1345 target_compile_definitions(alsoft.common PRIVATE ${CPP_DEFS})
1346 target_compile_options(alsoft.common PRIVATE ${C_FLAGS})
1347 set_target_properties(alsoft.common 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 alsoft.common ${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 alsoft.build_version)
1394             add_dependencies(OpenAL alsoft.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 alsoft.common ${LINKER_FLAGS} ${EXTRA_LIBS}
1414         ${MATH_LIB})
1416     if(ALSOFT_UWP)
1417         set(ALSOFT_CPPWINRT_VERSION "2.0.230706.1" CACHE STRING "The soft-oal default cppwinrt version")
1418         
1419         find_program(NUGET_EXE NAMES nuget)
1420         if(NOT NUGET_EXE)
1421             message("NUGET.EXE not found.")
1422             message(FATAL_ERROR "Please install this executable, and run CMake again.")
1423         endif()
1425         exec_program(${NUGET_EXE}
1426             ARGS install "Microsoft.Windows.CppWinRT" -Version ${ALSOFT_CPPWINRT_VERSION} -ExcludeVersion -OutputDirectory "\"${CMAKE_BINARY_DIR}/packages\"")
1428         set_target_properties(${IMPL_TARGET} PROPERTIES
1429             VS_PROJECT_IMPORT ${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.CppWinRT/build/native/Microsoft.Windows.CppWinRT.props
1430         )
1431         target_link_libraries(${IMPL_TARGET} PRIVATE ${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.CppWinRT/build/native/Microsoft.Windows.CppWinRT.targets)
1432     endif()
1434     if(NOT WIN32 AND NOT APPLE)
1435         # FIXME: This doesn't put a dependency on the version script. Changing
1436         # the version script will not cause a relink as it should.
1437         target_link_options(${IMPL_TARGET} PRIVATE
1438             "-Wl,--version-script=${OpenAL_SOURCE_DIR}/libopenal.version")
1439     endif()
1441     if(APPLE AND ALSOFT_OSX_FRAMEWORK)
1442         # Sets framework name to soft_oal to avoid ambiguity with the system OpenAL.framework
1443         set(LIBNAME "soft_oal")
1444         if(GIT_FOUND)
1445             execute_process(COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD
1446                 TIMEOUT 5
1447                 OUTPUT_VARIABLE BUNDLE_VERSION
1448                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1449         else()
1450             set(BUNDLE_VERSION 1)
1451         endif()
1453         # Build: Fix rpath in iOS shared libraries
1454         # If this flag is not set, the final dylib binary ld path will be
1455         # /User/xxx/*/soft_oal.framework/soft_oal, which can't be loaded by iOS devices.
1456         # See also: https://github.com/libjpeg-turbo/libjpeg-turbo/commit/c80ddef7a4ce21ace9e3ca0fd190d320cc8cdaeb
1457         if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
1458             set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
1459         endif()
1461         set_target_properties(${IMPL_TARGET} PROPERTIES
1462             FRAMEWORK TRUE
1463             FRAMEWORK_VERSION C
1464             MACOSX_FRAMEWORK_NAME "${IMPL_TARGET}"
1465             MACOSX_FRAMEWORK_IDENTIFIER "org.openal-soft.openal"
1466             MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${LIB_VERSION}"
1467             MACOSX_FRAMEWORK_BUNDLE_VERSION "${BUNDLE_VERSION}"
1468             XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
1469             XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
1470             XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
1471             PUBLIC_HEADER "${TARGET_PUBLIC_HEADERS}"
1472             MACOSX_RPATH TRUE)
1473     endif()
1474 endif()
1476 target_include_directories(${IMPL_TARGET}
1477   PUBLIC
1478     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1479   INTERFACE
1480     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include/AL>
1481     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1482     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/AL>
1483   PRIVATE
1484     ${INC_PATHS}
1485     ${OpenAL_BINARY_DIR}
1486     ${OpenAL_SOURCE_DIR}
1487     ${OpenAL_SOURCE_DIR}/common
1490 set_target_properties(${IMPL_TARGET} PROPERTIES ${DEFAULT_TARGET_PROPS}
1491     OUTPUT_NAME ${LIBNAME}
1492     VERSION ${LIB_VERSION}
1493     SOVERSION ${LIB_MAJOR_VERSION}
1495 target_compile_definitions(${IMPL_TARGET}
1496     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES  "ALC_API=${EXPORT_DECL}" "AL_API=${EXPORT_DECL}"
1497     ${CPP_DEFS})
1498 target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1500 if(TARGET alsoft.build_version)
1501     add_dependencies(${IMPL_TARGET} alsoft.build_version)
1502 endif()
1504 if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1505     find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
1506     if(NOT SED_EXECUTABLE OR NOT CMAKE_DLLTOOL)
1507         message(STATUS "")
1508         if(NOT SED_EXECUTABLE)
1509             message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1510         endif()
1511         if(NOT CMAKE_DLLTOOL)
1512             message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1513         endif()
1514     else()
1515         target_link_options(OpenAL PRIVATE "-Wl,--output-def,${PROJECT_BINARY_DIR}/OpenAL32.def")
1516         add_custom_command(TARGET OpenAL POST_BUILD
1517             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1518             COMMAND "${CMAKE_DLLTOOL}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1519             # Technically OpenAL32.def was created by the build, but cmake
1520             # doesn't recognize it due to -Wl,--output-def,OpenAL32.def being
1521             # manually specified. But declaring the file here allows it to be
1522             # properly cleaned, e.g. during make clean.
1523             BYPRODUCTS OpenAL32.def OpenAL32.lib
1524             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1525             VERBATIM
1526         )
1527     endif()
1528 endif()
1530 if(HAS_ROUTER)
1531     message(STATUS "")
1532     message(STATUS "Building DLL router")
1533 endif()
1535 message(STATUS "")
1536 message(STATUS "Building OpenAL with support for the following backends:")
1537 message(STATUS "   ${BACKENDS}")
1538 message(STATUS "")
1539 message(STATUS "Building with support for CPU extensions:")
1540 message(STATUS "    ${CPU_EXTS}")
1541 message(STATUS "")
1542 if(FPMATH_SET)
1543     message(STATUS "Building with SSE${FPMATH_SET} codegen")
1544     message(STATUS "")
1545 endif()
1546 if(ALSOFT_UWP)
1547     message(STATUS "Building with UWP support")
1548     message(STATUS "")
1549 endif()
1550 if(ALSOFT_EAX)
1551     message(STATUS "Building with legacy EAX extension support")
1552     message(STATUS "")
1553 endif()
1555 if(ALSOFT_EMBED_HRTF_DATA)
1556     message(STATUS "Embedding HRTF datasets")
1557     message(STATUS "")
1558 endif()
1560 # An alias for sub-project builds
1561 add_library(OpenAL::OpenAL ALIAS OpenAL)
1563 # Install main library
1564 if(ALSOFT_INSTALL)
1565     configure_package_config_file(OpenALConfig.cmake.in OpenALConfig.cmake
1566         INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL)
1567     install(TARGETS OpenAL EXPORT OpenAL
1568         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1569         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1570         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1571         FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
1572         INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1573     export(TARGETS OpenAL
1574         NAMESPACE OpenAL::
1575         FILE OpenALTargets.cmake)
1576     install(EXPORT OpenAL
1577         DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1578         NAMESPACE OpenAL::
1579         FILE OpenALTargets.cmake)
1580     install(DIRECTORY include/AL
1581         DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1582     install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1583         DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1584     install(FILES "${OpenAL_BINARY_DIR}/OpenALConfig.cmake"
1585         DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL")
1586     if(TARGET soft_oal)
1587         install(TARGETS soft_oal
1588             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1589     endif()
1590     message(STATUS "Installing library and headers")
1591 else()
1592     message(STATUS "NOT installing library and headers")
1593 endif()
1595 if(ALSOFT_INSTALL_CONFIG)
1596     install(FILES alsoftrc.sample
1597         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1598     message(STATUS "Installing sample configuration")
1599 endif()
1601 if(ALSOFT_INSTALL_HRTF_DATA)
1602     install(DIRECTORY hrtf
1603         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1604     message(STATUS "Installing HRTF data files")
1605 endif()
1607 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1608     install(DIRECTORY presets
1609         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1610     message(STATUS "Installing AmbDec presets")
1611 endif()
1612 message(STATUS "")
1614 set(UNICODE_FLAG )
1615 if(MINGW)
1616     set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1617 endif()
1618 set(EXTRA_INSTALLS )
1619 if(ALSOFT_UTILS)
1620     add_executable(openal-info utils/openal-info.c)
1621     target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1622     target_compile_options(openal-info PRIVATE ${C_FLAGS})
1623     target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
1624     set_target_properties(openal-info PROPERTIES ${DEFAULT_TARGET_PROPS})
1625     if(ALSOFT_INSTALL_EXAMPLES)
1626         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
1627     endif()
1629     if(SNDFILE_FOUND)
1630         add_executable(uhjdecoder utils/uhjdecoder.cpp)
1631         target_compile_definitions(uhjdecoder PRIVATE ${CPP_DEFS})
1632         target_include_directories(uhjdecoder
1633             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1634         target_compile_options(uhjdecoder PRIVATE ${C_FLAGS})
1635         target_link_libraries(uhjdecoder PUBLIC alsoft.common
1636             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1637         set_target_properties(uhjdecoder PROPERTIES ${DEFAULT_TARGET_PROPS})
1639         add_executable(uhjencoder utils/uhjencoder.cpp)
1640         target_compile_definitions(uhjencoder PRIVATE ${CPP_DEFS})
1641         target_include_directories(uhjencoder
1642             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1643         target_compile_options(uhjencoder PRIVATE ${C_FLAGS})
1644         target_link_libraries(uhjencoder PUBLIC alsoft.common
1645             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1646         set_target_properties(uhjencoder PROPERTIES ${DEFAULT_TARGET_PROPS})
1647     endif()
1649     if(MYSOFA_FOUND)
1650         set(SOFA_SUPPORT_SRCS
1651             utils/sofa-support.cpp
1652             utils/sofa-support.h)
1653         add_library(alsoft.sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
1654         target_compile_definitions(alsoft.sofa-support PRIVATE ${CPP_DEFS})
1655         target_include_directories(alsoft.sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
1656         target_compile_options(alsoft.sofa-support PRIVATE ${C_FLAGS})
1657         target_link_libraries(alsoft.sofa-support PUBLIC alsoft.common MySOFA::MySOFA
1658             PRIVATE ${LINKER_FLAGS})
1659         set_target_properties(alsoft.sofa-support PROPERTIES ${DEFAULT_TARGET_PROPS})
1661         set(MAKEMHR_SRCS
1662             utils/makemhr/loaddef.cpp
1663             utils/makemhr/loaddef.h
1664             utils/makemhr/loadsofa.cpp
1665             utils/makemhr/loadsofa.h
1666             utils/makemhr/makemhr.cpp
1667             utils/makemhr/makemhr.h)
1668         add_executable(makemhr ${MAKEMHR_SRCS})
1669         target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1670         target_include_directories(makemhr
1671             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
1672         target_compile_options(makemhr PRIVATE ${C_FLAGS})
1673         target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} alsoft.sofa-support ${UNICODE_FLAG})
1674         set_target_properties(makemhr PROPERTIES ${DEFAULT_TARGET_PROPS})
1675         if(ALSOFT_INSTALL_EXAMPLES)
1676             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
1677         endif()
1679         set(SOFAINFO_SRCS  utils/sofa-info.cpp)
1680         add_executable(sofa-info ${SOFAINFO_SRCS})
1681         target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1682         target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
1683         target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1684         target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} alsoft.sofa-support
1685             ${UNICODE_FLAG})
1686         set_target_properties(sofa-info PROPERTIES ${DEFAULT_TARGET_PROPS})
1687     endif()
1688     message(STATUS "Building utility programs")
1690     if(NOT ALSOFT_NO_CONFIG_UTIL)
1691         add_subdirectory(utils/alsoft-config)
1692     endif()
1693     message(STATUS "")
1694 endif()
1697 # Add a static library with common functions used by multiple example targets
1698 add_library(alsoft.excommon STATIC EXCLUDE_FROM_ALL
1699     examples/common/alhelpers.c
1700     examples/common/alhelpers.h)
1701 target_compile_definitions(alsoft.excommon PUBLIC ${CPP_DEFS})
1702 target_include_directories(alsoft.excommon PUBLIC ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1703 target_compile_options(alsoft.excommon PUBLIC ${C_FLAGS})
1704 target_link_libraries(alsoft.excommon PUBLIC OpenAL PRIVATE ${RT_LIB})
1705 set_target_properties(alsoft.excommon PROPERTIES ${DEFAULT_TARGET_PROPS})
1707 if(ALSOFT_EXAMPLES)
1708     add_executable(altonegen examples/altonegen.c)
1709     target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} alsoft.excommon
1710         ${UNICODE_FLAG})
1711     set_target_properties(altonegen PROPERTIES ${DEFAULT_TARGET_PROPS})
1713     add_executable(alrecord examples/alrecord.c)
1714     target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} alsoft.excommon ${UNICODE_FLAG})
1715     set_target_properties(alrecord PROPERTIES ${DEFAULT_TARGET_PROPS})
1717     add_executable(aldebug examples/aldebug.cpp)
1718     target_link_libraries(aldebug PRIVATE ${LINKER_FLAGS} alsoft.excommon ${UNICODE_FLAG})
1719     set_target_properties(aldebug PROPERTIES ${DEFAULT_TARGET_PROPS})
1721     add_executable(allafplay examples/allafplay.cpp)
1722     target_link_libraries(allafplay PRIVATE ${LINKER_FLAGS} alsoft.common alsoft.excommon
1723         ${UNICODE_FLAG})
1724     set_target_properties(allafplay PROPERTIES ${DEFAULT_TARGET_PROPS})
1726     if(ALSOFT_INSTALL_EXAMPLES)
1727         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord aldebug allafplay)
1728     endif()
1730     message(STATUS "Building example programs")
1732     if(SNDFILE_FOUND)
1733         add_executable(alplay examples/alplay.c)
1734         target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile alsoft.excommon
1735             ${UNICODE_FLAG})
1736         set_target_properties(alplay PROPERTIES ${DEFAULT_TARGET_PROPS})
1738         add_executable(alstream examples/alstream.c)
1739         target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile alsoft.excommon
1740             ${UNICODE_FLAG})
1741         set_target_properties(alstream PROPERTIES ${DEFAULT_TARGET_PROPS})
1743         add_executable(alreverb examples/alreverb.c)
1744         target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile alsoft.excommon
1745             ${UNICODE_FLAG})
1746         set_target_properties(alreverb PROPERTIES ${DEFAULT_TARGET_PROPS})
1748         add_executable(almultireverb examples/almultireverb.c)
1749         target_link_libraries(almultireverb
1750             PRIVATE ${LINKER_FLAGS} SndFile::SndFile alsoft.excommon ${MATH_LIB} ${UNICODE_FLAG})
1751         set_target_properties(almultireverb PROPERTIES ${DEFAULT_TARGET_PROPS})
1753         add_executable(allatency examples/allatency.c)
1754         target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile alsoft.excommon
1755             ${UNICODE_FLAG})
1756         set_target_properties(allatency PROPERTIES ${DEFAULT_TARGET_PROPS})
1758         add_executable(alhrtf examples/alhrtf.c)
1759         target_link_libraries(alhrtf
1760             PRIVATE ${LINKER_FLAGS} SndFile::SndFile alsoft.excommon ${MATH_LIB} ${UNICODE_FLAG})
1761         set_target_properties(alhrtf PROPERTIES ${DEFAULT_TARGET_PROPS})
1763         add_executable(alstreamcb examples/alstreamcb.cpp)
1764         target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile alsoft.excommon
1765             ${UNICODE_FLAG})
1766         set_target_properties(alstreamcb PROPERTIES ${DEFAULT_TARGET_PROPS})
1768         add_executable(aldirect examples/aldirect.cpp)
1769         target_link_libraries(aldirect PRIVATE ${LINKER_FLAGS} SndFile::SndFile alsoft.excommon
1770             ${UNICODE_FLAG})
1771         set_target_properties(aldirect PROPERTIES ${DEFAULT_TARGET_PROPS})
1773         add_executable(alconvolve examples/alconvolve.c)
1774         target_link_libraries(alconvolve PRIVATE ${LINKER_FLAGS} alsoft.common SndFile::SndFile
1775             alsoft.excommon ${UNICODE_FLAG})
1776         set_target_properties(alconvolve PROPERTIES ${DEFAULT_TARGET_PROPS})
1778         if(ALSOFT_INSTALL_EXAMPLES)
1779             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1780                 alhrtf aldirect)
1781         endif()
1783         message(STATUS "Building SndFile example programs")
1784     endif()
1786     if(SDL2_FOUND)
1787         add_executable(alloopback examples/alloopback.c)
1788         target_link_libraries(alloopback
1789             PRIVATE ${LINKER_FLAGS} SDL2::SDL2 alsoft.excommon ${MATH_LIB})
1790         set_target_properties(alloopback PROPERTIES ${DEFAULT_TARGET_PROPS})
1792         if(ALSOFT_INSTALL_EXAMPLES)
1793             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
1794         endif()
1796         message(STATUS "Building SDL example programs")
1798         set(FFVER_OK FALSE)
1799         if(FFMPEG_FOUND)
1800             set(FFVER_OK TRUE)
1801             if(AVFORMAT_VERSION VERSION_LESS "59.27.100")
1802                 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 59.27.100)")
1803                 set(FFVER_OK FALSE)
1804             endif()
1805             if(AVCODEC_VERSION VERSION_LESS "59.37.100")
1806                 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 59.37.100)")
1807                 set(FFVER_OK FALSE)
1808             endif()
1809             if(AVUTIL_VERSION VERSION_LESS "57.28.100")
1810                 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 57.28.100)")
1811                 set(FFVER_OK FALSE)
1812             endif()
1813             if(SWSCALE_VERSION VERSION_LESS "6.7.100")
1814                 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 6.7.100)")
1815                 set(FFVER_OK FALSE)
1816             endif()
1817             if(SWRESAMPLE_VERSION VERSION_LESS "4.7.100")
1818                 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 4.7.100)")
1819                 set(FFVER_OK FALSE)
1820             endif()
1821         endif()
1822         if(FFVER_OK)
1823             add_executable(alffplay examples/alffplay.cpp)
1824             target_include_directories(alffplay PRIVATE ${FFMPEG_INCLUDE_DIRS})
1825             target_link_libraries(alffplay
1826                 PRIVATE ${LINKER_FLAGS} SDL2::SDL2 ${FFMPEG_LIBRARIES} alsoft.excommon)
1827             set_target_properties(alffplay PROPERTIES ${DEFAULT_TARGET_PROPS})
1829             if(ALSOFT_INSTALL_EXAMPLES)
1830                 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
1831             endif()
1832             message(STATUS "Building SDL+FFmpeg example programs")
1833         endif()
1834     endif()
1835     message(STATUS "")
1836 endif()
1838 if (ALSOFT_TESTS)
1839 add_subdirectory(tests)
1840 endif()
1842 if(EXTRA_INSTALLS)
1843     install(TARGETS ${EXTRA_INSTALLS}
1844         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1845         BUNDLE  DESTINATION ${CMAKE_INSTALL_BINDIR}
1846         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1847         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1848 endif()