1 # CMake build file list for OpenAL
3 CMAKE_MINIMUM_REQUIRED(VERSION 3.0.2)
7 IF(COMMAND CMAKE_POLICY)
8 CMAKE_POLICY(SET CMP0003 NEW)
9 CMAKE_POLICY(SET CMP0005 NEW)
11 CMAKE_POLICY(SET CMP0020 NEW)
14 CMAKE_POLICY(SET CMP0042 NEW)
17 CMAKE_POLICY(SET CMP0054 NEW)
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)
41 OPTION(ALSOFT_BUILD_ROUTER "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)" OFF)
44 OPTION(ALSOFT_DLOPEN "Check for the dlopen API for loading optional libs" ON)
46 OPTION(ALSOFT_WERROR "Treat compile warnings as errors" OFF)
48 OPTION(ALSOFT_UTILS "Build and install utility programs" ON)
49 OPTION(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
51 OPTION(ALSOFT_EXAMPLES "Build and install example programs" ON)
52 OPTION(ALSOFT_TESTS "Build and install test programs" ON)
54 OPTION(ALSOFT_CONFIG "Install alsoft.conf sample configuration file" ON)
55 OPTION(ALSOFT_HRTF_DEFS "Install HRTF definition files" ON)
56 OPTION(ALSOFT_AMBDEC_PRESETS "Install AmbDec preset files" ON)
57 OPTION(ALSOFT_INSTALL "Install headers and libraries" ON)
59 if(DEFINED SHARE_INSTALL_DIR)
60 message(WARNING "SHARE_INSTALL_DIR is deprecated. Use the variables provided by the GNUInstallDirs module instead")
61 set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
64 if(DEFINED LIB_SUFFIX)
65 message(WARNING "LIB_SUFFIX is deprecated. Use the variables provided by the GNUInstallDirs module instead")
70 ADD_DEFINITIONS("-D_WIN32 -D_WIN32_WINNT=0x0502")
72 # This option is mainly for static linking OpenAL Soft into another project
73 # that already defines the IDs. It is up to that project to ensure all
74 # required IDs are defined.
75 OPTION(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
78 OPTION(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
81 SET(DLLTOOL "${HOST}-dlltool")
83 SET(DLLTOOL "dlltool")
93 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
94 IF ("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
95 ADD_DEFINITIONS("-I/usr/include")
96 SET(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} -L/usr/lib")
103 SET(LIB_MAJOR_VERSION "1")
104 SET(LIB_MINOR_VERSION "18")
105 SET(LIB_REVISION "0")
106 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
112 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
113 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
116 CHECK_C_COMPILER_FLAG(-std=c11 HAVE_STD_C11)
118 SET(CMAKE_C_FLAGS "-std=c11 ${CMAKE_C_FLAGS}")
120 CHECK_C_COMPILER_FLAG(-std=c99 HAVE_STD_C99)
122 SET(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
126 CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD_CXX11)
128 SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
132 # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
133 CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
134 IF(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
135 SET(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
136 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
137 CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
138 IF(NOT HAVE_POSIX_MEMALIGN_POSIX)
139 SET(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
141 ADD_DEFINITIONS(-D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600)
144 UNSET(OLD_REQUIRED_FLAGS)
147 # Set defines for large file support
148 CHECK_FILE_OFFSET_BITS()
149 IF(_FILE_OFFSET_BITS)
150 ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS})
151 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
153 ADD_DEFINITIONS(-D_LARGEFILE_SOURCE -D_LARGE_FILES)
154 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_LARGEFILE_SOURCE -D_LARGE_FILES")
156 # MSVC may need workarounds for C99 restrict and inline
158 # TODO: Once we truly require C99, these restrict and inline checks should go
160 CHECK_C_SOURCE_COMPILES("int *restrict foo;
161 int main() {return 0;}" HAVE_RESTRICT)
162 IF(NOT HAVE_RESTRICT)
163 ADD_DEFINITIONS("-Drestrict=")
164 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Drestrict=")
167 CHECK_C_SOURCE_COMPILES("inline void foo(void) { }
168 int main() {return 0;}" HAVE_INLINE)
170 CHECK_C_SOURCE_COMPILES("__inline void foo(void) { }
171 int main() {return 0;}" HAVE___INLINE)
172 IF(NOT HAVE___INLINE)
173 MESSAGE(FATAL_ERROR "No inline keyword found, please report!")
176 ADD_DEFINITIONS(-Dinline=__inline)
177 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Dinline=__inline")
181 # Make sure we have C99-style inline semantics with GCC (4.3 or newer).
182 IF(CMAKE_COMPILER_IS_GNUCC)
183 SET(CMAKE_C_FLAGS "-fno-gnu89-inline ${CMAKE_C_FLAGS}")
185 SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
186 # Force no inlining for the next test.
187 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -fno-inline")
189 CHECK_C_SOURCE_COMPILES("extern inline int foo() { return 0; }
190 int main() {return foo();}" INLINE_IS_C99)
191 IF(NOT INLINE_IS_C99)
192 MESSAGE(FATAL_ERROR "Your compiler does not seem to have C99 inline semantics!
193 Please update your compiler for better C99 compliance.")
196 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
199 # Check if we have a proper timespec declaration
200 CHECK_STRUCT_HAS_MEMBER("struct timespec" tv_sec time.h HAVE_STRUCT_TIMESPEC)
201 IF(HAVE_STRUCT_TIMESPEC)
202 # Define it here so we don't have to include config.h for it
203 ADD_DEFINITIONS("-DHAVE_STRUCT_TIMESPEC")
206 # Some systems may need libatomic for C11 atomic functions to work
207 SET(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
208 SET(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
209 CHECK_C_SOURCE_COMPILES("#include <stdatomic.h>
210 int _Atomic foo = ATOMIC_VAR_INIT(0);
213 return atomic_fetch_add(&foo, 2);
216 IF(NOT HAVE_LIBATOMIC)
217 SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
219 SET(EXTRA_LIBS atomic ${EXTRA_LIBS})
221 UNSET(OLD_REQUIRED_LIBRARIES)
223 # Include liblog for Android logging
224 CHECK_LIBRARY_EXISTS(log __android_log_print "" HAVE_LIBLOG)
226 SET(EXTRA_LIBS log ${EXTRA_LIBS})
227 SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
230 # Check if we have C99 variable length arrays
231 CHECK_C_SOURCE_COMPILES(
232 "int main(int argc, char *argv[])
234 volatile int tmp[argc];
240 # Check if we have C99 bool
241 CHECK_C_SOURCE_COMPILES(
242 "int main(int argc, char *argv[])
245 ret = (argc > 1) ? 1 : 0;
250 # Check if we have C11 static_assert
251 CHECK_C_SOURCE_COMPILES(
254 _Static_assert(sizeof(int) == sizeof(int), \"What\");
257 HAVE_C11_STATIC_ASSERT)
259 # Check if we have C11 alignas
260 CHECK_C_SOURCE_COMPILES(
261 "_Alignas(16) int foo;
268 # Check if we have C11 _Atomic
269 CHECK_C_SOURCE_COMPILES(
270 "#include <stdatomic.h>
271 int _Atomic foo = ATOMIC_VAR_INIT(0);
274 atomic_fetch_add(&foo, 2);
279 # Add definitions, compiler switches, etc.
280 INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_SOURCE_DIR}/common" "${OpenAL_BINARY_DIR}")
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 # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
331 FOREACH(flag_var CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
332 IF(${flag_var} MATCHES "-DNDEBUG")
333 STRING(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
337 CHECK_C_COMPILER_FLAG(-fno-math-errno HAVE_FNO_MATH_ERRNO)
338 IF(HAVE_FNO_MATH_ERRNO)
339 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fno-math-errno")
342 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
343 int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
345 option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
346 if(ALSOFT_STATIC_LIBGCC)
347 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
348 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
349 check_c_source_compiles(
355 HAVE_STATIC_LIBGCC_SWITCH
357 if(HAVE_STATIC_LIBGCC_SWITCH)
358 set(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} -static-libgcc")
360 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
361 unset(OLD_REQUIRED_LIBRARIES)
365 # Set visibility/export options if available
367 SET(EXPORT_DECL "__declspec(dllexport)")
369 SET(ALIGN_DECL "__declspec(align(x))")
371 SET(ALIGN_DECL "__declspec(aligned(x))")
374 SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
375 # Yes GCC, really don't accept visibility modes you don't support
376 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
378 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
379 int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
380 IF(HAVE_GCC_PROTECTED_VISIBILITY)
381 SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
383 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
384 int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
385 IF(HAVE_GCC_DEFAULT_VISIBILITY)
386 SET(EXPORT_DECL "__attribute__((visibility(\"default\")))")
390 IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
391 CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
392 IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
393 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
397 CHECK_C_SOURCE_COMPILES("int foo __attribute__((aligned(16)));
398 int main() {return 0;}" HAVE_ATTRIBUTE_ALIGNED)
399 IF(HAVE_ATTRIBUTE_ALIGNED)
400 SET(ALIGN_DECL "__attribute__((aligned(x)))")
403 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
406 CHECK_C_SOURCE_COMPILES("
410 ptr = __builtin_assume_aligned(ptr, 16);
412 }" HAVE___BUILTIN_ASSUME_ALIGNED)
413 IF(HAVE___BUILTIN_ASSUME_ALIGNED)
414 SET(ASSUME_ALIGNED_DECL "__builtin_assume_aligned(x, y)")
416 SET(ASSUME_ALIGNED_DECL "x")
422 SET(SSE4_1_SWITCH "")
423 SET(FPU_NEON_SWITCH "")
425 CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
427 SET(SSE_SWITCH "-msse")
429 CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
430 IF(HAVE_MSSE2_SWITCH)
431 SET(SSE2_SWITCH "-msse2")
433 CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
434 IF(HAVE_MSSE3_SWITCH)
435 SET(SSE3_SWITCH "-msse3")
437 CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
438 IF(HAVE_MSSE4_1_SWITCH)
439 SET(SSE4_1_SWITCH "-msse4.1")
441 CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
442 IF(HAVE_MFPU_NEON_SWITCH)
443 SET(FPU_NEON_SWITCH "-mfpu=neon")
447 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
448 int main() {return 0;}" HAVE_GCC_FORMAT)
450 CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
451 CHECK_INCLUDE_FILE(stdalign.h HAVE_STDALIGN_H)
452 CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
453 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
454 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
455 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
456 CHECK_INCLUDE_FILE(intrin.h HAVE_INTRIN_H)
457 CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
458 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
459 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
460 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
461 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
462 IF(NOT HAVE_GUIDDEF_H)
463 CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
466 # Some systems need libm for some of the following math functions to work
467 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
469 SET(EXTRA_LIBS m ${EXTRA_LIBS})
470 SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
473 # Check for the dlopen API (for dynamicly loading backend libs)
475 CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
477 SET(EXTRA_LIBS dl ${EXTRA_LIBS})
478 SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
481 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
484 # Check for a cpuid intrinsic
486 CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
489 unsigned int eax, ebx, ecx, edx;
490 return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
491 }" HAVE_GCC_GET_CPUID)
494 CHECK_C_SOURCE_COMPILES("#include <intrin.h>
500 }" HAVE_CPUID_INTRINSIC)
503 CHECK_SYMBOL_EXISTS(aligned_alloc stdlib.h HAVE_ALIGNED_ALLOC)
504 CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
505 CHECK_SYMBOL_EXISTS(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
506 CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
507 CHECK_SYMBOL_EXISTS(modff math.h HAVE_MODFF)
509 CHECK_SYMBOL_EXISTS(alloca malloc.h HAVE_ALLOCA)
511 MESSAGE(FATAL_ERROR "No alloca function found, please report!")
516 CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
517 CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
520 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
521 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
522 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
523 IF(NOT HAVE_STRCASECMP)
524 CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
525 IF(NOT HAVE__STRICMP)
526 MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
529 ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
532 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
533 IF(NOT HAVE_STRNCASECMP)
534 CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
535 IF(NOT HAVE__STRNICMP)
536 MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
539 ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
542 CHECK_SYMBOL_EXISTS(strnlen string.h HAVE_STRNLEN)
543 CHECK_SYMBOL_EXISTS(snprintf stdio.h HAVE_SNPRINTF)
544 IF(NOT HAVE_SNPRINTF)
545 CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
546 IF(NOT HAVE__SNPRINTF)
547 MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
550 ADD_DEFINITIONS(-Dsnprintf=_snprintf)
553 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
554 IF(NOT HAVE_ISFINITE)
555 CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
557 CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
559 MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
561 ADD_DEFINITIONS(-Disfinite=_finite)
563 ADD_DEFINITIONS(-Disfinite=finite)
567 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
569 CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
571 MESSAGE(FATAL_ERROR "No isnan function found, please report!")
574 ADD_DEFINITIONS(-Disnan=_isnan)
578 # Check if we have Windows headers
579 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0502)
580 IF(NOT HAVE_WINDOWS_H)
581 CHECK_SYMBOL_EXISTS(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
582 IF(NOT HAVE_GETTIMEOFDAY)
583 MESSAGE(FATAL_ERROR "No timing function found!")
586 CHECK_SYMBOL_EXISTS(nanosleep time.h HAVE_NANOSLEEP)
587 IF(NOT HAVE_NANOSLEEP)
588 MESSAGE(FATAL_ERROR "No sleep function found!")
591 # We need pthreads outside of Windows
592 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
593 IF(NOT HAVE_PTHREAD_H)
594 MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
596 # Some systems need pthread_np.h to get recursive mutexes
597 CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
599 CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
601 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pthread")
602 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
603 SET(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} -pthread")
606 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
608 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
611 CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
613 IF(HAVE_PTHREAD_NP_H)
614 CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
615 IF(NOT HAVE_PTHREAD_SETNAME_NP)
616 CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
618 CHECK_C_SOURCE_COMPILES("
620 #include <pthread_np.h>
623 pthread_setname_np(\"testname\");
626 PTHREAD_SETNAME_NP_ONE_PARAM
629 CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np "pthread.h;pthread_np.h" HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
631 CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
632 IF(NOT HAVE_PTHREAD_SETNAME_NP)
633 CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
635 CHECK_C_SOURCE_COMPILES("
639 pthread_setname_np(\"testname\");
642 PTHREAD_SETNAME_NP_ONE_PARAM
645 CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np pthread.h HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
648 CHECK_SYMBOL_EXISTS(pthread_mutex_timedlock pthread.h HAVE_PTHREAD_MUTEX_TIMEDLOCK)
650 CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
652 SET(EXTRA_LIBS rt ${EXTRA_LIBS})
656 # Check for a 64-bit type
657 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
658 IF(NOT HAVE_STDINT_H)
660 CHECK_C_SOURCE_COMPILES("#define _WIN32_WINNT 0x0502
663 int main() {return 0;}" HAVE___INT64)
666 IF(NOT SIZEOF_LONG MATCHES "8")
667 IF(NOT SIZEOF_LONG_LONG MATCHES "8")
668 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
675 SET(COMMON_OBJS common/almalloc.c
681 SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
685 OpenAL32/alExtension.c
687 OpenAL32/alListener.c
691 OpenAL32/sample_cvt.c
693 SET(ALC_OBJS Alc/ALc.c
701 Alc/effects/compressor.c
702 Alc/effects/dedicated.c
703 Alc/effects/distortion.c
705 Alc/effects/equalizer.c
706 Alc/effects/flanger.c
707 Alc/effects/modulator.c
723 SET(CPU_EXTS "Default")
738 SET(HAVE_PORTAUDIO 0)
739 SET(HAVE_PULSEAUDIO 0)
740 SET(HAVE_COREAUDIO 0)
744 # Check for SSE support
745 OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
746 CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE_SWITCH}")
748 OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
749 IF(ALSOFT_CPUEXT_SSE)
750 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
752 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse.c)
754 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse.c PROPERTIES
755 COMPILE_FLAGS "${SSE_SWITCH}")
757 SET(CPU_EXTS "${CPU_EXTS}, SSE")
761 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
762 MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
765 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
766 CHECK_INCLUDE_FILE(emmintrin.h HAVE_EMMINTRIN_H "${SSE2_SWITCH}")
768 OPTION(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
769 IF(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
770 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
772 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse2.c)
774 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse2.c PROPERTIES
775 COMPILE_FLAGS "${SSE2_SWITCH}")
777 SET(CPU_EXTS "${CPU_EXTS}, SSE2")
781 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
782 MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
785 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE3 support" OFF)
786 CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}")
788 OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
789 IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
790 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
792 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse3.c)
794 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse3.c PROPERTIES
795 COMPILE_FLAGS "${SSE3_SWITCH}")
797 SET(CPU_EXTS "${CPU_EXTS}, SSE3")
801 IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
802 MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
805 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
806 CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}")
808 OPTION(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
809 IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE4_1)
810 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
812 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse41.c)
814 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse41.c PROPERTIES
815 COMPILE_FLAGS "${SSE4_1_SWITCH}")
817 SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
821 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
822 MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
825 # Check for ARM Neon support
826 OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
827 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H)
829 OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
830 IF(ALSOFT_CPUEXT_NEON)
832 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_neon.c)
834 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_neon.c PROPERTIES
835 COMPILE_FLAGS "${FPU_NEON_SWITCH}")
837 SET(CPU_EXTS "${CPU_EXTS}, Neon")
840 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
841 MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
845 IF(WIN32 OR HAVE_DLFCN_H)
847 MACRO(ADD_BACKEND_LIBS _LIBS)
850 SET(IS_LINKED " (linked)")
851 MACRO(ADD_BACKEND_LIBS _LIBS)
852 SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
857 SET(ALC_OBJS ${ALC_OBJS}
859 # Default backends, always available
860 Alc/backends/loopback.c
865 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
868 OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
869 IF(ALSOFT_BACKEND_ALSA)
871 SET(BACKENDS "${BACKENDS} ALSA${IS_LINKED},")
872 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/alsa.c)
873 ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
876 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
877 MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
881 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
884 OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
885 IF(ALSOFT_BACKEND_OSS)
887 SET(BACKENDS "${BACKENDS} OSS,")
888 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/oss.c)
891 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
892 MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
895 # Check Solaris backend
896 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
897 FIND_PACKAGE(AudioIO)
899 OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
900 IF(ALSOFT_BACKEND_SOLARIS)
902 SET(BACKENDS "${BACKENDS} Solaris,")
903 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/solaris.c)
906 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
907 MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
910 # Check SndIO backend
911 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
912 FIND_PACKAGE(SoundIO)
914 OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
915 IF(ALSOFT_BACKEND_SNDIO)
917 SET(BACKENDS "${BACKENDS} SndIO (linked),")
918 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/sndio.c)
919 SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
922 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
923 MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
927 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
930 OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
931 IF(ALSOFT_BACKEND_QSA)
933 SET(BACKENDS "${BACKENDS} QSA (linked),")
934 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/qsa.c)
935 SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
938 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
939 MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
942 # Check Windows-only backends
943 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
944 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
945 OPTION(ALSOFT_REQUIRE_MMDEVAPI "Require MMDevApi backend" OFF)
947 # Check MMSystem backend
948 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0502)
950 CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
952 OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
953 IF(ALSOFT_BACKEND_WINMM)
955 SET(BACKENDS "${BACKENDS} WinMM,")
956 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/winmm.c)
957 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
962 # Check DSound backend
965 OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
966 IF(ALSOFT_BACKEND_DSOUND)
968 SET(BACKENDS "${BACKENDS} DirectSound${IS_LINKED},")
969 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/dsound.c)
970 ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
974 # Check for MMDevApi backend
975 CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
976 IF(HAVE_MMDEVICEAPI_H)
977 OPTION(ALSOFT_BACKEND_MMDEVAPI "Enable MMDevApi backend" ON)
978 IF(ALSOFT_BACKEND_MMDEVAPI)
980 SET(BACKENDS "${BACKENDS} MMDevApi,")
981 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/mmdevapi.c)
985 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
986 MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
988 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
989 MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
991 IF(ALSOFT_REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
992 MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
995 # Check PortAudio backend
996 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
997 FIND_PACKAGE(PortAudio)
999 OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1000 IF(ALSOFT_BACKEND_PORTAUDIO)
1001 SET(HAVE_PORTAUDIO 1)
1002 SET(BACKENDS "${BACKENDS} PortAudio${IS_LINKED},")
1003 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/portaudio.c)
1004 ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
1007 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1008 MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
1011 # Check PulseAudio backend
1012 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1013 FIND_PACKAGE(PulseAudio)
1014 IF(PULSEAUDIO_FOUND)
1015 OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1016 IF(ALSOFT_BACKEND_PULSEAUDIO)
1017 SET(HAVE_PULSEAUDIO 1)
1018 SET(BACKENDS "${BACKENDS} PulseAudio${IS_LINKED},")
1019 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/pulseaudio.c)
1020 ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
1023 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1024 MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1027 # Check JACK backend
1028 OPTION(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1031 OPTION(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1032 IF(ALSOFT_BACKEND_JACK)
1034 SET(BACKENDS "${BACKENDS} JACK${IS_LINKED},")
1035 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/jack.c)
1036 ADD_BACKEND_LIBS(${JACK_LIBRARIES})
1039 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1040 MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
1043 # Check CoreAudio backend
1044 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1045 FIND_LIBRARY(COREAUDIO_FRAMEWORK
1047 PATHS /System/Library/Frameworks
1049 IF(COREAUDIO_FRAMEWORK)
1050 OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1051 IF(ALSOFT_BACKEND_COREAUDIO)
1052 SET(HAVE_COREAUDIO 1)
1053 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/coreaudio.c)
1054 SET(BACKENDS "${BACKENDS} CoreAudio,")
1055 SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
1056 SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
1057 SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1059 # Some versions of OSX may need the AudioToolbox framework. Add it if
1061 FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
1063 PATHS ~/Library/Frameworks
1065 /System/Library/Frameworks
1067 IF(AUDIOTOOLBOX_LIBRARY)
1068 SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1072 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1073 MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1076 # Check for OpenSL (Android) backend
1077 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1078 CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
1079 IF(HAVE_SLES_OPENSLES_ANDROID_H)
1080 CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
1081 IF(HAVE_LIBOPENSLES)
1082 OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1083 IF(ALSOFT_BACKEND_OPENSL)
1085 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/opensl.c)
1086 SET(BACKENDS "${BACKENDS} OpenSL,")
1087 SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
1091 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1092 MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1095 # Optionally enable the Wave Writer backend
1096 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1097 IF(ALSOFT_BACKEND_WAVE)
1099 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/wave.c)
1100 SET(BACKENDS "${BACKENDS} WaveFile,")
1103 # This is always available
1104 SET(BACKENDS "${BACKENDS} Null")
1106 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" OFF)
1107 if(ALSOFT_EMBED_HRTF_DATA)
1108 SET(NATIVE_SRC_DIR "${OpenAL_SOURCE_DIR}/native-tools/")
1109 SET(NATIVE_BIN_DIR "${OpenAL_BINARY_DIR}/native-tools/")
1110 FILE(MAKE_DIRECTORY "${NATIVE_BIN_DIR}")
1112 SET(BIN2H_COMMAND "${NATIVE_BIN_DIR}bin2h")
1113 ADD_CUSTOM_COMMAND(OUTPUT "${BIN2H_COMMAND}"
1114 COMMAND ${CMAKE_COMMAND} "${NATIVE_SRC_DIR}"
1115 COMMAND ${CMAKE_COMMAND} --build . --config "Release"
1116 WORKING_DIRECTORY "${NATIVE_BIN_DIR}"
1117 DEPENDS "${NATIVE_SRC_DIR}CMakeLists.txt" "${NATIVE_SRC_DIR}bin2h.c"
1121 MACRO(make_hrtf_header FILENAME VARNAME)
1122 SET(infile "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1123 SET(outfile "${OpenAL_BINARY_DIR}/${FILENAME}.h")
1125 ADD_CUSTOM_COMMAND(OUTPUT "${outfile}"
1126 COMMAND "${BIN2H_COMMAND}" "${infile}" "${outfile}" ${VARNAME}
1127 DEPENDS "${BIN2H_COMMAND}" "${infile}"
1128 COMMENT "Generating ${FILENAME}.h"
1132 SET(ALC_OBJS ${ALC_OBJS} "${outfile}")
1135 make_hrtf_header(default-44100.mhr "hrtf_default_44100")
1136 make_hrtf_header(default-48000.mhr "hrtf_default_48000")
1140 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1141 add_subdirectory(utils/alsoft-config)
1146 FIND_PACKAGE(SDL_sound)
1147 FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1151 IF(LIBTYPE STREQUAL "STATIC")
1152 ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC)
1153 SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
1157 SET(LIBNAME "openal")
1159 SET(LIBNAME "OpenAL32")
1163 IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1164 # Get the current working branch and its latest abbreviated commit hash
1165 ADD_CUSTOM_TARGET(build_version
1166 ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
1167 -D LIB_VERSION=${LIB_VERSION}
1168 -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1169 -D DST=${OpenAL_BINARY_DIR}/version.h
1170 -P ${OpenAL_SOURCE_DIR}/version.cmake
1171 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1175 SET(GIT_BRANCH "UNKNOWN")
1176 SET(GIT_COMMIT_HASH "unknown")
1178 "${OpenAL_SOURCE_DIR}/version.h.in"
1179 "${OpenAL_BINARY_DIR}/version.h")
1182 # Needed for openal.pc.in
1183 SET(prefix ${CMAKE_INSTALL_PREFIX})
1184 SET(exec_prefix "\${prefix}")
1185 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1186 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1187 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1188 SET(PACKAGE_VERSION "${LIB_VERSION}")
1192 "${OpenAL_SOURCE_DIR}/config.h.in"
1193 "${OpenAL_BINARY_DIR}/config.h")
1195 "${OpenAL_SOURCE_DIR}/openal.pc.in"
1196 "${OpenAL_BINARY_DIR}/openal.pc"
1199 # Build main library
1200 IF(LIBTYPE STREQUAL "STATIC")
1201 ADD_LIBRARY(OpenAL STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1203 ADD_LIBRARY(OpenAL SHARED ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1205 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1206 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY COMPILE_DEFINITIONS AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES)
1207 IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1208 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY COMPILE_DEFINITIONS AL_NO_UID_DEFS)
1210 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc")
1212 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${ALSA_INCLUDE_DIRS})
1215 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${OSS_INCLUDE_DIRS})
1218 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${AUDIOIO_INCLUDE_DIRS})
1221 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${SOUNDIO_INCLUDE_DIRS})
1224 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${QSA_INCLUDE_DIRS})
1227 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${DSOUND_INCLUDE_DIRS})
1230 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${PORTAUDIO_INCLUDE_DIRS})
1233 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${PULSEAUDIO_INCLUDE_DIRS})
1236 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${JACK_INCLUDE_DIRS})
1240 SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:WINDOWS")
1241 ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1242 SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS " -mwindows")
1246 SET_TARGET_PROPERTIES(OpenAL PROPERTIES VERSION ${LIB_VERSION}
1247 SOVERSION ${LIB_MAJOR_VERSION})
1248 SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1250 if(WIN32 AND NOT LIBTYPE STREQUAL "STATIC")
1251 SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "")
1253 IF(MINGW AND ALSOFT_BUILD_IMPORT_LIB)
1254 FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1255 FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1256 IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1258 IF(NOT SED_EXECUTABLE)
1259 MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1261 IF(NOT DLLTOOL_EXECUTABLE)
1262 MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1265 SET(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} -Wl,--output-def,OpenAL32.def")
1266 ADD_CUSTOM_COMMAND(TARGET OpenAL POST_BUILD
1267 COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1268 COMMAND "${DLLTOOL_EXECUTABLE}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1269 COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1276 SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS ${EXTRA_LDFLAGS})
1277 TARGET_LINK_LIBRARIES(OpenAL ${EXTRA_LIBS})
1278 IF(TARGET build_version)
1279 ADD_DEPENDENCIES(OpenAL build_version)
1282 SET(EX_TARGET OpenAL)
1284 if(WIN32 AND ALSOFT_BUILD_ROUTER)
1285 SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME soft_oal)
1287 ADD_LIBRARY(Router SHARED router/router.c router/alc.c router/al.c ${COMMON_OBJS})
1288 SET_PROPERTY(TARGET Router APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1289 SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS ${EXTRA_LDFLAGS})
1291 SET_PROPERTY(TARGET Router APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:WINDOWS")
1292 ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1293 SET_PROPERTY(TARGET Router APPEND_STRING PROPERTY LINK_FLAGS " -mwindows")
1295 SET_TARGET_PROPERTIES(Router PROPERTIES PREFIX "")
1296 SET_TARGET_PROPERTIES(Router PROPERTIES OUTPUT_NAME ${LIBNAME})
1297 IF(TARGET build_version)
1298 ADD_DEPENDENCIES(Router build_version)
1300 SET(EX_TARGET Router)
1303 INSTALL(TARGETS Router
1304 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1305 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1306 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1312 INSTALL(TARGETS OpenAL EXPORT OpenAL
1313 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1314 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1315 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1316 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL
1318 EXPORT(TARGETS OpenAL
1320 FILE OpenALConfig.cmake)
1321 INSTALL(EXPORT OpenAL
1322 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1324 FILE OpenALConfig.cmake)
1325 INSTALL(FILES include/AL/al.h
1329 include/AL/efx-creative.h
1330 include/AL/efx-presets.h
1331 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
1333 INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1334 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1339 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1340 MESSAGE(STATUS " ${BACKENDS}")
1342 MESSAGE(STATUS "Building with support for CPU extensions:")
1343 MESSAGE(STATUS " ${CPU_EXTS}")
1348 MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
1349 MESSAGE(STATUS " This is probably NOT what you want!")
1354 if(ALSOFT_EMBED_HRTF_DATA)
1355 message(STATUS "Embedding HRTF datasets")
1360 message(STATUS "Building DLL router")
1364 # Install alsoft.conf configuration file
1366 INSTALL(FILES alsoftrc.sample
1367 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal
1369 MESSAGE(STATUS "Installing sample configuration")
1373 # Install HRTF definitions
1374 IF(ALSOFT_HRTF_DEFS)
1375 INSTALL(FILES hrtf/default-44100.mhr
1376 hrtf/default-48000.mhr
1377 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf
1379 MESSAGE(STATUS "Installing HRTF definitions")
1383 # Install AmbDec presets
1384 IF(ALSOFT_AMBDEC_PRESETS)
1385 INSTALL(FILES presets/3D7.1.ambdec
1386 presets/hexagon.ambdec
1387 presets/itu5.1.ambdec
1388 presets/rectangle.ambdec
1389 presets/square.ambdec
1391 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
1393 MESSAGE(STATUS "Installing AmbDec presets")
1398 ADD_EXECUTABLE(openal-info utils/openal-info.c)
1399 SET_PROPERTY(TARGET openal-info APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1400 TARGET_LINK_LIBRARIES(openal-info ${EX_TARGET})
1402 ADD_EXECUTABLE(makehrtf utils/makehrtf.c)
1403 SET_PROPERTY(TARGET makehrtf APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1405 TARGET_LINK_LIBRARIES(makehrtf m)
1408 ADD_EXECUTABLE(bsincgen utils/bsincgen.c)
1409 SET_PROPERTY(TARGET bsincgen APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1411 TARGET_LINK_LIBRARIES(bsincgen m)
1415 INSTALL(TARGETS openal-info makehrtf bsincgen
1416 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1417 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1418 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1422 MESSAGE(STATUS "Building utility programs")
1423 IF(TARGET alsoft-config)
1424 MESSAGE(STATUS "Building configuration program")
1430 SET(TEST_COMMON_OBJS examples/common/alhelpers.c)
1432 ADD_EXECUTABLE(altonegen examples/altonegen.c ${COMMON_OBJS} ${TEST_COMMON_OBJS})
1433 TARGET_LINK_LIBRARIES(altonegen ${EX_TARGET})
1434 SET_PROPERTY(TARGET altonegen APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1437 INSTALL(TARGETS altonegen
1438 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1439 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1440 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1444 MESSAGE(STATUS "Building test programs")
1449 ADD_EXECUTABLE(alrecord examples/alrecord.c ${COMMON_OBJS})
1450 TARGET_LINK_LIBRARIES(alrecord ${EX_TARGET})
1451 SET_PROPERTY(TARGET alrecord APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1454 INSTALL(TARGETS alrecord
1455 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1456 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1457 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1461 MESSAGE(STATUS "Building example programs")
1465 SET(EX_COMMON_OBJS examples/common/alhelpers.c)
1467 ADD_EXECUTABLE(alstream examples/alstream.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1468 TARGET_LINK_LIBRARIES(alstream ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${EX_TARGET})
1469 SET_PROPERTY(TARGET alstream APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1470 SET_PROPERTY(TARGET alstream APPEND PROPERTY
1471 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1474 ADD_EXECUTABLE(alreverb examples/alreverb.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1475 TARGET_LINK_LIBRARIES(alreverb ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${EX_TARGET})
1476 SET_PROPERTY(TARGET alreverb APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1477 SET_PROPERTY(TARGET alreverb APPEND PROPERTY
1478 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1481 ADD_EXECUTABLE(allatency examples/allatency.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1482 TARGET_LINK_LIBRARIES(allatency ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${EX_TARGET})
1483 SET_PROPERTY(TARGET allatency APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1484 SET_PROPERTY(TARGET allatency APPEND PROPERTY
1485 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1488 ADD_EXECUTABLE(alloopback examples/alloopback.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1489 TARGET_LINK_LIBRARIES(alloopback ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${EX_TARGET})
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 ${COMMON_OBJS} ${EX_COMMON_OBJS})
1496 TARGET_LINK_LIBRARIES(alhrtf ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${EX_TARGET})
1497 SET_PROPERTY(TARGET alhrtf APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1498 SET_PROPERTY(TARGET alhrtf APPEND PROPERTY
1499 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1503 INSTALL(TARGETS alstream alreverb allatency alloopback alhrtf
1504 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1505 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1506 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1510 MESSAGE(STATUS "Building SDL_sound example programs")
1516 IF(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1517 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1520 IF(AVCODEC_VERSION VERSION_LESS "57.64.101")
1521 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1524 IF(AVUTIL_VERSION VERSION_LESS "55.34.101")
1525 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1528 IF(SWSCALE_VERSION VERSION_LESS "4.2.100")
1529 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1532 IF(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1533 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1538 ADD_EXECUTABLE(alffplay examples/alffplay.cpp ${COMMON_OBJS})
1539 TARGET_LINK_LIBRARIES(alffplay ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ${EX_TARGET})
1540 SET_PROPERTY(TARGET alffplay APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1541 SET_PROPERTY(TARGET alffplay APPEND PROPERTY
1542 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS}
1546 INSTALL(TARGETS alffplay
1547 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1548 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1549 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1552 MESSAGE(STATUS "Building SDL+FFmpeg example programs")