Read the buffer unpack alignment under the buffer lock
[openal-soft.git] / CMakeLists.txt
blob29c0a3b76e4864b091ffa594ab8d4380875af22a
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 ENDIF(COMMAND CMAKE_POLICY)
21 SET(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
23 INCLUDE(CheckFunctionExists)
24 INCLUDE(CheckLibraryExists)
25 INCLUDE(CheckSharedFunctionExists)
26 INCLUDE(CheckIncludeFile)
27 INCLUDE(CheckIncludeFiles)
28 INCLUDE(CheckSymbolExists)
29 INCLUDE(CheckCCompilerFlag)
30 INCLUDE(CheckCXXCompilerFlag)
31 INCLUDE(CheckCSourceCompiles)
32 INCLUDE(CheckTypeSize)
33 include(CheckStructHasMember)
34 include(CheckFileOffsetBits)
35 include(GNUInstallDirs)
37 SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
40 OPTION(ALSOFT_DLOPEN  "Check for the dlopen API for loading optional libs"  ON)
42 OPTION(ALSOFT_WERROR  "Treat compile warnings as errors"      OFF)
44 OPTION(ALSOFT_UTILS          "Build and install utility programs"         ON)
45 OPTION(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
47 OPTION(ALSOFT_EXAMPLES  "Build and install example programs"  ON)
48 OPTION(ALSOFT_TESTS     "Build and install test programs"     ON)
50 OPTION(ALSOFT_CONFIG "Install alsoft.conf sample configuration file" ON)
51 OPTION(ALSOFT_HRTF_DEFS "Install HRTF definition files" ON)
52 OPTION(ALSOFT_AMBDEC_PRESETS "Install AmbDec preset files" ON)
53 OPTION(ALSOFT_INSTALL "Install headers and libraries" ON)
55 if(DEFINED SHARE_INSTALL_DIR)
56     message(WARNING "SHARE_INSTALL_DIR is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
57     set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
58 endif()
60 if(DEFINED LIB_SUFFIX)
61     message(WARNING "LIB_SUFFIX is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
62 endif()
65 SET(CPP_DEFS ) # C pre-process, not C++
66 SET(INC_PATHS )
67 SET(C_FLAGS )
68 SET(LINKER_FLAGS )
69 SET(EXTRA_LIBS )
71 IF(WIN32)
72     SET(CPP_DEFS ${CPP_DEFS} _WIN32 _WIN32_WINNT=0x0502)
74     OPTION(ALSOFT_BUILD_ROUTER  "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)"  OFF)
76     # This option is mainly for static linking OpenAL Soft into another project
77     # that already defines the IDs. It is up to that project to ensure all
78     # required IDs are defined.
79     OPTION(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
81     IF(MINGW)
82         OPTION(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
83         IF(NOT DLLTOOL)
84             IF(HOST)
85                 SET(DLLTOOL "${HOST}-dlltool")
86             ELSE()
87                 SET(DLLTOOL "dlltool")
88             ENDIF()
89         ENDIF()
90     ENDIF()
91 ENDIF()
94 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
95 IF ("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
96     SET(INC_PATHS ${INC_PATHS} /usr/include)
97     SET(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
98 ENDIF()
100 IF(NOT LIBTYPE)
101     SET(LIBTYPE SHARED)
102 ENDIF()
104 SET(LIB_MAJOR_VERSION "1")
105 SET(LIB_MINOR_VERSION "18")
106 SET(LIB_REVISION "2")
107 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
109 SET(EXPORT_DECL "")
110 SET(ALIGN_DECL "")
113 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
114 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
117 CHECK_C_COMPILER_FLAG(-std=c11 HAVE_STD_C11)
118 IF(HAVE_STD_C11)
119     SET(CMAKE_C_FLAGS "-std=c11 ${CMAKE_C_FLAGS}")
120 ELSE()
121     CHECK_C_COMPILER_FLAG(-std=c99 HAVE_STD_C99)
122     IF(HAVE_STD_C99)
123         SET(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
124     ENDIF()
125 ENDIF()
127 CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD_CXX11)
128 IF(HAVE_STD_CXX11)
129     SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
130 ENDIF()
132 if(NOT WIN32)
133     # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
134     CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
135     IF(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
136         SET(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
137         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
138         CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
139         IF(NOT HAVE_POSIX_MEMALIGN_POSIX)
140             SET(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
141         ELSE()
142             SET(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
143         ENDIF()
144     ENDIF()
145     UNSET(OLD_REQUIRED_FLAGS)
146 ENDIF()
148 # Set defines for large file support
149 CHECK_FILE_OFFSET_BITS()
150 IF(_FILE_OFFSET_BITS)
151     SET(CPP_DEFS ${CPP_DEFS} "_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
152     SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
153 ENDIF()
154 SET(CPP_DEFS ${CPP_DEFS} _LARGEFILE_SOURCE _LARGE_FILES)
155 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_LARGEFILE_SOURCE -D_LARGE_FILES")
157 # MSVC may need workarounds for C99 restrict and inline
158 IF(MSVC)
159     # TODO: Once we truly require C99, these restrict and inline checks should go
160     # away.
161     CHECK_C_SOURCE_COMPILES("int *restrict foo;
162                              int main() {return 0;}" HAVE_RESTRICT)
163     IF(NOT HAVE_RESTRICT)
164         SET(CPP_DEFS ${CPP_DEFS} "restrict=")
165         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Drestrict=")
166     ENDIF()
168     CHECK_C_SOURCE_COMPILES("inline void foo(void) { }
169                              int main() {return 0;}" HAVE_INLINE)
170     IF(NOT HAVE_INLINE)
171         CHECK_C_SOURCE_COMPILES("__inline void foo(void) { }
172                                  int main() {return 0;}" HAVE___INLINE)
173         IF(NOT HAVE___INLINE)
174             MESSAGE(FATAL_ERROR "No inline keyword found, please report!")
175         ENDIF()
177         SET(CPP_DEFS ${CPP_DEFS} inline=__inline)
178         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Dinline=__inline")
179     ENDIF()
180 ENDIF()
182 # Make sure we have C99-style inline semantics with GCC (4.3 or newer).
183 IF(CMAKE_COMPILER_IS_GNUCC)
184     SET(CMAKE_C_FLAGS "-fno-gnu89-inline ${CMAKE_C_FLAGS}")
186     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
187     # Force no inlining for the next test.
188     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -fno-inline")
190     CHECK_C_SOURCE_COMPILES("extern inline int foo() { return 0; }
191                              int main() {return foo();}" INLINE_IS_C99)
192     IF(NOT INLINE_IS_C99)
193         MESSAGE(FATAL_ERROR "Your compiler does not seem to have C99 inline semantics!
194                              Please update your compiler for better C99 compliance.")
195     ENDIF()
197     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
198 ENDIF()
200 # Check if we have a proper timespec declaration
201 CHECK_STRUCT_HAS_MEMBER("struct timespec" tv_sec time.h HAVE_STRUCT_TIMESPEC)
202 IF(HAVE_STRUCT_TIMESPEC)
203     # Define it here so we don't have to include config.h for it
204     SET(CPP_DEFS ${CPP_DEFS} HAVE_STRUCT_TIMESPEC)
205 ENDIF()
207 # Some systems may need libatomic for C11 atomic functions to work
208 SET(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
209 SET(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
210 CHECK_C_SOURCE_COMPILES("#include <stdatomic.h>
211 int _Atomic foo = ATOMIC_VAR_INIT(0);
212 int main()
214     return atomic_fetch_add(&foo, 2);
216 HAVE_LIBATOMIC)
217 IF(NOT HAVE_LIBATOMIC)
218     SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
219 ELSE()
220     SET(EXTRA_LIBS atomic ${EXTRA_LIBS})
221 ENDIF()
222 UNSET(OLD_REQUIRED_LIBRARIES)
224 # Include liblog for Android logging
225 CHECK_LIBRARY_EXISTS(log __android_log_print "" HAVE_LIBLOG)
226 IF(HAVE_LIBLOG)
227     SET(EXTRA_LIBS log ${EXTRA_LIBS})
228     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
229 ENDIF()
231 # Check if we have C99 bool
232 CHECK_C_SOURCE_COMPILES(
233 "int main(int argc, char *argv[])
235      volatile _Bool ret;
236      ret = (argc > 1) ? 1 : 0;
237      return ret ? -1 : 0;
238  }"
239 HAVE_C99_BOOL)
241 # Check if we have C11 static_assert
242 CHECK_C_SOURCE_COMPILES(
243 "int main()
245      _Static_assert(sizeof(int) == sizeof(int), \"What\");
246      return 0;
247  }"
248 HAVE_C11_STATIC_ASSERT)
250 # Check if we have C11 alignas
251 CHECK_C_SOURCE_COMPILES(
252 "_Alignas(16) int foo;
253  int main()
255      return 0;
256  }"
257 HAVE_C11_ALIGNAS)
259 # Check if we have C11 _Atomic
260 CHECK_C_SOURCE_COMPILES(
261 "#include <stdatomic.h>
262  int _Atomic foo = ATOMIC_VAR_INIT(0);
263  int main()
265      atomic_fetch_add(&foo, 2);
266      return 0;
267  }"
268 HAVE_C11_ATOMIC)
270 # Add definitions, compiler switches, etc.
271 INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_SOURCE_DIR}/common" "${OpenAL_BINARY_DIR}")
273 IF(NOT CMAKE_BUILD_TYPE)
274     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
275         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
276         FORCE)
277 ENDIF()
278 IF(NOT CMAKE_DEBUG_POSTFIX)
279     SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
280         "Library postfix for debug builds. Normally left blank."
281         FORCE)
282 ENDIF()
284 IF(MSVC)
285     SET(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE)
286     SET(C_FLAGS ${C_FLAGS} /wd4098)
288     IF(NOT DXSDK_DIR)
289         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
290     ELSE()
291         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
292     ENDIF()
293     IF(DXSDK_DIR)
294         MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
295     ENDIF()
297     OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
298     IF(FORCE_STATIC_VCRT)
299         FOREACH(flag_var
300                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
301                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
302             IF(${flag_var} MATCHES "/MD")
303                 STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
304             ENDIF()
305         ENDFOREACH(flag_var)
306     ENDIF()
307 ELSE()
308     SET(C_FLAGS ${C_FLAGS} -Winline -Wall)
309     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
310     IF(HAVE_W_EXTRA)
311         SET(C_FLAGS ${C_FLAGS} -Wextra)
312     ENDIF()
314     IF(ALSOFT_WERROR)
315         SET(C_FLAGS ${C_FLAGS} -Werror)
316     ENDIF()
318     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
319     # instead of NDEBUG)
320     FOREACH(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
321         IF(${flag_var} MATCHES "-DNDEBUG")
322             STRING(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
323         ENDIF()
324     ENDFOREACH()
326     CHECK_C_COMPILER_FLAG(-fno-math-errno HAVE_FNO_MATH_ERRNO)
327     IF(HAVE_FNO_MATH_ERRNO)
328         SET(C_FLAGS ${C_FLAGS} -fno-math-errno)
329     ENDIF()
331     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
332                              int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
334     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
335     if(ALSOFT_STATIC_LIBGCC)
336         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
337         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
338         check_c_source_compiles(
339 "#include <stdlib.h>
340 int main()
342     return 0;
344             HAVE_STATIC_LIBGCC_SWITCH
345         )
346         if(HAVE_STATIC_LIBGCC_SWITCH)
347             SET(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
348         endif()
349         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
350         unset(OLD_REQUIRED_LIBRARIES)
351     endif()
352 ENDIF()
354 # Set visibility/export options if available
355 IF(WIN32)
356     SET(EXPORT_DECL "__declspec(dllexport)")
357     IF(NOT MINGW)
358         SET(ALIGN_DECL "__declspec(align(x))")
359     ELSE()
360         SET(ALIGN_DECL "__declspec(aligned(x))")
361     ENDIF()
362 ELSE()
363     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
364     # Yes GCC, really don't accept visibility modes you don't support
365     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
367     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
368                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
369     IF(HAVE_GCC_PROTECTED_VISIBILITY)
370         SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
371     ELSE()
372         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
373                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
374         IF(HAVE_GCC_DEFAULT_VISIBILITY)
375             SET(EXPORT_DECL "__attribute__((visibility(\"default\")))")
376         ENDIF()
377     ENDIF()
379     IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
380         CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
381         IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
382             SET(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
383         ENDIF()
384     ENDIF()
386     CHECK_C_SOURCE_COMPILES("int foo __attribute__((aligned(16)));
387                              int main() {return 0;}" HAVE_ATTRIBUTE_ALIGNED)
388     IF(HAVE_ATTRIBUTE_ALIGNED)
389         SET(ALIGN_DECL "__attribute__((aligned(x)))")
390     ENDIF()
392     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
393 ENDIF()
395 CHECK_C_SOURCE_COMPILES("
396 int main()
398     float *ptr;
399     ptr = __builtin_assume_aligned(ptr, 16);
400     return 0;
401 }" HAVE___BUILTIN_ASSUME_ALIGNED)
402 IF(HAVE___BUILTIN_ASSUME_ALIGNED)
403     SET(ASSUME_ALIGNED_DECL "__builtin_assume_aligned(x, y)")
404 ELSE()
405     SET(ASSUME_ALIGNED_DECL "x")
406 ENDIF()
408 SET(SSE_SWITCH "")
409 SET(SSE2_SWITCH "")
410 SET(SSE3_SWITCH "")
411 SET(SSE4_1_SWITCH "")
412 SET(FPU_NEON_SWITCH "")
414 CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
415 IF(HAVE_MSSE_SWITCH)
416     SET(SSE_SWITCH "-msse")
417 ENDIF()
418 CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
419 IF(HAVE_MSSE2_SWITCH)
420     SET(SSE2_SWITCH "-msse2")
421 ENDIF()
422 CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
423 IF(HAVE_MSSE3_SWITCH)
424     SET(SSE3_SWITCH "-msse3")
425 ENDIF()
426 CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
427 IF(HAVE_MSSE4_1_SWITCH)
428     SET(SSE4_1_SWITCH "-msse4.1")
429 ENDIF()
430 CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
431 IF(HAVE_MFPU_NEON_SWITCH)
432     SET(FPU_NEON_SWITCH "-mfpu=neon")
433 ENDIF()
435 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
436                          int main() {return 0;}" HAVE_GCC_FORMAT)
438 CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
439 CHECK_INCLUDE_FILE(stdalign.h HAVE_STDALIGN_H)
440 CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
441 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
442 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
443 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
444 CHECK_INCLUDE_FILE(intrin.h HAVE_INTRIN_H)
445 CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
446 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
447 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
448 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
449 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
450 IF(NOT HAVE_GUIDDEF_H)
451     CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
452 ENDIF()
454 # Some systems need libm for some of the following math functions to work
455 SET(MATH_LIB )
456 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
457 IF(HAVE_LIBM)
458     SET(MATH_LIB ${MATH_LIB} m)
459     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
460 ENDIF()
462 # Check for the dlopen API (for dynamicly loading backend libs)
463 IF(ALSOFT_DLOPEN)
464     CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
465     IF(HAVE_LIBDL)
466         SET(EXTRA_LIBS dl ${EXTRA_LIBS})
467         SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
468     ENDIF()
470     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
471 ENDIF()
473 # Check for a cpuid intrinsic
474 IF(HAVE_CPUID_H)
475     CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
476         int main()
477         {
478             unsigned int eax, ebx, ecx, edx;
479             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
480         }" HAVE_GCC_GET_CPUID)
481 ENDIF()
482 IF(HAVE_INTRIN_H)
483     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
484         int main()
485         {
486             int regs[4];
487             __cpuid(regs, 0);
488             return regs[0];
489         }" HAVE_CPUID_INTRINSIC)
490 ENDIF()
492 CHECK_SYMBOL_EXISTS(sysconf          unistd.h HAVE_SYSCONF)
493 CHECK_SYMBOL_EXISTS(aligned_alloc    stdlib.h HAVE_ALIGNED_ALLOC)
494 CHECK_SYMBOL_EXISTS(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
495 CHECK_SYMBOL_EXISTS(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
496 CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
497 CHECK_SYMBOL_EXISTS(modff  math.h HAVE_MODFF)
498 CHECK_SYMBOL_EXISTS(log2f  math.h HAVE_LOG2F)
500 IF(HAVE_FLOAT_H)
501     CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
502     CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
503 ENDIF()
505 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
506 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
507 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
508 IF(NOT HAVE_STRCASECMP)
509     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
510     IF(NOT HAVE__STRICMP)
511         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
512     ENDIF()
514     SET(CPP_DEFS ${CPP_DEFS} strcasecmp=_stricmp)
515 ENDIF()
517 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
518 IF(NOT HAVE_STRNCASECMP)
519     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
520     IF(NOT HAVE__STRNICMP)
521         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
522     ENDIF()
524     SET(CPP_DEFS ${CPP_DEFS} strncasecmp=_strnicmp)
525 ENDIF()
527 CHECK_SYMBOL_EXISTS(strnlen string.h HAVE_STRNLEN)
528 CHECK_SYMBOL_EXISTS(snprintf stdio.h HAVE_SNPRINTF)
529 IF(NOT HAVE_SNPRINTF)
530     CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
531     IF(NOT HAVE__SNPRINTF)
532         MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
533     ENDIF()
535     SET(CPP_DEFS ${CPP_DEFS} snprintf=_snprintf)
536 ENDIF()
538 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
539 IF(NOT HAVE_ISFINITE)
540     CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
541     IF(NOT HAVE_FINITE)
542         CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
543         IF(NOT HAVE__FINITE)
544             MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
545         ENDIF()
546         SET(CPP_DEFS ${CPP_DEFS} isfinite=_finite)
547     ELSE()
548         SET(CPP_DEFS ${CPP_DEFS} isfinite=finite)
549     ENDIF()
550 ENDIF()
552 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
553 IF(NOT HAVE_ISNAN)
554     CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
555     IF(NOT HAVE__ISNAN)
556         MESSAGE(FATAL_ERROR "No isnan function found, please report!")
557     ENDIF()
559     SET(CPP_DEFS ${CPP_DEFS} isnan=_isnan)
560 ENDIF()
563 # Check if we have Windows headers
564 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0502)
565 IF(NOT HAVE_WINDOWS_H)
566     CHECK_SYMBOL_EXISTS(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
567     IF(NOT HAVE_GETTIMEOFDAY)
568         MESSAGE(FATAL_ERROR "No timing function found!")
569     ENDIF()
571     CHECK_SYMBOL_EXISTS(nanosleep time.h HAVE_NANOSLEEP)
572     IF(NOT HAVE_NANOSLEEP)
573         MESSAGE(FATAL_ERROR "No sleep function found!")
574     ENDIF()
576     # We need pthreads outside of Windows
577     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
578     IF(NOT HAVE_PTHREAD_H)
579         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
580     ENDIF()
581     # Some systems need pthread_np.h to get recursive mutexes
582     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
584     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
585     IF(HAVE_PTHREAD)
586         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
587         SET(C_FLAGS ${C_FLAGS} -pthread)
588         SET(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
589     ENDIF()
591     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
592     IF(HAVE_LIBPTHREAD)
593         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
594     ENDIF()
596     CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
598     IF(HAVE_PTHREAD_NP_H)
599         CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
600         IF(NOT HAVE_PTHREAD_SETNAME_NP)
601             CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
602         ELSE()
603             CHECK_C_SOURCE_COMPILES("
604 #include <pthread.h>
605 #include <pthread_np.h>
606 int main()
608     pthread_setname_np(\"testname\");
609     return 0;
611                 PTHREAD_SETNAME_NP_ONE_PARAM
612             )
613             CHECK_C_SOURCE_COMPILES("
614 #include <pthread.h>
615 #include <pthread_np.h>
616 int main()
618     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
619     return 0;
621                 PTHREAD_SETNAME_NP_THREE_PARAMS
622             )
623         ENDIF()
624         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np "pthread.h;pthread_np.h" HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
625     ELSE()
626         CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
627         IF(NOT HAVE_PTHREAD_SETNAME_NP)
628             CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
629         ELSE()
630             CHECK_C_SOURCE_COMPILES("
631 #include <pthread.h>
632 int main()
634     pthread_setname_np(\"testname\");
635     return 0;
637                 PTHREAD_SETNAME_NP_ONE_PARAM
638             )
639             CHECK_C_SOURCE_COMPILES("
640 #include <pthread.h>
641 int main()
643     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
644     return 0;
646                 PTHREAD_SETNAME_NP_THREE_PARAMS
647             )
648         ENDIF()
649         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np pthread.h HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
650     ENDIF()
652     CHECK_SYMBOL_EXISTS(pthread_mutex_timedlock pthread.h HAVE_PTHREAD_MUTEX_TIMEDLOCK)
654     CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
655     IF(HAVE_LIBRT)
656         SET(EXTRA_LIBS rt ${EXTRA_LIBS})
657     ENDIF()
658 ENDIF()
660 CHECK_SYMBOL_EXISTS(getopt unistd.h HAVE_GETOPT)
662 # Check for a 64-bit type
663 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
664 IF(NOT HAVE_STDINT_H)
665     IF(HAVE_WINDOWS_H)
666         CHECK_C_SOURCE_COMPILES("#define _WIN32_WINNT 0x0502
667                                  #include <windows.h>
668                                  __int64 foo;
669                                  int main() {return 0;}" HAVE___INT64)
670     ENDIF()
671     IF(NOT HAVE___INT64)
672         IF(NOT SIZEOF_LONG MATCHES "8")
673             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
674                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
675             ENDIF()
676         ENDIF()
677     ENDIF()
678 ENDIF()
681 SET(COMMON_OBJS  common/almalloc.c
682                  common/atomic.c
683                  common/rwlock.c
684                  common/threads.c
685                  common/uintmap.c
687 SET(OPENAL_OBJS  OpenAL32/alAuxEffectSlot.c
688                  OpenAL32/alBuffer.c
689                  OpenAL32/alEffect.c
690                  OpenAL32/alError.c
691                  OpenAL32/alExtension.c
692                  OpenAL32/alFilter.c
693                  OpenAL32/alListener.c
694                  OpenAL32/alSource.c
695                  OpenAL32/alState.c
696                  OpenAL32/alThunk.c
697                  OpenAL32/event.c
698                  OpenAL32/sample_cvt.c
700 SET(ALC_OBJS  Alc/ALc.c
701               Alc/ALu.c
702               Alc/alconfig.c
703               Alc/bs2b.c
704               Alc/converter.c
705               Alc/mastering.c
706               Alc/ringbuffer.c
707               Alc/effects/chorus.c
708               Alc/effects/compressor.c
709               Alc/effects/dedicated.c
710               Alc/effects/distortion.c
711               Alc/effects/echo.c
712               Alc/effects/equalizer.c
713               Alc/effects/modulator.c
714               Alc/effects/null.c
715               Alc/effects/reverb.c
716               Alc/helpers.c
717               Alc/hrtf.c
718               Alc/uhjfilter.c
719               Alc/ambdec.c
720               Alc/bformatdec.c
721               Alc/nfcfilter.c
722               Alc/panning.c
723               Alc/mixer.c
724               Alc/mixer_c.c
728 SET(CPU_EXTS "Default")
729 SET(HAVE_SSE        0)
730 SET(HAVE_SSE2       0)
731 SET(HAVE_SSE3       0)
732 SET(HAVE_SSE4_1     0)
733 SET(HAVE_NEON       0)
735 SET(HAVE_ALSA       0)
736 SET(HAVE_OSS        0)
737 SET(HAVE_SOLARIS    0)
738 SET(HAVE_SNDIO      0)
739 SET(HAVE_QSA        0)
740 SET(HAVE_DSOUND     0)
741 SET(HAVE_MMDEVAPI   0)
742 SET(HAVE_WINMM      0)
743 SET(HAVE_PORTAUDIO  0)
744 SET(HAVE_PULSEAUDIO 0)
745 SET(HAVE_COREAUDIO  0)
746 SET(HAVE_OPENSL     0)
747 SET(HAVE_WAVE       0)
749 # Check for SSE support
750 OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
751 CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE_SWITCH}")
752 IF(HAVE_XMMINTRIN_H)
753     OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
754     IF(ALSOFT_CPUEXT_SSE)
755         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
756             SET(HAVE_SSE 1)
757             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse.c)
758             IF(SSE_SWITCH)
759                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse.c PROPERTIES
760                                             COMPILE_FLAGS "${SSE_SWITCH}")
761             ENDIF()
762             SET(CPU_EXTS "${CPU_EXTS}, SSE")
763         ENDIF()
764     ENDIF()
765 ENDIF()
766 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
767     MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
768 ENDIF()
770 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
771 CHECK_INCLUDE_FILE(emmintrin.h HAVE_EMMINTRIN_H "${SSE2_SWITCH}")
772 IF(HAVE_EMMINTRIN_H)
773     OPTION(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
774     IF(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
775         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
776             SET(HAVE_SSE2 1)
777             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse2.c)
778             IF(SSE2_SWITCH)
779                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse2.c PROPERTIES
780                                             COMPILE_FLAGS "${SSE2_SWITCH}")
781             ENDIF()
782             SET(CPU_EXTS "${CPU_EXTS}, SSE2")
783         ENDIF()
784     ENDIF()
785 ENDIF()
786 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
787     MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
788 ENDIF()
790 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE3 support" OFF)
791 CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}")
792 IF(HAVE_EMMINTRIN_H)
793     OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
794     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
795         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
796             SET(HAVE_SSE3 1)
797             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse3.c)
798             IF(SSE2_SWITCH)
799                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse3.c PROPERTIES
800                                             COMPILE_FLAGS "${SSE3_SWITCH}")
801             ENDIF()
802             SET(CPU_EXTS "${CPU_EXTS}, SSE3")
803         ENDIF()
804     ENDIF()
805 ENDIF()
806 IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
807     MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
808 ENDIF()
810 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
811 CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}")
812 IF(HAVE_SMMINTRIN_H)
813     OPTION(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
814     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE4_1)
815         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
816             SET(HAVE_SSE4_1 1)
817             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse41.c)
818             IF(SSE4_1_SWITCH)
819                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse41.c PROPERTIES
820                                             COMPILE_FLAGS "${SSE4_1_SWITCH}")
821             ENDIF()
822             SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
823         ENDIF()
824     ENDIF()
825 ENDIF()
826 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
827     MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
828 ENDIF()
830 # Check for ARM Neon support
831 OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
832 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H ${FPU_NEON_SWITCH})
833 IF(HAVE_ARM_NEON_H)
834     OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
835     IF(ALSOFT_CPUEXT_NEON)
836         SET(HAVE_NEON 1)
837         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_neon.c)
838         IF(FPU_NEON_SWITCH)
839             SET_SOURCE_FILES_PROPERTIES(Alc/mixer_neon.c PROPERTIES
840                                         COMPILE_FLAGS "${FPU_NEON_SWITCH}")
841         ENDIF()
842         SET(CPU_EXTS "${CPU_EXTS}, Neon")
843     ENDIF()
844 ENDIF()
845 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
846     MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
847 ENDIF()
850 IF(WIN32 OR HAVE_DLFCN_H)
851     SET(IS_LINKED "")
852     MACRO(ADD_BACKEND_LIBS _LIBS)
853     ENDMACRO()
854 ELSE()
855     SET(IS_LINKED " (linked)")
856     MACRO(ADD_BACKEND_LIBS _LIBS)
857         SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
858     ENDMACRO()
859 ENDIF()
861 SET(BACKENDS "")
862 SET(ALC_OBJS  ${ALC_OBJS}
863               Alc/backends/base.c
864               # Default backends, always available
865               Alc/backends/loopback.c
866               Alc/backends/null.c
869 # Check ALSA backend
870 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
871 FIND_PACKAGE(ALSA)
872 IF(ALSA_FOUND)
873     OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
874     IF(ALSOFT_BACKEND_ALSA)
875         SET(HAVE_ALSA 1)
876         SET(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
877         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/alsa.c)
878         ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
879         SET(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
880     ENDIF()
881 ENDIF()
882 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
883     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
884 ENDIF()
886 # Check OSS backend
887 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
888 FIND_PACKAGE(OSS)
889 IF(OSS_FOUND)
890     OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
891     IF(ALSOFT_BACKEND_OSS)
892         SET(HAVE_OSS 1)
893         SET(BACKENDS  "${BACKENDS} OSS,")
894         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/oss.c)
895         IF(OSS_LIBRARIES)
896             SET(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
897         ENDIF()
898         SET(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
899     ENDIF()
900 ENDIF()
901 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
902     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
903 ENDIF()
905 # Check Solaris backend
906 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
907 FIND_PACKAGE(AudioIO)
908 IF(AUDIOIO_FOUND)
909     OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
910     IF(ALSOFT_BACKEND_SOLARIS)
911         SET(HAVE_SOLARIS 1)
912         SET(BACKENDS  "${BACKENDS} Solaris,")
913         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/solaris.c)
914         SET(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
915     ENDIF()
916 ENDIF()
917 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
918     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
919 ENDIF()
921 # Check SndIO backend
922 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
923 FIND_PACKAGE(SoundIO)
924 IF(SOUNDIO_FOUND)
925     OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
926     IF(ALSOFT_BACKEND_SNDIO)
927         SET(HAVE_SNDIO 1)
928         SET(BACKENDS  "${BACKENDS} SndIO (linked),")
929         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sndio.c)
930         SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
931         SET(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
932     ENDIF()
933 ENDIF()
934 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
935     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
936 ENDIF()
938 # Check QSA backend
939 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
940 FIND_PACKAGE(QSA)
941 IF(QSA_FOUND)
942     OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
943     IF(ALSOFT_BACKEND_QSA)
944         SET(HAVE_QSA 1)
945         SET(BACKENDS  "${BACKENDS} QSA (linked),")
946         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/qsa.c)
947         SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
948         SET(INC_PATHS ${INC_PATHS} ${QSA_INCLUDE_DIRS})
949     ENDIF()
950 ENDIF()
951 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
952     MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
953 ENDIF()
955 # Check Windows-only backends
956 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
957 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
958 OPTION(ALSOFT_REQUIRE_MMDEVAPI "Require MMDevApi backend" OFF)
959 IF(HAVE_WINDOWS_H)
960     # Check MMSystem backend
961     CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0502)
962     IF(HAVE_MMSYSTEM_H)
963         CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
964         IF(HAVE_LIBWINMM)
965             OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
966             IF(ALSOFT_BACKEND_WINMM)
967                 SET(HAVE_WINMM 1)
968                 SET(BACKENDS  "${BACKENDS} WinMM,")
969                 SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/winmm.c)
970                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
971             ENDIF()
972         ENDIF()
973     ENDIF()
975     # Check DSound backend
976     FIND_PACKAGE(DSound)
977     IF(DSOUND_FOUND)
978         OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
979         IF(ALSOFT_BACKEND_DSOUND)
980             SET(HAVE_DSOUND 1)
981             SET(BACKENDS  "${BACKENDS} DirectSound${IS_LINKED},")
982             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/dsound.c)
983             ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
984             SET(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIRS})
985         ENDIF()
986     ENDIF()
988     # Check for MMDevApi backend
989     CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
990     IF(HAVE_MMDEVICEAPI_H)
991         OPTION(ALSOFT_BACKEND_MMDEVAPI "Enable MMDevApi backend" ON)
992         IF(ALSOFT_BACKEND_MMDEVAPI)
993             SET(HAVE_MMDEVAPI 1)
994             SET(BACKENDS  "${BACKENDS} MMDevApi,")
995             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/mmdevapi.c)
996         ENDIF()
997     ENDIF()
998 ENDIF()
999 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1000     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
1001 ENDIF()
1002 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1003     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
1004 ENDIF()
1005 IF(ALSOFT_REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
1006     MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
1007 ENDIF()
1009 # Check PortAudio backend
1010 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1011 FIND_PACKAGE(PortAudio)
1012 IF(PORTAUDIO_FOUND)
1013     OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1014     IF(ALSOFT_BACKEND_PORTAUDIO)
1015         SET(HAVE_PORTAUDIO 1)
1016         SET(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
1017         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/portaudio.c)
1018         ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
1019         SET(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
1020     ENDIF()
1021 ENDIF()
1022 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1023     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
1024 ENDIF()
1026 # Check PulseAudio backend
1027 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1028 FIND_PACKAGE(PulseAudio)
1029 IF(PULSEAUDIO_FOUND)
1030     OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1031     IF(ALSOFT_BACKEND_PULSEAUDIO)
1032         SET(HAVE_PULSEAUDIO 1)
1033         SET(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
1034         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/pulseaudio.c)
1035         ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
1036         SET(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
1037     ENDIF()
1038 ENDIF()
1039 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1040     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1041 ENDIF()
1043 # Check JACK backend
1044 OPTION(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1045 FIND_PACKAGE(JACK)
1046 IF(JACK_FOUND)
1047     OPTION(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1048     IF(ALSOFT_BACKEND_JACK)
1049         SET(HAVE_JACK 1)
1050         SET(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1051         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/jack.c)
1052         ADD_BACKEND_LIBS(${JACK_LIBRARIES})
1053         SET(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1054     ENDIF()
1055 ENDIF()
1056 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1057     MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
1058 ENDIF()
1060 # Check CoreAudio backend
1061 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1062 FIND_LIBRARY(COREAUDIO_FRAMEWORK
1063              NAMES CoreAudio
1064              PATHS /System/Library/Frameworks
1066 IF(COREAUDIO_FRAMEWORK)
1067     OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1068     IF(ALSOFT_BACKEND_COREAUDIO)
1069         SET(HAVE_COREAUDIO 1)
1070         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/coreaudio.c)
1071         SET(BACKENDS  "${BACKENDS} CoreAudio,")
1072         SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
1073         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
1074         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1076         # Some versions of OSX may need the AudioToolbox framework. Add it if
1077         # it's found.
1078         FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
1079                      NAMES AudioToolbox
1080                      PATHS ~/Library/Frameworks
1081                            /Library/Frameworks
1082                            /System/Library/Frameworks
1083                     )
1084         IF(AUDIOTOOLBOX_LIBRARY)
1085             SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1086         ENDIF()
1087     ENDIF()
1088 ENDIF()
1089 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1090     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1091 ENDIF()
1093 # Check for OpenSL (Android) backend
1094 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1095 CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
1096 IF(HAVE_SLES_OPENSLES_ANDROID_H)
1097     CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
1098     IF(HAVE_LIBOPENSLES)
1099         OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1100         IF(ALSOFT_BACKEND_OPENSL)
1101             SET(HAVE_OPENSL 1)
1102             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/opensl.c)
1103             SET(BACKENDS  "${BACKENDS} OpenSL,")
1104             SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
1105         ENDIF()
1106     ENDIF()
1107 ENDIF()
1108 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1109     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1110 ENDIF()
1112 # Optionally enable the Wave Writer backend
1113 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1114 IF(ALSOFT_BACKEND_WAVE)
1115     SET(HAVE_WAVE 1)
1116     SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wave.c)
1117     SET(BACKENDS  "${BACKENDS} WaveFile,")
1118 ENDIF()
1120 # This is always available
1121 SET(BACKENDS  "${BACKENDS} Null")
1124 FIND_PACKAGE(Git)
1125 IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1126     # Get the current working branch and its latest abbreviated commit hash
1127     ADD_CUSTOM_TARGET(build_version
1128         ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
1129                          -D LIB_VERSION=${LIB_VERSION}
1130                          -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1131                          -D DST=${OpenAL_BINARY_DIR}/version.h
1132                          -P ${OpenAL_SOURCE_DIR}/version.cmake
1133         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1134         VERBATIM
1135     )
1136 ELSE()
1137     SET(GIT_BRANCH "UNKNOWN")
1138     SET(GIT_COMMIT_HASH "unknown")
1139     CONFIGURE_FILE(
1140         "${OpenAL_SOURCE_DIR}/version.h.in"
1141         "${OpenAL_BINARY_DIR}/version.h")
1142 ENDIF()
1144 SET(NATIVE_SRC_DIR  "${OpenAL_SOURCE_DIR}/native-tools/")
1145 SET(NATIVE_BIN_DIR  "${OpenAL_BINARY_DIR}/native-tools/")
1146 FILE(MAKE_DIRECTORY "${NATIVE_BIN_DIR}")
1148 SET(BIN2H_COMMAND  "${NATIVE_BIN_DIR}bin2h")
1149 SET(BSINCGEN_COMMAND  "${NATIVE_BIN_DIR}bsincgen")
1150 ADD_CUSTOM_COMMAND(OUTPUT "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1151     COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" "${NATIVE_SRC_DIR}"
1152     COMMAND ${CMAKE_COMMAND} -E remove "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1153     COMMAND ${CMAKE_COMMAND} --build . --config "Release"
1154     WORKING_DIRECTORY "${NATIVE_BIN_DIR}"
1155     DEPENDS "${NATIVE_SRC_DIR}CMakeLists.txt"
1156     IMPLICIT_DEPENDS C "${NATIVE_SRC_DIR}bin2h.c"
1157                      C "${NATIVE_SRC_DIR}bsincgen.c"
1158     VERBATIM
1160 ADD_CUSTOM_TARGET(native-tools
1161     DEPENDS "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1162     VERBATIM
1165 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" OFF)
1166 if(ALSOFT_EMBED_HRTF_DATA)
1167     MACRO(make_hrtf_header FILENAME VARNAME)
1168         SET(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1169         SET(outfile  "${OpenAL_BINARY_DIR}/${FILENAME}.h")
1171         ADD_CUSTOM_COMMAND(OUTPUT "${outfile}"
1172             COMMAND "${BIN2H_COMMAND}" "${infile}" "${outfile}" ${VARNAME}
1173             DEPENDS native-tools "${infile}"
1174             VERBATIM
1175         )
1176         SET(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1177     ENDMACRO()
1179     make_hrtf_header(default-44100.mhr "hrtf_default_44100")
1180     make_hrtf_header(default-48000.mhr "hrtf_default_48000")
1181 endif()
1183 ADD_CUSTOM_COMMAND(OUTPUT "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1184     COMMAND "${BSINCGEN_COMMAND}" "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1185     DEPENDS native-tools "${NATIVE_SRC_DIR}bsincgen.c"
1186     VERBATIM
1188 SET(ALC_OBJS  ${ALC_OBJS} "${OpenAL_BINARY_DIR}/bsinc_inc.h")
1191 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1192     add_subdirectory(utils/alsoft-config)
1193 ENDIF()
1194 IF(ALSOFT_EXAMPLES)
1195     FIND_PACKAGE(SDL2)
1196     IF(SDL2_FOUND)
1197         FIND_PACKAGE(SDL_sound)
1198         FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1199     ENDIF()
1200 ENDIF()
1202 IF(NOT WIN32)
1203     SET(LIBNAME "openal")
1204 ELSE()
1205     SET(LIBNAME "OpenAL32")
1206 ENDIF()
1208 # Needed for openal.pc.in
1209 SET(prefix ${CMAKE_INSTALL_PREFIX})
1210 SET(exec_prefix "\${prefix}")
1211 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1212 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1213 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1214 SET(PACKAGE_VERSION "${LIB_VERSION}")
1215 IF(LIBTYPE STREQUAL "STATIC")
1216     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
1217 ENDIF()
1219 # End configuration
1220 CONFIGURE_FILE(
1221     "${OpenAL_SOURCE_DIR}/config.h.in"
1222     "${OpenAL_BINARY_DIR}/config.h")
1223 CONFIGURE_FILE(
1224     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1225     "${OpenAL_BINARY_DIR}/openal.pc"
1226     @ONLY)
1229 # Add a static library with common functions used by multiple targets
1230 ADD_LIBRARY(common STATIC ${COMMON_OBJS})
1231 TARGET_COMPILE_DEFINITIONS(common PRIVATE ${CPP_DEFS})
1232 TARGET_COMPILE_OPTIONS(common PRIVATE ${C_FLAGS})
1235 UNSET(HAS_ROUTER)
1236 SET(IMPL_TARGET OpenAL)
1237 SET(COMMON_LIB )
1238 SET(SUBSYS_FLAG )
1240 # Build main library
1241 IF(LIBTYPE STREQUAL "STATIC")
1242     SET(CPP_DEFS ${CPP_DEFS} AL_LIBTYPE_STATIC)
1243     IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1244         SET(CPP_DEFS ${CPP_DEFS} AL_NO_UID_DEFS)
1245     ENDIF()
1246     ADD_LIBRARY(OpenAL STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1247 ELSE()
1248     # Make sure to compile the common code with PIC, since it'll be linked into
1249     # shared libs that needs it.
1250     SET_PROPERTY(TARGET common PROPERTY POSITION_INDEPENDENT_CODE TRUE)
1251     SET(COMMON_LIB common)
1253     IF(WIN32)
1254         IF(MSVC)
1255             SET(SUBSYS_FLAG ${SUBSYS_FLAG} "/SUBSYSTEM:WINDOWS")
1256         ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1257             SET(SUBSYS_FLAG ${SUBSYS_FLAG} "-mwindows")
1258         ENDIF()
1259     ENDIF()
1261     IF(WIN32 AND ALSOFT_BUILD_ROUTER)
1262         ADD_LIBRARY(OpenAL SHARED router/router.c router/alc.c router/al.c)
1263         TARGET_COMPILE_DEFINITIONS(OpenAL
1264             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1265         TARGET_COMPILE_OPTIONS(OpenAL PRIVATE ${C_FLAGS})
1266         TARGET_LINK_LIBRARIES(OpenAL PRIVATE ${LINKER_FLAGS} ${COMMON_LIB})
1267         SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "")
1268         SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1269         IF(TARGET build_version)
1270             ADD_DEPENDENCIES(OpenAL build_version)
1271         ENDIF()
1272         SET(HAS_ROUTER 1)
1274         SET(LIBNAME "soft_oal")
1275         SET(IMPL_TARGET soft_oal)
1276     ENDIF()
1278     ADD_LIBRARY(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
1279     IF(WIN32)
1280         SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES PREFIX "")
1281     ENDIF()
1282 ENDIF()
1283 SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1284     VERSION ${LIB_VERSION}
1285     SOVERSION ${LIB_MAJOR_VERSION}
1287 TARGET_COMPILE_DEFINITIONS(${IMPL_TARGET}
1288     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1289 TARGET_INCLUDE_DIRECTORIES(${IMPL_TARGET}
1290     PRIVATE "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc" ${INC_PATHS})
1291 TARGET_COMPILE_OPTIONS(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1292 TARGET_LINK_LIBRARIES(${IMPL_TARGET}
1293     PRIVATE ${LINKER_FLAGS} ${COMMON_LIB} ${EXTRA_LIBS} ${MATH_LIB})
1294 IF(TARGET build_version)
1295     ADD_DEPENDENCIES(${IMPL_TARGET} build_version)
1296 ENDIF()
1298 IF(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1299     FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1300     FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1301     IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1302         MESSAGE(STATUS "")
1303         IF(NOT SED_EXECUTABLE)
1304             MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1305         ENDIF()
1306         IF(NOT DLLTOOL_EXECUTABLE)
1307             MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1308         ENDIF()
1309     ELSE()
1310         SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS
1311                         " -Wl,--output-def,OpenAL32.def")
1312         ADD_CUSTOM_COMMAND(TARGET OpenAL POST_BUILD
1313             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1314             COMMAND "${DLLTOOL_EXECUTABLE}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1315             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1316             VERBATIM
1317         )
1318     ENDIF()
1319 ENDIF()
1321 IF(ALSOFT_INSTALL)
1322     INSTALL(TARGETS OpenAL EXPORT OpenAL
1323             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1324             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1325             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1326             INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL
1327     )
1328     EXPORT(TARGETS OpenAL
1329            NAMESPACE OpenAL::
1330            FILE OpenALConfig.cmake)
1331     INSTALL(EXPORT OpenAL
1332             DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1333             NAMESPACE OpenAL::
1334             FILE OpenALConfig.cmake)
1335     INSTALL(FILES include/AL/al.h
1336                   include/AL/alc.h
1337                   include/AL/alext.h
1338                   include/AL/efx.h
1339                   include/AL/efx-creative.h
1340                   include/AL/efx-presets.h
1341             DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
1342     )
1343     INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1344             DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1345     IF(TARGET soft_oal)
1346         INSTALL(TARGETS soft_oal
1347                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1348         )
1349     ENDIF()
1350 ENDIF()
1353 if(HAS_ROUTER)
1354     message(STATUS "")
1355     message(STATUS "Building DLL router")
1356 endif()
1358 MESSAGE(STATUS "")
1359 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1360 MESSAGE(STATUS "    ${BACKENDS}")
1361 MESSAGE(STATUS "")
1362 MESSAGE(STATUS "Building with support for CPU extensions:")
1363 MESSAGE(STATUS "    ${CPU_EXTS}")
1364 MESSAGE(STATUS "")
1366 IF(WIN32)
1367     IF(NOT HAVE_DSOUND)
1368         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
1369         MESSAGE(STATUS "         This is probably NOT what you want!")
1370         MESSAGE(STATUS "")
1371     ENDIF()
1372 ENDIF()
1374 if(ALSOFT_EMBED_HRTF_DATA)
1375     message(STATUS "Embedding HRTF datasets")
1376     message(STATUS "")
1377 endif()
1379 # Install alsoft.conf configuration file
1380 IF(ALSOFT_CONFIG)
1381     INSTALL(FILES alsoftrc.sample
1382             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal
1383     )
1384     MESSAGE(STATUS "Installing sample configuration")
1385     MESSAGE(STATUS "")
1386 ENDIF()
1388 # Install HRTF definitions
1389 IF(ALSOFT_HRTF_DEFS)
1390     INSTALL(FILES hrtf/default-44100.mhr
1391                   hrtf/default-48000.mhr
1392             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf
1393     )
1394     MESSAGE(STATUS "Installing HRTF definitions")
1395     MESSAGE(STATUS "")
1396 ENDIF()
1398 # Install AmbDec presets
1399 IF(ALSOFT_AMBDEC_PRESETS)
1400     INSTALL(FILES presets/3D7.1.ambdec
1401                   presets/hexagon.ambdec
1402                   presets/itu5.1.ambdec
1403                   presets/itu5.1-nocenter.ambdec
1404                   presets/rectangle.ambdec
1405                   presets/square.ambdec
1406                   presets/presets.txt
1407             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
1408     )
1409     MESSAGE(STATUS "Installing AmbDec presets")
1410     MESSAGE(STATUS "")
1411 ENDIF()
1413 IF(ALSOFT_UTILS)
1414     ADD_EXECUTABLE(openal-info utils/openal-info.c)
1415     TARGET_COMPILE_OPTIONS(openal-info PRIVATE ${C_FLAGS})
1416     TARGET_LINK_LIBRARIES(openal-info PRIVATE ${LINKER_FLAGS} OpenAL)
1418     SET(MAKEHRTF_SRCS  utils/makehrtf.c)
1419     IF(NOT HAVE_GETOPT)
1420         SET(MAKEHRTF_SRCS  ${MAKEHRTF_SRCS} utils/getopt.c)
1421     ENDIF()
1422     ADD_EXECUTABLE(makehrtf ${MAKEHRTF_SRCS})
1423     TARGET_COMPILE_DEFINITIONS(makehrtf PRIVATE ${CPP_DEFS})
1424     TARGET_COMPILE_OPTIONS(makehrtf PRIVATE ${C_FLAGS})
1425     IF(HAVE_LIBM)
1426         TARGET_LINK_LIBRARIES(makehrtf PRIVATE ${LINKER_FLAGS} m)
1427     ENDIF()
1429     IF(ALSOFT_INSTALL)
1430         INSTALL(TARGETS openal-info makehrtf
1431                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1432                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1433                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1434         )
1435     ENDIF()
1437     MESSAGE(STATUS "Building utility programs")
1438     IF(TARGET alsoft-config)
1439         MESSAGE(STATUS "Building configuration program")
1440     ENDIF()
1441     MESSAGE(STATUS "")
1442 ENDIF()
1444 IF(ALSOFT_TESTS)
1445     SET(TEST_COMMON_OBJS  examples/common/alhelpers.c)
1447     ADD_EXECUTABLE(altonegen examples/altonegen.c ${TEST_COMMON_OBJS})
1448     TARGET_COMPILE_DEFINITIONS(altonegen PRIVATE ${CPP_DEFS})
1449     TARGET_COMPILE_OPTIONS(altonegen PRIVATE ${C_FLAGS})
1450     TARGET_LINK_LIBRARIES(altonegen PRIVATE ${LINKER_FLAGS} common OpenAL ${MATH_LIB})
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         )
1458     ENDIF()
1460     MESSAGE(STATUS "Building test programs")
1461     MESSAGE(STATUS "")
1462 ENDIF()
1464 IF(ALSOFT_EXAMPLES)
1465     ADD_EXECUTABLE(alrecord examples/alrecord.c)
1466     TARGET_COMPILE_DEFINITIONS(alrecord PRIVATE ${CPP_DEFS})
1467     TARGET_COMPILE_OPTIONS(alrecord PRIVATE ${C_FLAGS})
1468     TARGET_LINK_LIBRARIES(alrecord PRIVATE ${LINKER_FLAGS} common OpenAL)
1470     IF(ALSOFT_INSTALL)
1471         INSTALL(TARGETS alrecord
1472                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1473                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1474                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1475         )
1476     ENDIF()
1478     MESSAGE(STATUS "Building example programs")
1480     IF(SDL2_FOUND)
1481         IF(SDL_SOUND_FOUND)
1482             # Add a static library with common functions used by multiple targets
1483             ADD_LIBRARY(ex-common STATIC examples/common/alhelpers.c)
1484             TARGET_COMPILE_DEFINITIONS(ex-common PRIVATE ${CPP_DEFS})
1485             TARGET_COMPILE_OPTIONS(ex-common PRIVATE ${C_FLAGS})
1487             ADD_EXECUTABLE(alplay examples/alplay.c)
1488             TARGET_COMPILE_DEFINITIONS(alplay PRIVATE ${CPP_DEFS})
1489             TARGET_INCLUDE_DIRECTORIES(alplay
1490                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1491             TARGET_COMPILE_OPTIONS(alplay PRIVATE ${C_FLAGS})
1492             TARGET_LINK_LIBRARIES(alplay
1493                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1494                         OpenAL)
1496             ADD_EXECUTABLE(alstream examples/alstream.c)
1497             TARGET_COMPILE_DEFINITIONS(alstream PRIVATE ${CPP_DEFS})
1498             TARGET_INCLUDE_DIRECTORIES(alstream
1499                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1500             TARGET_COMPILE_OPTIONS(alstream PRIVATE ${C_FLAGS})
1501             TARGET_LINK_LIBRARIES(alstream
1502                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1503                         OpenAL)
1505             ADD_EXECUTABLE(alreverb examples/alreverb.c)
1506             TARGET_COMPILE_DEFINITIONS(alreverb PRIVATE ${CPP_DEFS})
1507             TARGET_INCLUDE_DIRECTORIES(alreverb
1508                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1509             TARGET_COMPILE_OPTIONS(alreverb PRIVATE ${C_FLAGS})
1510             TARGET_LINK_LIBRARIES(alreverb
1511                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1512                         OpenAL)
1514             ADD_EXECUTABLE(allatency examples/allatency.c)
1515             TARGET_COMPILE_DEFINITIONS(allatency PRIVATE ${CPP_DEFS})
1516             TARGET_INCLUDE_DIRECTORIES(allatency
1517                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1518             TARGET_COMPILE_OPTIONS(allatency PRIVATE ${C_FLAGS})
1519             TARGET_LINK_LIBRARIES(allatency
1520                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1521                         OpenAL)
1523             ADD_EXECUTABLE(alloopback examples/alloopback.c)
1524             TARGET_COMPILE_DEFINITIONS(alloopback PRIVATE ${CPP_DEFS})
1525             TARGET_INCLUDE_DIRECTORIES(alloopback
1526                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1527             TARGET_COMPILE_OPTIONS(alloopback PRIVATE ${C_FLAGS})
1528             TARGET_LINK_LIBRARIES(alloopback
1529                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1530                         OpenAL ${MATH_LIB})
1532             ADD_EXECUTABLE(alhrtf examples/alhrtf.c)
1533             TARGET_COMPILE_DEFINITIONS(alhrtf PRIVATE ${CPP_DEFS})
1534             TARGET_INCLUDE_DIRECTORIES(alhrtf
1535                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1536             TARGET_COMPILE_OPTIONS(alhrtf PRIVATE ${C_FLAGS})
1537             TARGET_LINK_LIBRARIES(alhrtf
1538                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1539                         OpenAL ${MATH_LIB})
1541             IF(ALSOFT_INSTALL)
1542                 INSTALL(TARGETS alplay alstream alreverb allatency alloopback alhrtf
1543                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1544                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1545                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1546                 )
1547             ENDIF()
1549             MESSAGE(STATUS "Building SDL_sound example programs")
1550         ENDIF()
1552         SET(FFVER_OK FALSE)
1553         IF(FFMPEG_FOUND)
1554             SET(FFVER_OK TRUE)
1555             IF(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1556                 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1557                 SET(FFVER_OK FALSE)
1558             ENDIF()
1559             IF(AVCODEC_VERSION VERSION_LESS "57.64.101")
1560                 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1561                 SET(FFVER_OK FALSE)
1562             ENDIF()
1563             IF(AVUTIL_VERSION VERSION_LESS "55.34.101")
1564                 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1565                 SET(FFVER_OK FALSE)
1566             ENDIF()
1567             IF(SWSCALE_VERSION VERSION_LESS "4.2.100")
1568                 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1569                 SET(FFVER_OK FALSE)
1570             ENDIF()
1571             IF(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1572                 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1573                 SET(FFVER_OK FALSE)
1574             ENDIF()
1575         ENDIF()
1576         IF(FFVER_OK)
1577             ADD_EXECUTABLE(alffplay examples/alffplay.cpp)
1578             TARGET_COMPILE_DEFINITIONS(alffplay PRIVATE ${CPP_DEFS})
1579             TARGET_INCLUDE_DIRECTORIES(alffplay
1580                 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1581             TARGET_COMPILE_OPTIONS(alffplay PRIVATE ${C_FLAGS})
1582             TARGET_LINK_LIBRARIES(alffplay
1583                 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} common OpenAL)
1585             IF(ALSOFT_INSTALL)
1586                 INSTALL(TARGETS alffplay
1587                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1588                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1589                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1590                 )
1591             ENDIF()
1592             MESSAGE(STATUS "Building SDL+FFmpeg example programs")
1593         ENDIF()
1594         MESSAGE(STATUS "")
1595     ENDIF()
1596 ENDIF()