Improve handling of source state reads
[openal-soft.git] / CMakeLists.txt
blob7149351ab711a095a78aceabae57f18514dc0ed1
1 # CMake build file list for OpenAL
3 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5)
5 PROJECT(OpenAL)
7 IF(COMMAND CMAKE_POLICY)
8     CMAKE_POLICY(SET CMP0003 NEW)
9     CMAKE_POLICY(SET CMP0005 NEW)
10     IF(POLICY CMP0042)
11         CMAKE_POLICY(SET CMP0042 NEW)
12     ENDIF(POLICY CMP0042)
13     IF(POLICY CMP0054)
14         CMAKE_POLICY(SET CMP0054 NEW)
15     ENDIF(POLICY CMP0054)
16 ENDIF(COMMAND CMAKE_POLICY)
18 SET(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
20 INCLUDE(CheckFunctionExists)
21 INCLUDE(CheckLibraryExists)
22 INCLUDE(CheckSharedFunctionExists)
23 INCLUDE(CheckIncludeFile)
24 INCLUDE(CheckIncludeFiles)
25 INCLUDE(CheckSymbolExists)
26 INCLUDE(CheckCCompilerFlag)
27 INCLUDE(CheckCXXCompilerFlag)
28 INCLUDE(CheckCSourceCompiles)
29 INCLUDE(CheckTypeSize)
30 include(CheckStructHasMember)
31 include(CheckFileOffsetBits)
32 include(GNUInstallDirs)
34 SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
37 OPTION(ALSOFT_DLOPEN  "Check for the dlopen API for loading optional libs"  ON)
39 OPTION(ALSOFT_WERROR  "Treat compile warnings as errors"      OFF)
41 OPTION(ALSOFT_UTILS          "Build and install utility programs"         ON)
42 OPTION(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
44 OPTION(ALSOFT_EXAMPLES  "Build and install example programs"  ON)
45 OPTION(ALSOFT_TESTS     "Build and install test programs"     ON)
47 OPTION(ALSOFT_CONFIG "Install alsoft.conf sample configuration file" ON)
48 OPTION(ALSOFT_HRTF_DEFS "Install HRTF definition files" ON)
49 OPTION(ALSOFT_AMBDEC_PRESETS "Install AmbDec preset files" ON)
50 OPTION(ALSOFT_INSTALL "Install headers and libraries" ON)
52 if(DEFINED SHARE_INSTALL_DIR)
53     message(WARNING "SHARE_INSTALL_DIR is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
54     set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
55 endif()
57 if(DEFINED LIB_SUFFIX)
58     message(WARNING "LIB_SUFFIX is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
59 endif()
62 IF(NOT WIN32)
63     SET(LIBNAME openal)
64 ELSE()
65     SET(LIBNAME OpenAL32)
66     ADD_DEFINITIONS("-D_WIN32 -D_WIN32_WINNT=0x0502")
68     # This option is mainly for static linking OpenAL Soft into another project
69     # that already defines the IDs. It is up to that project to ensure all
70     # required IDs are defined.
71     OPTION(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
73     IF(MINGW)
74         OPTION(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
75         IF(NOT DLLTOOL)
76             IF(HOST)
77                 SET(DLLTOOL "${HOST}-dlltool")
78             ELSE()
79                 SET(DLLTOOL "dlltool")
80             ENDIF()
81         ENDIF()
82     ENDIF()
83 ENDIF()
86 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
87 IF ("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
88     ADD_DEFINITIONS("-I/usr/include")
89     SET(EXTRA_LIBS ${EXTRA_LIBS} -L/usr/lib)
90 ENDIF()
92 IF(NOT LIBTYPE)
93     SET(LIBTYPE SHARED)
94 ENDIF()
96 SET(LIB_MAJOR_VERSION "1")
97 SET(LIB_MINOR_VERSION "17")
98 SET(LIB_REVISION "2")
99 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
101 SET(EXPORT_DECL "")
102 SET(ALIGN_DECL "")
105 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
106 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
109 CHECK_C_COMPILER_FLAG(-std=c11 HAVE_STD_C11)
110 IF(HAVE_STD_C11)
111     SET(CMAKE_C_FLAGS "-std=c11 ${CMAKE_C_FLAGS}")
112 ELSE()
113     CHECK_C_COMPILER_FLAG(-std=c99 HAVE_STD_C99)
114     IF(HAVE_STD_C99)
115         SET(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
116     ENDIF()
117 ENDIF()
119 CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD_CXX11)
120 IF(HAVE_STD_CXX11)
121     SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
122 ENDIF()
124 if(NOT WIN32)
125     # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
126     CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
127     IF(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
128         SET(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
129         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=500")
130         CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
131         IF(NOT HAVE_POSIX_MEMALIGN_POSIX)
132             SET(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
133         ELSE()
134             ADD_DEFINITIONS(-D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=500)
135         ENDIF()
136     ENDIF()
137     UNSET(OLD_REQUIRED_FLAGS)
138 ENDIF()
140 # Set defines for large file support
141 CHECK_FILE_OFFSET_BITS()
142 IF(_FILE_OFFSET_BITS)
143     ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS})
144     SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
145 ENDIF()
146 ADD_DEFINITIONS(-D_LARGEFILE_SOURCE -D_LARGE_FILES)
147 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_LARGEFILE_SOURCE -D_LARGE_FILES")
149 # MSVC may need workarounds for C99 restrict and inline
150 IF(MSVC)
151     # TODO: Once we truly require C99, these restrict and inline checks should go
152     # away.
153     CHECK_C_SOURCE_COMPILES("int *restrict foo;
154                              int main() {return 0;}" HAVE_RESTRICT)
155     IF(NOT HAVE_RESTRICT)
156         ADD_DEFINITIONS("-Drestrict=")
157         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Drestrict=")
158     ENDIF()
160     CHECK_C_SOURCE_COMPILES("inline void foo(void) { }
161                              int main() {return 0;}" HAVE_INLINE)
162     IF(NOT HAVE_INLINE)
163         CHECK_C_SOURCE_COMPILES("__inline void foo(void) { }
164                                  int main() {return 0;}" HAVE___INLINE)
165         IF(NOT HAVE___INLINE)
166             MESSAGE(FATAL_ERROR "No inline keyword found, please report!")
167         ENDIF()
169         ADD_DEFINITIONS(-Dinline=__inline)
170         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Dinline=__inline")
171     ENDIF()
172 ENDIF()
174 # Make sure we have C99-style inline semantics with GCC (4.3 or newer).
175 IF(CMAKE_COMPILER_IS_GNUCC)
176     SET(CMAKE_C_FLAGS "-fno-gnu89-inline ${CMAKE_C_FLAGS}")
178     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
179     # Force no inlining for the next test.
180     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -fno-inline")
182     CHECK_C_SOURCE_COMPILES("extern inline int foo() { return 0; }
183                              int main() {return foo();}" INLINE_IS_C99)
184     IF(NOT INLINE_IS_C99)
185         MESSAGE(FATAL_ERROR "Your compiler does not seem to have C99 inline semantics!
186                              Please update your compiler for better C99 compliance.")
187     ENDIF()
189     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
190 ENDIF()
192 # Check if we have a proper timespec declaration
193 CHECK_STRUCT_HAS_MEMBER("struct timespec" tv_sec time.h HAVE_STRUCT_TIMESPEC)
194 IF(HAVE_STRUCT_TIMESPEC)
195     # Define it here so we don't have to include config.h for it
196     ADD_DEFINITIONS("-DHAVE_STRUCT_TIMESPEC")
197 ENDIF()
199 # Some systems may need libatomic for C11 atomic functions to work
200 SET(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
201 SET(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
202 CHECK_C_SOURCE_COMPILES("#include <stdatomic.h>
203 int _Atomic foo = ATOMIC_VAR_INIT(0);
204 int main()
206     return atomic_fetch_add(&foo, 2);
208 HAVE_LIBATOMIC)
209 IF(NOT HAVE_LIBATOMIC)
210     SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
211 ELSE()
212     SET(EXTRA_LIBS atomic ${EXTRA_LIBS})
213 ENDIF()
214 UNSET(OLD_REQUIRED_LIBRARIES)
216 # Include liblog for Android logging
217 CHECK_LIBRARY_EXISTS(log __android_log_print "" HAVE_LIBLOG)
218 IF(HAVE_LIBLOG)
219     SET(EXTRA_LIBS log ${EXTRA_LIBS})
220     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
221 ENDIF()
223 # Check if we have C99 variable length arrays
224 CHECK_C_SOURCE_COMPILES(
225 "int main(int argc, char *argv[])
227      volatile int tmp[argc];
228      tmp[0] = argv[0][0];
229      return tmp[0];
230  }"
231 HAVE_C99_VLA)
233 # Check if we have C99 bool
234 CHECK_C_SOURCE_COMPILES(
235 "int main(int argc, char *argv[])
237      volatile _Bool ret;
238      ret = (argc > 1) ? 1 : 0;
239      return ret ? -1 : 0;
240  }"
241 HAVE_C99_BOOL)
243 # Check if we have C11 static_assert
244 CHECK_C_SOURCE_COMPILES(
245 "int main()
247      _Static_assert(sizeof(int) == sizeof(int), \"What\");
248      return 0;
249  }"
250 HAVE_C11_STATIC_ASSERT)
252 # Check if we have C11 alignas
253 CHECK_C_SOURCE_COMPILES(
254 "_Alignas(16) int foo;
255  int main()
257      return 0;
258  }"
259 HAVE_C11_ALIGNAS)
261 # Check if we have C11 _Atomic
262 CHECK_C_SOURCE_COMPILES(
263 "#include <stdatomic.h>
264  const int _Atomic foo = ATOMIC_VAR_INIT(~0);
265  int _Atomic bar = ATOMIC_VAR_INIT(0);
266  int main()
268      atomic_fetch_add(&bar, 2);
269      return atomic_load(&foo);
270  }"
271 HAVE_C11_ATOMIC)
273 # Add definitions, compiler switches, etc.
274 INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_BINARY_DIR}")
275 IF(CMAKE_VERSION VERSION_LESS "2.8.8")
276     INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc")
277     IF(WIN32 AND ALSOFT_NO_UID_DEFS)
278         ADD_DEFINITIONS("-DAL_NO_UID_DEFS")
279     ENDIF()
280 ENDIF()
282 IF(NOT CMAKE_BUILD_TYPE)
283     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
284         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
285         FORCE)
286 ENDIF()
287 IF(NOT CMAKE_DEBUG_POSTFIX)
288     SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
289         "Library postfix for debug builds. Normally left blank."
290         FORCE)
291 ENDIF()
293 SET(EXTRA_CFLAGS "")
294 IF(MSVC)
295     ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
296     ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
297     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} /wd4098")
299     IF(NOT DXSDK_DIR)
300         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
301     ELSE()
302         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
303     ENDIF()
304     IF(DXSDK_DIR)
305         MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
306     ENDIF()
308     OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
309     IF(FORCE_STATIC_VCRT)
310         FOREACH(flag_var
311                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
312                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
313             IF(${flag_var} MATCHES "/MD")
314                 STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
315             ENDIF()
316         ENDFOREACH(flag_var)
317     ENDIF()
318 ELSE()
319     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Winline -Wall")
320     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
321     IF(HAVE_W_EXTRA)
322         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wextra")
323     ENDIF()
325     IF(ALSOFT_WERROR)
326         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror")
327     ENDIF()
329     # Force enable -fPIC for CMake versions before 2.8.9 (later versions have
330     # the POSITION_INDEPENDENT_CODE target property). The static common library
331     # will be linked into the dynamic openal library, which requires all its
332     # code to be position-independent.
333     IF(CMAKE_VERSION VERSION_LESS "2.8.9" AND NOT WIN32)
334         CHECK_C_COMPILER_FLAG(-fPIC HAVE_FPIC_SWITCH)
335         IF(HAVE_FPIC_SWITCH)
336             SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC")
337         ENDIF()
338     ENDIF()
340     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
341     # instead of NDEBUG)
342     FOREACH(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
343         IF(${flag_var} MATCHES "-DNDEBUG")
344             STRING(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
345         ENDIF()
346     ENDFOREACH()
348     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
349                              int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
351     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
352     if(ALSOFT_STATIC_LIBGCC)
353         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
354         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
355         check_c_source_compiles(
356 "#include <stdlib.h>
357 int main()
359     return 0;
361             HAVE_STATIC_LIBGCC_SWITCH
362         )
363         if(HAVE_STATIC_LIBGCC_SWITCH)
364             set(EXTRA_LIBS ${EXTRA_LIBS} -static-libgcc)
365         endif()
366         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
367         unset(OLD_REQUIRED_LIBRARIES)
368     endif()
369 ENDIF()
371 # Set visibility/export options if available
372 SET(HIDDEN_DECL "")
373 IF(WIN32)
374     SET(EXPORT_DECL "__declspec(dllexport)")
375     IF(NOT MINGW)
376         SET(ALIGN_DECL "__declspec(align(x))")
377     ELSE()
378         SET(ALIGN_DECL "__declspec(aligned(x))")
379     ENDIF()
380 ELSE()
381     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
382     # Yes GCC, really don't accept visibility modes you don't support
383     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
385     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
386                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
387     IF(HAVE_GCC_PROTECTED_VISIBILITY)
388         SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
389     ELSE()
390         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
391                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
392         IF(HAVE_GCC_DEFAULT_VISIBILITY)
393             SET(EXPORT_DECL "__attribute__((visibility(\"default\")))")
394         ENDIF()
395     ENDIF()
397     IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
398         CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
399         IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
400             SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
401             SET(HIDDEN_DECL "__attribute__((visibility(\"hidden\")))")
402         ENDIF()
403     ENDIF()
405     CHECK_C_SOURCE_COMPILES("int foo __attribute__((aligned(16)));
406                              int main() {return 0;}" HAVE_ATTRIBUTE_ALIGNED)
407     IF(HAVE_ATTRIBUTE_ALIGNED)
408         SET(ALIGN_DECL "__attribute__((aligned(x)))")
409     ENDIF()
411     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
412 ENDIF()
414 CHECK_C_SOURCE_COMPILES("
415 int main()
417     float *ptr;
418     ptr = __builtin_assume_aligned(ptr, 16);
419     return 0;
420 }" HAVE___BUILTIN_ASSUME_ALIGNED)
421 IF(HAVE___BUILTIN_ASSUME_ALIGNED)
422     SET(ASSUME_ALIGNED_DECL "__builtin_assume_aligned(x, y)")
423 ELSE()
424     SET(ASSUME_ALIGNED_DECL "x")
425 ENDIF()
427 SET(SSE_SWITCH "")
428 SET(SSE2_SWITCH "")
429 SET(SSE3_SWITCH "")
430 SET(SSE4_1_SWITCH "")
431 SET(FPU_NEON_SWITCH "")
432 IF(NOT MSVC)
433     CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
434     IF(HAVE_MSSE_SWITCH)
435         SET(SSE_SWITCH "-msse")
436     ENDIF()
437     CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
438     IF(HAVE_MSSE2_SWITCH)
439         SET(SSE2_SWITCH "-msse2")
440     ENDIF()
441     CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
442     IF(HAVE_MSSE3_SWITCH)
443         SET(SSE3_SWITCH "-msse3")
444     ENDIF()
445     CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
446     IF(HAVE_MSSE4_1_SWITCH)
447         SET(SSE4_1_SWITCH "-msse4.1")
448     ENDIF()
449     CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
450     IF(HAVE_MFPU_NEON_SWITCH)
451         SET(FPU_NEON_SWITCH "-mfpu=neon")
452     ENDIF()
453 ENDIF()
455 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
456                          int main() {return 0;}" HAVE_GCC_FORMAT)
458 CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
459 CHECK_INCLUDE_FILE(stdalign.h HAVE_STDALIGN_H)
460 CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
461 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
462 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
463 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
464 CHECK_INCLUDE_FILE(intrin.h HAVE_INTRIN_H)
465 CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
466 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
467 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
468 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
469 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
470 IF(NOT HAVE_GUIDDEF_H)
471     CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
472 ENDIF()
474 # Some systems need libm for some of the following math functions to work
475 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
476 IF(HAVE_LIBM)
477     SET(EXTRA_LIBS m ${EXTRA_LIBS})
478     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
479 ENDIF()
481 # Check for the dlopen API (for dynamicly loading backend libs)
482 IF(ALSOFT_DLOPEN)
483     CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
484     IF(HAVE_LIBDL)
485         SET(EXTRA_LIBS dl ${EXTRA_LIBS})
486         SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
487     ENDIF()
489     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
490 ENDIF()
492 # Check for a cpuid intrinsic
493 IF(HAVE_CPUID_H)
494     CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
495         int main()
496         {
497             unsigned int eax, ebx, ecx, edx;
498             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
499         }" HAVE_GCC_GET_CPUID)
500 ENDIF()
501 IF(HAVE_INTRIN_H)
502     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
503         int main()
504         {
505             int regs[4];
506             __cpuid(regs, 0);
507             return regs[0];
508         }" HAVE_CPUID_INTRINSIC)
509 ENDIF()
511 CHECK_SYMBOL_EXISTS(aligned_alloc    stdlib.h HAVE_ALIGNED_ALLOC)
512 CHECK_SYMBOL_EXISTS(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
513 CHECK_SYMBOL_EXISTS(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
514 CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
515 CHECK_SYMBOL_EXISTS(modff  math.h HAVE_MODFF)
516 IF(NOT HAVE_C99_VLA)
517     CHECK_SYMBOL_EXISTS(alloca malloc.h HAVE_ALLOCA)
518     IF(NOT HAVE_ALLOCA)
519         MESSAGE(FATAL_ERROR "No alloca function found, please report!")
520     ENDIF()
521 ENDIF()
523 IF(HAVE_FLOAT_H)
524     CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
525     CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
526 ENDIF()
528 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
529 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
530 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
531 IF(NOT HAVE_STRCASECMP)
532     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
533     IF(NOT HAVE__STRICMP)
534         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
535     ENDIF()
537     ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
538 ENDIF()
540 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
541 IF(NOT HAVE_STRNCASECMP)
542     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
543     IF(NOT HAVE__STRNICMP)
544         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
545     ENDIF()
547     ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
548 ENDIF()
550 CHECK_SYMBOL_EXISTS(strnlen string.h HAVE_STRNLEN)
551 CHECK_SYMBOL_EXISTS(snprintf stdio.h HAVE_SNPRINTF)
552 IF(NOT HAVE_SNPRINTF)
553     CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
554     IF(NOT HAVE__SNPRINTF)
555         MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
556     ENDIF()
558     ADD_DEFINITIONS(-Dsnprintf=_snprintf)
559 ENDIF()
561 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
562 IF(NOT HAVE_ISFINITE)
563     CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
564     IF(NOT HAVE_FINITE)
565         CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
566         IF(NOT HAVE__FINITE)
567             MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
568         ENDIF()
569         ADD_DEFINITIONS(-Disfinite=_finite)
570     ELSE()
571         ADD_DEFINITIONS(-Disfinite=finite)
572     ENDIF()
573 ENDIF()
575 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
576 IF(NOT HAVE_ISNAN)
577     CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
578     IF(NOT HAVE__ISNAN)
579         MESSAGE(FATAL_ERROR "No isnan function found, please report!")
580     ENDIF()
582     ADD_DEFINITIONS(-Disnan=_isnan)
583 ENDIF()
586 # Check if we have Windows headers
587 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0502)
588 IF(NOT HAVE_WINDOWS_H)
589     CHECK_SYMBOL_EXISTS(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
590     IF(NOT HAVE_GETTIMEOFDAY)
591         MESSAGE(FATAL_ERROR "No timing function found!")
592     ENDIF()
594     CHECK_SYMBOL_EXISTS(nanosleep time.h HAVE_NANOSLEEP)
595     IF(NOT HAVE_NANOSLEEP)
596         MESSAGE(FATAL_ERROR "No sleep function found!")
597     ENDIF()
599     # We need pthreads outside of Windows
600     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
601     IF(NOT HAVE_PTHREAD_H)
602         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
603     ENDIF()
604     # Some systems need pthread_np.h to get recursive mutexes
605     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
607     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
608     IF(HAVE_PTHREAD)
609         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pthread")
610         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
611         SET(EXTRA_LIBS ${EXTRA_LIBS} -pthread)
612     ENDIF()
614     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
615     IF(HAVE_LIBPTHREAD)
616         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
617     ENDIF()
619     CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
621     IF(HAVE_PTHREAD_NP_H)
622         CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
623         IF(NOT HAVE_PTHREAD_SETNAME_NP)
624             CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
625         ELSE()
626             CHECK_C_SOURCE_COMPILES("
627 #include <pthread.h>
628 #include <pthread_np.h>
629 int main()
631     pthread_setname_np(\"testname\");
632     return 0;
634                 PTHREAD_SETNAME_NP_ONE_PARAM
635             )
636         ENDIF()
637         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np "pthread.h;pthread_np.h" HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
638     ELSE()
639         CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
640         IF(NOT HAVE_PTHREAD_SETNAME_NP)
641             CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
642         ELSE()
643             CHECK_C_SOURCE_COMPILES("
644 #include <pthread.h>
645 int main()
647     pthread_setname_np(\"testname\");
648     return 0;
650                 PTHREAD_SETNAME_NP_ONE_PARAM
651             )
652         ENDIF()
653         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np pthread.h HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
654     ENDIF()
656     CHECK_SYMBOL_EXISTS(pthread_mutex_timedlock pthread.h HAVE_PTHREAD_MUTEX_TIMEDLOCK)
658     CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
659     IF(HAVE_LIBRT)
660         SET(EXTRA_LIBS rt ${EXTRA_LIBS})
661     ENDIF()
662 ENDIF()
664 # Check for a 64-bit type
665 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
666 IF(NOT HAVE_STDINT_H)
667     IF(HAVE_WINDOWS_H)
668         CHECK_C_SOURCE_COMPILES("#define _WIN32_WINNT 0x0502
669                                  #include <windows.h>
670                                  __int64 foo;
671                                  int main() {return 0;}" HAVE___INT64)
672     ENDIF()
673     IF(NOT HAVE___INT64)
674         IF(NOT SIZEOF_LONG MATCHES "8")
675             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
676                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
677             ENDIF()
678         ENDIF()
679     ENDIF()
680 ENDIF()
683 SET(COMMON_OBJS  common/almalloc.c
684                  common/atomic.c
685                  common/rwlock.c
686                  common/threads.c
687                  common/uintmap.c
689 SET(OPENAL_OBJS  OpenAL32/alAuxEffectSlot.c
690                  OpenAL32/alBuffer.c
691                  OpenAL32/alEffect.c
692                  OpenAL32/alError.c
693                  OpenAL32/alExtension.c
694                  OpenAL32/alFilter.c
695                  OpenAL32/alListener.c
696                  OpenAL32/alSource.c
697                  OpenAL32/alState.c
698                  OpenAL32/alThunk.c
699                  OpenAL32/sample_cvt.c
701 SET(ALC_OBJS  Alc/ALc.c
702               Alc/ALu.c
703               Alc/alcConfig.c
704               Alc/alcRing.c
705               Alc/bs2b.c
706               Alc/effects/chorus.c
707               Alc/effects/compressor.c
708               Alc/effects/dedicated.c
709               Alc/effects/distortion.c
710               Alc/effects/echo.c
711               Alc/effects/equalizer.c
712               Alc/effects/flanger.c
713               Alc/effects/modulator.c
714               Alc/effects/null.c
715               Alc/effects/reverb.c
716               Alc/helpers.c
717               Alc/bsinc.c
718               Alc/hrtf.c
719               Alc/uhjfilter.c
720               Alc/ambdec.c
721               Alc/bformatdec.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)
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         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
880             INCLUDE_DIRECTORIES(${ALSA_INCLUDE_DIRS})
881         ENDIF()
882     ENDIF()
883 ENDIF()
884 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
885     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
886 ENDIF()
888 # Check OSS backend
889 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
890 FIND_PACKAGE(OSS)
891 IF(OSS_FOUND)
892     OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
893     IF(ALSOFT_BACKEND_OSS)
894         SET(HAVE_OSS 1)
895         SET(BACKENDS  "${BACKENDS} OSS,")
896         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/oss.c)
897         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
898             INCLUDE_DIRECTORIES(${OSS_INCLUDE_DIRS})
899         ENDIF()
900     ENDIF()
901 ENDIF()
902 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
903     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
904 ENDIF()
906 # Check Solaris backend
907 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
908 FIND_PACKAGE(AudioIO)
909 IF(AUDIOIO_FOUND)
910     OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
911     IF(ALSOFT_BACKEND_SOLARIS)
912         SET(HAVE_SOLARIS 1)
913         SET(BACKENDS  "${BACKENDS} Solaris,")
914         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/solaris.c)
915         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
916             INCLUDE_DIRECTORIES(${AUDIOIO_INCLUDE_DIRS})
917         ENDIF()
918     ENDIF()
919 ENDIF()
920 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
921     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
922 ENDIF()
924 # Check SndIO backend
925 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
926 FIND_PACKAGE(SoundIO)
927 IF(SOUNDIO_FOUND)
928     OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
929     IF(ALSOFT_BACKEND_SNDIO)
930         SET(HAVE_SNDIO 1)
931         SET(BACKENDS  "${BACKENDS} SndIO (linked),")
932         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sndio.c)
933         SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
934         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
935             INCLUDE_DIRECTORIES(${SOUNDIO_INCLUDE_DIRS})
936         ENDIF()
937     ENDIF()
938 ENDIF()
939 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
940     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
941 ENDIF()
943 # Check QSA backend
944 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
945 FIND_PACKAGE(QSA)
946 IF(QSA_FOUND)
947     OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
948     IF(ALSOFT_BACKEND_QSA)
949         SET(HAVE_QSA 1)
950         SET(BACKENDS  "${BACKENDS} QSA (linked),")
951         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/qsa.c)
952         SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
953         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
954             INCLUDE_DIRECTORIES(${QSA_INCLUDE_DIRS})
955         ENDIF()
956     ENDIF()
957 ENDIF()
958 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
959     MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
960 ENDIF()
962 # Check Windows-only backends
963 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
964 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
965 OPTION(ALSOFT_REQUIRE_MMDEVAPI "Require MMDevApi backend" OFF)
966 IF(HAVE_WINDOWS_H)
967     # Check MMSystem backend
968     CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0502)
969     IF(HAVE_MMSYSTEM_H)
970         CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
971         IF(HAVE_LIBWINMM)
972             OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
973             IF(ALSOFT_BACKEND_WINMM)
974                 SET(HAVE_WINMM 1)
975                 SET(BACKENDS  "${BACKENDS} WinMM,")
976                 SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/winmm.c)
977                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
978             ENDIF()
979         ENDIF()
980     ENDIF()
982     # Check DSound backend
983     FIND_PACKAGE(DSound)
984     IF(DSOUND_FOUND)
985         OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
986         IF(ALSOFT_BACKEND_DSOUND)
987             SET(HAVE_DSOUND 1)
988             SET(BACKENDS  "${BACKENDS} DirectSound${IS_LINKED},")
989             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/dsound.c)
990             ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
991             IF(CMAKE_VERSION VERSION_LESS "2.8.8")
992                 INCLUDE_DIRECTORIES(${DSOUND_INCLUDE_DIRS})
993             ENDIF()
994         ENDIF()
995     ENDIF()
997     # Check for MMDevApi backend
998     CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
999     IF(HAVE_MMDEVICEAPI_H)
1000         OPTION(ALSOFT_BACKEND_MMDEVAPI "Enable MMDevApi backend" ON)
1001         IF(ALSOFT_BACKEND_MMDEVAPI)
1002             SET(HAVE_MMDEVAPI 1)
1003             SET(BACKENDS  "${BACKENDS} MMDevApi,")
1004             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/mmdevapi.c)
1005         ENDIF()
1006     ENDIF()
1007 ENDIF()
1008 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1009     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
1010 ENDIF()
1011 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1012     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
1013 ENDIF()
1014 IF(ALSOFT_REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
1015     MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
1016 ENDIF()
1018 # Check PortAudio backend
1019 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1020 FIND_PACKAGE(PortAudio)
1021 IF(PORTAUDIO_FOUND)
1022     OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1023     IF(ALSOFT_BACKEND_PORTAUDIO)
1024         SET(HAVE_PORTAUDIO 1)
1025         SET(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
1026         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/portaudio.c)
1027         ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
1028         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
1029             INCLUDE_DIRECTORIES(${PORTAUDIO_INCLUDE_DIRS})
1030         ENDIF()
1031     ENDIF()
1032 ENDIF()
1033 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1034     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
1035 ENDIF()
1037 # Check PulseAudio backend
1038 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1039 FIND_PACKAGE(PulseAudio)
1040 IF(PULSEAUDIO_FOUND)
1041     OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1042     IF(ALSOFT_BACKEND_PULSEAUDIO)
1043         SET(HAVE_PULSEAUDIO 1)
1044         SET(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
1045         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/pulseaudio.c)
1046         ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
1047         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
1048             INCLUDE_DIRECTORIES(${PULSEAUDIO_INCLUDE_DIRS})
1049         ENDIF()
1050     ENDIF()
1051 ENDIF()
1052 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1053     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1054 ENDIF()
1056 # Check JACK backend
1057 OPTION(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1058 FIND_PACKAGE(JACK)
1059 IF(JACK_FOUND)
1060     OPTION(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1061     IF(ALSOFT_BACKEND_JACK)
1062         SET(HAVE_JACK 1)
1063         SET(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1064         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/jack.c)
1065         ADD_BACKEND_LIBS(${JACK_LIBRARIES})
1066         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
1067             INCLUDE_DIRECTORIES(${JACK_INCLUDE_DIRS})
1068         ENDIF()
1069     ENDIF()
1070 ENDIF()
1071 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1072     MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
1073 ENDIF()
1075 # Check CoreAudio backend
1076 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1077 FIND_LIBRARY(COREAUDIO_FRAMEWORK
1078              NAMES CoreAudio
1079              PATHS /System/Library/Frameworks
1081 IF(COREAUDIO_FRAMEWORK)
1082     OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1083     IF(ALSOFT_BACKEND_COREAUDIO)
1084         SET(HAVE_COREAUDIO 1)
1085         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/coreaudio.c)
1086         SET(BACKENDS  "${BACKENDS} CoreAudio,")
1087         SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
1088         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
1089         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1091         # Some versions of OSX may need the AudioToolbox framework. Add it if
1092         # it's found.
1093         FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
1094                      NAMES AudioToolbox
1095                      PATHS ~/Library/Frameworks
1096                            /Library/Frameworks
1097                            /System/Library/Frameworks
1098                     )
1099         IF(AUDIOTOOLBOX_LIBRARY)
1100             SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1101         ENDIF()
1102     ENDIF()
1103 ENDIF()
1104 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1105     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1106 ENDIF()
1108 # Check for OpenSL (Android) backend
1109 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1110 CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
1111 IF(HAVE_SLES_OPENSLES_ANDROID_H)
1112     CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
1113     IF(HAVE_LIBOPENSLES)
1114         OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1115         IF(ALSOFT_BACKEND_OPENSL)
1116             SET(HAVE_OPENSL 1)
1117             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/opensl.c)
1118             SET(BACKENDS  "${BACKENDS} OpenSL,")
1119             SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
1120         ENDIF()
1121     ENDIF()
1122 ENDIF()
1123 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1124     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1125 ENDIF()
1127 # Optionally enable the Wave Writer backend
1128 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1129 IF(ALSOFT_BACKEND_WAVE)
1130     SET(HAVE_WAVE 1)
1131     SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wave.c)
1132     SET(BACKENDS  "${BACKENDS} WaveFile,")
1133 ENDIF()
1135 # This is always available
1136 SET(BACKENDS  "${BACKENDS} Null")
1138 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" OFF)
1139 if(ALSOFT_EMBED_HRTF_DATA)
1140     if(WIN32)
1141         set(ALC_OBJS  ${ALC_OBJS} Alc/hrtf_res.rc)
1142     elseif(APPLE)
1143         macro(add_custom_binary FILENAME BIN_NAME)
1144             set(outfile ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${FILENAME}${CMAKE_C_OUTPUT_EXTENSION})
1145             set(stubsrcfile ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${FILENAME}.stub.c)
1146             set(stubfile ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${FILENAME}.stub${CMAKE_C_OUTPUT_EXTENSION})
1147             add_custom_command(OUTPUT ${outfile}
1148                 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hrtf/${FILENAME}"
1149                 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/hrtf"
1150                 COMMAND touch "${stubsrcfile}"
1151                 COMMAND "${CMAKE_C_COMPILER}" -o "${stubfile}" -c "${stubsrcfile}"
1152                 COMMAND "${CMAKE_LINKER}" -r -o "${outfile}" -sectcreate binary ${BIN_NAME} ${FILENAME} "${stubfile}"
1153                 COMMAND rm "${stubsrcfile}" "${stubfile}"
1154                 COMMENT "Generating ${FILENAME}${CMAKE_C_OUTPUT_EXTENSION}"
1155                 VERBATIM
1156             )
1157             set(ALC_OBJS  ${ALC_OBJS} ${outfile})
1158         endmacro()
1159         add_custom_binary(default-44100.mhr "default_44100")
1160         add_custom_binary(default-48000.mhr "default_48000")
1161     else()
1162         set(FILENAMES default-44100.mhr default-48000.mhr)
1163         foreach(FILENAME ${FILENAMES})
1164             set(outfile ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${FILENAME}${CMAKE_C_OUTPUT_EXTENSION})
1165             add_custom_command(OUTPUT ${outfile}
1166                 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hrtf/${FILENAME}"
1167                 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/hrtf"
1168                 COMMAND "${CMAKE_LINKER}" -r -b binary -o "${outfile}" ${FILENAME}
1169                 COMMAND "${CMAKE_OBJCOPY}" --rename-section .data=.rodata,alloc,load,readonly,data,contents "${outfile}" "${outfile}"
1170                 COMMENT "Generating ${FILENAME}${CMAKE_C_OUTPUT_EXTENSION}"
1171                 VERBATIM
1172             )
1173             set(ALC_OBJS  ${ALC_OBJS} ${outfile})
1174         endforeach()
1175         unset(outfile)
1176         unset(FILENAMES)
1177     endif()
1178 endif()
1181 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1182     add_subdirectory(utils/alsoft-config)
1183 ENDIF()
1184 IF(ALSOFT_EXAMPLES)
1185     FIND_PACKAGE(SDL2)
1186     IF(SDL2_FOUND)
1187         FIND_PACKAGE(SDL_sound)
1188         IF(SDL_SOUND_FOUND AND CMAKE_VERSION VERSION_LESS "2.8.8")
1189             INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1190         ENDIF()
1191         FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1192         IF(FFMPEG_FOUND AND CMAKE_VERSION VERSION_LESS "2.8.8")
1193             INCLUDE_DIRECTORIES(${FFMPEG_INCLUDE_DIRS})
1194         ENDIF()
1195     ENDIF()
1196 ENDIF()
1198 IF(LIBTYPE STREQUAL "STATIC")
1199     ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC)
1200     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
1201 ENDIF()
1203 FIND_PACKAGE(Git)
1204 IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1205     # Get the current working branch and its latest abbreviated commit hash
1206     ADD_CUSTOM_TARGET(build_version
1207         ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
1208                          -D LIB_VERSION=${LIB_VERSION}
1209                          -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1210                          -D DST=${OpenAL_BINARY_DIR}/version.h
1211                          -P ${OpenAL_SOURCE_DIR}/version.cmake
1212         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1213         VERBATIM
1214     )
1215 ELSE()
1216     SET(GIT_BRANCH "UNKNOWN")
1217     SET(GIT_COMMIT_HASH "unknown")
1218     CONFIGURE_FILE(
1219         "${OpenAL_SOURCE_DIR}/version.h.in"
1220         "${OpenAL_BINARY_DIR}/version.h")
1221 ENDIF()
1223 # Needed for openal.pc.in
1224 SET(prefix ${CMAKE_INSTALL_PREFIX})
1225 SET(exec_prefix "\${prefix}")
1226 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1227 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1228 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1229 SET(PACKAGE_VERSION "${LIB_VERSION}")
1231 # End configuration
1232 CONFIGURE_FILE(
1233     "${OpenAL_SOURCE_DIR}/config.h.in"
1234     "${OpenAL_BINARY_DIR}/config.h")
1235 CONFIGURE_FILE(
1236     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1237     "${OpenAL_BINARY_DIR}/openal.pc"
1238     @ONLY)
1240 # Build a common library with reusable helpers
1241 ADD_LIBRARY(common STATIC ${COMMON_OBJS})
1242 SET_PROPERTY(TARGET common APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1243 IF(NOT LIBTYPE STREQUAL "STATIC")
1244     SET_PROPERTY(TARGET common PROPERTY POSITION_INDEPENDENT_CODE TRUE)
1245 ENDIF()
1247 # Build main library
1248 IF(LIBTYPE STREQUAL "STATIC")
1249     ADD_LIBRARY(${LIBNAME} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1250 ELSE()
1251     ADD_LIBRARY(${LIBNAME} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
1252 ENDIF()
1253 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1254 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY COMPILE_DEFINITIONS AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES)
1255 IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1256     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY COMPILE_DEFINITIONS AL_NO_UID_DEFS)
1257 ENDIF()
1258 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc")
1259 IF(HAVE_ALSA)
1260     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${ALSA_INCLUDE_DIRS})
1261 ENDIF()
1262 IF(HAVE_OSS)
1263     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${OSS_INCLUDE_DIRS})
1264 ENDIF()
1265 IF(HAVE_SOLARIS)
1266     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${AUDIOIO_INCLUDE_DIRS})
1267 ENDIF()
1268 IF(HAVE_SNDIO)
1269     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${SOUNDIO_INCLUDE_DIRS})
1270 ENDIF()
1271 IF(HAVE_QSA)
1272     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${QSA_INCLUDE_DIRS})
1273 ENDIF()
1274 IF(HAVE_DSOUND)
1275     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${DSOUND_INCLUDE_DIRS})
1276 ENDIF()
1277 IF(HAVE_PORTAUDIO)
1278     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${PORTAUDIO_INCLUDE_DIRS})
1279 ENDIF()
1280 IF(HAVE_PULSEAUDIO)
1281     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${PULSEAUDIO_INCLUDE_DIRS})
1282 ENDIF()
1283 IF(HAVE_JACK)
1284     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${JACK_INCLUDE_DIRS})
1285 ENDIF()
1286 IF(WIN32)
1287     IF(MSVC)
1288         SET_PROPERTY(TARGET ${LIBNAME} APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:WINDOWS")
1289     ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1290         SET_PROPERTY(TARGET ${LIBNAME} APPEND_STRING PROPERTY LINK_FLAGS " -mwindows")
1291     ENDIF()
1292 ENDIF()
1294 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
1295                                             SOVERSION ${LIB_MAJOR_VERSION})
1296 IF(WIN32 AND NOT LIBTYPE STREQUAL "STATIC")
1297     SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
1299     IF(MINGW AND ALSOFT_BUILD_IMPORT_LIB)
1300         FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1301         FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1302         IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1303             MESSAGE(STATUS "")
1304             IF(NOT SED_EXECUTABLE)
1305                 MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1306             ENDIF()
1307             IF(NOT DLLTOOL_EXECUTABLE)
1308                 MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1309             ENDIF()
1310         ELSE()
1311             SET_PROPERTY(TARGET ${LIBNAME} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--output-def,${LIBNAME}.def")
1312             ADD_CUSTOM_COMMAND(TARGET ${LIBNAME} POST_BUILD
1313                 COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" ${LIBNAME}.def
1314                 COMMAND "${DLLTOOL_EXECUTABLE}" -d ${LIBNAME}.def -l ${LIBNAME}.lib -D ${LIBNAME}.dll
1315                 COMMENT "Stripping ordinals from ${LIBNAME}.def and generating ${LIBNAME}.lib..."
1316                 VERBATIM
1317             )
1318         ENDIF()
1319     ENDIF()
1320 ENDIF()
1322 TARGET_LINK_LIBRARIES(${LIBNAME} common ${EXTRA_LIBS})
1323 IF(TARGET build_version)
1324     ADD_DEPENDENCIES(${LIBNAME} build_version)
1325 ENDIF()
1327 IF(ALSOFT_INSTALL)
1328     # Add an install target here
1329     INSTALL(TARGETS ${LIBNAME}
1330             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1331             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1332             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1333     )
1334     INSTALL(FILES include/AL/al.h
1335                   include/AL/alc.h
1336                   include/AL/alext.h
1337                   include/AL/efx.h
1338                   include/AL/efx-creative.h
1339                   include/AL/efx-presets.h
1340             DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
1341     )
1342     INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1343             DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1344 ENDIF()
1347 MESSAGE(STATUS "")
1348 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1349 MESSAGE(STATUS "    ${BACKENDS}")
1350 MESSAGE(STATUS "")
1351 MESSAGE(STATUS "Building with support for CPU extensions:")
1352 MESSAGE(STATUS "    ${CPU_EXTS}")
1353 MESSAGE(STATUS "")
1355 IF(WIN32)
1356     IF(NOT HAVE_DSOUND)
1357         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
1358         MESSAGE(STATUS "         This is probably NOT what you want!")
1359         MESSAGE(STATUS "")
1360     ENDIF()
1361 ENDIF()
1363 if(ALSOFT_EMBED_HRTF_DATA)
1364     message(STATUS "Embedding HRTF datasets")
1365     message(STATUS "")
1366 endif()
1368 # Install alsoft.conf configuration file
1369 IF(ALSOFT_CONFIG)
1370     INSTALL(FILES alsoftrc.sample
1371             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal
1372     )
1373     MESSAGE(STATUS "Installing sample configuration")
1374     MESSAGE(STATUS "")
1375 ENDIF()
1377 # Install HRTF definitions
1378 IF(ALSOFT_HRTF_DEFS)
1379     INSTALL(FILES hrtf/default-44100.mhr
1380                   hrtf/default-48000.mhr
1381             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf
1382     )
1383     MESSAGE(STATUS "Installing HRTF definitions")
1384     MESSAGE(STATUS "")
1385 ENDIF()
1387 # Install AmbDec presets
1388 IF(ALSOFT_AMBDEC_PRESETS)
1389     INSTALL(FILES presets/3D7.1.ambdec
1390                   presets/hexagon.ambdec
1391                   presets/itu5.1.ambdec
1392                   presets/rectangle.ambdec
1393                   presets/square.ambdec
1394                   presets/presets.txt
1395             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
1396     )
1397     MESSAGE(STATUS "Installing AmbDec presets")
1398     MESSAGE(STATUS "")
1399 ENDIF()
1401 IF(ALSOFT_UTILS)
1402     ADD_EXECUTABLE(openal-info utils/openal-info.c)
1403     SET_PROPERTY(TARGET openal-info APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1404     TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
1406     ADD_EXECUTABLE(makehrtf utils/makehrtf.c)
1407     SET_PROPERTY(TARGET makehrtf APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1408     IF(HAVE_LIBM)
1409         TARGET_LINK_LIBRARIES(makehrtf m)
1410     ENDIF()
1412     ADD_EXECUTABLE(bsincgen utils/bsincgen.c)
1413     SET_PROPERTY(TARGET bsincgen APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1414     IF(HAVE_LIBM)
1415         TARGET_LINK_LIBRARIES(bsincgen m)
1416     ENDIF()
1418     IF(ALSOFT_INSTALL)
1419         INSTALL(TARGETS openal-info makehrtf bsincgen
1420                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1421                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1422                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1423         )
1424     ENDIF()
1426     MESSAGE(STATUS "Building utility programs")
1427     IF(TARGET alsoft-config)
1428         MESSAGE(STATUS "Building configuration program")
1429     ENDIF()
1430     MESSAGE(STATUS "")
1431 ENDIF()
1433 IF(ALSOFT_TESTS)
1434     ADD_LIBRARY(test-common STATIC examples/common/alhelpers.c)
1435     SET_PROPERTY(TARGET test-common APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1437     ADD_EXECUTABLE(altonegen examples/altonegen.c)
1438     TARGET_LINK_LIBRARIES(altonegen test-common ${LIBNAME})
1439     SET_PROPERTY(TARGET altonegen APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1441     IF(ALSOFT_INSTALL)
1442         INSTALL(TARGETS altonegen
1443                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1444                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1445                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1446         )
1447     ENDIF()
1449     MESSAGE(STATUS "Building test programs")
1450     MESSAGE(STATUS "")
1451 ENDIF()
1453 IF(ALSOFT_EXAMPLES)
1454     IF(SDL2_FOUND)
1455         IF(SDL_SOUND_FOUND)
1456             ADD_LIBRARY(ex-common STATIC examples/common/alhelpers.c
1457                                          examples/common/sdl_sound.c)
1458             SET_PROPERTY(TARGET ex-common APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1459             SET_PROPERTY(TARGET ex-common APPEND PROPERTY
1460                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1461             )
1463             ADD_EXECUTABLE(alstream examples/alstream.c)
1464             TARGET_LINK_LIBRARIES(alstream ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1465                                            common ${LIBNAME})
1466             SET_PROPERTY(TARGET alstream APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1467             SET_PROPERTY(TARGET alstream APPEND PROPERTY
1468                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1469             )
1471             ADD_EXECUTABLE(alreverb examples/alreverb.c)
1472             TARGET_LINK_LIBRARIES(alreverb ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1473                                            common ${LIBNAME})
1474             SET_PROPERTY(TARGET alreverb APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1475             SET_PROPERTY(TARGET alreverb APPEND PROPERTY
1476                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1477             )
1479             ADD_EXECUTABLE(allatency examples/allatency.c)
1480             TARGET_LINK_LIBRARIES(allatency ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1481                                             common ${LIBNAME})
1482             SET_PROPERTY(TARGET allatency APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1483             SET_PROPERTY(TARGET allatency APPEND PROPERTY
1484                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1485             )
1487             ADD_EXECUTABLE(alloopback examples/alloopback.c)
1488             TARGET_LINK_LIBRARIES(alloopback ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1489                                              common ${LIBNAME})
1490             SET_PROPERTY(TARGET alloopback APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1491             SET_PROPERTY(TARGET alloopback APPEND PROPERTY
1492                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1493             )
1495             ADD_EXECUTABLE(alhrtf examples/alhrtf.c)
1496             TARGET_LINK_LIBRARIES(alhrtf ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1497                                          common ${LIBNAME})
1498             SET_PROPERTY(TARGET alhrtf APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1499             SET_PROPERTY(TARGET alhrtf APPEND PROPERTY
1500                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1501             )
1503             IF(ALSOFT_INSTALL)
1504                 INSTALL(TARGETS alstream alreverb allatency alloopback alhrtf
1505                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1506                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1507                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1508                 )
1509             ENDIF()
1511             MESSAGE(STATUS "Building SDL_sound example programs")
1512         ENDIF()
1514         SET(FFVER_OK FALSE)
1515         IF(FFMPEG_FOUND)
1516             SET(FFVER_OK TRUE)
1517             IF(AVFORMAT_VERSION VERSION_LESS "55.33.100")
1518                 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 55.33.100)")
1519                 SET(FFVER_OK FALSE)
1520             ENDIF()
1521             IF(AVCODEC_VERSION VERSION_LESS "55.52.102")
1522                 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 55.52.102)")
1523                 SET(FFVER_OK FALSE)
1524             ENDIF()
1525             IF(AVUTIL_VERSION VERSION_LESS "52.66.100")
1526                 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 52.66.100)")
1527                 SET(FFVER_OK FALSE)
1528             ENDIF()
1529             IF(SWSCALE_VERSION VERSION_LESS "2.5.102")
1530                 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 2.5.102)")
1531                 SET(FFVER_OK FALSE)
1532             ENDIF()
1533             IF(SWRESAMPLE_VERSION VERSION_LESS "0.18.100")
1534                 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 0.18.100)")
1535                 SET(FFVER_OK FALSE)
1536             ENDIF()
1537         ENDIF()
1538         IF(FFVER_OK AND NOT MSVC)
1539             ADD_EXECUTABLE(alffplay examples/alffplay.c)
1540             TARGET_LINK_LIBRARIES(alffplay common ${SDL2_LIBRARY} ${LIBNAME} ${FFMPEG_LIBRARIES})
1541             SET_PROPERTY(TARGET alffplay APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1542             SET_PROPERTY(TARGET alffplay APPEND PROPERTY
1543                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS}
1544             )
1546             IF(ALSOFT_INSTALL)
1547                 INSTALL(TARGETS alffplay
1548                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1549                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1550                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1551                 )
1552             ENDIF()
1553             MESSAGE(STATUS "Building SDL+FFmpeg example programs")
1554         ENDIF()
1555         MESSAGE(STATUS "")
1556     ENDIF()
1557 ENDIF()