1 # CMake build file list for OpenAL
3 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5)
7 IF(COMMAND CMAKE_POLICY)
8 CMAKE_POLICY(SET CMP0003 NEW)
9 CMAKE_POLICY(SET CMP0005 NEW)
11 CMAKE_POLICY(SET CMP0042 NEW)
14 CMAKE_POLICY(SET CMP0054 NEW)
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}")
57 if(DEFINED LIB_SUFFIX)
58 message(WARNING "LIB_SUFFIX is deprecated. Use the variables provided by the GNUInstallDirs module instead")
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)
74 OPTION(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
77 SET(DLLTOOL "${HOST}-dlltool")
79 SET(DLLTOOL "dlltool")
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)
96 SET(LIB_MAJOR_VERSION "1")
97 SET(LIB_MINOR_VERSION "17")
99 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
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)
111 SET(CMAKE_C_FLAGS "-std=c11 ${CMAKE_C_FLAGS}")
113 CHECK_C_COMPILER_FLAG(-std=c99 HAVE_STD_C99)
115 SET(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
119 CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD_CXX11)
121 SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
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})
134 ADD_DEFINITIONS(-D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=500)
137 UNSET(OLD_REQUIRED_FLAGS)
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}")
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
151 # TODO: Once we truly require C99, these restrict and inline checks should go
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=")
160 CHECK_C_SOURCE_COMPILES("inline void foo(void) { }
161 int main() {return 0;}" 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!")
169 ADD_DEFINITIONS(-Dinline=__inline)
170 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Dinline=__inline")
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.")
189 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
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")
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);
206 return atomic_fetch_add(&foo, 2);
209 IF(NOT HAVE_LIBATOMIC)
210 SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
212 SET(EXTRA_LIBS atomic ${EXTRA_LIBS})
214 UNSET(OLD_REQUIRED_LIBRARIES)
216 # Include liblog for Android logging
217 CHECK_LIBRARY_EXISTS(log __android_log_print "" HAVE_LIBLOG)
219 SET(EXTRA_LIBS log ${EXTRA_LIBS})
220 SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
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];
233 # Check if we have C99 bool
234 CHECK_C_SOURCE_COMPILES(
235 "int main(int argc, char *argv[])
238 ret = (argc > 1) ? 1 : 0;
243 # Check if we have C11 static_assert
244 CHECK_C_SOURCE_COMPILES(
247 _Static_assert(sizeof(int) == sizeof(int), \"What\");
250 HAVE_C11_STATIC_ASSERT)
252 # Check if we have C11 alignas
253 CHECK_C_SOURCE_COMPILES(
254 "_Alignas(16) int foo;
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);
268 atomic_fetch_add(&bar, 2);
269 return atomic_load(&foo);
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")
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."
287 IF(NOT CMAKE_DEBUG_POSTFIX)
288 SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
289 "Library postfix for debug builds. Normally left blank."
295 ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
296 ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
297 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} /wd4098")
300 STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
302 STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
305 MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
308 OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
309 IF(FORCE_STATIC_VCRT)
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}}")
319 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Winline -Wall")
320 CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
322 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wextra")
326 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror")
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)
336 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC")
340 # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
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}}")
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(
361 HAVE_STATIC_LIBGCC_SWITCH
363 if(HAVE_STATIC_LIBGCC_SWITCH)
364 set(EXTRA_LIBS ${EXTRA_LIBS} -static-libgcc)
366 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
367 unset(OLD_REQUIRED_LIBRARIES)
371 # Set visibility/export options if available
374 SET(EXPORT_DECL "__declspec(dllexport)")
376 SET(ALIGN_DECL "__declspec(align(x))")
378 SET(ALIGN_DECL "__declspec(aligned(x))")
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\")))")
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\")))")
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\")))")
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)))")
411 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
414 CHECK_C_SOURCE_COMPILES("
418 ptr = __builtin_assume_aligned(ptr, 16);
420 }" HAVE___BUILTIN_ASSUME_ALIGNED)
421 IF(HAVE___BUILTIN_ASSUME_ALIGNED)
422 SET(ASSUME_ALIGNED_DECL "__builtin_assume_aligned(x, y)")
424 SET(ASSUME_ALIGNED_DECL "x")
430 SET(SSE4_1_SWITCH "")
431 SET(FPU_NEON_SWITCH "")
433 CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
435 SET(SSE_SWITCH "-msse")
437 CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
438 IF(HAVE_MSSE2_SWITCH)
439 SET(SSE2_SWITCH "-msse2")
441 CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
442 IF(HAVE_MSSE3_SWITCH)
443 SET(SSE3_SWITCH "-msse3")
445 CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
446 IF(HAVE_MSSE4_1_SWITCH)
447 SET(SSE4_1_SWITCH "-msse4.1")
449 CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
450 IF(HAVE_MFPU_NEON_SWITCH)
451 SET(FPU_NEON_SWITCH "-mfpu=neon")
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)
474 # Some systems need libm for some of the following math functions to work
475 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
477 SET(EXTRA_LIBS m ${EXTRA_LIBS})
478 SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
481 # Check for the dlopen API (for dynamicly loading backend libs)
483 CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
485 SET(EXTRA_LIBS dl ${EXTRA_LIBS})
486 SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
489 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
492 # Check for a cpuid intrinsic
494 CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
497 unsigned int eax, ebx, ecx, edx;
498 return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
499 }" HAVE_GCC_GET_CPUID)
502 CHECK_C_SOURCE_COMPILES("#include <intrin.h>
508 }" HAVE_CPUID_INTRINSIC)
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)
517 CHECK_SYMBOL_EXISTS(alloca malloc.h HAVE_ALLOCA)
519 MESSAGE(FATAL_ERROR "No alloca function found, please report!")
524 CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
525 CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
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!")
537 ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
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!")
547 ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
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!")
558 ADD_DEFINITIONS(-Dsnprintf=_snprintf)
561 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
562 IF(NOT HAVE_ISFINITE)
563 CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
565 CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
567 MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
569 ADD_DEFINITIONS(-Disfinite=_finite)
571 ADD_DEFINITIONS(-Disfinite=finite)
575 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
577 CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
579 MESSAGE(FATAL_ERROR "No isnan function found, please report!")
582 ADD_DEFINITIONS(-Disnan=_isnan)
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!")
594 CHECK_SYMBOL_EXISTS(nanosleep time.h HAVE_NANOSLEEP)
595 IF(NOT HAVE_NANOSLEEP)
596 MESSAGE(FATAL_ERROR "No sleep function found!")
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!")
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)
609 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pthread")
610 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
611 SET(EXTRA_LIBS ${EXTRA_LIBS} -pthread)
614 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
616 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
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)
626 CHECK_C_SOURCE_COMPILES("
628 #include <pthread_np.h>
631 pthread_setname_np(\"testname\");
634 PTHREAD_SETNAME_NP_ONE_PARAM
637 CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np "pthread.h;pthread_np.h" HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
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)
643 CHECK_C_SOURCE_COMPILES("
647 pthread_setname_np(\"testname\");
650 PTHREAD_SETNAME_NP_ONE_PARAM
653 CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np pthread.h HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
656 CHECK_SYMBOL_EXISTS(pthread_mutex_timedlock pthread.h HAVE_PTHREAD_MUTEX_TIMEDLOCK)
658 CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
660 SET(EXTRA_LIBS rt ${EXTRA_LIBS})
664 # Check for a 64-bit type
665 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
666 IF(NOT HAVE_STDINT_H)
668 CHECK_C_SOURCE_COMPILES("#define _WIN32_WINNT 0x0502
671 int main() {return 0;}" 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!")
683 SET(COMMON_OBJS common/almalloc.c
689 SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
693 OpenAL32/alExtension.c
695 OpenAL32/alListener.c
699 OpenAL32/sample_cvt.c
701 SET(ALC_OBJS Alc/ALc.c
707 Alc/effects/compressor.c
708 Alc/effects/dedicated.c
709 Alc/effects/distortion.c
711 Alc/effects/equalizer.c
712 Alc/effects/flanger.c
713 Alc/effects/modulator.c
728 SET(CPU_EXTS "Default")
743 SET(HAVE_PORTAUDIO 0)
744 SET(HAVE_PULSEAUDIO 0)
745 SET(HAVE_COREAUDIO 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}")
753 OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
754 IF(ALSOFT_CPUEXT_SSE)
755 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
757 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse.c)
759 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse.c PROPERTIES
760 COMPILE_FLAGS "${SSE_SWITCH}")
762 SET(CPU_EXTS "${CPU_EXTS}, SSE")
766 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
767 MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
770 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
771 CHECK_INCLUDE_FILE(emmintrin.h HAVE_EMMINTRIN_H "${SSE2_SWITCH}")
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)
777 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse2.c)
779 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse2.c PROPERTIES
780 COMPILE_FLAGS "${SSE2_SWITCH}")
782 SET(CPU_EXTS "${CPU_EXTS}, SSE2")
786 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
787 MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
790 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE3 support" OFF)
791 CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}")
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)
797 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse3.c)
799 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse3.c PROPERTIES
800 COMPILE_FLAGS "${SSE3_SWITCH}")
802 SET(CPU_EXTS "${CPU_EXTS}, SSE3")
806 IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
807 MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
810 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
811 CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}")
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)
817 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse41.c)
819 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse41.c PROPERTIES
820 COMPILE_FLAGS "${SSE4_1_SWITCH}")
822 SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
826 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
827 MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
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)
834 OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
835 IF(ALSOFT_CPUEXT_NEON)
837 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_neon.c)
839 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_neon.c PROPERTIES
840 COMPILE_FLAGS "${FPU_NEON_SWITCH}")
842 SET(CPU_EXTS "${CPU_EXTS}, Neon")
845 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
846 MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
850 IF(WIN32 OR HAVE_DLFCN_H)
852 MACRO(ADD_BACKEND_LIBS _LIBS)
855 SET(IS_LINKED " (linked)")
856 MACRO(ADD_BACKEND_LIBS _LIBS)
857 SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
862 SET(ALC_OBJS ${ALC_OBJS}
864 # Default backends, always available
865 Alc/backends/loopback.c
870 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
873 OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
874 IF(ALSOFT_BACKEND_ALSA)
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})
884 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
885 MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
889 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
892 OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
893 IF(ALSOFT_BACKEND_OSS)
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})
902 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
903 MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
906 # Check Solaris backend
907 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
908 FIND_PACKAGE(AudioIO)
910 OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
911 IF(ALSOFT_BACKEND_SOLARIS)
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})
920 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
921 MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
924 # Check SndIO backend
925 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
926 FIND_PACKAGE(SoundIO)
928 OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
929 IF(ALSOFT_BACKEND_SNDIO)
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})
939 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
940 MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
944 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
947 OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
948 IF(ALSOFT_BACKEND_QSA)
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})
958 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
959 MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
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)
967 # Check MMSystem backend
968 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0502)
970 CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
972 OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
973 IF(ALSOFT_BACKEND_WINMM)
975 SET(BACKENDS "${BACKENDS} WinMM,")
976 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/winmm.c)
977 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
982 # Check DSound backend
985 OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
986 IF(ALSOFT_BACKEND_DSOUND)
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})
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)
1008 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1009 MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
1011 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1012 MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
1014 IF(ALSOFT_REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
1015 MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
1018 # Check PortAudio backend
1019 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1020 FIND_PACKAGE(PortAudio)
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})
1033 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1034 MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
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})
1052 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1053 MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1056 # Check JACK backend
1057 OPTION(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1060 OPTION(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1061 IF(ALSOFT_BACKEND_JACK)
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})
1071 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1072 MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
1075 # Check CoreAudio backend
1076 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1077 FIND_LIBRARY(COREAUDIO_FRAMEWORK
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
1093 FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
1095 PATHS ~/Library/Frameworks
1097 /System/Library/Frameworks
1099 IF(AUDIOTOOLBOX_LIBRARY)
1100 SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1104 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1105 MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
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)
1117 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/opensl.c)
1118 SET(BACKENDS "${BACKENDS} OpenSL,")
1119 SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
1123 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1124 MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1127 # Optionally enable the Wave Writer backend
1128 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1129 IF(ALSOFT_BACKEND_WAVE)
1131 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/wave.c)
1132 SET(BACKENDS "${BACKENDS} WaveFile,")
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)
1141 set(ALC_OBJS ${ALC_OBJS} Alc/hrtf_res.rc)
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}"
1157 set(ALC_OBJS ${ALC_OBJS} ${outfile})
1159 add_custom_binary(default-44100.mhr "default_44100")
1160 add_custom_binary(default-48000.mhr "default_48000")
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}"
1173 set(ALC_OBJS ${ALC_OBJS} ${outfile})
1181 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1182 add_subdirectory(utils/alsoft-config)
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})
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})
1198 IF(LIBTYPE STREQUAL "STATIC")
1199 ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC)
1200 SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
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}"
1216 SET(GIT_BRANCH "UNKNOWN")
1217 SET(GIT_COMMIT_HASH "unknown")
1219 "${OpenAL_SOURCE_DIR}/version.h.in"
1220 "${OpenAL_BINARY_DIR}/version.h")
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}")
1233 "${OpenAL_SOURCE_DIR}/config.h.in"
1234 "${OpenAL_BINARY_DIR}/config.h")
1236 "${OpenAL_SOURCE_DIR}/openal.pc.in"
1237 "${OpenAL_BINARY_DIR}/openal.pc"
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)
1247 # Build main library
1248 IF(LIBTYPE STREQUAL "STATIC")
1249 ADD_LIBRARY(${LIBNAME} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1251 ADD_LIBRARY(${LIBNAME} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
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)
1258 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc")
1260 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${ALSA_INCLUDE_DIRS})
1263 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${OSS_INCLUDE_DIRS})
1266 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${AUDIOIO_INCLUDE_DIRS})
1269 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${SOUNDIO_INCLUDE_DIRS})
1272 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${QSA_INCLUDE_DIRS})
1275 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${DSOUND_INCLUDE_DIRS})
1278 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${PORTAUDIO_INCLUDE_DIRS})
1281 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${PULSEAUDIO_INCLUDE_DIRS})
1284 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${JACK_INCLUDE_DIRS})
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")
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)
1304 IF(NOT SED_EXECUTABLE)
1305 MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1307 IF(NOT DLLTOOL_EXECUTABLE)
1308 MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
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..."
1322 TARGET_LINK_LIBRARIES(${LIBNAME} common ${EXTRA_LIBS})
1323 IF(TARGET build_version)
1324 ADD_DEPENDENCIES(${LIBNAME} build_version)
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}
1334 INSTALL(FILES include/AL/al.h
1338 include/AL/efx-creative.h
1339 include/AL/efx-presets.h
1340 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
1342 INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1343 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1348 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1349 MESSAGE(STATUS " ${BACKENDS}")
1351 MESSAGE(STATUS "Building with support for CPU extensions:")
1352 MESSAGE(STATUS " ${CPU_EXTS}")
1357 MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
1358 MESSAGE(STATUS " This is probably NOT what you want!")
1363 if(ALSOFT_EMBED_HRTF_DATA)
1364 message(STATUS "Embedding HRTF datasets")
1368 # Install alsoft.conf configuration file
1370 INSTALL(FILES alsoftrc.sample
1371 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal
1373 MESSAGE(STATUS "Installing sample configuration")
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
1383 MESSAGE(STATUS "Installing HRTF definitions")
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
1395 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
1397 MESSAGE(STATUS "Installing AmbDec presets")
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})
1409 TARGET_LINK_LIBRARIES(makehrtf m)
1412 ADD_EXECUTABLE(bsincgen utils/bsincgen.c)
1413 SET_PROPERTY(TARGET bsincgen APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1415 TARGET_LINK_LIBRARIES(bsincgen m)
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}
1426 MESSAGE(STATUS "Building utility programs")
1427 IF(TARGET alsoft-config)
1428 MESSAGE(STATUS "Building configuration program")
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})
1442 INSTALL(TARGETS altonegen
1443 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1444 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1445 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1449 MESSAGE(STATUS "Building test programs")
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}
1463 ADD_EXECUTABLE(alstream examples/alstream.c)
1464 TARGET_LINK_LIBRARIES(alstream ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
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}
1471 ADD_EXECUTABLE(alreverb examples/alreverb.c)
1472 TARGET_LINK_LIBRARIES(alreverb ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
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}
1479 ADD_EXECUTABLE(allatency examples/allatency.c)
1480 TARGET_LINK_LIBRARIES(allatency ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
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}
1487 ADD_EXECUTABLE(alloopback examples/alloopback.c)
1488 TARGET_LINK_LIBRARIES(alloopback ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
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}
1495 ADD_EXECUTABLE(alhrtf examples/alhrtf.c)
1496 TARGET_LINK_LIBRARIES(alhrtf ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
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}
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}
1511 MESSAGE(STATUS "Building SDL_sound example programs")
1517 IF(AVFORMAT_VERSION VERSION_LESS "55.33.100")
1518 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 55.33.100)")
1521 IF(AVCODEC_VERSION VERSION_LESS "55.52.102")
1522 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 55.52.102)")
1525 IF(AVUTIL_VERSION VERSION_LESS "52.66.100")
1526 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 52.66.100)")
1529 IF(SWSCALE_VERSION VERSION_LESS "2.5.102")
1530 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 2.5.102)")
1533 IF(SWRESAMPLE_VERSION VERSION_LESS "0.18.100")
1534 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 0.18.100)")
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}
1547 INSTALL(TARGETS alffplay
1548 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1549 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1550 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1553 MESSAGE(STATUS "Building SDL+FFmpeg example programs")