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