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