Check MAX_RESAMPLER_PADDING properly to ensure it's large enough
[openal-soft.git] / CMakeLists.txt
blob2f833e419a691410439958c002dacb975ab923ad
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 and install utility programs"         ON)
57 OPTION(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
59 OPTION(ALSOFT_EXAMPLES  "Build and install example programs"  ON)
60 OPTION(ALSOFT_TESTS     "Build and install test programs"     ON)
62 OPTION(ALSOFT_CONFIG "Install alsoft.conf sample configuration file" ON)
63 OPTION(ALSOFT_HRTF_DEFS "Install HRTF definition files" ON)
64 OPTION(ALSOFT_AMBDEC_PRESETS "Install AmbDec preset files" ON)
65 OPTION(ALSOFT_INSTALL "Install headers and libraries" ON)
67 if(DEFINED SHARE_INSTALL_DIR)
68     message(WARNING "SHARE_INSTALL_DIR is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
69     set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
70 endif()
72 if(DEFINED LIB_SUFFIX)
73     message(WARNING "LIB_SUFFIX is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
74 endif()
77 SET(CPP_DEFS ) # C pre-processor, not C++
78 SET(INC_PATHS )
79 SET(C_FLAGS )
80 SET(LINKER_FLAGS )
81 SET(EXTRA_LIBS )
83 IF(WIN32)
84     SET(CPP_DEFS ${CPP_DEFS} _WIN32 _WIN32_WINNT=0x0502)
86     OPTION(ALSOFT_BUILD_ROUTER  "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)"  OFF)
88     # This option is mainly for static linking OpenAL Soft into another project
89     # that already defines the IDs. It is up to that project to ensure all
90     # required IDs are defined.
91     OPTION(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
93     IF(MINGW)
94         OPTION(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
95         IF(NOT DLLTOOL)
96             IF(HOST)
97                 SET(DLLTOOL "${HOST}-dlltool")
98             ELSE()
99                 SET(DLLTOOL "dlltool")
100             ENDIF()
101         ENDIF()
102     ENDIF()
103 ENDIF()
106 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
107 IF ("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
108     SET(INC_PATHS ${INC_PATHS} /usr/include)
109     SET(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
110 ENDIF()
112 IF(NOT LIBTYPE)
113     SET(LIBTYPE SHARED)
114 ENDIF()
116 SET(LIB_MAJOR_VERSION "1")
117 SET(LIB_MINOR_VERSION "19")
118 SET(LIB_REVISION "1")
119 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
120 SET(LIB_VERSION_NUM ${LIB_MAJOR_VERSION},${LIB_MINOR_VERSION},${LIB_REVISION},0)
122 SET(EXPORT_DECL "")
125 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
128 # Require C++11
129 SET(CMAKE_CXX_STANDARD 11)
130 SET(CMAKE_CXX_STANDARD_REQUIRED TRUE)
132 # Prefer C11, but support C99 and C90 too.
133 SET(CMAKE_C_STANDARD 11)
136 if(NOT WIN32)
137     # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
138     CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
139     IF(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
140         SET(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
141         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
142         CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
143         IF(NOT HAVE_POSIX_MEMALIGN_POSIX)
144             SET(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
145         ELSE()
146             SET(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
147         ENDIF()
148     ENDIF()
149     UNSET(OLD_REQUIRED_FLAGS)
150 ENDIF()
152 # C99 has restrict, but C++ does not, so we can only utilize __restrict.
153 SET(RESTRICT_DECL )
154 CHECK_CXX_SOURCE_COMPILES("int *__restrict foo;
155 int main() { return 0; }" HAVE___RESTRICT)
156 IF(HAVE___RESTRICT)
157     SET(RESTRICT_DECL "__restrict")
158 ENDIF()
160 # Some systems may need libatomic for atomic functions to work
161 SET(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
162 SET(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
163 CHECK_CXX_SOURCE_COMPILES("#include <atomic>
164 std::atomic<int> foo{0};
165 int main() { return foo.fetch_add(2); }"
166 HAVE_LIBATOMIC)
167 IF(NOT HAVE_LIBATOMIC)
168     SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
169 ELSE()
170     SET(EXTRA_LIBS atomic ${EXTRA_LIBS})
171 ENDIF()
172 UNSET(OLD_REQUIRED_LIBRARIES)
174 # Include liblog for Android logging
175 CHECK_LIBRARY_EXISTS(log __android_log_print "" HAVE_LIBLOG)
176 IF(HAVE_LIBLOG)
177     SET(EXTRA_LIBS log ${EXTRA_LIBS})
178     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
179 ENDIF()
181 IF(MSVC)
182     SET(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS NOMINMAX)
183     CHECK_CXX_COMPILER_FLAG(/permissive- HAVE_PERMISSIVE_SWITCH)
184     IF(HAVE_PERMISSIVE_SWITCH)
185         SET(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
186     ENDIF()
187     SET(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4268 /wd4324)
189     IF(NOT DXSDK_DIR)
190         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
191     ELSE()
192         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
193     ENDIF()
194     IF(DXSDK_DIR)
195         MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
196     ENDIF()
198     OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
199     IF(FORCE_STATIC_VCRT)
200         FOREACH(flag_var
201                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
202                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
203             IF(${flag_var} MATCHES "/MD")
204                 STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
205             ENDIF()
206         ENDFOREACH(flag_var)
207     ENDIF()
208 ELSE()
209     SET(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
210         -Wpedantic
211         $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
213     IF(ALSOFT_WERROR)
214         SET(C_FLAGS ${C_FLAGS} -Werror)
215     ENDIF()
217     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
218     # instead of NDEBUG)
219     FOREACH(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
220         IF(${flag_var} MATCHES "-DNDEBUG")
221             STRING(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
222         ENDIF()
223     ENDFOREACH()
225     CHECK_C_COMPILER_FLAG(-fno-math-errno HAVE_FNO_MATH_ERRNO)
226     IF(HAVE_FNO_MATH_ERRNO)
227         SET(C_FLAGS ${C_FLAGS} -fno-math-errno)
228     ENDIF()
230     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
231     if(ALSOFT_STATIC_LIBGCC)
232         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
233         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
234         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
235         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
236         unset(OLD_REQUIRED_LIBRARIES)
238         if(NOT HAVE_STATIC_LIBGCC_SWITCH)
239             message(FATAL_ERROR "Cannot static link libgcc")
240         endif()
241         set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
242     endif()
244     option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
245     if(ALSOFT_STATIC_STDCXX)
246         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
247         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
248         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
249         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
250         unset(OLD_REQUIRED_LIBRARIES)
252         if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
253             message(FATAL_ERROR "Cannot static link libstdc++")
254         endif()
255         set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
256     endif()
258     if(WIN32)
259         option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
260         if(ALSOFT_STATIC_WINPTHREAD)
261             set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
262             set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
263             check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
264             set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
265             unset(OLD_REQUIRED_LIBRARIES)
267             if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
268                 message(FATAL_ERROR "Cannot static link libwinpthread")
269             endif()
270             set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
271         endif()
272     endif()
273 ENDIF()
275 # Set visibility/export options if available
276 IF(WIN32)
277     SET(EXPORT_DECL "__declspec(dllexport)")
278 ELSE()
279     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
280     # Yes GCC, really don't accept visibility modes you don't support
281     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
283     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
284                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
285     IF(HAVE_GCC_PROTECTED_VISIBILITY)
286         SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
287     ELSE()
288         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
289                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
290         IF(HAVE_GCC_DEFAULT_VISIBILITY)
291             SET(EXPORT_DECL "__attribute__((visibility(\"default\")))")
292         ENDIF()
293     ENDIF()
295     IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
296         CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
297         IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
298             SET(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
299         ENDIF()
300     ENDIF()
302     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
303 ENDIF()
305 SET(SSE2_SWITCH "")
306 SET(SSE3_SWITCH "")
307 SET(SSE4_1_SWITCH "")
308 SET(FPU_NEON_SWITCH "")
310 CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
311 IF(HAVE_MSSE2_SWITCH)
312     SET(SSE2_SWITCH "-msse2")
313 ENDIF()
314 CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
315 IF(HAVE_MSSE3_SWITCH)
316     SET(SSE3_SWITCH "-msse3")
317 ENDIF()
318 CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
319 IF(HAVE_MSSE4_1_SWITCH)
320     SET(SSE4_1_SWITCH "-msse4.1")
321 ENDIF()
322 CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
323 IF(HAVE_MFPU_NEON_SWITCH)
324     SET(FPU_NEON_SWITCH "-mfpu=neon")
325 ENDIF()
327 CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE2_SWITCH}")
328 CHECK_INCLUDE_FILE(emmintrin.h HAVE_EMMINTRIN_H "${SSE2_SWITCH}")
329 CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}")
330 CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}")
331 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H "${FPU_NEON_SWITCH}")
333 SET(SSE_FLAGS )
334 SET(FPMATH_SET "0")
335 IF(CMAKE_SIZEOF_VOID_P MATCHES "4")
336     IF(SSE2_SWITCH OR MSVC)
337         OPTION(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
338     ENDIF()
340     IF(ALSOFT_ENABLE_SSE2_CODEGEN)
341         IF(SSE2_SWITCH)
342             CHECK_C_COMPILER_FLAG("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
343             IF(HAVE_MFPMATH_SSE_2)
344                 SET(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
345                 SET(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
346                 SET(FPMATH_SET 2)
347             ENDIF()
348         ELSEIF(MSVC)
349             CHECK_C_COMPILER_FLAG("/arch:SSE2" HAVE_ARCH_SSE2)
350             IF(HAVE_ARCH_SSE2)
351                 SET(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
352                 SET(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
353                 SET(FPMATH_SET 2)
354             ENDIF()
355         ENDIF()
356     ENDIF()
357 ENDIF()
359 IF(HAVE_EMMINTRIN_H)
360     SET(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
361     FOREACH(flag_var ${SSE_FLAGS})
362         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
363     ENDFOREACH()
365     CHECK_C_SOURCE_COMPILES("#include <emmintrin.h>
366                              int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
368     SET(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
369 ENDIF()
372 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
373                          int main() {return 0;}" HAVE_GCC_FORMAT)
375 CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
376 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
377 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
378 CHECK_INCLUDE_FILE(intrin.h HAVE_INTRIN_H)
379 CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
380 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
381 IF(NOT HAVE_GUIDDEF_H)
382     CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
383 ENDIF()
385 # Some systems need libm for some math functions to work
386 SET(MATH_LIB )
387 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
388 IF(HAVE_LIBM)
389     SET(MATH_LIB ${MATH_LIB} m)
390     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
391 ENDIF()
393 # Check for the dlopen API (for dynamicly loading backend libs)
394 IF(ALSOFT_DLOPEN)
395     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
396     CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
397     IF(HAVE_LIBDL)
398         SET(EXTRA_LIBS dl ${EXTRA_LIBS})
399         SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
400     ENDIF()
401 ENDIF()
403 # Check for a cpuid intrinsic
404 IF(HAVE_CPUID_H)
405     CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
406         int main()
407         {
408             unsigned int eax, ebx, ecx, edx;
409             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
410         }" HAVE_GCC_GET_CPUID)
411 ENDIF()
412 IF(HAVE_INTRIN_H)
413     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
414         int main()
415         {
416             int regs[4];
417             __cpuid(regs, 0);
418             return regs[0];
419         }" HAVE_CPUID_INTRINSIC)
420     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
421         int main()
422         {
423             unsigned long idx = 0;
424             _BitScanForward64(&idx, 1);
425             return idx;
426         }" HAVE_BITSCANFORWARD64_INTRINSIC)
427     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
428         int main()
429         {
430             unsigned long idx = 0;
431             _BitScanForward(&idx, 1);
432             return idx;
433         }" HAVE_BITSCANFORWARD_INTRINSIC)
434 ENDIF()
436 CHECK_SYMBOL_EXISTS(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
437 CHECK_SYMBOL_EXISTS(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
438 CHECK_SYMBOL_EXISTS(proc_pidpath     libproc.h HAVE_PROC_PIDPATH)
440 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
442 IF(NOT WIN32)
443     # We need pthreads outside of Windows, for semaphores. It's also used to
444     # set the priority and name of threads, when possible.
445     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
446     IF(NOT HAVE_PTHREAD_H)
447         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
448     ENDIF()
450     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
451     IF(HAVE_PTHREAD)
452         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
453         SET(C_FLAGS ${C_FLAGS} -pthread)
454         SET(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
455     ENDIF()
457     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
458     IF(HAVE_LIBPTHREAD)
459         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
460     ENDIF()
462     CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
464     # Some systems need pthread_np.h to get pthread_setname_np
465     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
466     IF(HAVE_PTHREAD_NP_H)
467         CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
468         IF(NOT HAVE_PTHREAD_SETNAME_NP)
469             CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
470         ELSE()
471             CHECK_C_SOURCE_COMPILES("
472 #include <pthread.h>
473 #include <pthread_np.h>
474 int main()
476     pthread_setname_np(\"testname\");
477     return 0;
479                 PTHREAD_SETNAME_NP_ONE_PARAM
480             )
481             CHECK_C_SOURCE_COMPILES("
482 #include <pthread.h>
483 #include <pthread_np.h>
484 int main()
486     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
487     return 0;
489                 PTHREAD_SETNAME_NP_THREE_PARAMS
490             )
491         ENDIF()
492     ELSE()
493         CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
494         IF(NOT HAVE_PTHREAD_SETNAME_NP)
495             CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
496         ELSE()
497             CHECK_C_SOURCE_COMPILES("
498 #include <pthread.h>
499 int main()
501     pthread_setname_np(\"testname\");
502     return 0;
504                 PTHREAD_SETNAME_NP_ONE_PARAM
505             )
506             CHECK_C_SOURCE_COMPILES("
507 #include <pthread.h>
508 int main()
510     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
511     return 0;
513                 PTHREAD_SETNAME_NP_THREE_PARAMS
514             )
515         ENDIF()
516     ENDIF()
517 ENDIF()
519 CHECK_SYMBOL_EXISTS(getopt unistd.h HAVE_GETOPT)
522 # Common sources used by both the OpenAL implementation library and potentially
523 # the OpenAL router.
524 SET(COMMON_OBJS
525     common/albyte.h
526     common/alcomplex.cpp
527     common/alcomplex.h
528     common/alexcpt.cpp
529     common/alexcpt.h
530     common/alfstream.cpp
531     common/alfstream.h
532     common/almalloc.cpp
533     common/almalloc.h
534     common/alnumeric.h
535     common/aloptional.h
536     common/alspan.h
537     common/alstring.cpp
538     common/alstring.h
539     common/atomic.h
540     common/dynload.cpp
541     common/dynload.h
542     common/endiantest.h
543     common/intrusive_ptr.h
544     common/math_defs.h
545     common/opthelpers.h
546     common/strutils.cpp
547     common/strutils.h
548     common/threads.cpp
549     common/threads.h
550     common/vecmat.h
551     common/vector.h
553 SET(OPENAL_OBJS
554     al/auxeffectslot.cpp
555     al/auxeffectslot.h
556     al/buffer.cpp
557     al/buffer.h
558     al/effect.cpp
559     al/effect.h
560     al/error.cpp
561     al/event.cpp
562     al/event.h
563     al/extension.cpp
564     al/filter.cpp
565     al/filter.h
566     al/listener.cpp
567     al/listener.h
568     al/source.cpp
569     al/source.h
570     al/state.cpp
572 SET(ALC_OBJS
573     alc/alc.cpp
574     alc/alcmain.h
575     alc/alu.cpp
576     alc/alu.h
577     alc/alconfig.cpp
578     alc/alconfig.h
579     alc/alcontext.h
580     alc/ambdec.cpp
581     alc/ambdec.h
582     alc/ambidefs.h
583     alc/bformatdec.cpp
584     alc/bformatdec.h
585     alc/bs2b.cpp
586     alc/bs2b.h
587     alc/compat.h
588     alc/converter.cpp
589     alc/converter.h
590     alc/cpu_caps.h
591     alc/devformat.h
592     alc/effects/base.h
593     alc/effects/autowah.cpp
594     alc/effects/chorus.cpp
595     alc/effects/compressor.cpp
596     alc/effects/dedicated.cpp
597     alc/effects/distortion.cpp
598     alc/effects/echo.cpp
599     alc/effects/equalizer.cpp
600     alc/effects/fshifter.cpp
601     alc/effects/modulator.cpp
602     alc/effects/null.cpp
603     alc/effects/pshifter.cpp
604     alc/effects/reverb.cpp
605     alc/effects/vmorpher.cpp
606     alc/filters/biquad.h
607     alc/filters/biquad.cpp
608     alc/filters/nfc.cpp
609     alc/filters/nfc.h
610     alc/filters/splitter.cpp
611     alc/filters/splitter.h
612     alc/fpu_modes.h
613     alc/helpers.cpp
614     alc/hrtf.cpp
615     alc/hrtf.h
616     alc/inprogext.h
617     alc/logging.h
618     alc/mastering.cpp
619     alc/mastering.h
620     alc/mixvoice.cpp
621     alc/panning.cpp
622     alc/ringbuffer.cpp
623     alc/ringbuffer.h
624     alc/uhjfilter.cpp
625     alc/uhjfilter.h
626     alc/uiddefs.cpp
627     alc/mixer/defs.h
628     alc/mixer/hrtfbase.h
629     alc/mixer/mixer_c.cpp
633 SET(CPU_EXTS "Default")
634 SET(HAVE_SSE        0)
635 SET(HAVE_SSE2       0)
636 SET(HAVE_SSE3       0)
637 SET(HAVE_SSE4_1     0)
638 SET(HAVE_NEON       0)
640 # Check for SSE+SSE2 support
641 OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
642 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
643 IF(HAVE_XMMINTRIN_H AND HAVE_EMMINTRIN_H)
644     OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
645     OPTION(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
646     IF(ALSOFT_CPUEXT_SSE AND ALSOFT_CPUEXT_SSE2)
647         SET(HAVE_SSE 1)
648         SET(HAVE_SSE2 1)
649         SET(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse.cpp alc/mixer/mixer_sse2.cpp)
650         IF(SSE2_SWITCH)
651             SET_SOURCE_FILES_PROPERTIES(alc/mixer/mixer_sse.cpp alc/mixer/mixer_sse2.cpp
652                 PROPERTIES COMPILE_FLAGS "${SSE2_SWITCH}")
653         ENDIF()
654         SET(CPU_EXTS "${CPU_EXTS}, SSE, SSE2")
655     ENDIF()
656 ENDIF()
657 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
658     MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
659 ENDIF()
660 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
661     MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
662 ENDIF()
664 OPTION(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
665 IF(HAVE_EMMINTRIN_H)
666     OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
667     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
668         SET(HAVE_SSE3 1)
669         SET(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse3.cpp)
670         IF(SSE2_SWITCH)
671             SET_SOURCE_FILES_PROPERTIES(alc/mixer/mixer_sse3.cpp PROPERTIES
672                                         COMPILE_FLAGS "${SSE3_SWITCH}")
673         ENDIF()
674         SET(CPU_EXTS "${CPU_EXTS}, SSE3")
675     ENDIF()
676 ENDIF()
677 IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
678     MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
679 ENDIF()
681 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
682 IF(HAVE_SMMINTRIN_H)
683     OPTION(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
684     IF(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
685         SET(HAVE_SSE4_1 1)
686         SET(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse41.cpp)
687         IF(SSE4_1_SWITCH)
688             SET_SOURCE_FILES_PROPERTIES(alc/mixer/mixer_sse41.cpp PROPERTIES
689                                         COMPILE_FLAGS "${SSE4_1_SWITCH}")
690         ENDIF()
691         SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
692     ENDIF()
693 ENDIF()
694 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
695     MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
696 ENDIF()
698 # Check for ARM Neon support
699 OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
700 IF(HAVE_ARM_NEON_H)
701     OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
702     IF(ALSOFT_CPUEXT_NEON)
703         SET(HAVE_NEON 1)
704         SET(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_neon.cpp)
705         IF(FPU_NEON_SWITCH)
706             SET_SOURCE_FILES_PROPERTIES(alc/mixer/mixer_neon.cpp PROPERTIES
707                                         COMPILE_FLAGS "${FPU_NEON_SWITCH}")
708         ENDIF()
709         SET(CPU_EXTS "${CPU_EXTS}, Neon")
710     ENDIF()
711 ENDIF()
712 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
713     MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
714 ENDIF()
717 SET(HAVE_ALSA       0)
718 SET(HAVE_OSS        0)
719 SET(HAVE_SOLARIS    0)
720 SET(HAVE_SNDIO      0)
721 SET(HAVE_QSA        0)
722 SET(HAVE_DSOUND     0)
723 SET(HAVE_WASAPI     0)
724 SET(HAVE_WINMM      0)
725 SET(HAVE_PORTAUDIO  0)
726 SET(HAVE_PULSEAUDIO 0)
727 SET(HAVE_COREAUDIO  0)
728 SET(HAVE_OPENSL     0)
729 SET(HAVE_WAVE       0)
730 SET(HAVE_SDL2       0)
732 IF(WIN32 OR HAVE_DLFCN_H)
733     SET(IS_LINKED "")
734     MACRO(ADD_BACKEND_LIBS _LIBS)
735     ENDMACRO()
736 ELSE()
737     SET(IS_LINKED " (linked)")
738     MACRO(ADD_BACKEND_LIBS _LIBS)
739         SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
740     ENDMACRO()
741 ENDIF()
743 SET(BACKENDS "")
744 SET(ALC_OBJS  ${ALC_OBJS}
745     alc/backends/base.cpp
746     alc/backends/base.h
747     # Default backends, always available
748     alc/backends/loopback.cpp
749     alc/backends/loopback.h
750     alc/backends/null.cpp
751     alc/backends/null.h
754 # Check ALSA backend
755 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
756 FIND_PACKAGE(ALSA)
757 IF(ALSA_FOUND)
758     OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
759     IF(ALSOFT_BACKEND_ALSA)
760         SET(HAVE_ALSA 1)
761         SET(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
762         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
763         ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
764         SET(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
765     ENDIF()
766 ENDIF()
767 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
768     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
769 ENDIF()
771 # Check OSS backend
772 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
773 FIND_PACKAGE(OSS)
774 IF(OSS_FOUND)
775     OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
776     IF(ALSOFT_BACKEND_OSS)
777         SET(HAVE_OSS 1)
778         SET(BACKENDS  "${BACKENDS} OSS,")
779         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
780         IF(OSS_LIBRARIES)
781             SET(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
782         ENDIF()
783         SET(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
784     ENDIF()
785 ENDIF()
786 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
787     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
788 ENDIF()
790 # Check Solaris backend
791 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
792 FIND_PACKAGE(AudioIO)
793 IF(AUDIOIO_FOUND)
794     OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
795     IF(ALSOFT_BACKEND_SOLARIS)
796         SET(HAVE_SOLARIS 1)
797         SET(BACKENDS  "${BACKENDS} Solaris,")
798         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
799         SET(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
800     ENDIF()
801 ENDIF()
802 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
803     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
804 ENDIF()
806 # Check SndIO backend
807 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
808 FIND_PACKAGE(SoundIO)
809 IF(SOUNDIO_FOUND)
810     OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
811     IF(ALSOFT_BACKEND_SNDIO)
812         SET(HAVE_SNDIO 1)
813         SET(BACKENDS  "${BACKENDS} SndIO (linked),")
814         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
815         SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
816         SET(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
817     ENDIF()
818 ENDIF()
819 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
820     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
821 ENDIF()
823 # Check QSA backend
824 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
825 FIND_PACKAGE(QSA)
826 IF(QSA_FOUND)
827     OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
828     IF(ALSOFT_BACKEND_QSA)
829         SET(HAVE_QSA 1)
830         SET(BACKENDS  "${BACKENDS} QSA (linked),")
831         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/qsa.cpp alc/backends/qsa.h)
832         SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
833         SET(INC_PATHS ${INC_PATHS} ${QSA_INCLUDE_DIRS})
834     ENDIF()
835 ENDIF()
836 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
837     MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
838 ENDIF()
840 # Check Windows-only backends
841 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
842 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
843 OPTION(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
844 IF(WIN32)
845     SET(WINSDK_LIB_DIRS )
846     SET(WINSDK_INCLUDE_DIRS )
847     FIND_PACKAGE(WindowsSDK)
848     IF(WINDOWSSDK_FOUND)
849         get_windowssdk_library_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_LIB_DIRS)
850         get_windowssdk_include_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_INCLUDE_DIRS)
851     ENDIF()
853     SET(OLD_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS})
854     SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=0x0502)
856     # Check MMSystem backend
857     CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
858     FIND_LIBRARY(WINMM_LIBRARY NAMES winmm
859         PATHS ${WINSDK_LIB_DIRS}
860         PATH_SUFFIXES lib lib/x86 lib/x64)
861     IF(HAVE_MMSYSTEM_H AND WINMM_LIBRARY)
862         OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
863         IF(ALSOFT_BACKEND_WINMM)
864             SET(HAVE_WINMM 1)
865             SET(BACKENDS  "${BACKENDS} WinMM,")
866             SET(ALC_OBJS  ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
867             SET(EXTRA_LIBS ${WINMM_LIBRARY} ${EXTRA_LIBS})
868         ENDIF()
869     ENDIF()
871     # Check DSound backend
872     FIND_PACKAGE(DSound)
873     IF(DSOUND_FOUND)
874         OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
875         IF(ALSOFT_BACKEND_DSOUND)
876             SET(HAVE_DSOUND 1)
877             SET(BACKENDS  "${BACKENDS} DirectSound${IS_LINKED},")
878             SET(ALC_OBJS  ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
879             ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
880             SET(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIRS})
881         ENDIF()
882     ENDIF()
884     # Check for WASAPI backend
885     CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
886     IF(HAVE_MMDEVICEAPI_H)
887         OPTION(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
888         IF(ALSOFT_BACKEND_WASAPI)
889             SET(HAVE_WASAPI 1)
890             SET(BACKENDS  "${BACKENDS} WASAPI,")
891             SET(ALC_OBJS  ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
892         ENDIF()
893     ENDIF()
895     SET(CMAKE_REQUIRED_DEFINITIONS ${OLD_REQUIRED_DEFINITIONS})
896     UNSET(OLD_REQUIRED_DEFINITIONS)
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
962     NAMES CoreAudio
963     PATHS /System/Library/Frameworks
965 IF(COREAUDIO_FRAMEWORK)
966     OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
967     IF(ALSOFT_BACKEND_COREAUDIO)
968         SET(HAVE_COREAUDIO 1)
969         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
970         SET(BACKENDS  "${BACKENDS} CoreAudio,")
971         SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
972         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
973         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
975         # Some versions of OSX may need the AudioToolbox framework. Add it if
976         # it's found.
977         FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
978             NAMES AudioToolbox
979             PATHS
980                 ~/Library/Frameworks
981                 /Library/Frameworks
982                 /System/Library/Frameworks
983         )
984         IF(AUDIOTOOLBOX_LIBRARY)
985             SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
986         ENDIF()
987     ENDIF()
988 ENDIF()
989 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
990     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
991 ENDIF()
993 # Check for OpenSL (Android) backend
994 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
995 FIND_PACKAGE(OpenSL)
996 IF(OPENSL_FOUND)
997     OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
998     IF(ALSOFT_BACKEND_OPENSL)
999         SET(HAVE_OPENSL 1)
1000         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1001         SET(BACKENDS  "${BACKENDS} OpenSL,")
1002         SET(EXTRA_LIBS ${OPENSL_LIBRARIES} ${EXTRA_LIBS})
1003         SET(INC_PATHS ${INC_PATHS} ${OPENSL_INCLUDE_DIRS})
1004     ENDIF()
1005 ENDIF()
1006 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1007     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1008 ENDIF()
1010 # Check for SDL2 backend
1011 OPTION(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1012 FIND_PACKAGE(SDL2)
1013 IF(SDL2_FOUND)
1014     # Off by default, since it adds a runtime dependency
1015     OPTION(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1016     IF(ALSOFT_BACKEND_SDL2)
1017         SET(HAVE_SDL2 1)
1018         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1019         SET(BACKENDS  "${BACKENDS} SDL2,")
1020         SET(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
1021         SET(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
1022     ENDIF()
1023 ENDIF()
1024 IF(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1025     MESSAGE(FATAL_ERROR "Failed to enabled required SDL2 backend")
1026 ENDIF()
1028 # Optionally enable the Wave Writer backend
1029 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1030 IF(ALSOFT_BACKEND_WAVE)
1031     SET(HAVE_WAVE 1)
1032     SET(ALC_OBJS  ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1033     SET(BACKENDS  "${BACKENDS} WaveFile,")
1034 ENDIF()
1036 # This is always available
1037 SET(BACKENDS  "${BACKENDS} Null")
1040 FIND_PACKAGE(Git)
1041 IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1042     # Get the current working branch and its latest abbreviated commit hash
1043     ADD_CUSTOM_TARGET(build_version
1044         ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1045             -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1046             -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1047         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1048         VERBATIM
1049     )
1050 ELSE()
1051     SET(GIT_BRANCH "UNKNOWN")
1052     SET(GIT_COMMIT_HASH "unknown")
1053     CONFIGURE_FILE(
1054         "${OpenAL_SOURCE_DIR}/version.h.in"
1055         "${OpenAL_BINARY_DIR}/version.h")
1056 ENDIF()
1059 SET(NATIVE_SRC_DIR  "${OpenAL_SOURCE_DIR}/native-tools")
1061 SET(ALSOFT_NATIVE_TOOLS_PATH "" CACHE STRING "Path to prebuilt native tools (leave blank to auto-build)")
1062 IF(ALSOFT_NATIVE_TOOLS_PATH)
1063     find_program(BIN2H_NATIVE_COMMAND NAMES bin2h
1064         PATHS "${ALSOFT_NATIVE_TOOLS_PATH}"
1065         NO_DEFAULT_PATH)
1066     find_program(BSINCGEN_NATIVE_COMMAND NAMES bsincgen
1067         PATHS "${ALSOFT_NATIVE_TOOLS_PATH}"
1068         NO_DEFAULT_PATH)
1069     if(NOT BIN2H_NATIVE_COMMAND OR NOT BSINCGEN_NATIVE_COMMAND)
1070         message(FATAL_ERROR "Failed to find native tools in ${ALSOFT_NATIVE_TOOLS_PATH}.
1071 bin2h: ${BIN2H_NATIVE_COMMAND}
1072 bsincgen: ${BSINCGEN_NATIVE_COMMAND}")
1073     endif()
1074     SET(BIN2H_COMMAND  ${BIN2H_NATIVE_COMMAND})
1075     SET(BSINCGEN_COMMAND  ${BSINCGEN_NATIVE_COMMAND})
1076 ELSE()
1077     SET(NATIVE_BIN_DIR  "${OpenAL_BINARY_DIR}/native-tools")
1078     FILE(MAKE_DIRECTORY "${NATIVE_BIN_DIR}")
1080     SET(BIN2H_COMMAND  "${NATIVE_BIN_DIR}/bin2h")
1081     SET(BSINCGEN_COMMAND  "${NATIVE_BIN_DIR}/bsincgen")
1082     ADD_CUSTOM_COMMAND(OUTPUT "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1083         COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" "${NATIVE_SRC_DIR}"
1084         COMMAND ${CMAKE_COMMAND} -E remove "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1085         COMMAND ${CMAKE_COMMAND} --build . --config "Release"
1086         WORKING_DIRECTORY "${NATIVE_BIN_DIR}"
1087         DEPENDS "${NATIVE_SRC_DIR}/CMakeLists.txt"
1088         IMPLICIT_DEPENDS
1089             C "${NATIVE_SRC_DIR}/bin2h.c"
1090             C "${NATIVE_SRC_DIR}/bsincgen.c"
1091         VERBATIM
1092     )
1093 ENDIF()
1094 ADD_CUSTOM_TARGET(native-tools
1095     DEPENDS "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1096     VERBATIM
1099 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1100 if(ALSOFT_EMBED_HRTF_DATA)
1101     MACRO(make_hrtf_header FILENAME VARNAME)
1102         SET(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1103         SET(outfile  "${OpenAL_BINARY_DIR}/${FILENAME}.h")
1105         ADD_CUSTOM_COMMAND(OUTPUT "${outfile}"
1106             COMMAND "${BIN2H_COMMAND}" "${infile}" "${outfile}" ${VARNAME}
1107             DEPENDS native-tools "${infile}"
1108             VERBATIM
1109         )
1110         SET(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1111     ENDMACRO()
1113     make_hrtf_header(default-44100.mhr "hrtf_default_44100")
1114     make_hrtf_header(default-48000.mhr "hrtf_default_48000")
1115 endif()
1117 ADD_CUSTOM_COMMAND(OUTPUT "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1118     COMMAND "${BSINCGEN_COMMAND}" "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1119     DEPENDS native-tools "${NATIVE_SRC_DIR}/bsincgen.c"
1120     VERBATIM
1122 SET(ALC_OBJS  ${ALC_OBJS} "${OpenAL_BINARY_DIR}/bsinc_inc.h")
1125 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1126     add_subdirectory(utils/alsoft-config)
1127 ENDIF()
1128 IF(ALSOFT_EXAMPLES)
1129     IF(NOT SDL2_FOUND)
1130         FIND_PACKAGE(SDL2)
1131     ENDIF()
1132     IF(SDL2_FOUND)
1133         FIND_PACKAGE(SDL_sound)
1134         FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1135     ENDIF()
1136 ENDIF()
1138 IF(NOT WIN32)
1139     SET(LIBNAME "openal")
1140 ELSE()
1141     SET(LIBNAME "OpenAL32")
1142 ENDIF()
1144 # Needed for openal.pc.in
1145 SET(prefix ${CMAKE_INSTALL_PREFIX})
1146 SET(exec_prefix "\${prefix}")
1147 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1148 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1149 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1150 SET(PACKAGE_VERSION "${LIB_VERSION}")
1151 SET(PKG_CONFIG_CFLAGS )
1152 SET(PKG_CONFIG_PRIVATE_LIBS )
1153 IF(LIBTYPE STREQUAL "STATIC")
1154     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1155     FOREACH(FLAG  ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1156         # If this is already a linker flag, or is a full path+file, add it
1157         # as-is. Otherwise, it's a name intended to be dressed as -lname.
1158         IF(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1159             SET(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1160         ELSE()
1161             SET(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1162         ENDIF()
1163     ENDFOREACH()
1164 ENDIF()
1166 # End configuration
1167 CONFIGURE_FILE(
1168     "${OpenAL_SOURCE_DIR}/config.h.in"
1169     "${OpenAL_BINARY_DIR}/config.h")
1170 CONFIGURE_FILE(
1171     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1172     "${OpenAL_BINARY_DIR}/openal.pc"
1173     @ONLY)
1176 ADD_LIBRARY(common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1177 TARGET_INCLUDE_DIRECTORIES(common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include)
1178 TARGET_COMPILE_DEFINITIONS(common PRIVATE ${CPP_DEFS})
1179 TARGET_COMPILE_OPTIONS(common PRIVATE ${C_FLAGS})
1180 SET_TARGET_PROPERTIES(common PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
1183 UNSET(HAS_ROUTER)
1184 SET(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1185 SET(SUBSYS_FLAG )
1187 # Build main library
1188 IF(LIBTYPE STREQUAL "STATIC")
1189     SET(CPP_DEFS ${CPP_DEFS} AL_LIBTYPE_STATIC)
1190     IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1191         SET(CPP_DEFS ${CPP_DEFS} AL_NO_UID_DEFS)
1192     ENDIF()
1193     ADD_LIBRARY(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1194     TARGET_LINK_LIBRARIES(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1195 ELSE()
1196     IF(WIN32)
1197         IF(MSVC)
1198             SET(SUBSYS_FLAG ${SUBSYS_FLAG} "/SUBSYSTEM:WINDOWS")
1199         ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1200             SET(SUBSYS_FLAG ${SUBSYS_FLAG} "-mwindows")
1201         ENDIF()
1202     ENDIF()
1204     SET(RC_CONFIG resources/openal32.rc)
1205     IF(WIN32 AND ALSOFT_BUILD_ROUTER)
1206         ADD_LIBRARY(OpenAL SHARED
1207             resources/router.rc
1208             router/router.cpp
1209             router/router.h
1210             router/alc.cpp
1211             router/al.cpp
1212         )
1213         TARGET_COMPILE_DEFINITIONS(OpenAL
1214             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1215         TARGET_COMPILE_OPTIONS(OpenAL PRIVATE ${C_FLAGS})
1216         TARGET_LINK_LIBRARIES(OpenAL PRIVATE common ${LINKER_FLAGS})
1217         TARGET_INCLUDE_DIRECTORIES(OpenAL
1218           PUBLIC
1219             $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1220             $<INSTALL_INTERFACE:include>
1221           PRIVATE
1222             ${OpenAL_SOURCE_DIR}/common
1223             ${OpenAL_BINARY_DIR}
1224         )
1225         SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "")
1226         SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1227         IF(TARGET build_version)
1228             ADD_DEPENDENCIES(OpenAL build_version)
1229         ENDIF()
1230         SET(HAS_ROUTER 1)
1232         SET(LIBNAME "soft_oal")
1233         SET(IMPL_TARGET soft_oal)
1234         SET(RC_CONFIG resources/soft_oal.rc)
1235     ENDIF()
1237     ADD_LIBRARY(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${RC_CONFIG})
1238     IF(WIN32)
1239         SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES PREFIX "")
1240     ENDIF()
1241     TARGET_LINK_LIBRARIES(${IMPL_TARGET} PRIVATE common ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1242 ENDIF()
1244 TARGET_INCLUDE_DIRECTORIES(${IMPL_TARGET}
1245   PUBLIC
1246     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1247     $<INSTALL_INTERFACE:include>
1248   PRIVATE
1249     ${INC_PATHS}
1250     ${OpenAL_BINARY_DIR}
1251     ${OpenAL_SOURCE_DIR}
1252     ${OpenAL_SOURCE_DIR}/alc
1253     ${OpenAL_SOURCE_DIR}/common
1256 SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1257     VERSION ${LIB_VERSION}
1258     SOVERSION ${LIB_MAJOR_VERSION}
1260 TARGET_COMPILE_DEFINITIONS(${IMPL_TARGET}
1261     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1262 TARGET_COMPILE_OPTIONS(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1264 IF(TARGET build_version)
1265     ADD_DEPENDENCIES(${IMPL_TARGET} build_version)
1266 ENDIF()
1268 IF(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1269     FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1270     FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1271     IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1272         MESSAGE(STATUS "")
1273         IF(NOT SED_EXECUTABLE)
1274             MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1275         ENDIF()
1276         IF(NOT DLLTOOL_EXECUTABLE)
1277             MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1278         ENDIF()
1279     ELSE()
1280         SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY
1281             LINK_FLAGS " -Wl,--output-def,OpenAL32.def")
1282         ADD_CUSTOM_COMMAND(TARGET OpenAL POST_BUILD
1283             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1284             COMMAND "${DLLTOOL_EXECUTABLE}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1285             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1286             VERBATIM
1287         )
1288     ENDIF()
1289 ENDIF()
1291 IF(ALSOFT_INSTALL)
1292     INSTALL(TARGETS OpenAL EXPORT OpenAL
1293         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1294         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1295         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1296         INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1297     EXPORT(TARGETS OpenAL
1298         NAMESPACE OpenAL::
1299         FILE OpenALConfig.cmake)
1300     INSTALL(EXPORT OpenAL
1301         DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1302         NAMESPACE OpenAL::
1303         FILE OpenALConfig.cmake)
1304     INSTALL(FILES
1305         include/AL/al.h
1306         include/AL/alc.h
1307         include/AL/alext.h
1308         include/AL/efx.h
1309         include/AL/efx-creative.h
1310         include/AL/efx-presets.h
1311         DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1312     INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1313         DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1314     IF(TARGET soft_oal)
1315         INSTALL(TARGETS soft_oal
1316             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1317     ENDIF()
1318 ENDIF()
1321 if(HAS_ROUTER)
1322     message(STATUS "")
1323     message(STATUS "Building DLL router")
1324 endif()
1326 MESSAGE(STATUS "")
1327 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1328 MESSAGE(STATUS "    ${BACKENDS}")
1329 MESSAGE(STATUS "")
1330 MESSAGE(STATUS "Building with support for CPU extensions:")
1331 MESSAGE(STATUS "    ${CPU_EXTS}")
1332 MESSAGE(STATUS "")
1333 IF(FPMATH_SET)
1334     MESSAGE(STATUS "Building with SSE${FPMATH_SET} codegen")
1335     MESSAGE(STATUS "")
1336 ENDIF()
1338 if(ALSOFT_EMBED_HRTF_DATA)
1339     message(STATUS "Embedding HRTF datasets")
1340     message(STATUS "")
1341 endif()
1343 # Install alsoft.conf configuration file
1344 IF(ALSOFT_CONFIG)
1345     INSTALL(FILES alsoftrc.sample
1346         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1347     MESSAGE(STATUS "Installing sample configuration")
1348     MESSAGE(STATUS "")
1349 ENDIF()
1351 # Install HRTF definitions
1352 IF(ALSOFT_HRTF_DEFS)
1353     INSTALL(FILES hrtf/default-44100.mhr hrtf/default-48000.mhr
1354         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf)
1355     MESSAGE(STATUS "Installing HRTF definitions")
1356     MESSAGE(STATUS "")
1357 ENDIF()
1359 # Install AmbDec presets
1360 IF(ALSOFT_AMBDEC_PRESETS)
1361     INSTALL(FILES
1362         presets/3D7.1.ambdec
1363         presets/hexagon.ambdec
1364         presets/itu5.1.ambdec
1365         presets/itu5.1-nocenter.ambdec
1366         presets/rectangle.ambdec
1367         presets/square.ambdec
1368         presets/presets.txt
1369         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets)
1370     MESSAGE(STATUS "Installing AmbDec presets")
1371     MESSAGE(STATUS "")
1372 ENDIF()
1374 IF(ALSOFT_UTILS)
1375     set(UTIL_TARGETS )
1377     ADD_EXECUTABLE(openal-info utils/openal-info.c)
1378     TARGET_INCLUDE_DIRECTORIES(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1379     TARGET_COMPILE_OPTIONS(openal-info PRIVATE ${C_FLAGS})
1380     TARGET_LINK_LIBRARIES(openal-info PRIVATE ${LINKER_FLAGS} OpenAL)
1381     set(UTIL_TARGETS ${UTIL_TARGETS} openal-info)
1383     find_package(MySOFA)
1384     if(MYSOFA_FOUND)
1385         set(MAKEMHR_SRCS
1386             utils/makemhr/loaddef.cpp
1387             utils/makemhr/loaddef.h
1388             utils/makemhr/loadsofa.cpp
1389             utils/makemhr/loadsofa.h
1390             utils/makemhr/makemhr.cpp
1391             utils/makemhr/makemhr.h)
1392         if(NOT HAVE_GETOPT)
1393             set(MAKEMHR_SRCS  ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1394         endif()
1395         add_executable(makemhr ${MAKEMHR_SRCS})
1396         target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1397         target_include_directories(makemhr
1398             PRIVATE ${OpenAL_SOURCE_DIR}/common ${OpenAL_BINARY_DIR})
1399         target_compile_options(makemhr PRIVATE ${C_FLAGS})
1400         target_link_libraries(makemhr PRIVATE common ${LINKER_FLAGS} MySOFA::MySOFA)
1401         set(UTIL_TARGETS ${UTIL_TARGETS} makemhr)
1403         set(SOFAINFO_SRCS  utils/sofa-info.cpp)
1404         add_executable(sofa-info ${SOFAINFO_SRCS})
1405         target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1406         target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1407         target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1408         target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} MySOFA::MySOFA)
1409     endif()
1411     IF(ALSOFT_INSTALL)
1412         INSTALL(TARGETS ${UTIL_TARGETS}
1413             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1414             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1415             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1416     ENDIF()
1418     MESSAGE(STATUS "Building utility programs")
1419     IF(TARGET alsoft-config)
1420         MESSAGE(STATUS "Building configuration program")
1421     ENDIF()
1422     MESSAGE(STATUS "")
1423 ENDIF()
1426 # Add a static library with common functions used by multiple example targets
1427 ADD_LIBRARY(ex-common STATIC EXCLUDE_FROM_ALL examples/common/alhelpers.c)
1428 TARGET_COMPILE_DEFINITIONS(ex-common PUBLIC ${CPP_DEFS})
1429 TARGET_INCLUDE_DIRECTORIES(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
1430 TARGET_COMPILE_OPTIONS(ex-common PUBLIC ${C_FLAGS})
1431 TARGET_LINK_LIBRARIES(ex-common PUBLIC OpenAL)
1433 IF(ALSOFT_TESTS)
1434     ADD_EXECUTABLE(altonegen examples/altonegen.c)
1435     TARGET_COMPILE_DEFINITIONS(altonegen PRIVATE ${CPP_DEFS})
1436     TARGET_INCLUDE_DIRECTORIES(altonegen PRIVATE ${OpenAL_SOURCE_DIR}/common)
1437     TARGET_COMPILE_OPTIONS(altonegen PRIVATE ${C_FLAGS})
1438     TARGET_LINK_LIBRARIES(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common)
1440     IF(ALSOFT_INSTALL)
1441         INSTALL(TARGETS altonegen
1442             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1443             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1444             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1445     ENDIF()
1447     MESSAGE(STATUS "Building test programs")
1448     MESSAGE(STATUS "")
1449 ENDIF()
1451 IF(ALSOFT_EXAMPLES)
1452     ADD_EXECUTABLE(alrecord examples/alrecord.c)
1453     TARGET_LINK_LIBRARIES(alrecord PRIVATE ${LINKER_FLAGS} ex-common)
1455     IF(ALSOFT_INSTALL)
1456         INSTALL(TARGETS alrecord
1457             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1458             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1459             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1460     ENDIF()
1462     MESSAGE(STATUS "Building example programs")
1464     IF(SDL2_FOUND)
1465         IF(SDL_SOUND_FOUND)
1466             ADD_EXECUTABLE(alplay examples/alplay.c)
1467             TARGET_INCLUDE_DIRECTORIES(alplay
1468                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1469             TARGET_LINK_LIBRARIES(alplay
1470                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common)
1472             ADD_EXECUTABLE(alstream examples/alstream.c)
1473             TARGET_INCLUDE_DIRECTORIES(alstream
1474                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1475             TARGET_LINK_LIBRARIES(alstream
1476                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common)
1478             ADD_EXECUTABLE(alreverb examples/alreverb.c)
1479             TARGET_INCLUDE_DIRECTORIES(alreverb
1480                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1481             TARGET_LINK_LIBRARIES(alreverb
1482                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common)
1484             ADD_EXECUTABLE(almultireverb examples/almultireverb.c)
1485             TARGET_INCLUDE_DIRECTORIES(almultireverb
1486                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1487             TARGET_LINK_LIBRARIES(almultireverb
1488                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common
1489                 ${MATH_LIB})
1491             ADD_EXECUTABLE(allatency examples/allatency.c)
1492             TARGET_INCLUDE_DIRECTORIES(allatency
1493                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1494             TARGET_LINK_LIBRARIES(allatency
1495                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common)
1497             ADD_EXECUTABLE(alloopback examples/alloopback.c)
1498             TARGET_INCLUDE_DIRECTORIES(alloopback
1499                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1500             TARGET_LINK_LIBRARIES(alloopback
1501                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common ${MATH_LIB})
1503             ADD_EXECUTABLE(alhrtf examples/alhrtf.c)
1504             TARGET_INCLUDE_DIRECTORIES(alhrtf
1505                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1506             TARGET_LINK_LIBRARIES(alhrtf
1507                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common ${MATH_LIB})
1509             IF(ALSOFT_INSTALL)
1510                 INSTALL(TARGETS alplay alstream alreverb almultireverb allatency alloopback alhrtf
1511                     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1512                     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1513                     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1514             ENDIF()
1516             MESSAGE(STATUS "Building SDL_sound example programs")
1517         ENDIF()
1519         SET(FFVER_OK FALSE)
1520         IF(FFMPEG_FOUND)
1521             SET(FFVER_OK TRUE)
1522             IF(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1523                 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1524                 SET(FFVER_OK FALSE)
1525             ENDIF()
1526             IF(AVCODEC_VERSION VERSION_LESS "57.64.101")
1527                 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1528                 SET(FFVER_OK FALSE)
1529             ENDIF()
1530             IF(AVUTIL_VERSION VERSION_LESS "55.34.101")
1531                 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1532                 SET(FFVER_OK FALSE)
1533             ENDIF()
1534             IF(SWSCALE_VERSION VERSION_LESS "4.2.100")
1535                 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1536                 SET(FFVER_OK FALSE)
1537             ENDIF()
1538             IF(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1539                 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1540                 SET(FFVER_OK FALSE)
1541             ENDIF()
1542         ENDIF()
1543         IF(FFVER_OK)
1544             ADD_EXECUTABLE(alffplay examples/alffplay.cpp)
1545             TARGET_INCLUDE_DIRECTORIES(alffplay
1546                 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1547             TARGET_LINK_LIBRARIES(alffplay
1548                 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common)
1550             IF(ALSOFT_INSTALL)
1551                 INSTALL(TARGETS alffplay
1552                     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1553                     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1554                     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1555             ENDIF()
1556             MESSAGE(STATUS "Building SDL+FFmpeg example programs")
1557         ENDIF()
1558         MESSAGE(STATUS "")
1559     ENDIF()
1560 ENDIF()