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