Remove unnecessary wrappers around SDL_sound
[openal-soft.git] / CMakeLists.txt
blob8f2799517b3050050e2ba4c2fec67d44c2157774
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 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 IF(WIN32)
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 SET(EXTRA_LIBS "")
87 SET(EXTRA_LDFLAGS "")
89 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
90 IF ("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
91     ADD_DEFINITIONS("-I/usr/include")
92     SET(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} -L/usr/lib")
93 ENDIF()
95 IF(NOT LIBTYPE)
96     SET(LIBTYPE SHARED)
97 ENDIF()
99 SET(LIB_MAJOR_VERSION "1")
100 SET(LIB_MINOR_VERSION "17")
101 SET(LIB_REVISION "2")
102 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
104 SET(EXPORT_DECL "")
105 SET(ALIGN_DECL "")
108 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
109 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
112 CHECK_C_COMPILER_FLAG(-std=c11 HAVE_STD_C11)
113 IF(HAVE_STD_C11)
114     SET(CMAKE_C_FLAGS "-std=c11 ${CMAKE_C_FLAGS}")
115 ELSE()
116     CHECK_C_COMPILER_FLAG(-std=c99 HAVE_STD_C99)
117     IF(HAVE_STD_C99)
118         SET(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
119     ENDIF()
120 ENDIF()
122 CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD_CXX11)
123 IF(HAVE_STD_CXX11)
124     SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
125 ENDIF()
127 if(NOT WIN32)
128     # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
129     CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
130     IF(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
131         SET(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
132         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=500")
133         CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
134         IF(NOT HAVE_POSIX_MEMALIGN_POSIX)
135             SET(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
136         ELSE()
137             ADD_DEFINITIONS(-D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=500)
138         ENDIF()
139     ENDIF()
140     UNSET(OLD_REQUIRED_FLAGS)
141 ENDIF()
143 # Set defines for large file support
144 CHECK_FILE_OFFSET_BITS()
145 IF(_FILE_OFFSET_BITS)
146     ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS})
147     SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
148 ENDIF()
149 ADD_DEFINITIONS(-D_LARGEFILE_SOURCE -D_LARGE_FILES)
150 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_LARGEFILE_SOURCE -D_LARGE_FILES")
152 # MSVC may need workarounds for C99 restrict and inline
153 IF(MSVC)
154     # TODO: Once we truly require C99, these restrict and inline checks should go
155     # away.
156     CHECK_C_SOURCE_COMPILES("int *restrict foo;
157                              int main() {return 0;}" HAVE_RESTRICT)
158     IF(NOT HAVE_RESTRICT)
159         ADD_DEFINITIONS("-Drestrict=")
160         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Drestrict=")
161     ENDIF()
163     CHECK_C_SOURCE_COMPILES("inline void foo(void) { }
164                              int main() {return 0;}" HAVE_INLINE)
165     IF(NOT HAVE_INLINE)
166         CHECK_C_SOURCE_COMPILES("__inline void foo(void) { }
167                                  int main() {return 0;}" HAVE___INLINE)
168         IF(NOT HAVE___INLINE)
169             MESSAGE(FATAL_ERROR "No inline keyword found, please report!")
170         ENDIF()
172         ADD_DEFINITIONS(-Dinline=__inline)
173         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Dinline=__inline")
174     ENDIF()
175 ENDIF()
177 # Make sure we have C99-style inline semantics with GCC (4.3 or newer).
178 IF(CMAKE_COMPILER_IS_GNUCC)
179     SET(CMAKE_C_FLAGS "-fno-gnu89-inline ${CMAKE_C_FLAGS}")
181     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
182     # Force no inlining for the next test.
183     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -fno-inline")
185     CHECK_C_SOURCE_COMPILES("extern inline int foo() { return 0; }
186                              int main() {return foo();}" INLINE_IS_C99)
187     IF(NOT INLINE_IS_C99)
188         MESSAGE(FATAL_ERROR "Your compiler does not seem to have C99 inline semantics!
189                              Please update your compiler for better C99 compliance.")
190     ENDIF()
192     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
193 ENDIF()
195 # Check if we have a proper timespec declaration
196 CHECK_STRUCT_HAS_MEMBER("struct timespec" tv_sec time.h HAVE_STRUCT_TIMESPEC)
197 IF(HAVE_STRUCT_TIMESPEC)
198     # Define it here so we don't have to include config.h for it
199     ADD_DEFINITIONS("-DHAVE_STRUCT_TIMESPEC")
200 ENDIF()
202 # Some systems may need libatomic for C11 atomic functions to work
203 SET(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
204 SET(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
205 CHECK_C_SOURCE_COMPILES("#include <stdatomic.h>
206 int _Atomic foo = ATOMIC_VAR_INIT(0);
207 int main()
209     return atomic_fetch_add(&foo, 2);
211 HAVE_LIBATOMIC)
212 IF(NOT HAVE_LIBATOMIC)
213     SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
214 ELSE()
215     SET(EXTRA_LIBS atomic ${EXTRA_LIBS})
216 ENDIF()
217 UNSET(OLD_REQUIRED_LIBRARIES)
219 # Include liblog for Android logging
220 CHECK_LIBRARY_EXISTS(log __android_log_print "" HAVE_LIBLOG)
221 IF(HAVE_LIBLOG)
222     SET(EXTRA_LIBS log ${EXTRA_LIBS})
223     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
224 ENDIF()
226 # Check if we have C99 variable length arrays
227 CHECK_C_SOURCE_COMPILES(
228 "int main(int argc, char *argv[])
230      volatile int tmp[argc];
231      tmp[0] = argv[0][0];
232      return tmp[0];
233  }"
234 HAVE_C99_VLA)
236 # Check if we have C99 bool
237 CHECK_C_SOURCE_COMPILES(
238 "int main(int argc, char *argv[])
240      volatile _Bool ret;
241      ret = (argc > 1) ? 1 : 0;
242      return ret ? -1 : 0;
243  }"
244 HAVE_C99_BOOL)
246 # Check if we have C11 static_assert
247 CHECK_C_SOURCE_COMPILES(
248 "int main()
250      _Static_assert(sizeof(int) == sizeof(int), \"What\");
251      return 0;
252  }"
253 HAVE_C11_STATIC_ASSERT)
255 # Check if we have C11 alignas
256 CHECK_C_SOURCE_COMPILES(
257 "_Alignas(16) int foo;
258  int main()
260      return 0;
261  }"
262 HAVE_C11_ALIGNAS)
264 # Check if we have C11 _Atomic
265 CHECK_C_SOURCE_COMPILES(
266 "#include <stdatomic.h>
267  const int _Atomic foo = ATOMIC_VAR_INIT(~0);
268  int _Atomic bar = ATOMIC_VAR_INIT(0);
269  int main()
271      atomic_fetch_add(&bar, 2);
272      return atomic_load(&foo);
273  }"
274 HAVE_C11_ATOMIC)
276 # Add definitions, compiler switches, etc.
277 INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_BINARY_DIR}")
278 IF(CMAKE_VERSION VERSION_LESS "2.8.8")
279     INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc")
280     IF(WIN32 AND ALSOFT_NO_UID_DEFS)
281         ADD_DEFINITIONS("-DAL_NO_UID_DEFS")
282     ENDIF()
283 ENDIF()
285 IF(NOT CMAKE_BUILD_TYPE)
286     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
287         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
288         FORCE)
289 ENDIF()
290 IF(NOT CMAKE_DEBUG_POSTFIX)
291     SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
292         "Library postfix for debug builds. Normally left blank."
293         FORCE)
294 ENDIF()
296 SET(EXTRA_CFLAGS "")
297 IF(MSVC)
298     ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
299     ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
300     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} /wd4098")
302     IF(NOT DXSDK_DIR)
303         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
304     ELSE()
305         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
306     ENDIF()
307     IF(DXSDK_DIR)
308         MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
309     ENDIF()
311     OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
312     IF(FORCE_STATIC_VCRT)
313         FOREACH(flag_var
314                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
315                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
316             IF(${flag_var} MATCHES "/MD")
317                 STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
318             ENDIF()
319         ENDFOREACH(flag_var)
320     ENDIF()
321 ELSE()
322     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Winline -Wall")
323     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
324     IF(HAVE_W_EXTRA)
325         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wextra")
326     ENDIF()
328     IF(ALSOFT_WERROR)
329         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror")
330     ENDIF()
332     # Force enable -fPIC for CMake versions before 2.8.9 (later versions have
333     # the POSITION_INDEPENDENT_CODE target property). The static common library
334     # will be linked into the dynamic OpenAL library, which requires all its
335     # code to be position-independent.
336     IF(CMAKE_VERSION VERSION_LESS "2.8.9" AND NOT WIN32)
337         CHECK_C_COMPILER_FLAG(-fPIC HAVE_FPIC_SWITCH)
338         IF(HAVE_FPIC_SWITCH)
339             SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC")
340         ENDIF()
341     ENDIF()
343     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
344     # instead of NDEBUG)
345     FOREACH(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
346         IF(${flag_var} MATCHES "-DNDEBUG")
347             STRING(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
348         ENDIF()
349     ENDFOREACH()
351     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
352                              int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
354     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
355     if(ALSOFT_STATIC_LIBGCC)
356         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
357         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
358         check_c_source_compiles(
359 "#include <stdlib.h>
360 int main()
362     return 0;
364             HAVE_STATIC_LIBGCC_SWITCH
365         )
366         if(HAVE_STATIC_LIBGCC_SWITCH)
367             set(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} -static-libgcc")
368         endif()
369         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
370         unset(OLD_REQUIRED_LIBRARIES)
371     endif()
372 ENDIF()
374 # Set visibility/export options if available
375 SET(HIDDEN_DECL "")
376 IF(WIN32)
377     SET(EXPORT_DECL "__declspec(dllexport)")
378     IF(NOT MINGW)
379         SET(ALIGN_DECL "__declspec(align(x))")
380     ELSE()
381         SET(ALIGN_DECL "__declspec(aligned(x))")
382     ENDIF()
383 ELSE()
384     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
385     # Yes GCC, really don't accept visibility modes you don't support
386     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
388     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
389                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
390     IF(HAVE_GCC_PROTECTED_VISIBILITY)
391         SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
392     ELSE()
393         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
394                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
395         IF(HAVE_GCC_DEFAULT_VISIBILITY)
396             SET(EXPORT_DECL "__attribute__((visibility(\"default\")))")
397         ENDIF()
398     ENDIF()
400     IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
401         CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
402         IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
403             SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
404             SET(HIDDEN_DECL "__attribute__((visibility(\"hidden\")))")
405         ENDIF()
406     ENDIF()
408     CHECK_C_SOURCE_COMPILES("int foo __attribute__((aligned(16)));
409                              int main() {return 0;}" HAVE_ATTRIBUTE_ALIGNED)
410     IF(HAVE_ATTRIBUTE_ALIGNED)
411         SET(ALIGN_DECL "__attribute__((aligned(x)))")
412     ENDIF()
414     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
415 ENDIF()
417 CHECK_C_SOURCE_COMPILES("
418 int main()
420     float *ptr;
421     ptr = __builtin_assume_aligned(ptr, 16);
422     return 0;
423 }" HAVE___BUILTIN_ASSUME_ALIGNED)
424 IF(HAVE___BUILTIN_ASSUME_ALIGNED)
425     SET(ASSUME_ALIGNED_DECL "__builtin_assume_aligned(x, y)")
426 ELSE()
427     SET(ASSUME_ALIGNED_DECL "x")
428 ENDIF()
430 SET(SSE_SWITCH "")
431 SET(SSE2_SWITCH "")
432 SET(SSE3_SWITCH "")
433 SET(SSE4_1_SWITCH "")
434 SET(FPU_NEON_SWITCH "")
435 IF(NOT MSVC)
436     CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
437     IF(HAVE_MSSE_SWITCH)
438         SET(SSE_SWITCH "-msse")
439     ENDIF()
440     CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
441     IF(HAVE_MSSE2_SWITCH)
442         SET(SSE2_SWITCH "-msse2")
443     ENDIF()
444     CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
445     IF(HAVE_MSSE3_SWITCH)
446         SET(SSE3_SWITCH "-msse3")
447     ENDIF()
448     CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
449     IF(HAVE_MSSE4_1_SWITCH)
450         SET(SSE4_1_SWITCH "-msse4.1")
451     ENDIF()
452     CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
453     IF(HAVE_MFPU_NEON_SWITCH)
454         SET(FPU_NEON_SWITCH "-mfpu=neon")
455     ENDIF()
456 ENDIF()
458 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
459                          int main() {return 0;}" HAVE_GCC_FORMAT)
461 CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
462 CHECK_INCLUDE_FILE(stdalign.h HAVE_STDALIGN_H)
463 CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
464 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
465 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
466 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
467 CHECK_INCLUDE_FILE(intrin.h HAVE_INTRIN_H)
468 CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
469 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
470 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
471 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
472 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
473 IF(NOT HAVE_GUIDDEF_H)
474     CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
475 ENDIF()
477 # Some systems need libm for some of the following math functions to work
478 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
479 IF(HAVE_LIBM)
480     SET(EXTRA_LIBS m ${EXTRA_LIBS})
481     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
482 ENDIF()
484 # Check for the dlopen API (for dynamicly loading backend libs)
485 IF(ALSOFT_DLOPEN)
486     CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
487     IF(HAVE_LIBDL)
488         SET(EXTRA_LIBS dl ${EXTRA_LIBS})
489         SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
490     ENDIF()
492     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
493 ENDIF()
495 # Check for a cpuid intrinsic
496 IF(HAVE_CPUID_H)
497     CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
498         int main()
499         {
500             unsigned int eax, ebx, ecx, edx;
501             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
502         }" HAVE_GCC_GET_CPUID)
503 ENDIF()
504 IF(HAVE_INTRIN_H)
505     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
506         int main()
507         {
508             int regs[4];
509             __cpuid(regs, 0);
510             return regs[0];
511         }" HAVE_CPUID_INTRINSIC)
512 ENDIF()
514 CHECK_SYMBOL_EXISTS(aligned_alloc    stdlib.h HAVE_ALIGNED_ALLOC)
515 CHECK_SYMBOL_EXISTS(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
516 CHECK_SYMBOL_EXISTS(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
517 CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
518 CHECK_SYMBOL_EXISTS(modff  math.h HAVE_MODFF)
519 IF(NOT HAVE_C99_VLA)
520     CHECK_SYMBOL_EXISTS(alloca malloc.h HAVE_ALLOCA)
521     IF(NOT HAVE_ALLOCA)
522         MESSAGE(FATAL_ERROR "No alloca function found, please report!")
523     ENDIF()
524 ENDIF()
526 IF(HAVE_FLOAT_H)
527     CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
528     CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
529 ENDIF()
531 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
532 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
533 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
534 IF(NOT HAVE_STRCASECMP)
535     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
536     IF(NOT HAVE__STRICMP)
537         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
538     ENDIF()
540     ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
541 ENDIF()
543 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
544 IF(NOT HAVE_STRNCASECMP)
545     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
546     IF(NOT HAVE__STRNICMP)
547         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
548     ENDIF()
550     ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
551 ENDIF()
553 CHECK_SYMBOL_EXISTS(strnlen string.h HAVE_STRNLEN)
554 CHECK_SYMBOL_EXISTS(snprintf stdio.h HAVE_SNPRINTF)
555 IF(NOT HAVE_SNPRINTF)
556     CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
557     IF(NOT HAVE__SNPRINTF)
558         MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
559     ENDIF()
561     ADD_DEFINITIONS(-Dsnprintf=_snprintf)
562 ENDIF()
564 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
565 IF(NOT HAVE_ISFINITE)
566     CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
567     IF(NOT HAVE_FINITE)
568         CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
569         IF(NOT HAVE__FINITE)
570             MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
571         ENDIF()
572         ADD_DEFINITIONS(-Disfinite=_finite)
573     ELSE()
574         ADD_DEFINITIONS(-Disfinite=finite)
575     ENDIF()
576 ENDIF()
578 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
579 IF(NOT HAVE_ISNAN)
580     CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
581     IF(NOT HAVE__ISNAN)
582         MESSAGE(FATAL_ERROR "No isnan function found, please report!")
583     ENDIF()
585     ADD_DEFINITIONS(-Disnan=_isnan)
586 ENDIF()
589 # Check if we have Windows headers
590 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0502)
591 IF(NOT HAVE_WINDOWS_H)
592     CHECK_SYMBOL_EXISTS(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
593     IF(NOT HAVE_GETTIMEOFDAY)
594         MESSAGE(FATAL_ERROR "No timing function found!")
595     ENDIF()
597     CHECK_SYMBOL_EXISTS(nanosleep time.h HAVE_NANOSLEEP)
598     IF(NOT HAVE_NANOSLEEP)
599         MESSAGE(FATAL_ERROR "No sleep function found!")
600     ENDIF()
602     # We need pthreads outside of Windows
603     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
604     IF(NOT HAVE_PTHREAD_H)
605         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
606     ENDIF()
607     # Some systems need pthread_np.h to get recursive mutexes
608     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
610     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
611     IF(HAVE_PTHREAD)
612         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pthread")
613         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
614         SET(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} -pthread")
615     ENDIF()
617     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
618     IF(HAVE_LIBPTHREAD)
619         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
620     ENDIF()
622     CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
624     IF(HAVE_PTHREAD_NP_H)
625         CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
626         IF(NOT HAVE_PTHREAD_SETNAME_NP)
627             CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
628         ELSE()
629             CHECK_C_SOURCE_COMPILES("
630 #include <pthread.h>
631 #include <pthread_np.h>
632 int main()
634     pthread_setname_np(\"testname\");
635     return 0;
637                 PTHREAD_SETNAME_NP_ONE_PARAM
638             )
639         ENDIF()
640         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np "pthread.h;pthread_np.h" HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
641     ELSE()
642         CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
643         IF(NOT HAVE_PTHREAD_SETNAME_NP)
644             CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
645         ELSE()
646             CHECK_C_SOURCE_COMPILES("
647 #include <pthread.h>
648 int main()
650     pthread_setname_np(\"testname\");
651     return 0;
653                 PTHREAD_SETNAME_NP_ONE_PARAM
654             )
655         ENDIF()
656         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np pthread.h HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
657     ENDIF()
659     CHECK_SYMBOL_EXISTS(pthread_mutex_timedlock pthread.h HAVE_PTHREAD_MUTEX_TIMEDLOCK)
661     CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
662     IF(HAVE_LIBRT)
663         SET(EXTRA_LIBS rt ${EXTRA_LIBS})
664     ENDIF()
665 ENDIF()
667 # Check for a 64-bit type
668 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
669 IF(NOT HAVE_STDINT_H)
670     IF(HAVE_WINDOWS_H)
671         CHECK_C_SOURCE_COMPILES("#define _WIN32_WINNT 0x0502
672                                  #include <windows.h>
673                                  __int64 foo;
674                                  int main() {return 0;}" HAVE___INT64)
675     ENDIF()
676     IF(NOT HAVE___INT64)
677         IF(NOT SIZEOF_LONG MATCHES "8")
678             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
679                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
680             ENDIF()
681         ENDIF()
682     ENDIF()
683 ENDIF()
686 SET(COMMON_OBJS  common/almalloc.c
687                  common/atomic.c
688                  common/rwlock.c
689                  common/threads.c
690                  common/uintmap.c
692 SET(OPENAL_OBJS  OpenAL32/alAuxEffectSlot.c
693                  OpenAL32/alBuffer.c
694                  OpenAL32/alEffect.c
695                  OpenAL32/alError.c
696                  OpenAL32/alExtension.c
697                  OpenAL32/alFilter.c
698                  OpenAL32/alListener.c
699                  OpenAL32/alSource.c
700                  OpenAL32/alState.c
701                  OpenAL32/alThunk.c
702                  OpenAL32/sample_cvt.c
704 SET(ALC_OBJS  Alc/ALc.c
705               Alc/ALu.c
706               Alc/alcConfig.c
707               Alc/alcRing.c
708               Alc/bs2b.c
709               Alc/effects/chorus.c
710               Alc/effects/compressor.c
711               Alc/effects/dedicated.c
712               Alc/effects/distortion.c
713               Alc/effects/echo.c
714               Alc/effects/equalizer.c
715               Alc/effects/flanger.c
716               Alc/effects/modulator.c
717               Alc/effects/null.c
718               Alc/effects/reverb.c
719               Alc/helpers.c
720               Alc/bsinc.c
721               Alc/hrtf.c
722               Alc/uhjfilter.c
723               Alc/ambdec.c
724               Alc/bformatdec.c
725               Alc/panning.c
726               Alc/mixer.c
727               Alc/mixer_c.c
731 SET(CPU_EXTS "Default")
732 SET(HAVE_SSE        0)
733 SET(HAVE_SSE2       0)
734 SET(HAVE_SSE3       0)
735 SET(HAVE_SSE4_1     0)
736 SET(HAVE_NEON       0)
738 SET(HAVE_ALSA       0)
739 SET(HAVE_OSS        0)
740 SET(HAVE_SOLARIS    0)
741 SET(HAVE_SNDIO      0)
742 SET(HAVE_QSA        0)
743 SET(HAVE_DSOUND     0)
744 SET(HAVE_MMDEVAPI   0)
745 SET(HAVE_WINMM      0)
746 SET(HAVE_PORTAUDIO  0)
747 SET(HAVE_PULSEAUDIO 0)
748 SET(HAVE_COREAUDIO  0)
749 SET(HAVE_OPENSL     0)
750 SET(HAVE_WAVE       0)
752 # Check for SSE support
753 OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
754 CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE_SWITCH}")
755 IF(HAVE_XMMINTRIN_H)
756     OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
757     IF(ALSOFT_CPUEXT_SSE)
758         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
759             SET(HAVE_SSE 1)
760             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse.c)
761             IF(SSE_SWITCH)
762                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse.c PROPERTIES
763                                             COMPILE_FLAGS "${SSE_SWITCH}")
764             ENDIF()
765             SET(CPU_EXTS "${CPU_EXTS}, SSE")
766         ENDIF()
767     ENDIF()
768 ENDIF()
769 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
770     MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
771 ENDIF()
773 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
774 CHECK_INCLUDE_FILE(emmintrin.h HAVE_EMMINTRIN_H "${SSE2_SWITCH}")
775 IF(HAVE_EMMINTRIN_H)
776     OPTION(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
777     IF(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
778         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
779             SET(HAVE_SSE2 1)
780             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse2.c)
781             IF(SSE2_SWITCH)
782                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse2.c PROPERTIES
783                                             COMPILE_FLAGS "${SSE2_SWITCH}")
784             ENDIF()
785             SET(CPU_EXTS "${CPU_EXTS}, SSE2")
786         ENDIF()
787     ENDIF()
788 ENDIF()
789 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
790     MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
791 ENDIF()
793 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE3 support" OFF)
794 CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}")
795 IF(HAVE_EMMINTRIN_H)
796     OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
797     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
798         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
799             SET(HAVE_SSE3 1)
800             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse3.c)
801             IF(SSE2_SWITCH)
802                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse3.c PROPERTIES
803                                             COMPILE_FLAGS "${SSE3_SWITCH}")
804             ENDIF()
805             SET(CPU_EXTS "${CPU_EXTS}, SSE3")
806         ENDIF()
807     ENDIF()
808 ENDIF()
809 IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
810     MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
811 ENDIF()
813 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
814 CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}")
815 IF(HAVE_SMMINTRIN_H)
816     OPTION(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
817     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE4_1)
818         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
819             SET(HAVE_SSE4_1 1)
820             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse41.c)
821             IF(SSE4_1_SWITCH)
822                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse41.c PROPERTIES
823                                             COMPILE_FLAGS "${SSE4_1_SWITCH}")
824             ENDIF()
825             SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
826         ENDIF()
827     ENDIF()
828 ENDIF()
829 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
830     MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
831 ENDIF()
833 # Check for ARM Neon support
834 OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
835 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H)
836 IF(HAVE_ARM_NEON_H)
837     OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
838     IF(ALSOFT_CPUEXT_NEON)
839         SET(HAVE_NEON 1)
840         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_neon.c)
841         IF(FPU_NEON_SWITCH)
842             SET_SOURCE_FILES_PROPERTIES(Alc/mixer_neon.c PROPERTIES
843                                         COMPILE_FLAGS "${FPU_NEON_SWITCH}")
844         ENDIF()
845         SET(CPU_EXTS "${CPU_EXTS}, Neon")
846     ENDIF()
847 ENDIF()
848 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
849     MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
850 ENDIF()
853 IF(WIN32 OR HAVE_DLFCN_H)
854     SET(IS_LINKED "")
855     MACRO(ADD_BACKEND_LIBS _LIBS)
856     ENDMACRO()
857 ELSE()
858     SET(IS_LINKED " (linked)")
859     MACRO(ADD_BACKEND_LIBS _LIBS)
860         SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
861     ENDMACRO()
862 ENDIF()
864 SET(BACKENDS "")
865 SET(ALC_OBJS  ${ALC_OBJS}
866               Alc/backends/base.c
867               # Default backends, always available
868               Alc/backends/loopback.c
869               Alc/backends/null.c
872 # Check ALSA backend
873 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
874 FIND_PACKAGE(ALSA)
875 IF(ALSA_FOUND)
876     OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
877     IF(ALSOFT_BACKEND_ALSA)
878         SET(HAVE_ALSA 1)
879         SET(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
880         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/alsa.c)
881         ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
882         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
883             INCLUDE_DIRECTORIES(${ALSA_INCLUDE_DIRS})
884         ENDIF()
885     ENDIF()
886 ENDIF()
887 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
888     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
889 ENDIF()
891 # Check OSS backend
892 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
893 FIND_PACKAGE(OSS)
894 IF(OSS_FOUND)
895     OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
896     IF(ALSOFT_BACKEND_OSS)
897         SET(HAVE_OSS 1)
898         SET(BACKENDS  "${BACKENDS} OSS,")
899         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/oss.c)
900         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
901             INCLUDE_DIRECTORIES(${OSS_INCLUDE_DIRS})
902         ENDIF()
903     ENDIF()
904 ENDIF()
905 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
906     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
907 ENDIF()
909 # Check Solaris backend
910 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
911 FIND_PACKAGE(AudioIO)
912 IF(AUDIOIO_FOUND)
913     OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
914     IF(ALSOFT_BACKEND_SOLARIS)
915         SET(HAVE_SOLARIS 1)
916         SET(BACKENDS  "${BACKENDS} Solaris,")
917         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/solaris.c)
918         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
919             INCLUDE_DIRECTORIES(${AUDIOIO_INCLUDE_DIRS})
920         ENDIF()
921     ENDIF()
922 ENDIF()
923 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
924     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
925 ENDIF()
927 # Check SndIO backend
928 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
929 FIND_PACKAGE(SoundIO)
930 IF(SOUNDIO_FOUND)
931     OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
932     IF(ALSOFT_BACKEND_SNDIO)
933         SET(HAVE_SNDIO 1)
934         SET(BACKENDS  "${BACKENDS} SndIO (linked),")
935         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sndio.c)
936         SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
937         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
938             INCLUDE_DIRECTORIES(${SOUNDIO_INCLUDE_DIRS})
939         ENDIF()
940     ENDIF()
941 ENDIF()
942 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
943     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
944 ENDIF()
946 # Check QSA backend
947 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
948 FIND_PACKAGE(QSA)
949 IF(QSA_FOUND)
950     OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
951     IF(ALSOFT_BACKEND_QSA)
952         SET(HAVE_QSA 1)
953         SET(BACKENDS  "${BACKENDS} QSA (linked),")
954         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/qsa.c)
955         SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
956         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
957             INCLUDE_DIRECTORIES(${QSA_INCLUDE_DIRS})
958         ENDIF()
959     ENDIF()
960 ENDIF()
961 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
962     MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
963 ENDIF()
965 # Check Windows-only backends
966 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
967 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
968 OPTION(ALSOFT_REQUIRE_MMDEVAPI "Require MMDevApi backend" OFF)
969 IF(HAVE_WINDOWS_H)
970     # Check MMSystem backend
971     CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0502)
972     IF(HAVE_MMSYSTEM_H)
973         CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
974         IF(HAVE_LIBWINMM)
975             OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
976             IF(ALSOFT_BACKEND_WINMM)
977                 SET(HAVE_WINMM 1)
978                 SET(BACKENDS  "${BACKENDS} WinMM,")
979                 SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/winmm.c)
980                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
981             ENDIF()
982         ENDIF()
983     ENDIF()
985     # Check DSound backend
986     FIND_PACKAGE(DSound)
987     IF(DSOUND_FOUND)
988         OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
989         IF(ALSOFT_BACKEND_DSOUND)
990             SET(HAVE_DSOUND 1)
991             SET(BACKENDS  "${BACKENDS} DirectSound${IS_LINKED},")
992             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/dsound.c)
993             ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
994             IF(CMAKE_VERSION VERSION_LESS "2.8.8")
995                 INCLUDE_DIRECTORIES(${DSOUND_INCLUDE_DIRS})
996             ENDIF()
997         ENDIF()
998     ENDIF()
1000     # Check for MMDevApi backend
1001     CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1002     IF(HAVE_MMDEVICEAPI_H)
1003         OPTION(ALSOFT_BACKEND_MMDEVAPI "Enable MMDevApi backend" ON)
1004         IF(ALSOFT_BACKEND_MMDEVAPI)
1005             SET(HAVE_MMDEVAPI 1)
1006             SET(BACKENDS  "${BACKENDS} MMDevApi,")
1007             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/mmdevapi.c)
1008         ENDIF()
1009     ENDIF()
1010 ENDIF()
1011 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1012     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
1013 ENDIF()
1014 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1015     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
1016 ENDIF()
1017 IF(ALSOFT_REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
1018     MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
1019 ENDIF()
1021 # Check PortAudio backend
1022 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1023 FIND_PACKAGE(PortAudio)
1024 IF(PORTAUDIO_FOUND)
1025     OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1026     IF(ALSOFT_BACKEND_PORTAUDIO)
1027         SET(HAVE_PORTAUDIO 1)
1028         SET(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
1029         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/portaudio.c)
1030         ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
1031         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
1032             INCLUDE_DIRECTORIES(${PORTAUDIO_INCLUDE_DIRS})
1033         ENDIF()
1034     ENDIF()
1035 ENDIF()
1036 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1037     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
1038 ENDIF()
1040 # Check PulseAudio backend
1041 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1042 FIND_PACKAGE(PulseAudio)
1043 IF(PULSEAUDIO_FOUND)
1044     OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1045     IF(ALSOFT_BACKEND_PULSEAUDIO)
1046         SET(HAVE_PULSEAUDIO 1)
1047         SET(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
1048         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/pulseaudio.c)
1049         ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
1050         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
1051             INCLUDE_DIRECTORIES(${PULSEAUDIO_INCLUDE_DIRS})
1052         ENDIF()
1053     ENDIF()
1054 ENDIF()
1055 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1056     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1057 ENDIF()
1059 # Check JACK backend
1060 OPTION(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1061 FIND_PACKAGE(JACK)
1062 IF(JACK_FOUND)
1063     OPTION(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1064     IF(ALSOFT_BACKEND_JACK)
1065         SET(HAVE_JACK 1)
1066         SET(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1067         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/jack.c)
1068         ADD_BACKEND_LIBS(${JACK_LIBRARIES})
1069         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
1070             INCLUDE_DIRECTORIES(${JACK_INCLUDE_DIRS})
1071         ENDIF()
1072     ENDIF()
1073 ENDIF()
1074 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1075     MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
1076 ENDIF()
1078 # Check CoreAudio backend
1079 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1080 FIND_LIBRARY(COREAUDIO_FRAMEWORK
1081              NAMES CoreAudio
1082              PATHS /System/Library/Frameworks
1084 IF(COREAUDIO_FRAMEWORK)
1085     OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1086     IF(ALSOFT_BACKEND_COREAUDIO)
1087         SET(HAVE_COREAUDIO 1)
1088         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/coreaudio.c)
1089         SET(BACKENDS  "${BACKENDS} CoreAudio,")
1090         SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
1091         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
1092         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1094         # Some versions of OSX may need the AudioToolbox framework. Add it if
1095         # it's found.
1096         FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
1097                      NAMES AudioToolbox
1098                      PATHS ~/Library/Frameworks
1099                            /Library/Frameworks
1100                            /System/Library/Frameworks
1101                     )
1102         IF(AUDIOTOOLBOX_LIBRARY)
1103             SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1104         ENDIF()
1105     ENDIF()
1106 ENDIF()
1107 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1108     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1109 ENDIF()
1111 # Check for OpenSL (Android) backend
1112 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1113 CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
1114 IF(HAVE_SLES_OPENSLES_ANDROID_H)
1115     CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
1116     IF(HAVE_LIBOPENSLES)
1117         OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1118         IF(ALSOFT_BACKEND_OPENSL)
1119             SET(HAVE_OPENSL 1)
1120             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/opensl.c)
1121             SET(BACKENDS  "${BACKENDS} OpenSL,")
1122             SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
1123         ENDIF()
1124     ENDIF()
1125 ENDIF()
1126 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1127     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1128 ENDIF()
1130 # Optionally enable the Wave Writer backend
1131 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1132 IF(ALSOFT_BACKEND_WAVE)
1133     SET(HAVE_WAVE 1)
1134     SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wave.c)
1135     SET(BACKENDS  "${BACKENDS} WaveFile,")
1136 ENDIF()
1138 # This is always available
1139 SET(BACKENDS  "${BACKENDS} Null")
1141 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" OFF)
1142 if(ALSOFT_EMBED_HRTF_DATA)
1143     if(WIN32)
1144         set(ALC_OBJS  ${ALC_OBJS} Alc/hrtf_res.rc)
1145     elseif(APPLE)
1146         macro(add_custom_binary FILENAME BIN_NAME)
1147             set(outfile ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${FILENAME}${CMAKE_C_OUTPUT_EXTENSION})
1148             set(stubsrcfile ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${FILENAME}.stub.c)
1149             set(stubfile ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${FILENAME}.stub${CMAKE_C_OUTPUT_EXTENSION})
1150             add_custom_command(OUTPUT ${outfile}
1151                 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hrtf/${FILENAME}"
1152                 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/hrtf"
1153                 COMMAND touch "${stubsrcfile}"
1154                 COMMAND "${CMAKE_C_COMPILER}" -o "${stubfile}" -c "${stubsrcfile}"
1155                 COMMAND "${CMAKE_LINKER}" -r -o "${outfile}" -sectcreate binary ${BIN_NAME} ${FILENAME} "${stubfile}"
1156                 COMMAND rm "${stubsrcfile}" "${stubfile}"
1157                 COMMENT "Generating ${FILENAME}${CMAKE_C_OUTPUT_EXTENSION}"
1158                 VERBATIM
1159             )
1160             set(ALC_OBJS  ${ALC_OBJS} ${outfile})
1161         endmacro()
1162         add_custom_binary(default-44100.mhr "default_44100")
1163         add_custom_binary(default-48000.mhr "default_48000")
1164     else()
1165         set(FILENAMES default-44100.mhr default-48000.mhr)
1166         foreach(FILENAME ${FILENAMES})
1167             set(outfile ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${FILENAME}${CMAKE_C_OUTPUT_EXTENSION})
1168             add_custom_command(OUTPUT ${outfile}
1169                 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hrtf/${FILENAME}"
1170                 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/hrtf"
1171                 COMMAND "${CMAKE_LINKER}" -r -b binary -o "${outfile}" ${FILENAME}
1172                 COMMAND "${CMAKE_OBJCOPY}" --rename-section .data=.rodata,alloc,load,readonly,data,contents "${outfile}" "${outfile}"
1173                 COMMENT "Generating ${FILENAME}${CMAKE_C_OUTPUT_EXTENSION}"
1174                 VERBATIM
1175             )
1176             set(ALC_OBJS  ${ALC_OBJS} ${outfile})
1177         endforeach()
1178         unset(outfile)
1179         unset(FILENAMES)
1180     endif()
1181 endif()
1184 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1185     add_subdirectory(utils/alsoft-config)
1186 ENDIF()
1187 IF(ALSOFT_EXAMPLES)
1188     FIND_PACKAGE(SDL2)
1189     IF(SDL2_FOUND)
1190         FIND_PACKAGE(SDL_sound)
1191         IF(SDL_SOUND_FOUND AND CMAKE_VERSION VERSION_LESS "2.8.8")
1192             INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1193         ENDIF()
1194         FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1195         IF(FFMPEG_FOUND AND CMAKE_VERSION VERSION_LESS "2.8.8")
1196             INCLUDE_DIRECTORIES(${FFMPEG_INCLUDE_DIRS})
1197         ENDIF()
1198     ENDIF()
1199 ENDIF()
1201 IF(LIBTYPE STREQUAL "STATIC")
1202     ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC)
1203     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
1204 ENDIF()
1206 FIND_PACKAGE(Git)
1207 IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1208     # Get the current working branch and its latest abbreviated commit hash
1209     ADD_CUSTOM_TARGET(build_version
1210         ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
1211                          -D LIB_VERSION=${LIB_VERSION}
1212                          -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1213                          -D DST=${OpenAL_BINARY_DIR}/version.h
1214                          -P ${OpenAL_SOURCE_DIR}/version.cmake
1215         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1216         VERBATIM
1217     )
1218 ELSE()
1219     SET(GIT_BRANCH "UNKNOWN")
1220     SET(GIT_COMMIT_HASH "unknown")
1221     CONFIGURE_FILE(
1222         "${OpenAL_SOURCE_DIR}/version.h.in"
1223         "${OpenAL_BINARY_DIR}/version.h")
1224 ENDIF()
1226 # Needed for openal.pc.in
1227 SET(prefix ${CMAKE_INSTALL_PREFIX})
1228 SET(exec_prefix "\${prefix}")
1229 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1230 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1231 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1232 SET(PACKAGE_VERSION "${LIB_VERSION}")
1234 # End configuration
1235 CONFIGURE_FILE(
1236     "${OpenAL_SOURCE_DIR}/config.h.in"
1237     "${OpenAL_BINARY_DIR}/config.h")
1238 CONFIGURE_FILE(
1239     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1240     "${OpenAL_BINARY_DIR}/openal.pc"
1241     @ONLY)
1243 # Build main library
1244 IF(LIBTYPE STREQUAL "STATIC")
1245     ADD_LIBRARY(OpenAL STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1246 ELSE()
1247     ADD_LIBRARY(OpenAL SHARED ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1248 ENDIF()
1249 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1250 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY COMPILE_DEFINITIONS AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES)
1251 IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1252     SET_PROPERTY(TARGET OpenAL APPEND PROPERTY COMPILE_DEFINITIONS AL_NO_UID_DEFS)
1253 ENDIF()
1254 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc")
1255 IF(HAVE_ALSA)
1256     SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${ALSA_INCLUDE_DIRS})
1257 ENDIF()
1258 IF(HAVE_OSS)
1259     SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${OSS_INCLUDE_DIRS})
1260 ENDIF()
1261 IF(HAVE_SOLARIS)
1262     SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${AUDIOIO_INCLUDE_DIRS})
1263 ENDIF()
1264 IF(HAVE_SNDIO)
1265     SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${SOUNDIO_INCLUDE_DIRS})
1266 ENDIF()
1267 IF(HAVE_QSA)
1268     SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${QSA_INCLUDE_DIRS})
1269 ENDIF()
1270 IF(HAVE_DSOUND)
1271     SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${DSOUND_INCLUDE_DIRS})
1272 ENDIF()
1273 IF(HAVE_PORTAUDIO)
1274     SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${PORTAUDIO_INCLUDE_DIRS})
1275 ENDIF()
1276 IF(HAVE_PULSEAUDIO)
1277     SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${PULSEAUDIO_INCLUDE_DIRS})
1278 ENDIF()
1279 IF(HAVE_JACK)
1280     SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${JACK_INCLUDE_DIRS})
1281 ENDIF()
1282 IF(WIN32)
1283     IF(MSVC)
1284         SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:WINDOWS")
1285     ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1286         SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS " -mwindows")
1287     ENDIF()
1288 ENDIF()
1290 SET_TARGET_PROPERTIES(OpenAL PROPERTIES VERSION ${LIB_VERSION}
1291                                         SOVERSION ${LIB_MAJOR_VERSION})
1292 IF(NOT WIN32)
1293     SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME "openal")
1294 ELSE()
1295     SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME "OpenAL32")
1296 ENDIF()
1298 if(WIN32 AND NOT LIBTYPE STREQUAL "STATIC")
1299     SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "")
1301     IF(MINGW AND ALSOFT_BUILD_IMPORT_LIB)
1302         FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1303         FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1304         IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1305             MESSAGE(STATUS "")
1306             IF(NOT SED_EXECUTABLE)
1307                 MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1308             ENDIF()
1309             IF(NOT DLLTOOL_EXECUTABLE)
1310                 MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1311             ENDIF()
1312         ELSE()
1313             SET(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} -Wl,--output-def,OpenAL32.def")
1314             ADD_CUSTOM_COMMAND(TARGET OpenAL POST_BUILD
1315                 COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1316                 COMMAND "${DLLTOOL_EXECUTABLE}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1317                 COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1318                 VERBATIM
1319             )
1320         ENDIF()
1321     ENDIF()
1322 ENDIF()
1324 SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS ${EXTRA_LDFLAGS})
1325 TARGET_LINK_LIBRARIES(OpenAL ${EXTRA_LIBS})
1326 IF(TARGET build_version)
1327     ADD_DEPENDENCIES(OpenAL build_version)
1328 ENDIF()
1330 IF(ALSOFT_INSTALL)
1331     # Add an install target here
1332     INSTALL(TARGETS OpenAL EXPORT OpenAL
1333             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1334             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1335             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1336             INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
1337     )
1338     EXPORT(TARGETS OpenAL
1339            NAMESPACE OpenAL::
1340            FILE OpenALConfig.cmake)
1341     INSTALL(EXPORT OpenAL
1342             DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1343             NAMESPACE OpenAL::
1344             FILE OpenALConfig.cmake)
1345     INSTALL(FILES include/AL/al.h
1346                   include/AL/alc.h
1347                   include/AL/alext.h
1348                   include/AL/efx.h
1349                   include/AL/efx-creative.h
1350                   include/AL/efx-presets.h
1351             DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
1352     )
1353     INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1354             DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1355 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/rectangle.ambdec
1404                   presets/square.ambdec
1405                   presets/presets.txt
1406             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
1407     )
1408     MESSAGE(STATUS "Installing AmbDec presets")
1409     MESSAGE(STATUS "")
1410 ENDIF()
1412 IF(ALSOFT_UTILS)
1413     ADD_EXECUTABLE(openal-info utils/openal-info.c)
1414     SET_PROPERTY(TARGET openal-info APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1415     TARGET_LINK_LIBRARIES(openal-info OpenAL)
1417     ADD_EXECUTABLE(makehrtf utils/makehrtf.c)
1418     SET_PROPERTY(TARGET makehrtf APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1419     IF(HAVE_LIBM)
1420         TARGET_LINK_LIBRARIES(makehrtf m)
1421     ENDIF()
1423     ADD_EXECUTABLE(bsincgen utils/bsincgen.c)
1424     SET_PROPERTY(TARGET bsincgen APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1425     IF(HAVE_LIBM)
1426         TARGET_LINK_LIBRARIES(bsincgen m)
1427     ENDIF()
1429     IF(ALSOFT_INSTALL)
1430         INSTALL(TARGETS openal-info makehrtf bsincgen
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     ADD_LIBRARY(test-common STATIC examples/common/alhelpers.c)
1446     SET_PROPERTY(TARGET test-common APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1448     ADD_EXECUTABLE(altonegen examples/altonegen.c ${COMMON_OBJS})
1449     TARGET_LINK_LIBRARIES(altonegen test-common OpenAL)
1450     SET_PROPERTY(TARGET altonegen APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
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     IF(SDL2_FOUND)
1466         IF(SDL_SOUND_FOUND)
1467             ADD_LIBRARY(ex-common STATIC examples/common/alhelpers.c)
1468             SET_PROPERTY(TARGET ex-common APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1470             ADD_EXECUTABLE(alstream examples/alstream.c ${COMMON_OBJS})
1471             TARGET_LINK_LIBRARIES(alstream ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1472                                            OpenAL)
1473             SET_PROPERTY(TARGET alstream APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1474             SET_PROPERTY(TARGET alstream APPEND PROPERTY
1475                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1476             )
1478             ADD_EXECUTABLE(alreverb examples/alreverb.c ${COMMON_OBJS})
1479             TARGET_LINK_LIBRARIES(alreverb ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1480                                            OpenAL)
1481             SET_PROPERTY(TARGET alreverb APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1482             SET_PROPERTY(TARGET alreverb APPEND PROPERTY
1483                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1484             )
1486             ADD_EXECUTABLE(allatency examples/allatency.c ${COMMON_OBJS})
1487             TARGET_LINK_LIBRARIES(allatency ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1488                                             OpenAL)
1489             SET_PROPERTY(TARGET allatency APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1490             SET_PROPERTY(TARGET allatency APPEND PROPERTY
1491                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1492             )
1494             ADD_EXECUTABLE(alloopback examples/alloopback.c ${COMMON_OBJS})
1495             TARGET_LINK_LIBRARIES(alloopback ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1496                                              OpenAL)
1497             SET_PROPERTY(TARGET alloopback APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1498             SET_PROPERTY(TARGET alloopback APPEND PROPERTY
1499                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1500             )
1502             ADD_EXECUTABLE(alhrtf examples/alhrtf.c ${COMMON_OBJS})
1503             TARGET_LINK_LIBRARIES(alhrtf ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1504                                          OpenAL)
1505             SET_PROPERTY(TARGET alhrtf APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1506             SET_PROPERTY(TARGET alhrtf APPEND PROPERTY
1507                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1508             )
1510             IF(ALSOFT_INSTALL)
1511                 INSTALL(TARGETS alstream alreverb allatency alloopback alhrtf
1512                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1513                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1514                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1515                 )
1516             ENDIF()
1518             MESSAGE(STATUS "Building SDL_sound example programs")
1519         ENDIF()
1521         SET(FFVER_OK FALSE)
1522         IF(FFMPEG_FOUND)
1523             SET(FFVER_OK TRUE)
1524             IF(AVFORMAT_VERSION VERSION_LESS "55.33.100")
1525                 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 55.33.100)")
1526                 SET(FFVER_OK FALSE)
1527             ENDIF()
1528             IF(AVCODEC_VERSION VERSION_LESS "55.52.102")
1529                 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 55.52.102)")
1530                 SET(FFVER_OK FALSE)
1531             ENDIF()
1532             IF(AVUTIL_VERSION VERSION_LESS "52.66.100")
1533                 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 52.66.100)")
1534                 SET(FFVER_OK FALSE)
1535             ENDIF()
1536             IF(SWSCALE_VERSION VERSION_LESS "2.5.102")
1537                 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 2.5.102)")
1538                 SET(FFVER_OK FALSE)
1539             ENDIF()
1540             IF(SWRESAMPLE_VERSION VERSION_LESS "0.18.100")
1541                 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 0.18.100)")
1542                 SET(FFVER_OK FALSE)
1543             ENDIF()
1544         ENDIF()
1545         IF(FFVER_OK AND NOT MSVC)
1546             ADD_EXECUTABLE(alffplay examples/alffplay.c ${COMMON_OBJS})
1547             TARGET_LINK_LIBRARIES(alffplay ${SDL2_LIBRARY} OpenAL ${FFMPEG_LIBRARIES})
1548             SET_PROPERTY(TARGET alffplay APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1549             SET_PROPERTY(TARGET alffplay APPEND PROPERTY
1550                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS}
1551             )
1553             IF(ALSOFT_INSTALL)
1554                 INSTALL(TARGETS alffplay
1555                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1556                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1557                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1558                 )
1559             ENDIF()
1560             MESSAGE(STATUS "Building SDL+FFmpeg example programs")
1561         ENDIF()
1562         MESSAGE(STATUS "")
1563     ENDIF()
1564 ENDIF()