Use an inline function instead of a function-like macro
[openal-soft.git] / CMakeLists.txt
blob4442fdb5d5fae8f83904b3261ae81359f1e6f579
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 option(ALSOFT_SEARCH_INSTALL_DATADIR "Search the installation data directory" OFF)
101 if(ALSOFT_SEARCH_INSTALL_DATADIR)
102     set(ALSOFT_INSTALL_DATADIR ${CMAKE_INSTALL_FULL_DATADIR})
103 endif()
105 if(DEFINED SHARE_INSTALL_DIR)
106     message(WARNING "SHARE_INSTALL_DIR is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
107     set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
108 endif()
110 if(DEFINED LIB_SUFFIX)
111     message(WARNING "LIB_SUFFIX is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
112 endif()
113 if(DEFINED ALSOFT_CONFIG)
114     message(WARNING "ALSOFT_CONFIG is deprecated. Use ALSOFT_INSTALL_CONFIG instead")
115 endif()
116 if(DEFINED ALSOFT_HRTF_DEFS)
117     message(WARNING "ALSOFT_HRTF_DEFS is deprecated. Use ALSOFT_INSTALL_HRTF_DATA instead")
118 endif()
119 if(DEFINED ALSOFT_AMBDEC_PRESETS)
120     message(WARNING "ALSOFT_AMBDEC_PRESETS is deprecated. Use ALSOFT_INSTALL_AMBDEC_PRESETS instead")
121 endif()
124 set(CPP_DEFS ) # C pre-processor, not C++
125 set(INC_PATHS )
126 set(C_FLAGS )
127 set(LINKER_FLAGS )
128 set(EXTRA_LIBS )
130 if(WIN32)
131     set(CPP_DEFS ${CPP_DEFS} _WIN32 NOMINMAX)
132     if(MINGW)
133         set(CPP_DEFS ${CPP_DEFS} __USE_MINGW_ANSI_STDIO)
134     endif()
136     option(ALSOFT_BUILD_ROUTER  "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)"  OFF)
137     if(MINGW)
138         option(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
139     endif()
140 elseif(APPLE)
141     option(ALSOFT_OSX_FRAMEWORK "Build as macOS framework" OFF)
142 endif()
145 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
146 if("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
147     set(INC_PATHS ${INC_PATHS} /usr/include)
148     set(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
149 endif()
151 # When the library is built for static linking, apps should define
152 # AL_LIBTYPE_STATIC when including the AL headers.
153 if(NOT LIBTYPE)
154     set(LIBTYPE SHARED)
155 endif()
157 set(LIB_MAJOR_VERSION "1")
158 set(LIB_MINOR_VERSION "22")
159 set(LIB_REVISION "0")
160 set(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
161 set(LIB_VERSION_NUM ${LIB_MAJOR_VERSION},${LIB_MINOR_VERSION},${LIB_REVISION},0)
163 set(EXPORT_DECL "")
166 # Require C++14
167 set(CMAKE_CXX_STANDARD 14)
168 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
170 # Prefer C11, but support C99 and C90 too.
171 set(CMAKE_C_STANDARD 11)
173 if(NOT WIN32)
174     # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
175     check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
176     if(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
177         set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
178         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
179         check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
180         if(NOT HAVE_POSIX_MEMALIGN_POSIX)
181             set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
182         else()
183             set(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
184         endif()
185     endif()
186     unset(OLD_REQUIRED_FLAGS)
187 endif()
189 # C99 has restrict, but C++ does not, so we can only utilize __restrict.
190 check_cxx_source_compiles("int *__restrict foo;
191 int main() { return 0; }" HAVE___RESTRICT)
192 if(HAVE___RESTRICT)
193     set(CPP_DEFS ${CPP_DEFS} RESTRICT=__restrict)
194 else()
195     set(CPP_DEFS ${CPP_DEFS} "RESTRICT=")
196 endif()
198 # Some systems may need libatomic for atomic functions to work
199 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
200 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
201 check_cxx_source_compiles("#include <atomic>
202 std::atomic<int> foo{0};
203 int main() { return foo.fetch_add(2); }"
204 HAVE_LIBATOMIC)
205 if(NOT HAVE_LIBATOMIC)
206     set(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
207 else()
208     set(EXTRA_LIBS atomic ${EXTRA_LIBS})
209 endif()
210 unset(OLD_REQUIRED_LIBRARIES)
212 if(ANDROID)
213     # Include liblog for Android logging
214     check_library_exists(log __android_log_print "" HAVE_LIBLOG)
215     if(HAVE_LIBLOG)
216         set(EXTRA_LIBS log ${EXTRA_LIBS})
217         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
218     endif()
219 endif()
221 if(MSVC)
222     set(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS)
223     check_cxx_compiler_flag(/permissive- HAVE_PERMISSIVE_SWITCH)
224     if(HAVE_PERMISSIVE_SWITCH)
225         set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
226     endif()
227     set(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4127 /wd4268 /wd4324 /wd5030)
228     # Remove /W3, which is added by default, since we set /W4. Some build
229     # generators with MSVC complain about both /W3 and /W4 being specified.
230     foreach(flag_var  CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
231         if(${flag_var} MATCHES "/W3")
232             string(REGEX REPLACE "/W3" "" ${flag_var} "${${flag_var}}")
233         endif()
234     endforeach()
236     if(NOT DXSDK_DIR)
237         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
238     else()
239         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
240     endif()
241     if(DXSDK_DIR)
242         message(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
243     endif()
245     option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
246     if(FORCE_STATIC_VCRT)
247         foreach(flag_var
248                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
249                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
250                 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
251                 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
252             if(${flag_var} MATCHES "/MD")
253                 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
254             endif()
255         endforeach(flag_var)
256     endif()
257 else()
258     set(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
259         -Wpedantic
260         $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
262     if(ALSOFT_WERROR)
263         set(C_FLAGS ${C_FLAGS} -Werror)
264     endif()
266     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
267     # instead of NDEBUG)
268     foreach(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
269         if(${flag_var} MATCHES "-DNDEBUG")
270             string(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
271         endif()
272     endforeach()
274     check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
275     if(HAVE_FNO_MATH_ERRNO)
276         set(C_FLAGS ${C_FLAGS} -fno-math-errno)
277     endif()
279     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
280     if(ALSOFT_STATIC_LIBGCC)
281         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
282         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
283         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
284         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
285         unset(OLD_REQUIRED_LIBRARIES)
287         if(NOT HAVE_STATIC_LIBGCC_SWITCH)
288             message(FATAL_ERROR "Cannot static link libgcc")
289         endif()
290         set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
291     endif()
293     option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
294     if(ALSOFT_STATIC_STDCXX)
295         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
296         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
297         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
298         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
299         unset(OLD_REQUIRED_LIBRARIES)
301         if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
302             message(FATAL_ERROR "Cannot static link libstdc++")
303         endif()
304         set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
305     endif()
307     if(WIN32)
308         option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
309         if(ALSOFT_STATIC_WINPTHREAD)
310             set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
311             set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
312             check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
313             set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
314             unset(OLD_REQUIRED_LIBRARIES)
316             if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
317                 message(FATAL_ERROR "Cannot static link libwinpthread")
318             endif()
319             set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
320         endif()
321     endif()
322 endif()
324 # Set visibility/export options if available
325 if(WIN32)
326     if(NOT LIBTYPE STREQUAL "STATIC")
327         set(EXPORT_DECL "__declspec(dllexport)")
328     endif()
329 else()
330     set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
331     # Yes GCC, really don't accept visibility modes you don't support
332     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
334     check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
335                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
336     if(HAVE_GCC_PROTECTED_VISIBILITY)
337         if(NOT LIBTYPE STREQUAL "STATIC")
338             set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
339         endif()
340     else()
341         check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
342                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
343         if(HAVE_GCC_DEFAULT_VISIBILITY)
344             if(NOT LIBTYPE STREQUAL "STATIC")
345                 set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
346             endif()
347         endif()
348     endif()
350     if(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
351         check_c_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
352         if(HAVE_VISIBILITY_HIDDEN_SWITCH)
353             set(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
354         endif()
355     endif()
357     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
358 endif()
361 set(SSE2_SWITCH "")
363 if(NOT MSVC)
364     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
365     # Yes GCC, really don't accept command line options you don't support
366     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
367     check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
368     if(HAVE_MSSE2_SWITCH)
369         set(SSE2_SWITCH "-msse2")
370     endif()
371     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
372     unset(OLD_REQUIRED_FLAGS)
373 endif()
375 check_include_file(xmmintrin.h HAVE_XMMINTRIN_H)
376 check_include_file(emmintrin.h HAVE_EMMINTRIN_H)
377 check_include_file(pmmintrin.h HAVE_PMMINTRIN_H)
378 check_include_file(smmintrin.h HAVE_SMMINTRIN_H)
379 check_include_file(arm_neon.h HAVE_ARM_NEON_H)
381 set(HAVE_SSE        0)
382 set(HAVE_SSE2       0)
383 set(HAVE_SSE3       0)
384 set(HAVE_SSE4_1     0)
385 set(HAVE_NEON       0)
387 # Check for SSE support
388 option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
389 if(HAVE_XMMINTRIN_H)
390     option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
391     if(ALSOFT_CPUEXT_SSE)
392         set(HAVE_SSE 1)
393     endif()
394 endif()
395 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
396     message(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
397 endif()
399 option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
400 if(HAVE_EMMINTRIN_H)
401     option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
402     if(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
403         set(HAVE_SSE2 1)
404     endif()
405 endif()
406 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
407     message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
408 endif()
410 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
411 if(HAVE_PMMINTRIN_H)
412     option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
413     if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
414         set(HAVE_SSE3 1)
415     endif()
416 endif()
417 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
418     message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
419 endif()
421 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
422 if(HAVE_SMMINTRIN_H)
423     option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
424     if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
425         set(HAVE_SSE4_1 1)
426     endif()
427 endif()
428 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
429     message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
430 endif()
432 # Check for ARM Neon support
433 option(ALSOFT_REQUIRE_NEON "Require ARM NEON support" OFF)
434 if(HAVE_ARM_NEON_H)
435     option(ALSOFT_CPUEXT_NEON "Enable ARM NEON support" ON)
436     if(ALSOFT_CPUEXT_NEON)
437         check_c_source_compiles("#include <arm_neon.h>
438             int main()
439             {
440                 int32x4_t ret4 = vdupq_n_s32(0);
441                 return vgetq_lane_s32(ret4, 0);
442             }" HAVE_NEON_INTRINSICS)
443         if(HAVE_NEON_INTRINSICS)
444             set(HAVE_NEON 1)
445         endif()
446     endif()
447 endif()
448 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
449     message(FATAL_ERROR "Failed to enabled required ARM NEON CPU extensions")
450 endif()
453 set(SSE_FLAGS )
454 set(FPMATH_SET "0")
455 if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND HAVE_SSE2)
456     option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
457     if(ALSOFT_ENABLE_SSE2_CODEGEN)
458         if(MSVC)
459             check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
460             if(HAVE_ARCH_SSE2)
461                 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
462                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
463                 set(FPMATH_SET 2)
464             endif()
465         elseif(SSE2_SWITCH)
466             check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
467             if(HAVE_MFPMATH_SSE_2)
468                 set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
469                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
470                 set(FPMATH_SET 2)
471             endif()
472             # SSE depends on a 16-byte aligned stack, and by default, GCC
473             # assumes the stack is suitably aligned. Older Linux code or other
474             # OSs don't guarantee this on 32-bit, so externally-callable
475             # functions need to ensure an aligned stack.
476             set(EXPORT_DECL "${EXPORT_DECL} __attribute__((force_align_arg_pointer))")
477         endif()
478     endif()
479 endif()
481 if(HAVE_SSE2)
482     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
483     foreach(flag_var ${SSE_FLAGS})
484         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
485     endforeach()
487     check_c_source_compiles("#include <emmintrin.h>
488         int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
490     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
491 endif()
494 check_include_file(malloc.h HAVE_MALLOC_H)
495 check_include_file(cpuid.h HAVE_CPUID_H)
496 check_include_file(intrin.h HAVE_INTRIN_H)
497 check_include_file(guiddef.h HAVE_GUIDDEF_H)
498 if(NOT HAVE_GUIDDEF_H)
499     check_include_file(initguid.h HAVE_INITGUID_H)
500 endif()
502 # Some systems need libm for some math functions to work
503 set(MATH_LIB )
504 check_library_exists(m pow "" HAVE_LIBM)
505 if(HAVE_LIBM)
506     set(MATH_LIB ${MATH_LIB} m)
507     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
508 endif()
510 # Some systems need to link with -lrt for clock_gettime as used by the common
511 # eaxmple functions.
512 set(RT_LIB )
513 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
514 if(HAVE_LIBRT)
515     set(RT_LIB rt)
516 endif()
518 # Check for the dlopen API (for dynamicly loading backend libs)
519 if(ALSOFT_DLOPEN)
520     check_include_file(dlfcn.h HAVE_DLFCN_H)
521     check_library_exists(dl dlopen "" HAVE_LIBDL)
522     if(HAVE_LIBDL)
523         set(EXTRA_LIBS dl ${EXTRA_LIBS})
524         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
525     endif()
526 endif()
528 # Check for a cpuid intrinsic
529 if(HAVE_CPUID_H)
530     check_c_source_compiles("#include <cpuid.h>
531         int main()
532         {
533             unsigned int eax, ebx, ecx, edx;
534             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
535         }" HAVE_GCC_GET_CPUID)
536 endif()
537 if(HAVE_INTRIN_H)
538     check_c_source_compiles("#include <intrin.h>
539         int main()
540         {
541             int regs[4];
542             __cpuid(regs, 0);
543             return regs[0];
544         }" HAVE_CPUID_INTRINSIC)
545 endif()
547 check_symbol_exists(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
548 check_symbol_exists(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
549 check_symbol_exists(proc_pidpath     libproc.h HAVE_PROC_PIDPATH)
551 if(NOT WIN32)
552     # We need pthreads outside of Windows, for semaphores. It's also used to
553     # set the priority and name of threads, when possible.
554     check_include_file(pthread.h HAVE_PTHREAD_H)
555     if(NOT HAVE_PTHREAD_H)
556         message(FATAL_ERROR "PThreads is required for non-Windows builds!")
557     endif()
559     check_c_compiler_flag(-pthread HAVE_PTHREAD)
560     if(HAVE_PTHREAD)
561         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
562         set(C_FLAGS ${C_FLAGS} -pthread)
563         set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
564     endif()
566     check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
568     # Some systems need pthread_np.h to get pthread_setname_np
569     check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
570     if(HAVE_PTHREAD_NP_H)
571         check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
572         if(NOT HAVE_PTHREAD_SETNAME_NP)
573             check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
574         endif()
575     else()
576         check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
577         if(NOT HAVE_PTHREAD_SETNAME_NP)
578             check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
579         endif()
580     endif()
581 endif()
583 check_symbol_exists(getopt unistd.h HAVE_GETOPT)
586 # Common sources used by both the OpenAL implementation library, the OpenAL
587 # router, and certain tools and examples.
588 set(COMMON_OBJS
589     common/albit.h
590     common/albyte.h
591     common/alcomplex.cpp
592     common/alcomplex.h
593     common/aldeque.h
594     common/alfstream.cpp
595     common/alfstream.h
596     common/almalloc.cpp
597     common/almalloc.h
598     common/alnumbers.h
599     common/alnumeric.h
600     common/aloptional.h
601     common/alspan.h
602     common/alstring.cpp
603     common/alstring.h
604     common/atomic.h
605     common/comptr.h
606     common/dynload.cpp
607     common/dynload.h
608     common/intrusive_ptr.h
609     common/opthelpers.h
610     common/phase_shifter.h
611     common/polyphase_resampler.cpp
612     common/polyphase_resampler.h
613     common/pragmadefs.h
614     common/ringbuffer.cpp
615     common/ringbuffer.h
616     common/strutils.cpp
617     common/strutils.h
618     common/threads.cpp
619     common/threads.h
620     common/vecmat.h
621     common/vector.h)
623 # Core library routines
624 set(CORE_OBJS
625     core/ambdec.cpp
626     core/ambdec.h
627     core/ambidefs.cpp
628     core/ambidefs.h
629     core/async_event.h
630     core/bformatdec.cpp
631     core/bformatdec.h
632     core/bs2b.cpp
633     core/bs2b.h
634     core/bsinc_defs.h
635     core/bsinc_tables.cpp
636     core/bsinc_tables.h
637     core/bufferline.h
638     core/buffer_storage.cpp
639     core/buffer_storage.h
640     core/context.cpp
641     core/context.h
642     core/converter.cpp
643     core/converter.h
644     core/cpu_caps.cpp
645     core/cpu_caps.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/uhjfilter.cpp
678     core/uhjfilter.h
679     core/uiddefs.cpp
680     core/voice.cpp
681     core/voice.h
682     core/voice_change.h)
684 set(HAVE_RTKIT 0)
685 if(NOT WIN32)
686     option(ALSOFT_REQUIRE_RTKIT "Require RTKit/D-Bus support" FALSE)
687     find_package(DBus1 QUIET)
688     if(NOT DBus1_FOUND AND PkgConfig_FOUND)
689         pkg_check_modules(DBUS dbus-1)
690     endif()
691     if(DBus1_FOUND OR DBUS_FOUND)
692         option(ALSOFT_RTKIT "Enable RTKit support" ON)
693         if(ALSOFT_RTKIT)
694             set(HAVE_RTKIT 1)
695             set(CORE_OBJS ${CORE_OBJS} core/dbus_wrap.cpp core/dbus_wrap.h
696                 core/rtkit.cpp core/rtkit.h)
697             if(NOT DBus1_FOUND)
698                 set(INC_PATHS ${INC_PATHS} ${DBUS_INCLUDE_DIRS})
699                 set(CPP_DEFS ${CPP_DEFS} ${DBUS_CFLAGS_OTHER})
700                 if(NOT HAVE_DLFCN_H)
701                     set(EXTRA_LIBS ${EXTRA_LIBS} ${DBUS_LINK_LIBRARIES})
702                 endif()
703             elseif(HAVE_DLFCN_H)
704                 set(INC_PATHS ${INC_PATHS} ${DBus1_INCLUDE_DIRS})
705                 set(CPP_DEFS ${CPP_DEFS} ${DBus1_DEFINITIONS})
706             else()
707                 set(EXTRA_LIBS ${EXTRA_LIBS} ${DBus1_LIBRARIES})
708             endif()
709         endif()
710     else()
711         set(MISSING_VARS "")
712         if(NOT DBus1_INCLUDE_DIRS)
713             set(MISSING_VARS "${MISSING_VARS} DBus1_INCLUDE_DIRS")
714         endif()
715         if(NOT DBus1_LIBRARIES)
716             set(MISSING_VARS "${MISSING_VARS} DBus1_LIBRARIES")
717         endif()
718         message(STATUS "Could NOT find DBus1 (missing:${MISSING_VARS})")
719         unset(MISSING_VARS)
720     endif()
721 endif()
722 if(ALSOFT_REQUIRE_RTKIT AND NOT HAVE_RTKIT)
723     message(FATAL_ERROR "Failed to enabled required RTKit support")
724 endif()
726 # Default mixers, always available
727 set(CORE_OBJS ${CORE_OBJS}
728     core/mixer/defs.h
729     core/mixer/hrtfbase.h
730     core/mixer/hrtfdefs.h
731     core/mixer/mixer_c.cpp)
733 # AL and related routines
734 set(OPENAL_OBJS
735     al/auxeffectslot.cpp
736     al/auxeffectslot.h
737     al/buffer.cpp
738     al/buffer.h
739     al/effect.cpp
740     al/effect.h
741     al/effects/autowah.cpp
742     al/effects/chorus.cpp
743     al/effects/compressor.cpp
744     al/effects/convolution.cpp
745     al/effects/dedicated.cpp
746     al/effects/distortion.cpp
747     al/effects/echo.cpp
748         al/effects/effects.cpp
749     al/effects/effects.h
750     al/effects/equalizer.cpp
751     al/effects/fshifter.cpp
752     al/effects/modulator.cpp
753     al/effects/null.cpp
754     al/effects/pshifter.cpp
755     al/effects/reverb.cpp
756     al/effects/vmorpher.cpp
757     al/error.cpp
758     al/event.cpp
759     al/event.h
760     al/extension.cpp
761     al/filter.cpp
762     al/filter.h
763     al/listener.cpp
764     al/listener.h
765     al/source.cpp
766     al/source.h
767     al/state.cpp)
769 # ALC and related routines
770 set(ALC_OBJS
771     alc/alc.cpp
772     alc/alu.cpp
773     alc/alu.h
774     alc/alconfig.cpp
775     alc/alconfig.h
776     alc/context.cpp
777     alc/context.h
778     alc/device.cpp
779     alc/device.h
780     alc/effects/base.h
781     alc/effects/autowah.cpp
782     alc/effects/chorus.cpp
783     alc/effects/compressor.cpp
784     alc/effects/convolution.cpp
785     alc/effects/dedicated.cpp
786     alc/effects/distortion.cpp
787     alc/effects/echo.cpp
788     alc/effects/equalizer.cpp
789     alc/effects/fshifter.cpp
790     alc/effects/modulator.cpp
791     alc/effects/null.cpp
792     alc/effects/pshifter.cpp
793     alc/effects/reverb.cpp
794     alc/effects/vmorpher.cpp
795     alc/inprogext.h
796     alc/panning.cpp)
798 if (ALSOFT_EAX)
799     set(OPENAL_OBJS
800         ${OPENAL_OBJS}
801         al/eax/api.cpp
802         al/eax/api.h
803         al/eax/call.cpp
804         al/eax/call.h
805         al/eax/effect.h
806         al/eax/exception.cpp
807         al/eax/exception.h
808         al/eax/fx_slot_index.cpp
809         al/eax/fx_slot_index.h
810         al/eax/fx_slots.cpp
811         al/eax/fx_slots.h
812         al/eax/globals.cpp
813         al/eax/globals.h
814         al/eax/utils.cpp
815         al/eax/utils.h
816         al/eax/x_ram.h
818 endif ()
820 # Include SIMD mixers
821 set(CPU_EXTS "Default")
822 if(HAVE_SSE)
823     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse.cpp)
824     set(CPU_EXTS "${CPU_EXTS}, SSE")
825 endif()
826 if(HAVE_SSE2)
827     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse2.cpp)
828     set(CPU_EXTS "${CPU_EXTS}, SSE2")
829 endif()
830 if(HAVE_SSE3)
831     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse3.cpp)
832     set(CPU_EXTS "${CPU_EXTS}, SSE3")
833 endif()
834 if(HAVE_SSE4_1)
835     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse41.cpp)
836     set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
837 endif()
838 if(HAVE_NEON)
839     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_neon.cpp)
840     set(CPU_EXTS "${CPU_EXTS}, Neon")
841 endif()
844 set(HAVE_ALSA       0)
845 set(HAVE_OSS        0)
846 set(HAVE_PIPEWIRE   0)
847 set(HAVE_SOLARIS    0)
848 set(HAVE_SNDIO      0)
849 set(HAVE_DSOUND     0)
850 set(HAVE_WASAPI     0)
851 set(HAVE_WINMM      0)
852 set(HAVE_PORTAUDIO  0)
853 set(HAVE_PULSEAUDIO 0)
854 set(HAVE_COREAUDIO  0)
855 set(HAVE_OPENSL     0)
856 set(HAVE_OBOE       0)
857 set(HAVE_WAVE       0)
858 set(HAVE_SDL2       0)
860 if(WIN32 OR HAVE_DLFCN_H)
861     set(IS_LINKED "")
862     macro(ADD_BACKEND_LIBS _LIBS)
863     endmacro()
864 else()
865     set(IS_LINKED " (linked)")
866     macro(ADD_BACKEND_LIBS _LIBS)
867         set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
868     endmacro()
869 endif()
871 set(BACKENDS "")
872 set(ALC_OBJS  ${ALC_OBJS}
873     alc/backends/base.cpp
874     alc/backends/base.h
875     # Default backends, always available
876     alc/backends/loopback.cpp
877     alc/backends/loopback.h
878     alc/backends/null.cpp
879     alc/backends/null.h
882 # Check ALSA backend
883 option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
884 find_package(ALSA)
885 if(ALSA_FOUND)
886     option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
887     if(ALSOFT_BACKEND_ALSA)
888         set(HAVE_ALSA 1)
889         set(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
890         set(ALC_OBJS  ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
891         add_backend_libs(${ALSA_LIBRARIES})
892         set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
893     endif()
894 endif()
895 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
896     message(FATAL_ERROR "Failed to enabled required ALSA backend")
897 endif()
899 # Check OSS backend
900 option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
901 find_package(OSS)
902 if(OSS_FOUND)
903     option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
904     if(ALSOFT_BACKEND_OSS)
905         set(HAVE_OSS 1)
906         set(BACKENDS  "${BACKENDS} OSS,")
907         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
908         if(OSS_LIBRARIES)
909             set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
910         endif()
911         set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
912     endif()
913 endif()
914 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
915     message(FATAL_ERROR "Failed to enabled required OSS backend")
916 endif()
918 # Check PipeWire backend
919 option(ALSOFT_REQUIRE_PIPEWIRE "Require PipeWire backend" OFF)
920 if(PkgConfig_FOUND)
921     pkg_check_modules(PIPEWIRE libpipewire-0.3>=0.3.23)
922     if(PIPEWIRE_FOUND)
923         option(ALSOFT_BACKEND_PIPEWIRE "Enable PipeWire backend" ON)
924         if(ALSOFT_BACKEND_PIPEWIRE)
925             set(HAVE_PIPEWIRE 1)
926             set(BACKENDS  "${BACKENDS} PipeWire${IS_LINKED},")
927             set(ALC_OBJS  ${ALC_OBJS} alc/backends/pipewire.cpp alc/backends/pipewire.h)
928             add_backend_libs(${PIPEWIRE_LIBRARIES})
929             set(INC_PATHS ${INC_PATHS} ${PIPEWIRE_INCLUDE_DIRS})
930         endif()
931     endif()
932 endif()
933 if(ALSOFT_REQUIRE_PIPEWIRE AND NOT HAVE_PIPEWIRE)
934     message(FATAL_ERROR "Failed to enabled required PipeWire backend")
935 endif()
937 # Check Solaris backend
938 option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
939 find_package(AudioIO)
940 if(AUDIOIO_FOUND)
941     option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
942     if(ALSOFT_BACKEND_SOLARIS)
943         set(HAVE_SOLARIS 1)
944         set(BACKENDS  "${BACKENDS} Solaris,")
945         set(ALC_OBJS  ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
946         set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
947     endif()
948 endif()
949 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
950     message(FATAL_ERROR "Failed to enabled required Solaris backend")
951 endif()
953 # Check SndIO backend
954 option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
955 find_package(SoundIO)
956 if(SOUNDIO_FOUND)
957     option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
958     if(ALSOFT_BACKEND_SNDIO)
959         set(HAVE_SNDIO 1)
960         set(BACKENDS  "${BACKENDS} SndIO (linked),")
961         set(ALC_OBJS  ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
962         set(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
963         set(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
964     endif()
965 endif()
966 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
967     message(FATAL_ERROR "Failed to enabled required SndIO backend")
968 endif()
970 # Check Windows-only backends
971 option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
972 option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
973 option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
974 if(WIN32)
975     # Check MMSystem backend
976     option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
977     if(ALSOFT_BACKEND_WINMM)
978         set(HAVE_WINMM 1)
979         set(BACKENDS "${BACKENDS} WinMM,")
980         set(ALC_OBJS ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
981         # There doesn't seem to be good way to search for winmm.lib for MSVC.
982         # find_library doesn't find it without being told to look in a specific
983         # place in the WindowsSDK, but it links anyway. If there ends up being
984         # Windows targets without this, another means to detect it is needed.
985         set(EXTRA_LIBS winmm ${EXTRA_LIBS})
986     endif()
988     # Check DSound backend
989     check_include_file(dsound.h HAVE_DSOUND_H)
990     if(DXSDK_DIR)
991         find_path(DSOUND_INCLUDE_DIR NAMES "dsound.h"
992             PATHS "${DXSDK_DIR}" PATH_SUFFIXES include
993             DOC "The DirectSound include directory")
994     endif()
995     if(HAVE_DSOUND_H OR DSOUND_INCLUDE_DIR)
996         option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
997         if(ALSOFT_BACKEND_DSOUND)
998             set(HAVE_DSOUND 1)
999             set(BACKENDS "${BACKENDS} DirectSound,")
1000             set(ALC_OBJS ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
1002             if(NOT HAVE_DSOUND_H)
1003                 set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIR})
1004             endif()
1005         endif()
1006     endif()
1008     # Check for WASAPI backend
1009     check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1010     if(HAVE_MMDEVICEAPI_H)
1011         option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
1012         if(ALSOFT_BACKEND_WASAPI)
1013             set(HAVE_WASAPI 1)
1014             set(BACKENDS  "${BACKENDS} WASAPI,")
1015             set(ALC_OBJS  ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
1016         endif()
1017     endif()
1018 endif()
1019 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1020     message(FATAL_ERROR "Failed to enabled required WinMM backend")
1021 endif()
1022 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1023     message(FATAL_ERROR "Failed to enabled required DSound backend")
1024 endif()
1025 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
1026     message(FATAL_ERROR "Failed to enabled required WASAPI backend")
1027 endif()
1029 # Check PortAudio backend
1030 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1031 find_package(PortAudio)
1032 if(PORTAUDIO_FOUND)
1033     option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1034     if(ALSOFT_BACKEND_PORTAUDIO)
1035         set(HAVE_PORTAUDIO 1)
1036         set(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
1037         set(ALC_OBJS  ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
1038         add_backend_libs(${PORTAUDIO_LIBRARIES})
1039         set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
1040     endif()
1041 endif()
1042 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1043     message(FATAL_ERROR "Failed to enabled required PortAudio backend")
1044 endif()
1046 # Check PulseAudio backend
1047 option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1048 find_package(PulseAudio)
1049 if(PULSEAUDIO_FOUND)
1050     option(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1051     if(ALSOFT_BACKEND_PULSEAUDIO)
1052         set(HAVE_PULSEAUDIO 1)
1053         set(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
1054         set(ALC_OBJS  ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
1055         add_backend_libs(${PULSEAUDIO_LIBRARIES})
1056         set(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
1057     endif()
1058 endif()
1059 if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1060     message(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1061 endif()
1063 # Check JACK backend
1064 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1065 find_package(JACK)
1066 if(JACK_FOUND)
1067     option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1068     if(ALSOFT_BACKEND_JACK)
1069         set(HAVE_JACK 1)
1070         set(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1071         set(ALC_OBJS  ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
1072         add_backend_libs(${JACK_LIBRARIES})
1073         set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1074     endif()
1075 endif()
1076 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1077     message(FATAL_ERROR "Failed to enabled required JACK backend")
1078 endif()
1080 # Check CoreAudio backend
1081 option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1082 find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
1083 find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
1084 if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
1085     option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1086     if(ALSOFT_BACKEND_COREAUDIO)
1087         set(HAVE_COREAUDIO 1)
1088         set(ALC_OBJS  ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
1089         set(BACKENDS  "${BACKENDS} CoreAudio,")
1090         if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
1091             find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
1092             set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${COREFOUNDATION_FRAMEWORK} ${EXTRA_LIBS})
1093         else()
1094             set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} /System/Library/Frameworks/AudioUnit.framework
1095                 /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1096         endif()
1098         # Some versions of OSX may need the AudioToolbox framework. Add it if
1099         # it's found.
1100         find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
1101         if(AUDIOTOOLBOX_LIBRARY)
1102             set(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1103         endif()
1105         set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
1106     endif()
1107 endif()
1108 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1109     message(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1110 endif()
1112 # Check for OpenSL (Android) backend
1113 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1114 find_package(OpenSL)
1115 if(OPENSL_FOUND)
1116     option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1117     if(ALSOFT_BACKEND_OPENSL)
1118         set(HAVE_OPENSL 1)
1119         set(ALC_OBJS  ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1120         set(BACKENDS  "${BACKENDS} OpenSL,")
1121         set(EXTRA_LIBS "OpenSL::OpenSLES" ${EXTRA_LIBS})
1122     endif()
1123 endif()
1124 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1125     message(FATAL_ERROR "Failed to enabled required OpenSL backend")
1126 endif()
1128 # Check for Oboe (Android) backend
1129 set(OBOE_TARGET )
1130 if(ANDROID)
1131     set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1132     if(OBOE_SOURCE)
1133         # Force Oboe to build with hidden symbols. Don't want to be exporting
1134         # them from OpenAL.
1135         set(OLD_CXX_FLAGS ${CMAKE_CXX_FLAGS})
1136         check_cxx_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
1137         if(HAVE_VISIBILITY_HIDDEN_SWITCH)
1138             set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
1139         endif()
1140         add_subdirectory(${OBOE_SOURCE} ./oboe)
1141         set(CMAKE_CXX_FLAGS ${OLD_CXX_FLAGS})
1142         unset(OLD_CXX_FLAGS)
1144         set(OBOE_TARGET oboe)
1145     else()
1146         find_package(oboe CONFIG)
1147         if(NOT TARGET oboe::oboe)
1148             find_package(Oboe)
1149         endif()
1150         if(TARGET oboe::oboe)
1151             set(OBOE_TARGET "oboe::oboe")
1152         endif()
1153     endif()
1154 endif()
1156 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1157 if(OBOE_TARGET)
1158     option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1159     if(ALSOFT_BACKEND_OBOE)
1160         set(HAVE_OBOE 1)
1161         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
1162         set(BACKENDS  "${BACKENDS} Oboe,")
1163         set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
1164     endif()
1165 endif()
1166 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1167     message(FATAL_ERROR "Failed to enabled required Oboe backend")
1168 endif()
1170 # Check for SDL2 backend
1171 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1172 find_package(SDL2)
1173 if(SDL2_FOUND)
1174     # Off by default, since it adds a runtime dependency
1175     option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1176     if(ALSOFT_BACKEND_SDL2)
1177         set(HAVE_SDL2 1)
1178         set(ALC_OBJS  ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1179         set(BACKENDS  "${BACKENDS} SDL2,")
1180         set(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
1181         set(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
1182     endif()
1183 endif()
1184 if(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1185     message(FATAL_ERROR "Failed to enabled required SDL2 backend")
1186 endif()
1188 # Optionally enable the Wave Writer backend
1189 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1190 if(ALSOFT_BACKEND_WAVE)
1191     set(HAVE_WAVE 1)
1192     set(ALC_OBJS  ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1193     set(BACKENDS  "${BACKENDS} WaveFile,")
1194 endif()
1196 # This is always available
1197 set(BACKENDS  "${BACKENDS} Null")
1200 find_package(Git)
1201 if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1202     # Get the current working branch and its latest abbreviated commit hash
1203     add_custom_target(build_version
1204         ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1205             -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1206             -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1207         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1208         VERBATIM
1209     )
1210 else()
1211     set(GIT_BRANCH "UNKNOWN")
1212     set(GIT_COMMIT_HASH "unknown")
1213     configure_file(
1214         "${OpenAL_SOURCE_DIR}/version.h.in"
1215         "${OpenAL_BINARY_DIR}/version.h")
1216 endif()
1219 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1220 if(ALSOFT_EMBED_HRTF_DATA)
1221     macro(make_hrtf_header FILENAME VARNAME)
1222         set(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1223         set(outfile  "${OpenAL_BINARY_DIR}/${VARNAME}.h")
1225         add_custom_command(OUTPUT "${outfile}"
1226             COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
1227                 -D "VARIABLE_NAME=${VARNAME}" -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1228             WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1229             DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1230             VERBATIM
1231         )
1232         set(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1233     endmacro()
1235     make_hrtf_header("Default HRTF.mhr" "hrtf_default")
1236 endif()
1239 if(ALSOFT_UTILS)
1240     find_package(MySOFA)
1241     if(NOT ALSOFT_NO_CONFIG_UTIL)
1242         find_package(Qt5Widgets QUIET)
1243         if(NOT Qt5Widgets_FOUND)
1244             message(STATUS "Could NOT find Qt5Widgets")
1245         endif()
1246     endif()
1247 endif()
1248 if(ALSOFT_UTILS OR ALSOFT_EXAMPLES)
1249     find_package(SndFile)
1250     find_package(SDL2)
1251     if(SDL2_FOUND)
1252         find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1253     endif()
1254 endif()
1256 if(NOT WIN32)
1257     set(LIBNAME "openal")
1258 else()
1259     set(LIBNAME "OpenAL32")
1260 endif()
1262 # Needed for openal.pc.in
1263 set(prefix ${CMAKE_INSTALL_PREFIX})
1264 set(exec_prefix "\${prefix}")
1265 set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
1266 set(bindir "${CMAKE_INSTALL_FULL_BINDIR}")
1267 set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
1268 set(PACKAGE_VERSION "${LIB_VERSION}")
1269 set(PKG_CONFIG_CFLAGS )
1270 set(PKG_CONFIG_PRIVATE_LIBS )
1271 if(LIBTYPE STREQUAL "STATIC")
1272     set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1273     foreach(FLAG  ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1274         # If this is already a linker flag, or is a full path+file, add it
1275         # as-is. Otherwise, it's a name intended to be dressed as -lname.
1276         if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1277             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1278         else()
1279             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1280         endif()
1281     endforeach()
1282 endif()
1284 # End configuration
1285 configure_file(
1286     "${OpenAL_SOURCE_DIR}/config.h.in"
1287     "${OpenAL_BINARY_DIR}/config.h")
1288 configure_file(
1289     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1290     "${OpenAL_BINARY_DIR}/openal.pc"
1291     @ONLY)
1294 add_library(common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1295 target_include_directories(common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include)
1296 target_compile_definitions(common PRIVATE ${CPP_DEFS})
1297 target_compile_options(common PRIVATE ${C_FLAGS})
1298 set_target_properties(common PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
1301 unset(HAS_ROUTER)
1302 set(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1304 # Build main library
1305 if(LIBTYPE STREQUAL "STATIC")
1306     add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS})
1307     target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
1308     target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1310     if(WIN32)
1311         # This option is for static linking OpenAL Soft into another project
1312         # that already defines the IDs. It is up to that project to ensure all
1313         # required IDs are defined.
1314         option(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
1315         if(ALSOFT_NO_UID_DEFS)
1316             target_compile_definitions(${IMPL_TARGET} PRIVATE AL_NO_UID_DEFS)
1317         endif()
1318     endif()
1319 else()
1320     set(RC_CONFIG resources/openal32.rc)
1321     if(WIN32 AND ALSOFT_BUILD_ROUTER)
1322         add_library(OpenAL SHARED
1323             resources/router.rc
1324             router/router.cpp
1325             router/router.h
1326             router/alc.cpp
1327             router/al.cpp
1328         )
1329         target_compile_definitions(OpenAL
1330             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}"
1331             "AL_API=${EXPORT_DECL}" ${CPP_DEFS})
1332         target_compile_options(OpenAL PRIVATE ${C_FLAGS})
1333         target_link_libraries(OpenAL PRIVATE common ${LINKER_FLAGS})
1334         target_include_directories(OpenAL
1335           PUBLIC
1336             $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1337             $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1338           PRIVATE
1339             ${OpenAL_SOURCE_DIR}/common
1340             ${OpenAL_BINARY_DIR}
1341         )
1342         set_target_properties(OpenAL PROPERTIES PREFIX "")
1343         set_target_properties(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1344         if(TARGET build_version)
1345             add_dependencies(OpenAL build_version)
1346         endif()
1347         set(HAS_ROUTER 1)
1349         set(LIBNAME "soft_oal")
1350         set(IMPL_TARGET soft_oal)
1351         set(RC_CONFIG resources/soft_oal.rc)
1352     endif()
1354     # !important: for osx framework public header works, the headers must be in
1355     # the project
1356     set(TARGET_PUBLIC_HEADERS include/AL/al.h include/AL/alc.h include/AL/alext.h include/AL/efx.h)
1357     add_library(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS} ${RC_CONFIG}
1358         ${TARGET_PUBLIC_HEADERS})
1359     if(WIN32)
1360         set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
1361     endif()
1362     target_link_libraries(${IMPL_TARGET} PRIVATE common ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1364     if(APPLE AND ALSOFT_OSX_FRAMEWORK)
1365         # Sets framework name to soft_oal to avoid ambiguity with the system OpenAL.framework
1366         set(LIBNAME "soft_oal")
1367         if(GIT_FOUND)
1368             EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list --count head
1369                 TIMEOUT 5
1370                 OUTPUT_VARIABLE BUNDLE_VERSION
1371                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1372         else()
1373             set(BUNDLE_VERSION 1)
1374         endif()
1376         # Build: Fix rpath in iOS shared libraries
1377         # If this flag is not set, the final dylib binary ld path will be
1378         # /User/xxx/*/soft_oal.framework/soft_oal, which can't be loaded by iOS devices.
1379         # See also: https://github.com/libjpeg-turbo/libjpeg-turbo/commit/c80ddef7a4ce21ace9e3ca0fd190d320cc8cdaeb
1380         if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
1381             set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
1382         endif()
1384         set_target_properties(${IMPL_TARGET} PROPERTIES
1385             FRAMEWORK TRUE
1386             FRAMEWORK_VERSION C
1387             MACOSX_FRAMEWORK_NAME "${IMPL_TARGET}"
1388             MACOSX_FRAMEWORK_IDENTIFIER "org.openal-soft.openal"
1389             MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${LIB_VERSION}
1390             MACOSX_FRAMEWORK_BUNDLE_VERSION ${BUNDLE_VERSION}
1391             XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
1392             XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
1393             XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
1394             PUBLIC_HEADER "${TARGET_PUBLIC_HEADERS}"
1395             MACOSX_RPATH TRUE)
1396     endif()
1397 endif()
1399 target_include_directories(${IMPL_TARGET}
1400   PUBLIC
1401     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1402   INTERFACE
1403     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include/AL>
1404     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1405     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/AL>
1406   PRIVATE
1407     ${INC_PATHS}
1408     ${OpenAL_BINARY_DIR}
1409     ${OpenAL_SOURCE_DIR}
1410     ${OpenAL_SOURCE_DIR}/common
1413 set_target_properties(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1414     VERSION ${LIB_VERSION}
1415     SOVERSION ${LIB_MAJOR_VERSION}
1417 target_compile_definitions(${IMPL_TARGET}
1418     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}" "AL_API=${EXPORT_DECL}"
1419     ${CPP_DEFS})
1420 target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1422 if(TARGET build_version)
1423     add_dependencies(${IMPL_TARGET} build_version)
1424 endif()
1426 if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1427     find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
1428     if(NOT SED_EXECUTABLE OR NOT CMAKE_DLLTOOL)
1429         message(STATUS "")
1430         if(NOT SED_EXECUTABLE)
1431             message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1432         endif()
1433         if(NOT CMAKE_DLLTOOL)
1434             message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1435         endif()
1436     else()
1437         set_property(TARGET OpenAL APPEND_STRING PROPERTY
1438             LINK_FLAGS " -Wl,--output-def,OpenAL32.def")
1439         add_custom_command(TARGET OpenAL POST_BUILD
1440             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1441             COMMAND "${CMAKE_DLLTOOL}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1442             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1443             VERBATIM
1444         )
1445     endif()
1446 endif()
1448 if(HAS_ROUTER)
1449     message(STATUS "")
1450     message(STATUS "Building DLL router")
1451 endif()
1453 message(STATUS "")
1454 message(STATUS "Building OpenAL with support for the following backends:")
1455 message(STATUS "   ${BACKENDS}")
1456 message(STATUS "")
1457 message(STATUS "Building with support for CPU extensions:")
1458 message(STATUS "    ${CPU_EXTS}")
1459 message(STATUS "")
1460 if(FPMATH_SET)
1461     message(STATUS "Building with SSE${FPMATH_SET} codegen")
1462     message(STATUS "")
1463 endif()
1465 if(ALSOFT_EAX)
1466     message(STATUS "Building with legacy EAX extension support")
1467     message(STATUS "")
1468 endif()
1470 if(ALSOFT_EMBED_HRTF_DATA)
1471     message(STATUS "Embedding HRTF datasets")
1472     message(STATUS "")
1473 endif()
1475 # An alias for sub-project builds
1476 add_library(OpenAL::OpenAL ALIAS OpenAL)
1478 # Install main library
1479 if(ALSOFT_INSTALL)
1480     configure_package_config_file(OpenALConfig.cmake.in OpenALConfig.cmake
1481         INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL)
1482     install(TARGETS OpenAL EXPORT OpenAL
1483         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1484         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1485         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1486         FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
1487         INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1488     export(TARGETS OpenAL
1489         NAMESPACE OpenAL::
1490         FILE OpenALTargets.cmake)
1491     install(EXPORT OpenAL
1492         DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1493         NAMESPACE OpenAL::
1494         FILE OpenALTargets.cmake)
1495     install(DIRECTORY include/AL
1496         DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1497     install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1498         DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1499     install(FILES "${OpenAL_BINARY_DIR}/OpenALConfig.cmake"
1500         DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL")
1501     if(TARGET soft_oal)
1502         install(TARGETS soft_oal
1503             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1504     endif()
1505     message(STATUS "Installing library and headers")
1506 else()
1507     message(STATUS "NOT installing library and headers")
1508 endif()
1510 if(ALSOFT_INSTALL_CONFIG)
1511     install(FILES alsoftrc.sample
1512         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1513     message(STATUS "Installing sample configuration")
1514 endif()
1516 if(ALSOFT_INSTALL_HRTF_DATA)
1517     install(DIRECTORY hrtf
1518         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1519     message(STATUS "Installing HRTF data files")
1520 endif()
1522 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1523     install(DIRECTORY presets
1524         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1525     message(STATUS "Installing AmbDec presets")
1526 endif()
1527 message(STATUS "")
1529 set(UNICODE_FLAG )
1530 if(MINGW)
1531     set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1532 endif()
1533 set(EXTRA_INSTALLS )
1534 if(ALSOFT_UTILS)
1535     add_executable(openal-info utils/openal-info.c)
1536     target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1537     target_compile_options(openal-info PRIVATE ${C_FLAGS})
1538     target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
1539     if(ALSOFT_INSTALL_EXAMPLES)
1540         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
1541     endif()
1543     if(SNDFILE_FOUND)
1544         add_executable(uhjdecoder utils/uhjdecoder.cpp)
1545         target_compile_definitions(uhjdecoder PRIVATE ${CPP_DEFS})
1546         target_include_directories(uhjdecoder
1547             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1548         target_compile_options(uhjdecoder PRIVATE ${C_FLAGS})
1549         target_link_libraries(uhjdecoder PUBLIC common
1550             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1552         add_executable(uhjencoder utils/uhjencoder.cpp)
1553         target_compile_definitions(uhjencoder PRIVATE ${CPP_DEFS})
1554         target_include_directories(uhjencoder
1555             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1556         target_compile_options(uhjencoder PRIVATE ${C_FLAGS})
1557         target_link_libraries(uhjencoder PUBLIC common
1558             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1559     endif()
1561     if(MYSOFA_FOUND)
1562         set(SOFA_SUPPORT_SRCS
1563             utils/sofa-support.cpp
1564             utils/sofa-support.h)
1565         add_library(sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
1566         target_compile_definitions(sofa-support PRIVATE ${CPP_DEFS})
1567         target_include_directories(sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
1568         target_compile_options(sofa-support PRIVATE ${C_FLAGS})
1569         target_link_libraries(sofa-support PUBLIC common MySOFA::MySOFA PRIVATE ${LINKER_FLAGS})
1571         set(MAKEMHR_SRCS
1572             utils/makemhr/loaddef.cpp
1573             utils/makemhr/loaddef.h
1574             utils/makemhr/loadsofa.cpp
1575             utils/makemhr/loadsofa.h
1576             utils/makemhr/makemhr.cpp
1577             utils/makemhr/makemhr.h)
1578         if(NOT HAVE_GETOPT)
1579             set(MAKEMHR_SRCS  ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1580         endif()
1581         add_executable(makemhr ${MAKEMHR_SRCS})
1582         target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1583         target_include_directories(makemhr
1584             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
1585         target_compile_options(makemhr PRIVATE ${C_FLAGS})
1586         target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1587         if(ALSOFT_INSTALL_EXAMPLES)
1588             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
1589         endif()
1591         set(SOFAINFO_SRCS  utils/sofa-info.cpp)
1592         add_executable(sofa-info ${SOFAINFO_SRCS})
1593         target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1594         target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
1595         target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1596         target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1597     endif()
1598     message(STATUS "Building utility programs")
1600     if(NOT ALSOFT_NO_CONFIG_UTIL)
1601         add_subdirectory(utils/alsoft-config)
1602     endif()
1603     message(STATUS "")
1604 endif()
1607 # Add a static library with common functions used by multiple example targets
1608 add_library(ex-common STATIC EXCLUDE_FROM_ALL
1609     examples/common/alhelpers.c
1610     examples/common/alhelpers.h)
1611 target_compile_definitions(ex-common PUBLIC ${CPP_DEFS})
1612 target_include_directories(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
1613 target_compile_options(ex-common PUBLIC ${C_FLAGS})
1614 target_link_libraries(ex-common PUBLIC OpenAL PRIVATE ${RT_LIB})
1616 if(ALSOFT_EXAMPLES)
1617     add_executable(altonegen examples/altonegen.c)
1618     target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common ${UNICODE_FLAG})
1620     add_executable(alrecord examples/alrecord.c)
1621     target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} ex-common ${UNICODE_FLAG})
1623     if(ALSOFT_INSTALL_EXAMPLES)
1624         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord)
1625     endif()
1627     message(STATUS "Building example programs")
1629     if(SNDFILE_FOUND)
1630         add_executable(alplay examples/alplay.c)
1631         target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1632             ${UNICODE_FLAG})
1634         add_executable(alstream examples/alstream.c)
1635         target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1636             ${UNICODE_FLAG})
1638         add_executable(alreverb examples/alreverb.c)
1639         target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1640             ${UNICODE_FLAG})
1642         add_executable(almultireverb examples/almultireverb.c)
1643         target_link_libraries(almultireverb
1644             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1646         add_executable(allatency examples/allatency.c)
1647         target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1648             ${UNICODE_FLAG})
1650         add_executable(alhrtf examples/alhrtf.c)
1651         target_link_libraries(alhrtf
1652             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1654         add_executable(alstreamcb examples/alstreamcb.cpp)
1655         target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1656             ${UNICODE_FLAG})
1658         add_executable(alconvolve examples/alconvolve.c)
1659         target_link_libraries(alconvolve PRIVATE ${LINKER_FLAGS} common SndFile::SndFile ex-common
1660             ${UNICODE_FLAG})
1662         if(ALSOFT_INSTALL_EXAMPLES)
1663             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1664                 alhrtf)
1665         endif()
1667         message(STATUS "Building SndFile example programs")
1668     endif()
1670     if(SDL2_FOUND)
1671         add_executable(alloopback examples/alloopback.c)
1672         target_include_directories(alloopback PRIVATE ${SDL2_INCLUDE_DIR})
1673         target_link_libraries(alloopback
1674             PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ex-common ${MATH_LIB})
1676         if(ALSOFT_INSTALL_EXAMPLES)
1677             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
1678         endif()
1680         message(STATUS "Building SDL example programs")
1682         set(FFVER_OK FALSE)
1683         if(FFMPEG_FOUND)
1684             set(FFVER_OK TRUE)
1685             if(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1686                 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1687                 set(FFVER_OK FALSE)
1688             endif()
1689             if(AVCODEC_VERSION VERSION_LESS "57.64.101")
1690                 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1691                 set(FFVER_OK FALSE)
1692             endif()
1693             if(AVUTIL_VERSION VERSION_LESS "55.34.101")
1694                 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1695                 set(FFVER_OK FALSE)
1696             endif()
1697             if(SWSCALE_VERSION VERSION_LESS "4.2.100")
1698                 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1699                 set(FFVER_OK FALSE)
1700             endif()
1701             if(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1702                 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1703                 set(FFVER_OK FALSE)
1704             endif()
1705         endif()
1706         if(FFVER_OK)
1707             add_executable(alffplay examples/alffplay.cpp)
1708             target_include_directories(alffplay
1709                 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1710             target_link_libraries(alffplay
1711                 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common)
1713             if(ALSOFT_INSTALL_EXAMPLES)
1714                 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
1715             endif()
1716             message(STATUS "Building SDL+FFmpeg example programs")
1717         endif()
1718     endif()
1719     message(STATUS "")
1720 endif()
1722 if(EXTRA_INSTALLS)
1723     install(TARGETS ${EXTRA_INSTALLS}
1724         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1725         BUNDLE  DESTINATION ${CMAKE_INSTALL_BINDIR}
1726         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1727         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1728 endif()