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)
508 CHECK_SYMBOL_EXISTS(log2f math.h HAVE_LOG2F)
510 CHECK_SYMBOL_EXISTS(alloca malloc.h HAVE_ALLOCA)
512 MESSAGE(FATAL_ERROR "No alloca function found, please report!")
517 CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
518 CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
521 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
522 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
523 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
524 IF(NOT HAVE_STRCASECMP)
525 CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
526 IF(NOT HAVE__STRICMP)
527 MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
530 ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
533 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
534 IF(NOT HAVE_STRNCASECMP)
535 CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
536 IF(NOT HAVE__STRNICMP)
537 MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
540 ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
543 CHECK_SYMBOL_EXISTS(strnlen string.h HAVE_STRNLEN)
544 CHECK_SYMBOL_EXISTS(snprintf stdio.h HAVE_SNPRINTF)
545 IF(NOT HAVE_SNPRINTF)
546 CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
547 IF(NOT HAVE__SNPRINTF)
548 MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
551 ADD_DEFINITIONS(-Dsnprintf=_snprintf)
554 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
555 IF(NOT HAVE_ISFINITE)
556 CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
558 CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
560 MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
562 ADD_DEFINITIONS(-Disfinite=_finite)
564 ADD_DEFINITIONS(-Disfinite=finite)
568 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
570 CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
572 MESSAGE(FATAL_ERROR "No isnan function found, please report!")
575 ADD_DEFINITIONS(-Disnan=_isnan)
579 # Check if we have Windows headers
580 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0502)
581 IF(NOT HAVE_WINDOWS_H)
582 CHECK_SYMBOL_EXISTS(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
583 IF(NOT HAVE_GETTIMEOFDAY)
584 MESSAGE(FATAL_ERROR "No timing function found!")
587 CHECK_SYMBOL_EXISTS(nanosleep time.h HAVE_NANOSLEEP)
588 IF(NOT HAVE_NANOSLEEP)
589 MESSAGE(FATAL_ERROR "No sleep function found!")
592 # We need pthreads outside of Windows
593 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
594 IF(NOT HAVE_PTHREAD_H)
595 MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
597 # Some systems need pthread_np.h to get recursive mutexes
598 CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
600 CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
602 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pthread")
603 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
604 SET(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} -pthread")
607 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
609 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
612 CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
614 IF(HAVE_PTHREAD_NP_H)
615 CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
616 IF(NOT HAVE_PTHREAD_SETNAME_NP)
617 CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
619 CHECK_C_SOURCE_COMPILES("
621 #include <pthread_np.h>
624 pthread_setname_np(\"testname\");
627 PTHREAD_SETNAME_NP_ONE_PARAM
630 CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np "pthread.h;pthread_np.h" HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
632 CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
633 IF(NOT HAVE_PTHREAD_SETNAME_NP)
634 CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
636 CHECK_C_SOURCE_COMPILES("
640 pthread_setname_np(\"testname\");
643 PTHREAD_SETNAME_NP_ONE_PARAM
646 CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np pthread.h HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
649 CHECK_SYMBOL_EXISTS(pthread_mutex_timedlock pthread.h HAVE_PTHREAD_MUTEX_TIMEDLOCK)
651 CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
653 SET(EXTRA_LIBS rt ${EXTRA_LIBS})
657 # Check for a 64-bit type
658 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
659 IF(NOT HAVE_STDINT_H)
661 CHECK_C_SOURCE_COMPILES("#define _WIN32_WINNT 0x0502
664 int main() {return 0;}" HAVE___INT64)
667 IF(NOT SIZEOF_LONG MATCHES "8")
668 IF(NOT SIZEOF_LONG_LONG MATCHES "8")
669 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
676 SET(COMMON_OBJS common/almalloc.c
682 SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
686 OpenAL32/alExtension.c
688 OpenAL32/alListener.c
692 OpenAL32/sample_cvt.c
694 SET(ALC_OBJS Alc/ALc.c
702 Alc/effects/compressor.c
703 Alc/effects/dedicated.c
704 Alc/effects/distortion.c
706 Alc/effects/equalizer.c
707 Alc/effects/flanger.c
708 Alc/effects/modulator.c
724 SET(CPU_EXTS "Default")
739 SET(HAVE_PORTAUDIO 0)
740 SET(HAVE_PULSEAUDIO 0)
741 SET(HAVE_COREAUDIO 0)
745 # Check for SSE support
746 OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
747 CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE_SWITCH}")
749 OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
750 IF(ALSOFT_CPUEXT_SSE)
751 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
753 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse.c)
755 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse.c PROPERTIES
756 COMPILE_FLAGS "${SSE_SWITCH}")
758 SET(CPU_EXTS "${CPU_EXTS}, SSE")
762 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
763 MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
766 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
767 CHECK_INCLUDE_FILE(emmintrin.h HAVE_EMMINTRIN_H "${SSE2_SWITCH}")
769 OPTION(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
770 IF(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
771 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
773 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse2.c)
775 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse2.c PROPERTIES
776 COMPILE_FLAGS "${SSE2_SWITCH}")
778 SET(CPU_EXTS "${CPU_EXTS}, SSE2")
782 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
783 MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
786 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE3 support" OFF)
787 CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}")
789 OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
790 IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
791 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
793 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse3.c)
795 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse3.c PROPERTIES
796 COMPILE_FLAGS "${SSE3_SWITCH}")
798 SET(CPU_EXTS "${CPU_EXTS}, SSE3")
802 IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
803 MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
806 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
807 CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}")
809 OPTION(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
810 IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE4_1)
811 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
813 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse41.c)
815 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse41.c PROPERTIES
816 COMPILE_FLAGS "${SSE4_1_SWITCH}")
818 SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
822 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
823 MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
826 # Check for ARM Neon support
827 OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
828 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H)
830 OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
831 IF(ALSOFT_CPUEXT_NEON)
833 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_neon.c)
835 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_neon.c PROPERTIES
836 COMPILE_FLAGS "${FPU_NEON_SWITCH}")
838 SET(CPU_EXTS "${CPU_EXTS}, Neon")
841 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
842 MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
846 IF(WIN32 OR HAVE_DLFCN_H)
848 MACRO(ADD_BACKEND_LIBS _LIBS)
851 SET(IS_LINKED " (linked)")
852 MACRO(ADD_BACKEND_LIBS _LIBS)
853 SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
858 SET(ALC_OBJS ${ALC_OBJS}
860 # Default backends, always available
861 Alc/backends/loopback.c
866 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
869 OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
870 IF(ALSOFT_BACKEND_ALSA)
872 SET(BACKENDS "${BACKENDS} ALSA${IS_LINKED},")
873 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/alsa.c)
874 ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
877 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
878 MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
882 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
885 OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
886 IF(ALSOFT_BACKEND_OSS)
888 SET(BACKENDS "${BACKENDS} OSS,")
889 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/oss.c)
892 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
893 MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
896 # Check Solaris backend
897 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
898 FIND_PACKAGE(AudioIO)
900 OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
901 IF(ALSOFT_BACKEND_SOLARIS)
903 SET(BACKENDS "${BACKENDS} Solaris,")
904 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/solaris.c)
907 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
908 MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
911 # Check SndIO backend
912 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
913 FIND_PACKAGE(SoundIO)
915 OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
916 IF(ALSOFT_BACKEND_SNDIO)
918 SET(BACKENDS "${BACKENDS} SndIO (linked),")
919 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/sndio.c)
920 SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
923 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
924 MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
928 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
931 OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
932 IF(ALSOFT_BACKEND_QSA)
934 SET(BACKENDS "${BACKENDS} QSA (linked),")
935 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/qsa.c)
936 SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
939 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
940 MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
943 # Check Windows-only backends
944 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
945 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
946 OPTION(ALSOFT_REQUIRE_MMDEVAPI "Require MMDevApi backend" OFF)
948 # Check MMSystem backend
949 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0502)
951 CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
953 OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
954 IF(ALSOFT_BACKEND_WINMM)
956 SET(BACKENDS "${BACKENDS} WinMM,")
957 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/winmm.c)
958 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
963 # Check DSound backend
966 OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
967 IF(ALSOFT_BACKEND_DSOUND)
969 SET(BACKENDS "${BACKENDS} DirectSound${IS_LINKED},")
970 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/dsound.c)
971 ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
975 # Check for MMDevApi backend
976 CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
977 IF(HAVE_MMDEVICEAPI_H)
978 OPTION(ALSOFT_BACKEND_MMDEVAPI "Enable MMDevApi backend" ON)
979 IF(ALSOFT_BACKEND_MMDEVAPI)
981 SET(BACKENDS "${BACKENDS} MMDevApi,")
982 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/mmdevapi.c)
986 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
987 MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
989 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
990 MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
992 IF(ALSOFT_REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
993 MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
996 # Check PortAudio backend
997 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
998 FIND_PACKAGE(PortAudio)
1000 OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1001 IF(ALSOFT_BACKEND_PORTAUDIO)
1002 SET(HAVE_PORTAUDIO 1)
1003 SET(BACKENDS "${BACKENDS} PortAudio${IS_LINKED},")
1004 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/portaudio.c)
1005 ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
1008 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1009 MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
1012 # Check PulseAudio backend
1013 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1014 FIND_PACKAGE(PulseAudio)
1015 IF(PULSEAUDIO_FOUND)
1016 OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1017 IF(ALSOFT_BACKEND_PULSEAUDIO)
1018 SET(HAVE_PULSEAUDIO 1)
1019 SET(BACKENDS "${BACKENDS} PulseAudio${IS_LINKED},")
1020 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/pulseaudio.c)
1021 ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
1024 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1025 MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1028 # Check JACK backend
1029 OPTION(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1032 OPTION(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1033 IF(ALSOFT_BACKEND_JACK)
1035 SET(BACKENDS "${BACKENDS} JACK${IS_LINKED},")
1036 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/jack.c)
1037 ADD_BACKEND_LIBS(${JACK_LIBRARIES})
1040 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1041 MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
1044 # Check CoreAudio backend
1045 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1046 FIND_LIBRARY(COREAUDIO_FRAMEWORK
1048 PATHS /System/Library/Frameworks
1050 IF(COREAUDIO_FRAMEWORK)
1051 OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1052 IF(ALSOFT_BACKEND_COREAUDIO)
1053 SET(HAVE_COREAUDIO 1)
1054 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/coreaudio.c)
1055 SET(BACKENDS "${BACKENDS} CoreAudio,")
1056 SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
1057 SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
1058 SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1060 # Some versions of OSX may need the AudioToolbox framework. Add it if
1062 FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
1064 PATHS ~/Library/Frameworks
1066 /System/Library/Frameworks
1068 IF(AUDIOTOOLBOX_LIBRARY)
1069 SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1073 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1074 MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1077 # Check for OpenSL (Android) backend
1078 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1079 CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
1080 IF(HAVE_SLES_OPENSLES_ANDROID_H)
1081 CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
1082 IF(HAVE_LIBOPENSLES)
1083 OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1084 IF(ALSOFT_BACKEND_OPENSL)
1086 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/opensl.c)
1087 SET(BACKENDS "${BACKENDS} OpenSL,")
1088 SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
1092 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1093 MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1096 # Optionally enable the Wave Writer backend
1097 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1098 IF(ALSOFT_BACKEND_WAVE)
1100 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/wave.c)
1101 SET(BACKENDS "${BACKENDS} WaveFile,")
1104 # This is always available
1105 SET(BACKENDS "${BACKENDS} Null")
1107 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" OFF)
1108 if(ALSOFT_EMBED_HRTF_DATA)
1109 SET(NATIVE_SRC_DIR "${OpenAL_SOURCE_DIR}/native-tools/")
1110 SET(NATIVE_BIN_DIR "${OpenAL_BINARY_DIR}/native-tools/")
1111 FILE(MAKE_DIRECTORY "${NATIVE_BIN_DIR}")
1113 SET(BIN2H_COMMAND "${NATIVE_BIN_DIR}bin2h")
1114 ADD_CUSTOM_COMMAND(OUTPUT "${BIN2H_COMMAND}"
1115 COMMAND ${CMAKE_COMMAND} "${NATIVE_SRC_DIR}"
1116 COMMAND ${CMAKE_COMMAND} --build . --config "Release"
1117 WORKING_DIRECTORY "${NATIVE_BIN_DIR}"
1118 DEPENDS "${NATIVE_SRC_DIR}CMakeLists.txt" "${NATIVE_SRC_DIR}bin2h.c"
1122 MACRO(make_hrtf_header FILENAME VARNAME)
1123 SET(infile "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1124 SET(outfile "${OpenAL_BINARY_DIR}/${FILENAME}.h")
1126 ADD_CUSTOM_COMMAND(OUTPUT "${outfile}"
1127 COMMAND "${BIN2H_COMMAND}" "${infile}" "${outfile}" ${VARNAME}
1128 DEPENDS "${BIN2H_COMMAND}" "${infile}"
1129 COMMENT "Generating ${FILENAME}.h"
1133 SET(ALC_OBJS ${ALC_OBJS} "${outfile}")
1136 make_hrtf_header(default-44100.mhr "hrtf_default_44100")
1137 make_hrtf_header(default-48000.mhr "hrtf_default_48000")
1141 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1142 add_subdirectory(utils/alsoft-config)
1147 FIND_PACKAGE(SDL_sound)
1148 FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1152 IF(LIBTYPE STREQUAL "STATIC")
1153 ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC)
1154 SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
1158 SET(LIBNAME "openal")
1160 SET(LIBNAME "OpenAL32")
1164 IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1165 # Get the current working branch and its latest abbreviated commit hash
1166 ADD_CUSTOM_TARGET(build_version
1167 ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
1168 -D LIB_VERSION=${LIB_VERSION}
1169 -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1170 -D DST=${OpenAL_BINARY_DIR}/version.h
1171 -P ${OpenAL_SOURCE_DIR}/version.cmake
1172 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1176 SET(GIT_BRANCH "UNKNOWN")
1177 SET(GIT_COMMIT_HASH "unknown")
1179 "${OpenAL_SOURCE_DIR}/version.h.in"
1180 "${OpenAL_BINARY_DIR}/version.h")
1183 # Needed for openal.pc.in
1184 SET(prefix ${CMAKE_INSTALL_PREFIX})
1185 SET(exec_prefix "\${prefix}")
1186 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1187 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1188 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1189 SET(PACKAGE_VERSION "${LIB_VERSION}")
1193 "${OpenAL_SOURCE_DIR}/config.h.in"
1194 "${OpenAL_BINARY_DIR}/config.h")
1196 "${OpenAL_SOURCE_DIR}/openal.pc.in"
1197 "${OpenAL_BINARY_DIR}/openal.pc"
1200 # Build main library
1201 IF(LIBTYPE STREQUAL "STATIC")
1202 ADD_LIBRARY(OpenAL STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1204 ADD_LIBRARY(OpenAL SHARED ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1206 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1207 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY COMPILE_DEFINITIONS AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES)
1208 IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1209 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY COMPILE_DEFINITIONS AL_NO_UID_DEFS)
1211 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc")
1213 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${ALSA_INCLUDE_DIRS})
1216 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${OSS_INCLUDE_DIRS})
1219 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${AUDIOIO_INCLUDE_DIRS})
1222 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${SOUNDIO_INCLUDE_DIRS})
1225 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${QSA_INCLUDE_DIRS})
1228 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${DSOUND_INCLUDE_DIRS})
1231 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${PORTAUDIO_INCLUDE_DIRS})
1234 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${PULSEAUDIO_INCLUDE_DIRS})
1237 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY INCLUDE_DIRECTORIES ${JACK_INCLUDE_DIRS})
1241 SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:WINDOWS")
1242 ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1243 SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS " -mwindows")
1247 SET_TARGET_PROPERTIES(OpenAL PROPERTIES VERSION ${LIB_VERSION}
1248 SOVERSION ${LIB_MAJOR_VERSION})
1249 SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1251 if(WIN32 AND NOT LIBTYPE STREQUAL "STATIC")
1252 SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "")
1254 IF(MINGW AND ALSOFT_BUILD_IMPORT_LIB)
1255 FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1256 FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1257 IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1259 IF(NOT SED_EXECUTABLE)
1260 MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1262 IF(NOT DLLTOOL_EXECUTABLE)
1263 MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1266 SET(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} -Wl,--output-def,OpenAL32.def")
1267 ADD_CUSTOM_COMMAND(TARGET OpenAL POST_BUILD
1268 COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1269 COMMAND "${DLLTOOL_EXECUTABLE}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1270 COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1277 SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS ${EXTRA_LDFLAGS})
1278 TARGET_LINK_LIBRARIES(OpenAL ${EXTRA_LIBS})
1279 IF(TARGET build_version)
1280 ADD_DEPENDENCIES(OpenAL build_version)
1283 SET(EX_TARGET OpenAL)
1285 if(WIN32 AND ALSOFT_BUILD_ROUTER)
1286 SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME soft_oal)
1288 ADD_LIBRARY(Router SHARED router/router.c router/alc.c router/al.c ${COMMON_OBJS})
1289 SET_PROPERTY(TARGET Router APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1290 SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS ${EXTRA_LDFLAGS})
1292 SET_PROPERTY(TARGET Router APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:WINDOWS")
1293 ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1294 SET_PROPERTY(TARGET Router APPEND_STRING PROPERTY LINK_FLAGS " -mwindows")
1296 SET_TARGET_PROPERTIES(Router PROPERTIES PREFIX "")
1297 SET_TARGET_PROPERTIES(Router PROPERTIES OUTPUT_NAME ${LIBNAME})
1298 IF(TARGET build_version)
1299 ADD_DEPENDENCIES(Router build_version)
1301 SET(EX_TARGET Router)
1304 INSTALL(TARGETS Router
1305 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1306 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1307 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1313 INSTALL(TARGETS OpenAL EXPORT OpenAL
1314 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1315 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1316 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1317 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL
1319 EXPORT(TARGETS OpenAL
1321 FILE OpenALConfig.cmake)
1322 INSTALL(EXPORT OpenAL
1323 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1325 FILE OpenALConfig.cmake)
1326 INSTALL(FILES include/AL/al.h
1330 include/AL/efx-creative.h
1331 include/AL/efx-presets.h
1332 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
1334 INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1335 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1340 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1341 MESSAGE(STATUS " ${BACKENDS}")
1343 MESSAGE(STATUS "Building with support for CPU extensions:")
1344 MESSAGE(STATUS " ${CPU_EXTS}")
1349 MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
1350 MESSAGE(STATUS " This is probably NOT what you want!")
1355 if(ALSOFT_EMBED_HRTF_DATA)
1356 message(STATUS "Embedding HRTF datasets")
1361 message(STATUS "Building DLL router")
1365 # Install alsoft.conf configuration file
1367 INSTALL(FILES alsoftrc.sample
1368 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal
1370 MESSAGE(STATUS "Installing sample configuration")
1374 # Install HRTF definitions
1375 IF(ALSOFT_HRTF_DEFS)
1376 INSTALL(FILES hrtf/default-44100.mhr
1377 hrtf/default-48000.mhr
1378 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf
1380 MESSAGE(STATUS "Installing HRTF definitions")
1384 # Install AmbDec presets
1385 IF(ALSOFT_AMBDEC_PRESETS)
1386 INSTALL(FILES presets/3D7.1.ambdec
1387 presets/hexagon.ambdec
1388 presets/itu5.1.ambdec
1389 presets/rectangle.ambdec
1390 presets/square.ambdec
1392 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
1394 MESSAGE(STATUS "Installing AmbDec presets")
1399 ADD_EXECUTABLE(openal-info utils/openal-info.c)
1400 SET_PROPERTY(TARGET openal-info APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1401 TARGET_LINK_LIBRARIES(openal-info ${EX_TARGET})
1403 ADD_EXECUTABLE(makehrtf utils/makehrtf.c)
1404 SET_PROPERTY(TARGET makehrtf APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1406 TARGET_LINK_LIBRARIES(makehrtf m)
1409 ADD_EXECUTABLE(bsincgen utils/bsincgen.c)
1410 SET_PROPERTY(TARGET bsincgen APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1412 TARGET_LINK_LIBRARIES(bsincgen m)
1416 INSTALL(TARGETS openal-info makehrtf bsincgen
1417 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1418 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1419 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1423 MESSAGE(STATUS "Building utility programs")
1424 IF(TARGET alsoft-config)
1425 MESSAGE(STATUS "Building configuration program")
1431 SET(TEST_COMMON_OBJS examples/common/alhelpers.c)
1433 ADD_EXECUTABLE(altonegen examples/altonegen.c ${COMMON_OBJS} ${TEST_COMMON_OBJS})
1434 TARGET_LINK_LIBRARIES(altonegen ${EX_TARGET})
1435 SET_PROPERTY(TARGET altonegen APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1438 INSTALL(TARGETS altonegen
1439 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1440 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1441 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1445 MESSAGE(STATUS "Building test programs")
1450 ADD_EXECUTABLE(alrecord examples/alrecord.c ${COMMON_OBJS})
1451 TARGET_LINK_LIBRARIES(alrecord ${EX_TARGET})
1452 SET_PROPERTY(TARGET alrecord APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1455 INSTALL(TARGETS alrecord
1456 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1457 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1458 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1462 MESSAGE(STATUS "Building example programs")
1466 SET(EX_COMMON_OBJS examples/common/alhelpers.c)
1468 ADD_EXECUTABLE(alstream examples/alstream.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1469 TARGET_LINK_LIBRARIES(alstream ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${EX_TARGET})
1470 SET_PROPERTY(TARGET alstream APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1471 SET_PROPERTY(TARGET alstream APPEND PROPERTY
1472 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1475 ADD_EXECUTABLE(alreverb examples/alreverb.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1476 TARGET_LINK_LIBRARIES(alreverb ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${EX_TARGET})
1477 SET_PROPERTY(TARGET alreverb APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1478 SET_PROPERTY(TARGET alreverb APPEND PROPERTY
1479 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1482 ADD_EXECUTABLE(allatency examples/allatency.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1483 TARGET_LINK_LIBRARIES(allatency ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${EX_TARGET})
1484 SET_PROPERTY(TARGET allatency APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1485 SET_PROPERTY(TARGET allatency APPEND PROPERTY
1486 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1489 ADD_EXECUTABLE(alloopback examples/alloopback.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1490 TARGET_LINK_LIBRARIES(alloopback ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${EX_TARGET})
1491 SET_PROPERTY(TARGET alloopback APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1492 SET_PROPERTY(TARGET alloopback APPEND PROPERTY
1493 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1496 ADD_EXECUTABLE(alhrtf examples/alhrtf.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1497 TARGET_LINK_LIBRARIES(alhrtf ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${EX_TARGET})
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 "57.56.101")
1518 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1521 IF(AVCODEC_VERSION VERSION_LESS "57.64.101")
1522 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1525 IF(AVUTIL_VERSION VERSION_LESS "55.34.101")
1526 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1529 IF(SWSCALE_VERSION VERSION_LESS "4.2.100")
1530 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1533 IF(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1534 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1539 ADD_EXECUTABLE(alffplay examples/alffplay.cpp ${COMMON_OBJS})
1540 TARGET_LINK_LIBRARIES(alffplay ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ${EX_TARGET})
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")