Release 1.21.0
[openal-soft.git] / CMakeLists.txt
blobf811f31f02c010061a04ac8af95c06ece66f3f2b
1 # CMake build file list for OpenAL
3 cmake_minimum_required(VERSION 3.0.2)
5 # The workaround for try_compile failing with code signing
6 # since cmake-3.18.2, not required
7 set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
8     "CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED"
9     "CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED")
10 set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
11 set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
13 # Fix compile failure with armv7 deployment target >= 11.0, xcode clang will
14 # report:
15 # error: invalid iOS deployment version '--target=armv7-apple-ios13.6',
16 # iOS 10 is the maximum deployment target for 32-bit targets
17 # If CMAKE_OSX_DEPLOYMENT_TARGET is not defined, cmake will choose latest
18 # deployment target
19 if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
20     if("${CMAKE_OSX_ARCHITECTURES}" MATCHES ".*armv7.*")
21         if(NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET
22             OR NOT CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS "11.0")
23             message(STATUS "Forcing iOS deployment target to 10.0 for armv7")
24             set(CMAKE_OSX_DEPLOYMENT_TARGET "10.0" CACHE STRING "Minimum OS X deployment version"
25                 FORCE)
26         endif()
27     endif()
28 endif()
30 project(OpenAL)
32 if(COMMAND CMAKE_POLICY)
33     cmake_policy(SET CMP0003 NEW)
34     cmake_policy(SET CMP0005 NEW)
35     if(POLICY CMP0020)
36         cmake_policy(SET CMP0020 NEW)
37     endif(POLICY CMP0020)
38     if(POLICY CMP0042)
39         cmake_policy(SET CMP0042 NEW)
40     endif(POLICY CMP0042)
41     if(POLICY CMP0054)
42         cmake_policy(SET CMP0054 NEW)
43     endif(POLICY CMP0054)
44     if(POLICY CMP0075)
45         cmake_policy(SET CMP0075 NEW)
46     endif(POLICY CMP0075)
47 endif(COMMAND CMAKE_POLICY)
49 if(NOT CMAKE_BUILD_TYPE)
50     set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
51         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
52         FORCE)
53 endif()
54 if(NOT CMAKE_DEBUG_POSTFIX)
55     set(CMAKE_DEBUG_POSTFIX "" CACHE STRING
56         "Library postfix for debug builds. Normally left blank."
57         FORCE)
58 endif()
60 set(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
62 include(CheckFunctionExists)
63 include(CheckLibraryExists)
64 include(CheckIncludeFile)
65 include(CheckIncludeFiles)
66 include(CheckSymbolExists)
67 include(CheckCCompilerFlag)
68 include(CheckCXXCompilerFlag)
69 include(CheckCSourceCompiles)
70 include(CheckCXXSourceCompiles)
71 include(CheckStructHasMember)
72 include(GNUInstallDirs)
75 option(ALSOFT_DLOPEN  "Check for the dlopen API for loading optional libs"  ON)
77 option(ALSOFT_WERROR  "Treat compile warnings as errors"      OFF)
79 option(ALSOFT_UTILS "Build utility programs"  ON)
80 option(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
82 option(ALSOFT_EXAMPLES  "Build example programs"  ON)
84 option(ALSOFT_INSTALL "Install main library" ON)
85 option(ALSOFT_INSTALL_CONFIG "Install alsoft.conf sample configuration file" ON)
86 option(ALSOFT_INSTALL_HRTF_DATA "Install HRTF data files" ON)
87 option(ALSOFT_INSTALL_AMBDEC_PRESETS "Install AmbDec preset files" ON)
88 option(ALSOFT_INSTALL_EXAMPLES "Install example programs (alplay, alstream, ...)" ON)
89 option(ALSOFT_INSTALL_UTILS "Install utility programs (openal-info, alsoft-config, ...)" ON)
90 option(ALSOFT_UPDATE_BUILD_VERSION "Update git build version info" ON)
92 if(DEFINED SHARE_INSTALL_DIR)
93     message(WARNING "SHARE_INSTALL_DIR is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
94     set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
95 endif()
97 if(DEFINED LIB_SUFFIX)
98     message(WARNING "LIB_SUFFIX is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
99 endif()
100 if(DEFINED ALSOFT_CONFIG)
101     message(WARNING "ALSOFT_CONFIG is deprecated. Use ALSOFT_INSTALL_CONFIG instead")
102 endif()
103 if(DEFINED ALSOFT_HRTF_DEFS)
104     message(WARNING "ALSOFT_HRTF_DEFS is deprecated. Use ALSOFT_INSTALL_HRTF_DATA instead")
105 endif()
106 if(DEFINED ALSOFT_AMBDEC_PRESETS)
107     message(WARNING "ALSOFT_AMBDEC_PRESETS is deprecated. Use ALSOFT_INSTALL_AMBDEC_PRESETS instead")
108 endif()
111 set(CPP_DEFS ) # C pre-processor, not C++
112 set(INC_PATHS )
113 set(C_FLAGS )
114 set(LINKER_FLAGS )
115 set(EXTRA_LIBS )
117 if(WIN32)
118     set(CPP_DEFS ${CPP_DEFS} _WIN32)
119     if(MINGW)
120         set(CPP_DEFS ${CPP_DEFS} __USE_MINGW_ANSI_STDIO)
121     endif()
123     option(ALSOFT_BUILD_ROUTER  "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)"  OFF)
124     if(MINGW)
125         option(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
126     endif()
127 elseif(APPLE)
128     option(ALSOFT_OSX_FRAMEWORK "Build as macOS framework" OFF)
129 endif()
132 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
133 if("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
134     set(INC_PATHS ${INC_PATHS} /usr/include)
135     set(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
136 endif()
138 # When the library is built for static linking, apps should define
139 # AL_LIBTYPE_STATIC when including the AL headers.
140 if(NOT LIBTYPE)
141     set(LIBTYPE SHARED)
142 endif()
144 set(LIB_MAJOR_VERSION "1")
145 set(LIB_MINOR_VERSION "21")
146 set(LIB_REVISION "0")
147 set(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
148 set(LIB_VERSION_NUM ${LIB_MAJOR_VERSION},${LIB_MINOR_VERSION},${LIB_REVISION},0)
150 set(EXPORT_DECL "")
153 # Require C++14
154 set(CMAKE_CXX_STANDARD 14)
155 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
157 # Prefer C11, but support C99 and C90 too.
158 set(CMAKE_C_STANDARD 11)
160 if(NOT WIN32)
161     # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
162     check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
163     if(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
164         set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
165         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
166         check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
167         if(NOT HAVE_POSIX_MEMALIGN_POSIX)
168             set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
169         else()
170             set(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
171         endif()
172     endif()
173     unset(OLD_REQUIRED_FLAGS)
174 endif()
176 # C99 has restrict, but C++ does not, so we can only utilize __restrict.
177 check_cxx_source_compiles("int *__restrict foo;
178 int main() { return 0; }" HAVE___RESTRICT)
179 if(HAVE___RESTRICT)
180     set(CPP_DEFS ${CPP_DEFS} RESTRICT=__restrict)
181 else()
182     set(CPP_DEFS ${CPP_DEFS} "RESTRICT=")
183 endif()
185 # Some systems may need libatomic for atomic functions to work
186 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
187 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
188 check_cxx_source_compiles("#include <atomic>
189 std::atomic<int> foo{0};
190 int main() { return foo.fetch_add(2); }"
191 HAVE_LIBATOMIC)
192 if(NOT HAVE_LIBATOMIC)
193     set(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
194 else()
195     set(EXTRA_LIBS atomic ${EXTRA_LIBS})
196 endif()
197 unset(OLD_REQUIRED_LIBRARIES)
199 # Include liblog for Android logging
200 check_library_exists(log __android_log_print "" HAVE_LIBLOG)
201 if(HAVE_LIBLOG)
202     set(EXTRA_LIBS log ${EXTRA_LIBS})
203     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
204 endif()
206 if(MSVC)
207     set(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS NOMINMAX)
208     check_cxx_compiler_flag(/permissive- HAVE_PERMISSIVE_SWITCH)
209     if(HAVE_PERMISSIVE_SWITCH)
210         set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
211     endif()
212     set(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4268 /wd4324 /wd5030)
213     # Remove /W3, which is added by default, since we set /W4. Some build
214     # generators with MSVC complain about both /W3 and /W4 being specified.
215     foreach(flag_var  CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
216         if(${flag_var} MATCHES "/W3")
217             string(REGEX REPLACE "/W3" "" ${flag_var} "${${flag_var}}")
218         endif()
219     endforeach()
221     if(NOT DXSDK_DIR)
222         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
223     else()
224         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
225     endif()
226     if(DXSDK_DIR)
227         message(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
228     endif()
230     option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
231     if(FORCE_STATIC_VCRT)
232         foreach(flag_var
233                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
234                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
235                 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
236                 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
237             if(${flag_var} MATCHES "/MD")
238                 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
239             endif()
240         endforeach(flag_var)
241     endif()
242 else()
243     set(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
244         -Wpedantic
245         $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
247     if(ALSOFT_WERROR)
248         set(C_FLAGS ${C_FLAGS} -Werror)
249     endif()
251     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
252     # instead of NDEBUG)
253     foreach(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
254         if(${flag_var} MATCHES "-DNDEBUG")
255             string(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
256         endif()
257     endforeach()
259     check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
260     if(HAVE_FNO_MATH_ERRNO)
261         set(C_FLAGS ${C_FLAGS} -fno-math-errno)
262     endif()
264     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
265     if(ALSOFT_STATIC_LIBGCC)
266         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
267         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
268         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
269         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
270         unset(OLD_REQUIRED_LIBRARIES)
272         if(NOT HAVE_STATIC_LIBGCC_SWITCH)
273             message(FATAL_ERROR "Cannot static link libgcc")
274         endif()
275         set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
276     endif()
278     option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
279     if(ALSOFT_STATIC_STDCXX)
280         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
281         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
282         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
283         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
284         unset(OLD_REQUIRED_LIBRARIES)
286         if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
287             message(FATAL_ERROR "Cannot static link libstdc++")
288         endif()
289         set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
290     endif()
292     if(WIN32)
293         option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
294         if(ALSOFT_STATIC_WINPTHREAD)
295             set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
296             set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
297             check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
298             set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
299             unset(OLD_REQUIRED_LIBRARIES)
301             if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
302                 message(FATAL_ERROR "Cannot static link libwinpthread")
303             endif()
304             set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
305         endif()
306     endif()
307 endif()
309 # Set visibility/export options if available
310 if(WIN32)
311     if(NOT LIBTYPE STREQUAL "STATIC")
312         set(EXPORT_DECL "__declspec(dllexport)")
313     endif()
314 else()
315     set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
316     # Yes GCC, really don't accept visibility modes you don't support
317     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
319     check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
320                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
321     if(HAVE_GCC_PROTECTED_VISIBILITY)
322         if(NOT LIBTYPE STREQUAL "STATIC")
323             set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
324         endif()
325     else()
326         check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
327                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
328         if(HAVE_GCC_DEFAULT_VISIBILITY)
329             if(NOT LIBTYPE STREQUAL "STATIC")
330                 set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
331             endif()
332         endif()
333     endif()
335     if(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
336         check_c_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
337         if(HAVE_VISIBILITY_HIDDEN_SWITCH)
338             set(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
339         endif()
340     endif()
342     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
343 endif()
346 set(SSE2_SWITCH "")
347 set(SSE3_SWITCH "")
348 set(SSE4_1_SWITCH "")
349 set(FPU_NEON_SWITCH "")
351 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
352 if(NOT MSVC)
353     # Yes GCC, really don't accept command line options you don't support
354     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
355 endif()
356 check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
357 if(HAVE_MSSE2_SWITCH)
358     set(SSE2_SWITCH "-msse2")
359     check_c_compiler_flag(-msse3 HAVE_MSSE3_SWITCH)
360     if(HAVE_MSSE3_SWITCH)
361         set(SSE3_SWITCH "-msse3")
362         check_c_compiler_flag(-msse4.1 HAVE_MSSE4_1_SWITCH)
363         if(HAVE_MSSE4_1_SWITCH)
364             set(SSE4_1_SWITCH "-msse4.1")
365         endif()
366     endif()
367 endif()
368 check_c_compiler_flag(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
369 if(HAVE_MFPU_NEON_SWITCH)
370     set(FPU_NEON_SWITCH "-mfpu=neon")
371 endif()
372 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
373 unset(OLD_REQUIRED_FLAGS)
375 check_include_file(xmmintrin.h HAVE_XMMINTRIN_H ${SSE2_SWITCH})
376 check_include_file(emmintrin.h HAVE_EMMINTRIN_H ${SSE2_SWITCH})
377 check_include_file(pmmintrin.h HAVE_PMMINTRIN_H ${SSE3_SWITCH})
378 check_include_file(smmintrin.h HAVE_SMMINTRIN_H ${SSE4_1_SWITCH})
379 check_include_file(arm_neon.h HAVE_ARM_NEON_H ${FPU_NEON_SWITCH})
381 set(SSE_FLAGS )
382 set(FPMATH_SET "0")
383 if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND (SSE2_SWITCH OR MSVC))
384     option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
385     if(ALSOFT_ENABLE_SSE2_CODEGEN)
386         if(SSE2_SWITCH)
387             check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
388             if(HAVE_MFPMATH_SSE_2)
389                 set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
390                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
391                 set(FPMATH_SET 2)
392             endif()
393             # SSE depends on a 16-byte aligned stack, and by default, GCC
394             # assumes the stack is suitably aligned. Older Linux code or other
395             # OSs don't guarantee this on 32-bit, so externally-callable
396             # functions need to ensure an aligned stack.
397             set(EXPORT_DECL "${EXPORT_DECL} __attribute__((force_align_arg_pointer))")
398         elseif(MSVC)
399             check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
400             if(HAVE_ARCH_SSE2)
401                 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
402                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
403                 set(FPMATH_SET 2)
404             endif()
405         endif()
406     endif()
407 endif()
409 if(HAVE_EMMINTRIN_H)
410     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
411     foreach(flag_var ${SSE_FLAGS})
412         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
413     endforeach()
415     check_c_source_compiles("#include <emmintrin.h>
416                              int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
418     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
419 endif()
422 check_include_file(malloc.h HAVE_MALLOC_H)
423 check_include_file(cpuid.h HAVE_CPUID_H)
424 check_include_file(intrin.h HAVE_INTRIN_H)
425 check_include_file(guiddef.h HAVE_GUIDDEF_H)
426 if(NOT HAVE_GUIDDEF_H)
427     check_include_file(initguid.h HAVE_INITGUID_H)
428 endif()
430 # Some systems need libm for some math functions to work
431 set(MATH_LIB )
432 check_library_exists(m pow "" HAVE_LIBM)
433 if(HAVE_LIBM)
434     set(MATH_LIB ${MATH_LIB} m)
435     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
436 endif()
438 # Some systems need to link with -lrt for clock_gettime as used by the common
439 # eaxmple functions.
440 set(RT_LIB )
441 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
442 if(HAVE_LIBRT)
443     set(RT_LIB rt)
444 endif()
446 # Check for the dlopen API (for dynamicly loading backend libs)
447 if(ALSOFT_DLOPEN)
448     check_include_file(dlfcn.h HAVE_DLFCN_H)
449     check_library_exists(dl dlopen "" HAVE_LIBDL)
450     if(HAVE_LIBDL)
451         set(EXTRA_LIBS dl ${EXTRA_LIBS})
452         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
453     endif()
454 endif()
456 # Check for a cpuid intrinsic
457 if(HAVE_CPUID_H)
458     check_c_source_compiles("#include <cpuid.h>
459         int main()
460         {
461             unsigned int eax, ebx, ecx, edx;
462             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
463         }" HAVE_GCC_GET_CPUID)
464 endif()
465 if(HAVE_INTRIN_H)
466     check_c_source_compiles("#include <intrin.h>
467         int main()
468         {
469             int regs[4];
470             __cpuid(regs, 0);
471             return regs[0];
472         }" HAVE_CPUID_INTRINSIC)
473 endif()
475 check_cxx_source_compiles("#include <cstdlib>
476 int main()
478     void *ptr{std::aligned_alloc(alignof(int), sizeof(int))};
479     std::free(ptr);
480     return 0;
481 }" HAVE_STD_ALIGNED_ALLOC)
482 check_symbol_exists(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
483 check_symbol_exists(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
484 check_symbol_exists(proc_pidpath     libproc.h HAVE_PROC_PIDPATH)
486 if(NOT WIN32)
487     # We need pthreads outside of Windows, for semaphores. It's also used to
488     # set the priority and name of threads, when possible.
489     check_include_file(pthread.h HAVE_PTHREAD_H)
490     if(NOT HAVE_PTHREAD_H)
491         message(FATAL_ERROR "PThreads is required for non-Windows builds!")
492     endif()
494     check_c_compiler_flag(-pthread HAVE_PTHREAD)
495     if(HAVE_PTHREAD)
496         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
497         set(C_FLAGS ${C_FLAGS} -pthread)
498         set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
499     endif()
501     check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
503     # Some systems need pthread_np.h to get pthread_setname_np
504     check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
505     if(HAVE_PTHREAD_NP_H)
506         check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
507         if(NOT HAVE_PTHREAD_SETNAME_NP)
508             check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
509         else()
510             check_c_source_compiles("
511 #include <pthread.h>
512 #include <pthread_np.h>
513 int main()
515     pthread_setname_np(\"testname\");
516     return 0;
518                 PTHREAD_SETNAME_NP_ONE_PARAM
519             )
520             check_c_source_compiles("
521 #include <pthread.h>
522 #include <pthread_np.h>
523 int main()
525     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
526     return 0;
528                 PTHREAD_SETNAME_NP_THREE_PARAMS
529             )
530         endif()
531     else()
532         check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
533         if(NOT HAVE_PTHREAD_SETNAME_NP)
534             check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
535         else()
536             check_c_source_compiles("
537 #include <pthread.h>
538 int main()
540     pthread_setname_np(\"testname\");
541     return 0;
543                 PTHREAD_SETNAME_NP_ONE_PARAM
544             )
545             check_c_source_compiles("
546 #include <pthread.h>
547 int main()
549     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
550     return 0;
552                 PTHREAD_SETNAME_NP_THREE_PARAMS
553             )
554         endif()
555     endif()
556 endif()
558 check_symbol_exists(getopt unistd.h HAVE_GETOPT)
561 # Common sources used by both the OpenAL implementation library and potentially
562 # the OpenAL router.
563 set(COMMON_OBJS
564     common/albyte.h
565     common/alcomplex.cpp
566     common/alcomplex.h
567     common/alexcpt.cpp
568     common/alexcpt.h
569     common/alfstream.cpp
570     common/alfstream.h
571     common/almalloc.cpp
572     common/almalloc.h
573     common/alnumeric.h
574     common/aloptional.h
575     common/alspan.h
576     common/alstring.cpp
577     common/alstring.h
578     common/atomic.h
579     common/dynload.cpp
580     common/dynload.h
581     common/endiantest.h
582     common/intrusive_ptr.h
583     common/math_defs.h
584     common/opthelpers.h
585     common/polyphase_resampler.cpp
586     common/polyphase_resampler.h
587     common/pragmadefs.h
588     common/strutils.cpp
589     common/strutils.h
590     common/threads.cpp
591     common/threads.h
592     common/vecmat.h
593     common/vector.h
595 set(OPENAL_OBJS
596     al/auxeffectslot.cpp
597     al/auxeffectslot.h
598     al/buffer.cpp
599     al/buffer.h
600     al/effect.cpp
601     al/effect.h
602     al/error.cpp
603     al/event.cpp
604     al/event.h
605     al/extension.cpp
606     al/filter.cpp
607     al/filter.h
608     al/listener.cpp
609     al/listener.h
610     al/source.cpp
611     al/source.h
612     al/state.cpp
614 set(ALC_OBJS
615     alc/alc.cpp
616     alc/alcmain.h
617     alc/alu.cpp
618     alc/alu.h
619     alc/alconfig.cpp
620     alc/alconfig.h
621     alc/alcontext.h
622     alc/ambdec.cpp
623     alc/ambdec.h
624     alc/ambidefs.h
625     alc/bformatdec.cpp
626     alc/bformatdec.h
627     alc/bs2b.cpp
628     alc/bs2b.h
629     alc/bsinc_defs.h
630     alc/bsinc_tables.cpp
631     alc/bsinc_tables.h
632     alc/bufferline.h
633     alc/buffer_storage.cpp
634     alc/buffer_storage.h
635     alc/compat.h
636     alc/converter.cpp
637     alc/converter.h
638     alc/cpu_caps.cpp
639     alc/cpu_caps.h
640     alc/devformat.h
641     alc/effects/base.h
642     alc/effects/autowah.cpp
643     alc/effects/chorus.cpp
644     alc/effects/compressor.cpp
645     alc/effects/convolution.cpp
646     alc/effects/dedicated.cpp
647     alc/effects/distortion.cpp
648     alc/effects/echo.cpp
649     alc/effects/equalizer.cpp
650     alc/effects/fshifter.cpp
651     alc/effects/modulator.cpp
652     alc/effects/null.cpp
653     alc/effects/pshifter.cpp
654     alc/effects/reverb.cpp
655     alc/effects/vmorpher.cpp
656     alc/filters/biquad.h
657     alc/filters/biquad.cpp
658     alc/filters/nfc.cpp
659     alc/filters/nfc.h
660     alc/filters/splitter.cpp
661     alc/filters/splitter.h
662     alc/fmt_traits.cpp
663     alc/fmt_traits.h
664     alc/fpu_ctrl.cpp
665     alc/fpu_ctrl.h
666     alc/front_stablizer.h
667     alc/helpers.cpp
668     alc/hrtf.cpp
669     alc/hrtf.h
670     alc/inprogext.h
671     alc/logging.h
672     alc/mastering.cpp
673     alc/mastering.h
674     alc/panning.cpp
675     alc/ringbuffer.cpp
676     alc/ringbuffer.h
677     alc/uhjfilter.cpp
678     alc/uhjfilter.h
679     alc/uiddefs.cpp
680     alc/voice.cpp
681     alc/voice.h
682     alc/mixer/defs.h
683     alc/mixer/hrtfbase.h
684     alc/mixer/mixer_c.cpp
688 set(CPU_EXTS "Default")
689 set(HAVE_SSE        0)
690 set(HAVE_SSE2       0)
691 set(HAVE_SSE3       0)
692 set(HAVE_SSE4_1     0)
693 set(HAVE_NEON       0)
695 # Check for SSE+SSE2 support
696 option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
697 option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
698 if(HAVE_XMMINTRIN_H AND HAVE_EMMINTRIN_H)
699     option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
700     option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
701     if(ALSOFT_CPUEXT_SSE AND ALSOFT_CPUEXT_SSE2)
702         set(HAVE_SSE 1)
703         set(HAVE_SSE2 1)
704         set(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse.cpp alc/mixer/mixer_sse2.cpp)
705         if(SSE2_SWITCH)
706             set_source_files_properties(alc/mixer/mixer_sse.cpp alc/mixer/mixer_sse2.cpp
707                 PROPERTIES COMPILE_FLAGS "${SSE2_SWITCH}")
708         endif()
709         set(CPU_EXTS "${CPU_EXTS}, SSE, SSE2")
710     endif()
711 endif()
712 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
713     message(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
714 endif()
715 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
716     message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
717 endif()
719 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
720 if(HAVE_EMMINTRIN_H)
721     option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
722     if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
723         set(HAVE_SSE3 1)
724         set(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse3.cpp)
725         if(SSE2_SWITCH)
726             set_source_files_properties(alc/mixer/mixer_sse3.cpp PROPERTIES
727                 COMPILE_FLAGS "${SSE3_SWITCH}")
728         endif()
729         set(CPU_EXTS "${CPU_EXTS}, SSE3")
730     endif()
731 endif()
732 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
733     message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
734 endif()
736 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
737 if(HAVE_SMMINTRIN_H)
738     option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
739     if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
740         set(HAVE_SSE4_1 1)
741         set(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse41.cpp)
742         if(SSE4_1_SWITCH)
743             set_source_files_properties(alc/mixer/mixer_sse41.cpp PROPERTIES
744                 COMPILE_FLAGS "${SSE4_1_SWITCH}")
745         endif()
746         set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
747     endif()
748 endif()
749 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
750     message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
751 endif()
753 # Check for ARM Neon support
754 option(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
755 if(HAVE_ARM_NEON_H)
756     option(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
757     if(ALSOFT_CPUEXT_NEON)
758         set(HAVE_NEON 1)
759         set(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_neon.cpp)
760         if(FPU_NEON_SWITCH)
761             set_source_files_properties(alc/mixer/mixer_neon.cpp PROPERTIES
762                 COMPILE_FLAGS "${FPU_NEON_SWITCH}")
763         endif()
764         set(CPU_EXTS "${CPU_EXTS}, Neon")
765     endif()
766 endif()
767 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
768     message(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
769 endif()
772 set(HAVE_ALSA       0)
773 set(HAVE_OSS        0)
774 set(HAVE_SOLARIS    0)
775 set(HAVE_SNDIO      0)
776 set(HAVE_DSOUND     0)
777 set(HAVE_WASAPI     0)
778 set(HAVE_WINMM      0)
779 set(HAVE_PORTAUDIO  0)
780 set(HAVE_PULSEAUDIO 0)
781 set(HAVE_COREAUDIO  0)
782 set(HAVE_OPENSL     0)
783 set(HAVE_OBOE       0)
784 set(HAVE_WAVE       0)
785 set(HAVE_SDL2       0)
787 if(WIN32 OR HAVE_DLFCN_H)
788     set(IS_LINKED "")
789     macro(ADD_BACKEND_LIBS _LIBS)
790     endmacro()
791 else()
792     set(IS_LINKED " (linked)")
793     macro(ADD_BACKEND_LIBS _LIBS)
794         set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
795     endmacro()
796 endif()
798 set(BACKENDS "")
799 set(ALC_OBJS  ${ALC_OBJS}
800     alc/backends/base.cpp
801     alc/backends/base.h
802     # Default backends, always available
803     alc/backends/loopback.cpp
804     alc/backends/loopback.h
805     alc/backends/null.cpp
806     alc/backends/null.h
809 # Check ALSA backend
810 option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
811 find_package(ALSA)
812 if(ALSA_FOUND)
813     option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
814     if(ALSOFT_BACKEND_ALSA)
815         set(HAVE_ALSA 1)
816         set(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
817         set(ALC_OBJS  ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
818         add_backend_libs(${ALSA_LIBRARIES})
819         set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
820     endif()
821 endif()
822 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
823     message(FATAL_ERROR "Failed to enabled required ALSA backend")
824 endif()
826 # Check OSS backend
827 option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
828 find_package(OSS)
829 if(OSS_FOUND)
830     option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
831     if(ALSOFT_BACKEND_OSS)
832         set(HAVE_OSS 1)
833         set(BACKENDS  "${BACKENDS} OSS,")
834         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
835         if(OSS_LIBRARIES)
836             set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
837         endif()
838         set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
839     endif()
840 endif()
841 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
842     message(FATAL_ERROR "Failed to enabled required OSS backend")
843 endif()
845 # Check Solaris backend
846 option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
847 find_package(AudioIO)
848 if(AUDIOIO_FOUND)
849     option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
850     if(ALSOFT_BACKEND_SOLARIS)
851         set(HAVE_SOLARIS 1)
852         set(BACKENDS  "${BACKENDS} Solaris,")
853         set(ALC_OBJS  ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
854         set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
855     endif()
856 endif()
857 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
858     message(FATAL_ERROR "Failed to enabled required Solaris backend")
859 endif()
861 # Check SndIO backend
862 option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
863 find_package(SoundIO)
864 if(SOUNDIO_FOUND)
865     option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
866     if(ALSOFT_BACKEND_SNDIO)
867         set(HAVE_SNDIO 1)
868         set(BACKENDS  "${BACKENDS} SndIO (linked),")
869         set(ALC_OBJS  ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
870         set(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
871         set(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
872     endif()
873 endif()
874 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
875     message(FATAL_ERROR "Failed to enabled required SndIO backend")
876 endif()
878 # Check Windows-only backends
879 option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
880 option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
881 option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
882 if(WIN32)
883     set(WINSDK_LIB_DIRS )
884     set(WINSDK_INCLUDE_DIRS )
885     find_package(WindowsSDK)
886     if(WINDOWSSDK_FOUND)
887         get_windowssdk_library_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_LIB_DIRS)
888         get_windowssdk_include_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_INCLUDE_DIRS)
889     endif()
891     # Check MMSystem backend
892     check_include_files("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
893     find_library(WINMM_LIBRARY NAMES winmm
894         PATHS ${WINSDK_LIB_DIRS})
895     if(HAVE_MMSYSTEM_H AND WINMM_LIBRARY)
896         option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
897         if(ALSOFT_BACKEND_WINMM)
898             set(HAVE_WINMM 1)
899             set(BACKENDS  "${BACKENDS} WinMM,")
900             set(ALC_OBJS  ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
901             set(EXTRA_LIBS ${WINMM_LIBRARY} ${EXTRA_LIBS})
902         endif()
903     endif()
905     # Check DSound backend
906     find_package(DSound)
907     if(DSOUND_FOUND)
908         option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
909         if(ALSOFT_BACKEND_DSOUND)
910             set(HAVE_DSOUND 1)
911             set(BACKENDS  "${BACKENDS} DirectSound${IS_LINKED},")
912             set(ALC_OBJS  ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
913             add_backend_libs(${DSOUND_LIBRARIES})
914             set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIRS})
915         endif()
916     endif()
918     # Check for WASAPI backend
919     check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
920     if(HAVE_MMDEVICEAPI_H)
921         option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
922         if(ALSOFT_BACKEND_WASAPI)
923             set(HAVE_WASAPI 1)
924             set(BACKENDS  "${BACKENDS} WASAPI,")
925             set(ALC_OBJS  ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
926         endif()
927     endif()
928 endif()
929 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
930     message(FATAL_ERROR "Failed to enabled required WinMM backend")
931 endif()
932 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
933     message(FATAL_ERROR "Failed to enabled required DSound backend")
934 endif()
935 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
936     message(FATAL_ERROR "Failed to enabled required WASAPI backend")
937 endif()
939 # Check PortAudio backend
940 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
941 find_package(PortAudio)
942 if(PORTAUDIO_FOUND)
943     option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
944     if(ALSOFT_BACKEND_PORTAUDIO)
945         set(HAVE_PORTAUDIO 1)
946         set(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
947         set(ALC_OBJS  ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
948         add_backend_libs(${PORTAUDIO_LIBRARIES})
949         set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
950     endif()
951 endif()
952 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
953     message(FATAL_ERROR "Failed to enabled required PortAudio backend")
954 endif()
956 # Check PulseAudio backend
957 option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
958 find_package(PulseAudio)
959 if(PULSEAUDIO_FOUND)
960     option(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
961     if(ALSOFT_BACKEND_PULSEAUDIO)
962         set(HAVE_PULSEAUDIO 1)
963         set(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
964         set(ALC_OBJS  ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
965         add_backend_libs(${PULSEAUDIO_LIBRARIES})
966         set(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
967     endif()
968 endif()
969 if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
970     message(FATAL_ERROR "Failed to enabled required PulseAudio backend")
971 endif()
973 # Check JACK backend
974 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
975 find_package(JACK)
976 if(JACK_FOUND)
977     option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
978     if(ALSOFT_BACKEND_JACK)
979         set(HAVE_JACK 1)
980         set(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
981         set(ALC_OBJS  ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
982         add_backend_libs(${JACK_LIBRARIES})
983         set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
984     endif()
985 endif()
986 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
987     message(FATAL_ERROR "Failed to enabled required JACK backend")
988 endif()
990 # Check CoreAudio backend
991 option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
992 find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
993 find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
994 if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
995     option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
996     if(ALSOFT_BACKEND_COREAUDIO)
997         set(HAVE_COREAUDIO 1)
998         set(ALC_OBJS  ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
999         set(BACKENDS  "${BACKENDS} CoreAudio,")
1000         if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
1001             find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
1002             set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${COREFOUNDATION_FRAMEWORK} ${EXTRA_LIBS})
1003         else()
1004             set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} /System/Library/Frameworks/AudioUnit.framework
1005                 /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1006         endif()
1008         # Some versions of OSX may need the AudioToolbox framework. Add it if
1009         # it's found.
1010         find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
1011         if(AUDIOTOOLBOX_LIBRARY)
1012             set(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1013         endif()
1015         set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
1016     endif()
1017 endif()
1018 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1019     message(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1020 endif()
1022 # Check for OpenSL (Android) backend
1023 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1024 find_package(OpenSL)
1025 if(OPENSL_FOUND)
1026     option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1027     if(ALSOFT_BACKEND_OPENSL)
1028         set(HAVE_OPENSL 1)
1029         set(ALC_OBJS  ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1030         set(BACKENDS  "${BACKENDS} OpenSL,")
1031         set(EXTRA_LIBS ${OPENSL_LIBRARIES} ${EXTRA_LIBS})
1032         set(INC_PATHS ${INC_PATHS} ${OPENSL_INCLUDE_DIRS})
1033     endif()
1034 endif()
1035 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1036     message(FATAL_ERROR "Failed to enabled required OpenSL backend")
1037 endif()
1039 # Check for Oboe (Android) backend
1040 set(OBOE_TARGET )
1041 if(ANDROID)
1042     set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1043     if(OBOE_SOURCE)
1044         # Force Oboe to build with hidden symbols. Don't want to be exporting
1045         # them from OpenAL.
1046         set(OLD_CXX_FLAGS ${CMAKE_CXX_FLAGS})
1047         check_cxx_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
1048         if(HAVE_VISIBILITY_HIDDEN_SWITCH)
1049             set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
1050         endif()
1051         add_subdirectory(${OBOE_SOURCE} ./oboe)
1052         set(CMAKE_CXX_FLAGS ${OLD_CXX_FLAGS})
1053         unset(OLD_CXX_FLAGS)
1055         set(OBOE_TARGET oboe)
1056     else()
1057         find_package(Oboe)
1058         if(OBOE_FOUND)
1059             set(OBOE_TARGET "oboe::oboe")
1060         endif()
1061     endif()
1062 endif()
1064 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1065 if(OBOE_TARGET)
1066     option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1067     if(ALSOFT_BACKEND_OBOE)
1068         set(HAVE_OBOE 1)
1069         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
1070         set(BACKENDS  "${BACKENDS} Oboe,")
1071         set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
1072     endif()
1073 endif()
1074 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1075     message(FATAL_ERROR "Failed to enabled required Oboe backend")
1076 endif()
1078 # Check for SDL2 backend
1079 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1080 find_package(SDL2)
1081 if(SDL2_FOUND)
1082     # Off by default, since it adds a runtime dependency
1083     option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1084     if(ALSOFT_BACKEND_SDL2)
1085         set(HAVE_SDL2 1)
1086         set(ALC_OBJS  ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1087         set(BACKENDS  "${BACKENDS} SDL2,")
1088         set(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
1089         set(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
1090     endif()
1091 endif()
1092 if(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1093     message(FATAL_ERROR "Failed to enabled required SDL2 backend")
1094 endif()
1096 # Optionally enable the Wave Writer backend
1097 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1098 if(ALSOFT_BACKEND_WAVE)
1099     set(HAVE_WAVE 1)
1100     set(ALC_OBJS  ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1101     set(BACKENDS  "${BACKENDS} WaveFile,")
1102 endif()
1104 # This is always available
1105 set(BACKENDS  "${BACKENDS} Null")
1108 find_package(Git)
1109 if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1110     # Get the current working branch and its latest abbreviated commit hash
1111     add_custom_target(build_version
1112         ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1113             -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1114             -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1115         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1116         VERBATIM
1117     )
1118 else()
1119     set(GIT_BRANCH "UNKNOWN")
1120     set(GIT_COMMIT_HASH "unknown")
1121     configure_file(
1122         "${OpenAL_SOURCE_DIR}/version.h.in"
1123         "${OpenAL_BINARY_DIR}/version.h")
1124 endif()
1127 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1128 if(ALSOFT_EMBED_HRTF_DATA)
1129     macro(make_hrtf_header FILENAME VARNAME)
1130         set(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1131         set(outfile  "${OpenAL_BINARY_DIR}/${VARNAME}.h")
1133         add_custom_command(OUTPUT "${outfile}"
1134             COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
1135                 -D "VARIABLE_NAME=${VARNAME}" -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1136             WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1137             DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1138             VERBATIM
1139         )
1140         set(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1141     endmacro()
1143     make_hrtf_header("Default HRTF.mhr" "hrtf_default")
1144 endif()
1147 if(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1148     find_package(Qt5Widgets)
1149 endif()
1150 if(ALSOFT_EXAMPLES)
1151     find_package(SndFile)
1152     find_package(SDL2)
1153     if(SDL2_FOUND)
1154         find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1155     endif()
1156 endif()
1158 if(NOT WIN32)
1159     set(LIBNAME "openal")
1160 else()
1161     set(LIBNAME "OpenAL32")
1162 endif()
1164 # Needed for openal.pc.in
1165 set(prefix ${CMAKE_INSTALL_PREFIX})
1166 set(exec_prefix "\${prefix}")
1167 set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1168 set(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1169 set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1170 set(PACKAGE_VERSION "${LIB_VERSION}")
1171 set(PKG_CONFIG_CFLAGS )
1172 set(PKG_CONFIG_PRIVATE_LIBS )
1173 if(LIBTYPE STREQUAL "STATIC")
1174     set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1175     foreach(FLAG  ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1176         # If this is already a linker flag, or is a full path+file, add it
1177         # as-is. Otherwise, it's a name intended to be dressed as -lname.
1178         if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1179             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1180         else()
1181             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1182         endif()
1183     endforeach()
1184 endif()
1186 # End configuration
1187 configure_file(
1188     "${OpenAL_SOURCE_DIR}/config.h.in"
1189     "${OpenAL_BINARY_DIR}/config.h")
1190 configure_file(
1191     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1192     "${OpenAL_BINARY_DIR}/openal.pc"
1193     @ONLY)
1196 add_library(common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1197 target_include_directories(common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include)
1198 target_compile_definitions(common PRIVATE ${CPP_DEFS})
1199 target_compile_options(common PRIVATE ${C_FLAGS})
1200 set_target_properties(common PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
1203 unset(HAS_ROUTER)
1204 set(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1206 # Build main library
1207 if(LIBTYPE STREQUAL "STATIC")
1208     add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1209     target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
1210     target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1211     if(WIN32)
1212         # This option is for static linking OpenAL Soft into another project
1213         # that already defines the IDs. It is up to that project to ensure all
1214         # required IDs are defined.
1215         option(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
1216         if(ALSOFT_NO_UID_DEFS)
1217             target_compile_definitions(${IMPL_TARGET} PRIVATE AL_NO_UID_DEFS)
1218         endif()
1219     endif()
1220 else()
1221     set(RC_CONFIG resources/openal32.rc)
1222     if(WIN32 AND ALSOFT_BUILD_ROUTER)
1223         add_library(OpenAL SHARED
1224             resources/router.rc
1225             router/router.cpp
1226             router/router.h
1227             router/alc.cpp
1228             router/al.cpp
1229         )
1230         target_compile_definitions(OpenAL
1231             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1232         target_compile_options(OpenAL PRIVATE ${C_FLAGS})
1233         target_link_libraries(OpenAL PRIVATE common ${LINKER_FLAGS})
1234         target_include_directories(OpenAL
1235           PUBLIC
1236             $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1237             $<INSTALL_INTERFACE:include>
1238           PRIVATE
1239             ${OpenAL_SOURCE_DIR}/common
1240             ${OpenAL_BINARY_DIR}
1241         )
1242         set_target_properties(OpenAL PROPERTIES PREFIX "")
1243         set_target_properties(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1244         if(TARGET build_version)
1245             add_dependencies(OpenAL build_version)
1246         endif()
1247         set(HAS_ROUTER 1)
1249         set(LIBNAME "soft_oal")
1250         set(IMPL_TARGET soft_oal)
1251         set(RC_CONFIG resources/soft_oal.rc)
1252     endif()
1254     # !important: for osx framework public header works, the headers must be in
1255     # the project
1256     set(TARGET_PUBLIC_HEADERS include/AL/al.h include/AL/alc.h include/AL/alext.h include/AL/efx.h)
1257     add_library(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${RC_CONFIG}
1258         ${TARGET_PUBLIC_HEADERS})
1259     if(WIN32)
1260         set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
1261     endif()
1262     target_link_libraries(${IMPL_TARGET} PRIVATE common ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1264     if(APPLE AND ALSOFT_OSX_FRAMEWORK)
1265         # Sets framework name to soft_oal to avoid ambiguity with the system OpenAL.framework
1266         set(LIBNAME "soft_oal")
1267         if(GIT_FOUND)
1268             EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list --count head
1269                 TIMEOUT 5
1270                 OUTPUT_VARIABLE BUNDLE_VERSION
1271                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1272         else()
1273             set(BUNDLE_VERSION 1)
1274         endif()
1276         # Build: Fix rpath in iOS shared libraries
1277         # If this flag is not set, the final dylib binary ld path will be
1278         # /User/xxx/*/soft_oal.framework/soft_oal, which can't be loaded by iOS devices.
1279         # See also: https://github.com/libjpeg-turbo/libjpeg-turbo/commit/c80ddef7a4ce21ace9e3ca0fd190d320cc8cdaeb
1280         if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
1281             set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
1282         endif()
1284         set_target_properties(${IMPL_TARGET} PROPERTIES
1285             FRAMEWORK TRUE
1286             FRAMEWORK_VERSION C
1287             MACOSX_FRAMEWORK_NAME "${IMPL_TARGET}"
1288             MACOSX_FRAMEWORK_IDENTIFIER "org.openal-soft.openal"
1289             MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${LIB_VERSION}
1290             MACOSX_FRAMEWORK_BUNDLE_VERSION ${BUNDLE_VERSION}
1291             XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
1292             XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
1293             XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
1294             PUBLIC_HEADER "${TARGET_PUBLIC_HEADERS}"
1295             MACOSX_RPATH TRUE)
1296     endif()
1297 endif()
1299 target_include_directories(${IMPL_TARGET}
1300   PUBLIC
1301     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1302     $<INSTALL_INTERFACE:include>
1303   PRIVATE
1304     ${INC_PATHS}
1305     ${OpenAL_BINARY_DIR}
1306     ${OpenAL_SOURCE_DIR}
1307     ${OpenAL_SOURCE_DIR}/alc
1308     ${OpenAL_SOURCE_DIR}/common
1311 set_target_properties(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1312     VERSION ${LIB_VERSION}
1313     SOVERSION ${LIB_MAJOR_VERSION}
1315 target_compile_definitions(${IMPL_TARGET}
1316     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1317 target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1319 if(TARGET build_version)
1320     add_dependencies(${IMPL_TARGET} build_version)
1321 endif()
1323 if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1324     find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
1325     if(NOT SED_EXECUTABLE OR NOT CMAKE_DLLTOOL)
1326         message(STATUS "")
1327         if(NOT SED_EXECUTABLE)
1328             message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1329         endif()
1330         if(NOT CMAKE_DLLTOOL)
1331             message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1332         endif()
1333     else()
1334         set_property(TARGET OpenAL APPEND_STRING PROPERTY
1335             LINK_FLAGS " -Wl,--output-def,OpenAL32.def")
1336         add_custom_command(TARGET OpenAL POST_BUILD
1337             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1338             COMMAND "${CMAKE_DLLTOOL}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1339             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1340             VERBATIM
1341         )
1342     endif()
1343 endif()
1345 if(HAS_ROUTER)
1346     message(STATUS "")
1347     message(STATUS "Building DLL router")
1348 endif()
1350 message(STATUS "
1351 Building OpenAL with support for the following backends:
1352     ${BACKENDS}
1354 Building with support for CPU extensions:
1355     ${CPU_EXTS}
1357 if(FPMATH_SET)
1358     message(STATUS "Building with SSE${FPMATH_SET} codegen
1360 endif()
1362 if(ALSOFT_EMBED_HRTF_DATA)
1363     message(STATUS "Embedding HRTF datasets
1365 endif()
1367 # Install main library
1368 if(ALSOFT_INSTALL)
1369     install(TARGETS OpenAL EXPORT OpenAL
1370         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1371         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1372         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1373         FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
1374         INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1375     export(TARGETS OpenAL
1376         NAMESPACE OpenAL::
1377         FILE OpenALConfig.cmake)
1378     install(EXPORT OpenAL
1379         DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1380         NAMESPACE OpenAL::
1381         FILE OpenALConfig.cmake)
1382     install(DIRECTORY include/AL
1383         DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1384     install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1385         DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1386     if(TARGET soft_oal)
1387         install(TARGETS soft_oal
1388             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1389     endif()
1390     message(STATUS "Installing library and headers")
1391 else()
1392     message(STATUS "NOT installing library and headers")
1393 endif()
1395 if(ALSOFT_INSTALL_CONFIG)
1396     install(FILES alsoftrc.sample
1397         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1398     message(STATUS "Installing sample configuration")
1399 endif()
1401 if(ALSOFT_INSTALL_HRTF_DATA)
1402     install(DIRECTORY hrtf
1403         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1404     message(STATUS "Installing HRTF data files")
1405 endif()
1407 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1408     install(DIRECTORY presets
1409         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1410     message(STATUS "Installing AmbDec presets")
1411 endif()
1412 message(STATUS "")
1414 set(UNICODE_FLAG )
1415 if(MINGW)
1416     set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1417 endif()
1418 set(EXTRA_INSTALLS )
1419 if(ALSOFT_UTILS)
1420     add_executable(openal-info utils/openal-info.c)
1421     target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1422     target_compile_options(openal-info PRIVATE ${C_FLAGS})
1423     target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
1424     if(ALSOFT_INSTALL_EXAMPLES)
1425         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
1426     endif()
1428     find_package(MySOFA)
1429     if(MYSOFA_FOUND)
1430         set(SOFA_SUPPORT_SRCS
1431             utils/sofa-support.cpp
1432             utils/sofa-support.h)
1433         add_library(sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
1434         target_compile_definitions(sofa-support PRIVATE ${CPP_DEFS})
1435         target_include_directories(sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
1436         target_compile_options(sofa-support PRIVATE ${C_FLAGS})
1437         target_link_libraries(sofa-support PUBLIC common MySOFA::MySOFA PRIVATE ${LINKER_FLAGS})
1439         set(MAKEMHR_SRCS
1440             utils/makemhr/loaddef.cpp
1441             utils/makemhr/loaddef.h
1442             utils/makemhr/loadsofa.cpp
1443             utils/makemhr/loadsofa.h
1444             utils/makemhr/makemhr.cpp
1445             utils/makemhr/makemhr.h)
1446         if(NOT HAVE_GETOPT)
1447             set(MAKEMHR_SRCS  ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1448         endif()
1449         add_executable(makemhr ${MAKEMHR_SRCS})
1450         target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1451         target_include_directories(makemhr
1452             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
1453         target_compile_options(makemhr PRIVATE ${C_FLAGS})
1454         target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1455         if(ALSOFT_INSTALL_EXAMPLES)
1456             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
1457         endif()
1459         set(SOFAINFO_SRCS  utils/sofa-info.cpp)
1460         add_executable(sofa-info ${SOFAINFO_SRCS})
1461         target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1462         target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
1463         target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1464         target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1465     endif()
1466     message(STATUS "Building utility programs")
1468     if(NOT ALSOFT_NO_CONFIG_UTIL)
1469         add_subdirectory(utils/alsoft-config)
1470     endif()
1471     message(STATUS "")
1472 endif()
1475 # Add a static library with common functions used by multiple example targets
1476 add_library(ex-common STATIC EXCLUDE_FROM_ALL
1477     examples/common/alhelpers.c
1478     examples/common/alhelpers.h)
1479 target_compile_definitions(ex-common PUBLIC ${CPP_DEFS})
1480 target_include_directories(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
1481 target_compile_options(ex-common PUBLIC ${C_FLAGS})
1482 target_link_libraries(ex-common PUBLIC OpenAL PRIVATE ${RT_LIB})
1484 if(ALSOFT_EXAMPLES)
1485     add_executable(altonegen examples/altonegen.c)
1486     target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common ${UNICODE_FLAG})
1488     add_executable(alrecord examples/alrecord.c)
1489     target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} ex-common ${UNICODE_FLAG})
1491     if(ALSOFT_INSTALL_EXAMPLES)
1492         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord)
1493     endif()
1495     message(STATUS "Building example programs")
1497     if(SNDFILE_FOUND)
1498         add_executable(alplay examples/alplay.c)
1499         target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1500             ${UNICODE_FLAG})
1502         add_executable(alstream examples/alstream.c)
1503         target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1504             ${UNICODE_FLAG})
1506         add_executable(alreverb examples/alreverb.c)
1507         target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1508             ${UNICODE_FLAG})
1510         add_executable(almultireverb examples/almultireverb.c)
1511         target_link_libraries(almultireverb
1512             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1514         add_executable(allatency examples/allatency.c)
1515         target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1516             ${UNICODE_FLAG})
1518         add_executable(alhrtf examples/alhrtf.c)
1519         target_link_libraries(alhrtf
1520             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1522         add_executable(alstreamcb examples/alstreamcb.cpp)
1523         target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1524             ${UNICODE_FLAG})
1526         add_executable(alconvolve examples/alconvolve.c)
1527         target_link_libraries(alconvolve PRIVATE ${LINKER_FLAGS} common SndFile::SndFile ex-common
1528             ${UNICODE_FLAG})
1530         if(ALSOFT_INSTALL_EXAMPLES)
1531             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1532                 alhrtf)
1533         endif()
1535         message(STATUS "Building SndFile example programs")
1536     endif()
1538     if(SDL2_FOUND)
1539         add_executable(alloopback examples/alloopback.c)
1540         target_include_directories(alloopback PRIVATE ${SDL2_INCLUDE_DIR})
1541         target_link_libraries(alloopback
1542             PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ex-common ${MATH_LIB})
1544         if(ALSOFT_INSTALL_EXAMPLES)
1545             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
1546         endif()
1548         message(STATUS "Building SDL example programs")
1550         set(FFVER_OK FALSE)
1551         if(FFMPEG_FOUND)
1552             set(FFVER_OK TRUE)
1553             if(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1554                 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1555                 set(FFVER_OK FALSE)
1556             endif()
1557             if(AVCODEC_VERSION VERSION_LESS "57.64.101")
1558                 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1559                 set(FFVER_OK FALSE)
1560             endif()
1561             if(AVUTIL_VERSION VERSION_LESS "55.34.101")
1562                 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1563                 set(FFVER_OK FALSE)
1564             endif()
1565             if(SWSCALE_VERSION VERSION_LESS "4.2.100")
1566                 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1567                 set(FFVER_OK FALSE)
1568             endif()
1569             if(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1570                 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1571                 set(FFVER_OK FALSE)
1572             endif()
1573         endif()
1574         if(FFVER_OK)
1575             add_executable(alffplay examples/alffplay.cpp)
1576             target_include_directories(alffplay
1577                 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1578             target_link_libraries(alffplay
1579                 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common)
1581             if(ALSOFT_INSTALL_EXAMPLES)
1582                 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
1583             endif()
1584             message(STATUS "Building SDL+FFmpeg example programs")
1585         endif()
1586     endif()
1587     message(STATUS "")
1588 endif()
1590 if(EXTRA_INSTALLS)
1591     install(TARGETS ${EXTRA_INSTALLS}
1592         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1593         BUNDLE  DESTINATION ${CMAKE_INSTALL_BINDIR}
1594         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1595         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1596 endif()