Release 1.20.0
[openal-soft.git] / CMakeLists.txt
blob98f9ad497a414102c19aeb575f871bca95068714
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 "20")
118 SET(LIB_REVISION "0")
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 # Some systems need to link with -lrt for clock_gettime as used by the common
394 # eaxmple functions.
395 SET(RT_LIB )
396 CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
397 IF(HAVE_LIBRT)
398     SET(RT_LIB rt)
399 ENDIF()
401 # Check for the dlopen API (for dynamicly loading backend libs)
402 IF(ALSOFT_DLOPEN)
403     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
404     CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
405     IF(HAVE_LIBDL)
406         SET(EXTRA_LIBS dl ${EXTRA_LIBS})
407         SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
408     ENDIF()
409 ENDIF()
411 # Check for a cpuid intrinsic
412 IF(HAVE_CPUID_H)
413     CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
414         int main()
415         {
416             unsigned int eax, ebx, ecx, edx;
417             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
418         }" HAVE_GCC_GET_CPUID)
419 ENDIF()
420 IF(HAVE_INTRIN_H)
421     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
422         int main()
423         {
424             int regs[4];
425             __cpuid(regs, 0);
426             return regs[0];
427         }" HAVE_CPUID_INTRINSIC)
428     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
429         int main()
430         {
431             unsigned long idx = 0;
432             _BitScanForward64(&idx, 1);
433             return idx;
434         }" HAVE_BITSCANFORWARD64_INTRINSIC)
435     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
436         int main()
437         {
438             unsigned long idx = 0;
439             _BitScanForward(&idx, 1);
440             return idx;
441         }" HAVE_BITSCANFORWARD_INTRINSIC)
442 ENDIF()
444 CHECK_SYMBOL_EXISTS(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
445 CHECK_SYMBOL_EXISTS(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
446 CHECK_SYMBOL_EXISTS(proc_pidpath     libproc.h HAVE_PROC_PIDPATH)
448 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
450 IF(NOT WIN32)
451     # We need pthreads outside of Windows, for semaphores. It's also used to
452     # set the priority and name of threads, when possible.
453     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
454     IF(NOT HAVE_PTHREAD_H)
455         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
456     ENDIF()
458     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
459     IF(HAVE_PTHREAD)
460         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
461         SET(C_FLAGS ${C_FLAGS} -pthread)
462         SET(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
463     ENDIF()
465     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
466     IF(HAVE_LIBPTHREAD)
467         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
468     ENDIF()
470     CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
472     # Some systems need pthread_np.h to get pthread_setname_np
473     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
474     IF(HAVE_PTHREAD_NP_H)
475         CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
476         IF(NOT HAVE_PTHREAD_SETNAME_NP)
477             CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
478         ELSE()
479             CHECK_C_SOURCE_COMPILES("
480 #include <pthread.h>
481 #include <pthread_np.h>
482 int main()
484     pthread_setname_np(\"testname\");
485     return 0;
487                 PTHREAD_SETNAME_NP_ONE_PARAM
488             )
489             CHECK_C_SOURCE_COMPILES("
490 #include <pthread.h>
491 #include <pthread_np.h>
492 int main()
494     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
495     return 0;
497                 PTHREAD_SETNAME_NP_THREE_PARAMS
498             )
499         ENDIF()
500     ELSE()
501         CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
502         IF(NOT HAVE_PTHREAD_SETNAME_NP)
503             CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
504         ELSE()
505             CHECK_C_SOURCE_COMPILES("
506 #include <pthread.h>
507 int main()
509     pthread_setname_np(\"testname\");
510     return 0;
512                 PTHREAD_SETNAME_NP_ONE_PARAM
513             )
514             CHECK_C_SOURCE_COMPILES("
515 #include <pthread.h>
516 int main()
518     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
519     return 0;
521                 PTHREAD_SETNAME_NP_THREE_PARAMS
522             )
523         ENDIF()
524     ENDIF()
525 ENDIF()
527 CHECK_SYMBOL_EXISTS(getopt unistd.h HAVE_GETOPT)
530 # Common sources used by both the OpenAL implementation library and potentially
531 # the OpenAL router.
532 SET(COMMON_OBJS
533     common/albyte.h
534     common/alcomplex.cpp
535     common/alcomplex.h
536     common/alexcpt.cpp
537     common/alexcpt.h
538     common/alfstream.cpp
539     common/alfstream.h
540     common/almalloc.cpp
541     common/almalloc.h
542     common/alnumeric.h
543     common/aloptional.h
544     common/alspan.h
545     common/alstring.cpp
546     common/alstring.h
547     common/atomic.h
548     common/dynload.cpp
549     common/dynload.h
550     common/endiantest.h
551     common/intrusive_ptr.h
552     common/math_defs.h
553     common/opthelpers.h
554     common/pragmadefs.h
555     common/strutils.cpp
556     common/strutils.h
557     common/threads.cpp
558     common/threads.h
559     common/vecmat.h
560     common/vector.h
562 SET(OPENAL_OBJS
563     al/auxeffectslot.cpp
564     al/auxeffectslot.h
565     al/buffer.cpp
566     al/buffer.h
567     al/effect.cpp
568     al/effect.h
569     al/error.cpp
570     al/event.cpp
571     al/event.h
572     al/extension.cpp
573     al/filter.cpp
574     al/filter.h
575     al/listener.cpp
576     al/listener.h
577     al/source.cpp
578     al/source.h
579     al/state.cpp
581 SET(ALC_OBJS
582     alc/alc.cpp
583     alc/alcmain.h
584     alc/alu.cpp
585     alc/alu.h
586     alc/alconfig.cpp
587     alc/alconfig.h
588     alc/alcontext.h
589     alc/ambdec.cpp
590     alc/ambdec.h
591     alc/ambidefs.h
592     alc/bformatdec.cpp
593     alc/bformatdec.h
594     alc/bs2b.cpp
595     alc/bs2b.h
596     alc/compat.h
597     alc/converter.cpp
598     alc/converter.h
599     alc/cpu_caps.h
600     alc/devformat.h
601     alc/effects/base.h
602     alc/effects/autowah.cpp
603     alc/effects/chorus.cpp
604     alc/effects/compressor.cpp
605     alc/effects/dedicated.cpp
606     alc/effects/distortion.cpp
607     alc/effects/echo.cpp
608     alc/effects/equalizer.cpp
609     alc/effects/fshifter.cpp
610     alc/effects/modulator.cpp
611     alc/effects/null.cpp
612     alc/effects/pshifter.cpp
613     alc/effects/reverb.cpp
614     alc/effects/vmorpher.cpp
615     alc/filters/biquad.h
616     alc/filters/biquad.cpp
617     alc/filters/nfc.cpp
618     alc/filters/nfc.h
619     alc/filters/splitter.cpp
620     alc/filters/splitter.h
621     alc/fpu_modes.h
622     alc/helpers.cpp
623     alc/hrtf.cpp
624     alc/hrtf.h
625     alc/inprogext.h
626     alc/logging.h
627     alc/mastering.cpp
628     alc/mastering.h
629     alc/panning.cpp
630     alc/ringbuffer.cpp
631     alc/ringbuffer.h
632     alc/uhjfilter.cpp
633     alc/uhjfilter.h
634     alc/uiddefs.cpp
635     alc/voice.cpp
636     alc/voice.h
637     alc/mixer/defs.h
638     alc/mixer/hrtfbase.h
639     alc/mixer/mixer_c.cpp
643 SET(CPU_EXTS "Default")
644 SET(HAVE_SSE        0)
645 SET(HAVE_SSE2       0)
646 SET(HAVE_SSE3       0)
647 SET(HAVE_SSE4_1     0)
648 SET(HAVE_NEON       0)
650 # Check for SSE+SSE2 support
651 OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
652 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
653 IF(HAVE_XMMINTRIN_H AND HAVE_EMMINTRIN_H)
654     OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
655     OPTION(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
656     IF(ALSOFT_CPUEXT_SSE AND ALSOFT_CPUEXT_SSE2)
657         SET(HAVE_SSE 1)
658         SET(HAVE_SSE2 1)
659         SET(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse.cpp alc/mixer/mixer_sse2.cpp)
660         IF(SSE2_SWITCH)
661             SET_SOURCE_FILES_PROPERTIES(alc/mixer/mixer_sse.cpp alc/mixer/mixer_sse2.cpp
662                 PROPERTIES COMPILE_FLAGS "${SSE2_SWITCH}")
663         ENDIF()
664         SET(CPU_EXTS "${CPU_EXTS}, SSE, SSE2")
665     ENDIF()
666 ENDIF()
667 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
668     MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
669 ENDIF()
670 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
671     MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
672 ENDIF()
674 OPTION(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
675 IF(HAVE_EMMINTRIN_H)
676     OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
677     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
678         SET(HAVE_SSE3 1)
679         SET(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse3.cpp)
680         IF(SSE2_SWITCH)
681             SET_SOURCE_FILES_PROPERTIES(alc/mixer/mixer_sse3.cpp PROPERTIES
682                                         COMPILE_FLAGS "${SSE3_SWITCH}")
683         ENDIF()
684         SET(CPU_EXTS "${CPU_EXTS}, SSE3")
685     ENDIF()
686 ENDIF()
687 IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
688     MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
689 ENDIF()
691 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
692 IF(HAVE_SMMINTRIN_H)
693     OPTION(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
694     IF(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
695         SET(HAVE_SSE4_1 1)
696         SET(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse41.cpp)
697         IF(SSE4_1_SWITCH)
698             SET_SOURCE_FILES_PROPERTIES(alc/mixer/mixer_sse41.cpp PROPERTIES
699                                         COMPILE_FLAGS "${SSE4_1_SWITCH}")
700         ENDIF()
701         SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
702     ENDIF()
703 ENDIF()
704 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
705     MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
706 ENDIF()
708 # Check for ARM Neon support
709 OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
710 IF(HAVE_ARM_NEON_H)
711     OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
712     IF(ALSOFT_CPUEXT_NEON)
713         SET(HAVE_NEON 1)
714         SET(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_neon.cpp)
715         IF(FPU_NEON_SWITCH)
716             SET_SOURCE_FILES_PROPERTIES(alc/mixer/mixer_neon.cpp PROPERTIES
717                                         COMPILE_FLAGS "${FPU_NEON_SWITCH}")
718         ENDIF()
719         SET(CPU_EXTS "${CPU_EXTS}, Neon")
720     ENDIF()
721 ENDIF()
722 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
723     MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
724 ENDIF()
727 SET(HAVE_ALSA       0)
728 SET(HAVE_OSS        0)
729 SET(HAVE_SOLARIS    0)
730 SET(HAVE_SNDIO      0)
731 SET(HAVE_QSA        0)
732 SET(HAVE_DSOUND     0)
733 SET(HAVE_WASAPI     0)
734 SET(HAVE_WINMM      0)
735 SET(HAVE_PORTAUDIO  0)
736 SET(HAVE_PULSEAUDIO 0)
737 SET(HAVE_COREAUDIO  0)
738 SET(HAVE_OPENSL     0)
739 SET(HAVE_WAVE       0)
740 SET(HAVE_SDL2       0)
742 IF(WIN32 OR HAVE_DLFCN_H)
743     SET(IS_LINKED "")
744     MACRO(ADD_BACKEND_LIBS _LIBS)
745     ENDMACRO()
746 ELSE()
747     SET(IS_LINKED " (linked)")
748     MACRO(ADD_BACKEND_LIBS _LIBS)
749         SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
750     ENDMACRO()
751 ENDIF()
753 SET(BACKENDS "")
754 SET(ALC_OBJS  ${ALC_OBJS}
755     alc/backends/base.cpp
756     alc/backends/base.h
757     # Default backends, always available
758     alc/backends/loopback.cpp
759     alc/backends/loopback.h
760     alc/backends/null.cpp
761     alc/backends/null.h
764 # Check ALSA backend
765 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
766 FIND_PACKAGE(ALSA)
767 IF(ALSA_FOUND)
768     OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
769     IF(ALSOFT_BACKEND_ALSA)
770         SET(HAVE_ALSA 1)
771         SET(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
772         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
773         ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
774         SET(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
775     ENDIF()
776 ENDIF()
777 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
778     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
779 ENDIF()
781 # Check OSS backend
782 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
783 FIND_PACKAGE(OSS)
784 IF(OSS_FOUND)
785     OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
786     IF(ALSOFT_BACKEND_OSS)
787         SET(HAVE_OSS 1)
788         SET(BACKENDS  "${BACKENDS} OSS,")
789         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
790         IF(OSS_LIBRARIES)
791             SET(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
792         ENDIF()
793         SET(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
794     ENDIF()
795 ENDIF()
796 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
797     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
798 ENDIF()
800 # Check Solaris backend
801 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
802 FIND_PACKAGE(AudioIO)
803 IF(AUDIOIO_FOUND)
804     OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
805     IF(ALSOFT_BACKEND_SOLARIS)
806         SET(HAVE_SOLARIS 1)
807         SET(BACKENDS  "${BACKENDS} Solaris,")
808         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
809         SET(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
810     ENDIF()
811 ENDIF()
812 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
813     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
814 ENDIF()
816 # Check SndIO backend
817 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
818 FIND_PACKAGE(SoundIO)
819 IF(SOUNDIO_FOUND)
820     OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
821     IF(ALSOFT_BACKEND_SNDIO)
822         SET(HAVE_SNDIO 1)
823         SET(BACKENDS  "${BACKENDS} SndIO (linked),")
824         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
825         SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
826         SET(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
827     ENDIF()
828 ENDIF()
829 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
830     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
831 ENDIF()
833 # Check QSA backend
834 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
835 FIND_PACKAGE(QSA)
836 IF(QSA_FOUND)
837     OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
838     IF(ALSOFT_BACKEND_QSA)
839         SET(HAVE_QSA 1)
840         SET(BACKENDS  "${BACKENDS} QSA (linked),")
841         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/qsa.cpp alc/backends/qsa.h)
842         SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
843         SET(INC_PATHS ${INC_PATHS} ${QSA_INCLUDE_DIRS})
844     ENDIF()
845 ENDIF()
846 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
847     MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
848 ENDIF()
850 # Check Windows-only backends
851 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
852 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
853 OPTION(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
854 IF(WIN32)
855     SET(WINSDK_LIB_DIRS )
856     SET(WINSDK_INCLUDE_DIRS )
857     FIND_PACKAGE(WindowsSDK)
858     IF(WINDOWSSDK_FOUND)
859         get_windowssdk_library_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_LIB_DIRS)
860         get_windowssdk_include_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_INCLUDE_DIRS)
861     ENDIF()
863     SET(OLD_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS})
864     SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=0x0502)
866     # Check MMSystem backend
867     CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
868     FIND_LIBRARY(WINMM_LIBRARY NAMES winmm
869         PATHS ${WINSDK_LIB_DIRS}
870         PATH_SUFFIXES lib lib/x86 lib/x64)
871     IF(HAVE_MMSYSTEM_H AND WINMM_LIBRARY)
872         OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
873         IF(ALSOFT_BACKEND_WINMM)
874             SET(HAVE_WINMM 1)
875             SET(BACKENDS  "${BACKENDS} WinMM,")
876             SET(ALC_OBJS  ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
877             SET(EXTRA_LIBS ${WINMM_LIBRARY} ${EXTRA_LIBS})
878         ENDIF()
879     ENDIF()
881     # Check DSound backend
882     FIND_PACKAGE(DSound)
883     IF(DSOUND_FOUND)
884         OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
885         IF(ALSOFT_BACKEND_DSOUND)
886             SET(HAVE_DSOUND 1)
887             SET(BACKENDS  "${BACKENDS} DirectSound${IS_LINKED},")
888             SET(ALC_OBJS  ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
889             ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
890             SET(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIRS})
891         ENDIF()
892     ENDIF()
894     # Check for WASAPI backend
895     CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
896     IF(HAVE_MMDEVICEAPI_H)
897         OPTION(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
898         IF(ALSOFT_BACKEND_WASAPI)
899             SET(HAVE_WASAPI 1)
900             SET(BACKENDS  "${BACKENDS} WASAPI,")
901             SET(ALC_OBJS  ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
902         ENDIF()
903     ENDIF()
905     SET(CMAKE_REQUIRED_DEFINITIONS ${OLD_REQUIRED_DEFINITIONS})
906     UNSET(OLD_REQUIRED_DEFINITIONS)
907 ENDIF()
908 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
909     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
910 ENDIF()
911 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
912     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
913 ENDIF()
914 IF(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
915     MESSAGE(FATAL_ERROR "Failed to enabled required WASAPI backend")
916 ENDIF()
918 # Check PortAudio backend
919 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
920 FIND_PACKAGE(PortAudio)
921 IF(PORTAUDIO_FOUND)
922     OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
923     IF(ALSOFT_BACKEND_PORTAUDIO)
924         SET(HAVE_PORTAUDIO 1)
925         SET(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
926         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
927         ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
928         SET(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
929     ENDIF()
930 ENDIF()
931 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
932     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
933 ENDIF()
935 # Check PulseAudio backend
936 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
937 FIND_PACKAGE(PulseAudio)
938 IF(PULSEAUDIO_FOUND)
939     OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
940     IF(ALSOFT_BACKEND_PULSEAUDIO)
941         SET(HAVE_PULSEAUDIO 1)
942         SET(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
943         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
944         ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
945         SET(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
946     ENDIF()
947 ENDIF()
948 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
949     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
950 ENDIF()
952 # Check JACK backend
953 OPTION(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
954 FIND_PACKAGE(JACK)
955 IF(JACK_FOUND)
956     OPTION(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
957     IF(ALSOFT_BACKEND_JACK)
958         SET(HAVE_JACK 1)
959         SET(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
960         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
961         ADD_BACKEND_LIBS(${JACK_LIBRARIES})
962         SET(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
963     ENDIF()
964 ENDIF()
965 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
966     MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
967 ENDIF()
969 # Check CoreAudio backend
970 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
971 FIND_LIBRARY(COREAUDIO_FRAMEWORK
972     NAMES CoreAudio
973     PATHS /System/Library/Frameworks
975 IF(COREAUDIO_FRAMEWORK)
976     OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
977     IF(ALSOFT_BACKEND_COREAUDIO)
978         SET(HAVE_COREAUDIO 1)
979         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
980         SET(BACKENDS  "${BACKENDS} CoreAudio,")
981         SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
982         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
983         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
985         # Some versions of OSX may need the AudioToolbox framework. Add it if
986         # it's found.
987         FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
988             NAMES AudioToolbox
989             PATHS
990                 ~/Library/Frameworks
991                 /Library/Frameworks
992                 /System/Library/Frameworks
993         )
994         IF(AUDIOTOOLBOX_LIBRARY)
995             SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
996         ENDIF()
997     ENDIF()
998 ENDIF()
999 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1000     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1001 ENDIF()
1003 # Check for OpenSL (Android) backend
1004 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1005 FIND_PACKAGE(OpenSL)
1006 IF(OPENSL_FOUND)
1007     OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1008     IF(ALSOFT_BACKEND_OPENSL)
1009         SET(HAVE_OPENSL 1)
1010         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1011         SET(BACKENDS  "${BACKENDS} OpenSL,")
1012         SET(EXTRA_LIBS ${OPENSL_LIBRARIES} ${EXTRA_LIBS})
1013         SET(INC_PATHS ${INC_PATHS} ${OPENSL_INCLUDE_DIRS})
1014     ENDIF()
1015 ENDIF()
1016 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1017     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1018 ENDIF()
1020 # Check for SDL2 backend
1021 OPTION(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1022 FIND_PACKAGE(SDL2)
1023 IF(SDL2_FOUND)
1024     # Off by default, since it adds a runtime dependency
1025     OPTION(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1026     IF(ALSOFT_BACKEND_SDL2)
1027         SET(HAVE_SDL2 1)
1028         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1029         SET(BACKENDS  "${BACKENDS} SDL2,")
1030         SET(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
1031         SET(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
1032     ENDIF()
1033 ENDIF()
1034 IF(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1035     MESSAGE(FATAL_ERROR "Failed to enabled required SDL2 backend")
1036 ENDIF()
1038 # Optionally enable the Wave Writer backend
1039 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1040 IF(ALSOFT_BACKEND_WAVE)
1041     SET(HAVE_WAVE 1)
1042     SET(ALC_OBJS  ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1043     SET(BACKENDS  "${BACKENDS} WaveFile,")
1044 ENDIF()
1046 # This is always available
1047 SET(BACKENDS  "${BACKENDS} Null")
1050 FIND_PACKAGE(Git)
1051 IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1052     # Get the current working branch and its latest abbreviated commit hash
1053     ADD_CUSTOM_TARGET(build_version
1054         ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1055             -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1056             -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1057         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1058         VERBATIM
1059     )
1060 ELSE()
1061     SET(GIT_BRANCH "UNKNOWN")
1062     SET(GIT_COMMIT_HASH "unknown")
1063     CONFIGURE_FILE(
1064         "${OpenAL_SOURCE_DIR}/version.h.in"
1065         "${OpenAL_BINARY_DIR}/version.h")
1066 ENDIF()
1069 SET(NATIVE_SRC_DIR  "${OpenAL_SOURCE_DIR}/native-tools")
1071 SET(ALSOFT_NATIVE_TOOLS_PATH "" CACHE STRING "Path to prebuilt native tools (leave blank to auto-build)")
1072 IF(ALSOFT_NATIVE_TOOLS_PATH)
1073     find_program(BIN2H_NATIVE_COMMAND NAMES bin2h
1074         PATHS "${ALSOFT_NATIVE_TOOLS_PATH}"
1075         NO_DEFAULT_PATH)
1076     find_program(BSINCGEN_NATIVE_COMMAND NAMES bsincgen
1077         PATHS "${ALSOFT_NATIVE_TOOLS_PATH}"
1078         NO_DEFAULT_PATH)
1079     if(NOT BIN2H_NATIVE_COMMAND OR NOT BSINCGEN_NATIVE_COMMAND)
1080         message(FATAL_ERROR "Failed to find native tools in ${ALSOFT_NATIVE_TOOLS_PATH}.
1081 bin2h: ${BIN2H_NATIVE_COMMAND}
1082 bsincgen: ${BSINCGEN_NATIVE_COMMAND}")
1083     endif()
1084     SET(BIN2H_COMMAND  ${BIN2H_NATIVE_COMMAND})
1085     SET(BSINCGEN_COMMAND  ${BSINCGEN_NATIVE_COMMAND})
1086 ELSE()
1087     SET(NATIVE_BIN_DIR  "${OpenAL_BINARY_DIR}/native-tools")
1088     FILE(MAKE_DIRECTORY "${NATIVE_BIN_DIR}")
1090     SET(BIN2H_COMMAND  "${NATIVE_BIN_DIR}/bin2h")
1091     SET(BSINCGEN_COMMAND  "${NATIVE_BIN_DIR}/bsincgen")
1092     ADD_CUSTOM_COMMAND(OUTPUT "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1093         COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" "${NATIVE_SRC_DIR}"
1094         COMMAND ${CMAKE_COMMAND} -E remove "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1095         COMMAND ${CMAKE_COMMAND} --build . --config "Release"
1096         WORKING_DIRECTORY "${NATIVE_BIN_DIR}"
1097         DEPENDS "${NATIVE_SRC_DIR}/CMakeLists.txt"
1098         IMPLICIT_DEPENDS
1099             C "${NATIVE_SRC_DIR}/bin2h.c"
1100             C "${NATIVE_SRC_DIR}/bsincgen.c"
1101         VERBATIM
1102     )
1103 ENDIF()
1104 ADD_CUSTOM_TARGET(native-tools
1105     DEPENDS "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1106     VERBATIM
1109 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1110 if(ALSOFT_EMBED_HRTF_DATA)
1111     MACRO(make_hrtf_header FILENAME VARNAME)
1112         SET(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1113         SET(outfile  "${OpenAL_BINARY_DIR}/${FILENAME}.h")
1115         ADD_CUSTOM_COMMAND(OUTPUT "${outfile}"
1116             COMMAND "${BIN2H_COMMAND}" "${infile}" "${outfile}" ${VARNAME}
1117             DEPENDS native-tools "${infile}"
1118             VERBATIM
1119         )
1120         SET(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1121     ENDMACRO()
1123     make_hrtf_header(default-44100.mhr "hrtf_default_44100")
1124     make_hrtf_header(default-48000.mhr "hrtf_default_48000")
1125 endif()
1127 ADD_CUSTOM_COMMAND(OUTPUT "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1128     COMMAND "${BSINCGEN_COMMAND}" "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1129     DEPENDS native-tools "${NATIVE_SRC_DIR}/bsincgen.c"
1130     VERBATIM
1132 SET(ALC_OBJS  ${ALC_OBJS} "${OpenAL_BINARY_DIR}/bsinc_inc.h")
1135 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1136     add_subdirectory(utils/alsoft-config)
1137 ENDIF()
1138 IF(ALSOFT_EXAMPLES)
1139     IF(NOT SDL2_FOUND)
1140         FIND_PACKAGE(SDL2)
1141     ENDIF()
1142     IF(SDL2_FOUND)
1143         FIND_PACKAGE(SDL_sound)
1144         FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1145     ENDIF()
1146 ENDIF()
1148 IF(NOT WIN32)
1149     SET(LIBNAME "openal")
1150 ELSE()
1151     SET(LIBNAME "OpenAL32")
1152 ENDIF()
1154 # Needed for openal.pc.in
1155 SET(prefix ${CMAKE_INSTALL_PREFIX})
1156 SET(exec_prefix "\${prefix}")
1157 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1158 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1159 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1160 SET(PACKAGE_VERSION "${LIB_VERSION}")
1161 SET(PKG_CONFIG_CFLAGS )
1162 SET(PKG_CONFIG_PRIVATE_LIBS )
1163 IF(LIBTYPE STREQUAL "STATIC")
1164     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1165     FOREACH(FLAG  ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1166         # If this is already a linker flag, or is a full path+file, add it
1167         # as-is. Otherwise, it's a name intended to be dressed as -lname.
1168         IF(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1169             SET(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1170         ELSE()
1171             SET(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1172         ENDIF()
1173     ENDFOREACH()
1174 ENDIF()
1176 # End configuration
1177 CONFIGURE_FILE(
1178     "${OpenAL_SOURCE_DIR}/config.h.in"
1179     "${OpenAL_BINARY_DIR}/config.h")
1180 CONFIGURE_FILE(
1181     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1182     "${OpenAL_BINARY_DIR}/openal.pc"
1183     @ONLY)
1186 ADD_LIBRARY(common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1187 TARGET_INCLUDE_DIRECTORIES(common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include)
1188 TARGET_COMPILE_DEFINITIONS(common PRIVATE ${CPP_DEFS})
1189 TARGET_COMPILE_OPTIONS(common PRIVATE ${C_FLAGS})
1190 SET_TARGET_PROPERTIES(common PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
1193 UNSET(HAS_ROUTER)
1194 SET(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1195 SET(SUBSYS_FLAG )
1197 # Build main library
1198 IF(LIBTYPE STREQUAL "STATIC")
1199     SET(CPP_DEFS ${CPP_DEFS} AL_LIBTYPE_STATIC)
1200     IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1201         SET(CPP_DEFS ${CPP_DEFS} AL_NO_UID_DEFS)
1202     ENDIF()
1203     ADD_LIBRARY(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1204     TARGET_LINK_LIBRARIES(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1205 ELSE()
1206     IF(WIN32)
1207         IF(MSVC)
1208             SET(SUBSYS_FLAG ${SUBSYS_FLAG} "/SUBSYSTEM:WINDOWS")
1209         ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1210             SET(SUBSYS_FLAG ${SUBSYS_FLAG} "-mwindows")
1211         ENDIF()
1212     ENDIF()
1214     SET(RC_CONFIG resources/openal32.rc)
1215     IF(WIN32 AND ALSOFT_BUILD_ROUTER)
1216         ADD_LIBRARY(OpenAL SHARED
1217             resources/router.rc
1218             router/router.cpp
1219             router/router.h
1220             router/alc.cpp
1221             router/al.cpp
1222         )
1223         TARGET_COMPILE_DEFINITIONS(OpenAL
1224             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1225         TARGET_COMPILE_OPTIONS(OpenAL PRIVATE ${C_FLAGS})
1226         TARGET_LINK_LIBRARIES(OpenAL PRIVATE common ${LINKER_FLAGS})
1227         TARGET_INCLUDE_DIRECTORIES(OpenAL
1228           PUBLIC
1229             $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1230             $<INSTALL_INTERFACE:include>
1231           PRIVATE
1232             ${OpenAL_SOURCE_DIR}/common
1233             ${OpenAL_BINARY_DIR}
1234         )
1235         SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "")
1236         SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1237         IF(TARGET build_version)
1238             ADD_DEPENDENCIES(OpenAL build_version)
1239         ENDIF()
1240         SET(HAS_ROUTER 1)
1242         SET(LIBNAME "soft_oal")
1243         SET(IMPL_TARGET soft_oal)
1244         SET(RC_CONFIG resources/soft_oal.rc)
1245     ENDIF()
1247     ADD_LIBRARY(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${RC_CONFIG})
1248     IF(WIN32)
1249         SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES PREFIX "")
1250     ENDIF()
1251     TARGET_LINK_LIBRARIES(${IMPL_TARGET} PRIVATE common ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1252 ENDIF()
1254 TARGET_INCLUDE_DIRECTORIES(${IMPL_TARGET}
1255   PUBLIC
1256     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1257     $<INSTALL_INTERFACE:include>
1258   PRIVATE
1259     ${INC_PATHS}
1260     ${OpenAL_BINARY_DIR}
1261     ${OpenAL_SOURCE_DIR}
1262     ${OpenAL_SOURCE_DIR}/alc
1263     ${OpenAL_SOURCE_DIR}/common
1266 SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1267     VERSION ${LIB_VERSION}
1268     SOVERSION ${LIB_MAJOR_VERSION}
1270 TARGET_COMPILE_DEFINITIONS(${IMPL_TARGET}
1271     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1272 TARGET_COMPILE_OPTIONS(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1274 IF(TARGET build_version)
1275     ADD_DEPENDENCIES(${IMPL_TARGET} build_version)
1276 ENDIF()
1278 IF(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1279     FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1280     FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1281     IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1282         MESSAGE(STATUS "")
1283         IF(NOT SED_EXECUTABLE)
1284             MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1285         ENDIF()
1286         IF(NOT DLLTOOL_EXECUTABLE)
1287             MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1288         ENDIF()
1289     ELSE()
1290         SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY
1291             LINK_FLAGS " -Wl,--output-def,OpenAL32.def")
1292         ADD_CUSTOM_COMMAND(TARGET OpenAL POST_BUILD
1293             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1294             COMMAND "${DLLTOOL_EXECUTABLE}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1295             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1296             VERBATIM
1297         )
1298     ENDIF()
1299 ENDIF()
1301 IF(ALSOFT_INSTALL)
1302     INSTALL(TARGETS OpenAL EXPORT OpenAL
1303         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1304         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1305         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1306         INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1307     EXPORT(TARGETS OpenAL
1308         NAMESPACE OpenAL::
1309         FILE OpenALConfig.cmake)
1310     INSTALL(EXPORT OpenAL
1311         DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1312         NAMESPACE OpenAL::
1313         FILE OpenALConfig.cmake)
1314     INSTALL(FILES
1315         include/AL/al.h
1316         include/AL/alc.h
1317         include/AL/alext.h
1318         include/AL/efx.h
1319         include/AL/efx-creative.h
1320         include/AL/efx-presets.h
1321         DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1322     INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1323         DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1324     IF(TARGET soft_oal)
1325         INSTALL(TARGETS soft_oal
1326             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1327     ENDIF()
1328 ENDIF()
1331 if(HAS_ROUTER)
1332     message(STATUS "")
1333     message(STATUS "Building DLL router")
1334 endif()
1336 MESSAGE(STATUS "")
1337 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1338 MESSAGE(STATUS "    ${BACKENDS}")
1339 MESSAGE(STATUS "")
1340 MESSAGE(STATUS "Building with support for CPU extensions:")
1341 MESSAGE(STATUS "    ${CPU_EXTS}")
1342 MESSAGE(STATUS "")
1343 IF(FPMATH_SET)
1344     MESSAGE(STATUS "Building with SSE${FPMATH_SET} codegen")
1345     MESSAGE(STATUS "")
1346 ENDIF()
1348 if(ALSOFT_EMBED_HRTF_DATA)
1349     message(STATUS "Embedding HRTF datasets")
1350     message(STATUS "")
1351 endif()
1353 # Install alsoft.conf configuration file
1354 IF(ALSOFT_CONFIG)
1355     INSTALL(FILES alsoftrc.sample
1356         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1357     MESSAGE(STATUS "Installing sample configuration")
1358     MESSAGE(STATUS "")
1359 ENDIF()
1361 # Install HRTF definitions
1362 IF(ALSOFT_HRTF_DEFS)
1363     INSTALL(FILES hrtf/default-44100.mhr hrtf/default-48000.mhr
1364         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf)
1365     MESSAGE(STATUS "Installing HRTF definitions")
1366     MESSAGE(STATUS "")
1367 ENDIF()
1369 # Install AmbDec presets
1370 IF(ALSOFT_AMBDEC_PRESETS)
1371     INSTALL(FILES
1372         presets/3D7.1.ambdec
1373         presets/hexagon.ambdec
1374         presets/itu5.1.ambdec
1375         presets/itu5.1-nocenter.ambdec
1376         presets/rectangle.ambdec
1377         presets/square.ambdec
1378         presets/presets.txt
1379         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets)
1380     MESSAGE(STATUS "Installing AmbDec presets")
1381     MESSAGE(STATUS "")
1382 ENDIF()
1384 IF(ALSOFT_UTILS)
1385     set(UTIL_TARGETS )
1387     ADD_EXECUTABLE(openal-info utils/openal-info.c)
1388     TARGET_INCLUDE_DIRECTORIES(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1389     TARGET_COMPILE_OPTIONS(openal-info PRIVATE ${C_FLAGS})
1390     TARGET_LINK_LIBRARIES(openal-info PRIVATE ${LINKER_FLAGS} OpenAL)
1391     set(UTIL_TARGETS ${UTIL_TARGETS} openal-info)
1393     find_package(MySOFA)
1394     if(MYSOFA_FOUND)
1395         set(MAKEMHR_SRCS
1396             utils/makemhr/loaddef.cpp
1397             utils/makemhr/loaddef.h
1398             utils/makemhr/loadsofa.cpp
1399             utils/makemhr/loadsofa.h
1400             utils/makemhr/makemhr.cpp
1401             utils/makemhr/makemhr.h)
1402         if(NOT HAVE_GETOPT)
1403             set(MAKEMHR_SRCS  ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1404         endif()
1405         add_executable(makemhr ${MAKEMHR_SRCS})
1406         target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1407         target_include_directories(makemhr
1408             PRIVATE ${OpenAL_SOURCE_DIR}/common ${OpenAL_BINARY_DIR})
1409         target_compile_options(makemhr PRIVATE ${C_FLAGS})
1410         target_link_libraries(makemhr PRIVATE common ${LINKER_FLAGS} MySOFA::MySOFA)
1411         set(UTIL_TARGETS ${UTIL_TARGETS} makemhr)
1413         set(SOFAINFO_SRCS  utils/sofa-info.cpp)
1414         add_executable(sofa-info ${SOFAINFO_SRCS})
1415         target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1416         target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1417         target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1418         target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} MySOFA::MySOFA)
1419     endif()
1421     IF(ALSOFT_INSTALL)
1422         INSTALL(TARGETS ${UTIL_TARGETS}
1423             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1424             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1425             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1426     ENDIF()
1428     MESSAGE(STATUS "Building utility programs")
1429     IF(TARGET alsoft-config)
1430         MESSAGE(STATUS "Building configuration program")
1431     ENDIF()
1432     MESSAGE(STATUS "")
1433 ENDIF()
1436 # Add a static library with common functions used by multiple example targets
1437 ADD_LIBRARY(ex-common STATIC EXCLUDE_FROM_ALL
1438     examples/common/alhelpers.c
1439     examples/common/alhelpers.h)
1440 TARGET_COMPILE_DEFINITIONS(ex-common PUBLIC ${CPP_DEFS})
1441 TARGET_INCLUDE_DIRECTORIES(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
1442 TARGET_COMPILE_OPTIONS(ex-common PUBLIC ${C_FLAGS})
1443 TARGET_LINK_LIBRARIES(ex-common PUBLIC OpenAL PRIVATE ${RT_LIB})
1445 IF(ALSOFT_TESTS)
1446     ADD_EXECUTABLE(altonegen examples/altonegen.c)
1447     TARGET_COMPILE_DEFINITIONS(altonegen PRIVATE ${CPP_DEFS})
1448     TARGET_INCLUDE_DIRECTORIES(altonegen PRIVATE ${OpenAL_SOURCE_DIR}/common)
1449     TARGET_COMPILE_OPTIONS(altonegen PRIVATE ${C_FLAGS})
1450     TARGET_LINK_LIBRARIES(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common)
1452     IF(ALSOFT_INSTALL)
1453         INSTALL(TARGETS altonegen
1454             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1455             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1456             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1457     ENDIF()
1459     MESSAGE(STATUS "Building test programs")
1460     MESSAGE(STATUS "")
1461 ENDIF()
1463 IF(ALSOFT_EXAMPLES)
1464     ADD_EXECUTABLE(alrecord examples/alrecord.c)
1465     TARGET_LINK_LIBRARIES(alrecord PRIVATE ${LINKER_FLAGS} ex-common)
1467     IF(ALSOFT_INSTALL)
1468         INSTALL(TARGETS alrecord
1469             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1470             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1471             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1472     ENDIF()
1474     MESSAGE(STATUS "Building example programs")
1476     IF(SDL2_FOUND)
1477         IF(SDL_SOUND_FOUND)
1478             ADD_EXECUTABLE(alplay examples/alplay.c)
1479             TARGET_INCLUDE_DIRECTORIES(alplay
1480                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1481             TARGET_LINK_LIBRARIES(alplay
1482                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common)
1484             ADD_EXECUTABLE(alstream examples/alstream.c)
1485             TARGET_INCLUDE_DIRECTORIES(alstream
1486                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1487             TARGET_LINK_LIBRARIES(alstream
1488                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common)
1490             ADD_EXECUTABLE(alreverb examples/alreverb.c)
1491             TARGET_INCLUDE_DIRECTORIES(alreverb
1492                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1493             TARGET_LINK_LIBRARIES(alreverb
1494                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common)
1496             ADD_EXECUTABLE(almultireverb examples/almultireverb.c)
1497             TARGET_INCLUDE_DIRECTORIES(almultireverb
1498                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1499             TARGET_LINK_LIBRARIES(almultireverb
1500                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common
1501                 ${MATH_LIB})
1503             ADD_EXECUTABLE(allatency examples/allatency.c)
1504             TARGET_INCLUDE_DIRECTORIES(allatency
1505                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1506             TARGET_LINK_LIBRARIES(allatency
1507                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common)
1509             ADD_EXECUTABLE(alloopback examples/alloopback.c)
1510             TARGET_INCLUDE_DIRECTORIES(alloopback
1511                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1512             TARGET_LINK_LIBRARIES(alloopback
1513                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common ${MATH_LIB})
1515             ADD_EXECUTABLE(alhrtf examples/alhrtf.c)
1516             TARGET_INCLUDE_DIRECTORIES(alhrtf
1517                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1518             TARGET_LINK_LIBRARIES(alhrtf
1519                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common ${MATH_LIB})
1521             IF(ALSOFT_INSTALL)
1522                 INSTALL(TARGETS alplay alstream alreverb almultireverb allatency alloopback alhrtf
1523                     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1524                     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1525                     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1526             ENDIF()
1528             MESSAGE(STATUS "Building SDL_sound example programs")
1529         ENDIF()
1531         SET(FFVER_OK FALSE)
1532         IF(FFMPEG_FOUND)
1533             SET(FFVER_OK TRUE)
1534             IF(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1535                 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1536                 SET(FFVER_OK FALSE)
1537             ENDIF()
1538             IF(AVCODEC_VERSION VERSION_LESS "57.64.101")
1539                 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1540                 SET(FFVER_OK FALSE)
1541             ENDIF()
1542             IF(AVUTIL_VERSION VERSION_LESS "55.34.101")
1543                 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1544                 SET(FFVER_OK FALSE)
1545             ENDIF()
1546             IF(SWSCALE_VERSION VERSION_LESS "4.2.100")
1547                 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1548                 SET(FFVER_OK FALSE)
1549             ENDIF()
1550             IF(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1551                 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1552                 SET(FFVER_OK FALSE)
1553             ENDIF()
1554         ENDIF()
1555         IF(FFVER_OK)
1556             ADD_EXECUTABLE(alffplay examples/alffplay.cpp)
1557             TARGET_INCLUDE_DIRECTORIES(alffplay
1558                 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1559             TARGET_LINK_LIBRARIES(alffplay
1560                 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common)
1562             IF(ALSOFT_INSTALL)
1563                 INSTALL(TARGETS alffplay
1564                     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1565                     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1566                     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1567             ENDIF()
1568             MESSAGE(STATUS "Building SDL+FFmpeg example programs")
1569         ENDIF()
1570         MESSAGE(STATUS "")
1571     ENDIF()
1572 ENDIF()