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)
40 OPTION(ALSOFT_DLOPEN "Check for the dlopen API for loading optional libs" ON)
42 OPTION(ALSOFT_WERROR "Treat compile warnings as errors" OFF)
44 OPTION(ALSOFT_UTILS "Build and install utility programs" ON)
45 OPTION(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
47 OPTION(ALSOFT_EXAMPLES "Build and install example programs" ON)
48 OPTION(ALSOFT_TESTS "Build and install test programs" ON)
50 OPTION(ALSOFT_CONFIG "Install alsoft.conf sample configuration file" ON)
51 OPTION(ALSOFT_HRTF_DEFS "Install HRTF definition files" ON)
52 OPTION(ALSOFT_AMBDEC_PRESETS "Install AmbDec preset files" ON)
53 OPTION(ALSOFT_INSTALL "Install headers and libraries" ON)
55 if(DEFINED SHARE_INSTALL_DIR)
56 message(WARNING "SHARE_INSTALL_DIR is deprecated. Use the variables provided by the GNUInstallDirs module instead")
57 set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
60 if(DEFINED LIB_SUFFIX)
61 message(WARNING "LIB_SUFFIX is deprecated. Use the variables provided by the GNUInstallDirs module instead")
65 SET(CPP_DEFS ) # C pre-process, not C++
72 SET(CPP_DEFS ${CPP_DEFS} _WIN32 _WIN32_WINNT=0x0502)
74 OPTION(ALSOFT_BUILD_ROUTER "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)" OFF)
76 # This option is mainly for static linking OpenAL Soft into another project
77 # that already defines the IDs. It is up to that project to ensure all
78 # required IDs are defined.
79 OPTION(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
82 OPTION(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
85 SET(DLLTOOL "${HOST}-dlltool")
87 SET(DLLTOOL "dlltool")
94 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
95 IF ("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
96 SET(INC_PATHS ${INC_PATHS} /usr/include)
97 SET(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
104 SET(LIB_MAJOR_VERSION "1")
105 SET(LIB_MINOR_VERSION "18")
106 SET(LIB_REVISION "2")
107 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
113 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
114 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
117 CHECK_C_COMPILER_FLAG(-std=c11 HAVE_STD_C11)
119 SET(CMAKE_C_FLAGS "-std=c11 ${CMAKE_C_FLAGS}")
121 CHECK_C_COMPILER_FLAG(-std=c99 HAVE_STD_C99)
123 SET(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
127 CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD_CXX11)
129 SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
133 # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
134 CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
135 IF(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
136 SET(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
137 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
138 CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
139 IF(NOT HAVE_POSIX_MEMALIGN_POSIX)
140 SET(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
142 SET(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
145 UNSET(OLD_REQUIRED_FLAGS)
148 # Set defines for large file support
149 CHECK_FILE_OFFSET_BITS()
150 IF(_FILE_OFFSET_BITS)
151 SET(CPP_DEFS ${CPP_DEFS} "_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
152 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
154 SET(CPP_DEFS ${CPP_DEFS} _LARGEFILE_SOURCE _LARGE_FILES)
155 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_LARGEFILE_SOURCE -D_LARGE_FILES")
157 # MSVC may need workarounds for C99 restrict and inline
159 # TODO: Once we truly require C99, these restrict and inline checks should go
161 CHECK_C_SOURCE_COMPILES("int *restrict foo;
162 int main() {return 0;}" HAVE_RESTRICT)
163 IF(NOT HAVE_RESTRICT)
164 SET(CPP_DEFS ${CPP_DEFS} "restrict=")
165 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Drestrict=")
168 CHECK_C_SOURCE_COMPILES("inline void foo(void) { }
169 int main() {return 0;}" HAVE_INLINE)
171 CHECK_C_SOURCE_COMPILES("__inline void foo(void) { }
172 int main() {return 0;}" HAVE___INLINE)
173 IF(NOT HAVE___INLINE)
174 MESSAGE(FATAL_ERROR "No inline keyword found, please report!")
177 SET(CPP_DEFS ${CPP_DEFS} inline=__inline)
178 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Dinline=__inline")
182 # Make sure we have C99-style inline semantics with GCC (4.3 or newer).
183 IF(CMAKE_COMPILER_IS_GNUCC)
184 SET(CMAKE_C_FLAGS "-fno-gnu89-inline ${CMAKE_C_FLAGS}")
186 SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
187 # Force no inlining for the next test.
188 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -fno-inline")
190 CHECK_C_SOURCE_COMPILES("extern inline int foo() { return 0; }
191 int main() {return foo();}" INLINE_IS_C99)
192 IF(NOT INLINE_IS_C99)
193 MESSAGE(FATAL_ERROR "Your compiler does not seem to have C99 inline semantics!
194 Please update your compiler for better C99 compliance.")
197 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
200 # Check if we have a proper timespec declaration
201 CHECK_STRUCT_HAS_MEMBER("struct timespec" tv_sec time.h HAVE_STRUCT_TIMESPEC)
202 IF(HAVE_STRUCT_TIMESPEC)
203 # Define it here so we don't have to include config.h for it
204 SET(CPP_DEFS ${CPP_DEFS} HAVE_STRUCT_TIMESPEC)
207 # Some systems may need libatomic for C11 atomic functions to work
208 SET(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
209 SET(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
210 CHECK_C_SOURCE_COMPILES("#include <stdatomic.h>
211 int _Atomic foo = ATOMIC_VAR_INIT(0);
214 return atomic_fetch_add(&foo, 2);
217 IF(NOT HAVE_LIBATOMIC)
218 SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
220 SET(EXTRA_LIBS atomic ${EXTRA_LIBS})
222 UNSET(OLD_REQUIRED_LIBRARIES)
224 # Include liblog for Android logging
225 CHECK_LIBRARY_EXISTS(log __android_log_print "" HAVE_LIBLOG)
227 SET(EXTRA_LIBS log ${EXTRA_LIBS})
228 SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
231 # Check if we have C99 bool
232 CHECK_C_SOURCE_COMPILES(
233 "int main(int argc, char *argv[])
236 ret = (argc > 1) ? 1 : 0;
241 # Check if we have C11 static_assert
242 CHECK_C_SOURCE_COMPILES(
245 _Static_assert(sizeof(int) == sizeof(int), \"What\");
248 HAVE_C11_STATIC_ASSERT)
250 # Check if we have C11 alignas
251 CHECK_C_SOURCE_COMPILES(
252 "_Alignas(16) int foo;
259 # Check if we have C11 _Atomic
260 CHECK_C_SOURCE_COMPILES(
261 "#include <stdatomic.h>
262 int _Atomic foo = ATOMIC_VAR_INIT(0);
265 atomic_fetch_add(&foo, 2);
270 # Add definitions, compiler switches, etc.
271 INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_SOURCE_DIR}/common" "${OpenAL_BINARY_DIR}")
273 IF(NOT CMAKE_BUILD_TYPE)
274 SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
275 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
278 IF(NOT CMAKE_DEBUG_POSTFIX)
279 SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
280 "Library postfix for debug builds. Normally left blank."
285 SET(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE)
286 SET(C_FLAGS ${C_FLAGS} /wd4098)
289 STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
291 STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
294 MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
297 OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
298 IF(FORCE_STATIC_VCRT)
300 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
301 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
302 IF(${flag_var} MATCHES "/MD")
303 STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
308 SET(C_FLAGS ${C_FLAGS} -Winline -Wall)
309 CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
311 SET(C_FLAGS ${C_FLAGS} -Wextra)
315 SET(C_FLAGS ${C_FLAGS} -Werror)
318 # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
320 FOREACH(flag_var CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
321 IF(${flag_var} MATCHES "-DNDEBUG")
322 STRING(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
326 CHECK_C_COMPILER_FLAG(-fno-math-errno HAVE_FNO_MATH_ERRNO)
327 IF(HAVE_FNO_MATH_ERRNO)
328 SET(C_FLAGS ${C_FLAGS} -fno-math-errno)
331 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
332 int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
334 option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
335 if(ALSOFT_STATIC_LIBGCC)
336 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
337 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
338 check_c_source_compiles(
344 HAVE_STATIC_LIBGCC_SWITCH
346 if(HAVE_STATIC_LIBGCC_SWITCH)
347 SET(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
349 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
350 unset(OLD_REQUIRED_LIBRARIES)
354 # Set visibility/export options if available
356 SET(EXPORT_DECL "__declspec(dllexport)")
358 SET(ALIGN_DECL "__declspec(align(x))")
360 SET(ALIGN_DECL "__declspec(aligned(x))")
363 SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
364 # Yes GCC, really don't accept visibility modes you don't support
365 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
367 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
368 int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
369 IF(HAVE_GCC_PROTECTED_VISIBILITY)
370 SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
372 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
373 int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
374 IF(HAVE_GCC_DEFAULT_VISIBILITY)
375 SET(EXPORT_DECL "__attribute__((visibility(\"default\")))")
379 IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
380 CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
381 IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
382 SET(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
386 CHECK_C_SOURCE_COMPILES("int foo __attribute__((aligned(16)));
387 int main() {return 0;}" HAVE_ATTRIBUTE_ALIGNED)
388 IF(HAVE_ATTRIBUTE_ALIGNED)
389 SET(ALIGN_DECL "__attribute__((aligned(x)))")
392 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
395 CHECK_C_SOURCE_COMPILES("
399 ptr = __builtin_assume_aligned(ptr, 16);
401 }" HAVE___BUILTIN_ASSUME_ALIGNED)
402 IF(HAVE___BUILTIN_ASSUME_ALIGNED)
403 SET(ASSUME_ALIGNED_DECL "__builtin_assume_aligned(x, y)")
405 SET(ASSUME_ALIGNED_DECL "x")
411 SET(SSE4_1_SWITCH "")
412 SET(FPU_NEON_SWITCH "")
414 CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
416 SET(SSE_SWITCH "-msse")
418 CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
419 IF(HAVE_MSSE2_SWITCH)
420 SET(SSE2_SWITCH "-msse2")
422 CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
423 IF(HAVE_MSSE3_SWITCH)
424 SET(SSE3_SWITCH "-msse3")
426 CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
427 IF(HAVE_MSSE4_1_SWITCH)
428 SET(SSE4_1_SWITCH "-msse4.1")
430 CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
431 IF(HAVE_MFPU_NEON_SWITCH)
432 SET(FPU_NEON_SWITCH "-mfpu=neon")
435 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
436 int main() {return 0;}" HAVE_GCC_FORMAT)
438 CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
439 CHECK_INCLUDE_FILE(stdalign.h HAVE_STDALIGN_H)
440 CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
441 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
442 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
443 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
444 CHECK_INCLUDE_FILE(intrin.h HAVE_INTRIN_H)
445 CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
446 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
447 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
448 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
449 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
450 IF(NOT HAVE_GUIDDEF_H)
451 CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
454 # Some systems need libm for some of the following math functions to work
456 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
458 SET(MATH_LIB ${MATH_LIB} m)
459 SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
462 # Check for the dlopen API (for dynamicly loading backend libs)
464 CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
466 SET(EXTRA_LIBS dl ${EXTRA_LIBS})
467 SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
470 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
473 # Check for a cpuid intrinsic
475 CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
478 unsigned int eax, ebx, ecx, edx;
479 return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
480 }" HAVE_GCC_GET_CPUID)
483 CHECK_C_SOURCE_COMPILES("#include <intrin.h>
489 }" HAVE_CPUID_INTRINSIC)
492 CHECK_SYMBOL_EXISTS(sysconf unistd.h HAVE_SYSCONF)
493 CHECK_SYMBOL_EXISTS(aligned_alloc stdlib.h HAVE_ALIGNED_ALLOC)
494 CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
495 CHECK_SYMBOL_EXISTS(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
496 CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
497 CHECK_SYMBOL_EXISTS(modff math.h HAVE_MODFF)
498 CHECK_SYMBOL_EXISTS(log2f math.h HAVE_LOG2F)
501 CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
502 CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
505 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
506 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
507 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
508 IF(NOT HAVE_STRCASECMP)
509 CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
510 IF(NOT HAVE__STRICMP)
511 MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
514 SET(CPP_DEFS ${CPP_DEFS} strcasecmp=_stricmp)
517 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
518 IF(NOT HAVE_STRNCASECMP)
519 CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
520 IF(NOT HAVE__STRNICMP)
521 MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
524 SET(CPP_DEFS ${CPP_DEFS} strncasecmp=_strnicmp)
527 CHECK_SYMBOL_EXISTS(strnlen string.h HAVE_STRNLEN)
528 CHECK_SYMBOL_EXISTS(snprintf stdio.h HAVE_SNPRINTF)
529 IF(NOT HAVE_SNPRINTF)
530 CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
531 IF(NOT HAVE__SNPRINTF)
532 MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
535 SET(CPP_DEFS ${CPP_DEFS} snprintf=_snprintf)
538 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
539 IF(NOT HAVE_ISFINITE)
540 CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
542 CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
544 MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
546 SET(CPP_DEFS ${CPP_DEFS} isfinite=_finite)
548 SET(CPP_DEFS ${CPP_DEFS} isfinite=finite)
552 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
554 CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
556 MESSAGE(FATAL_ERROR "No isnan function found, please report!")
559 SET(CPP_DEFS ${CPP_DEFS} isnan=_isnan)
563 # Check if we have Windows headers
564 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0502)
565 IF(NOT HAVE_WINDOWS_H)
566 CHECK_SYMBOL_EXISTS(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
567 IF(NOT HAVE_GETTIMEOFDAY)
568 MESSAGE(FATAL_ERROR "No timing function found!")
571 CHECK_SYMBOL_EXISTS(nanosleep time.h HAVE_NANOSLEEP)
572 IF(NOT HAVE_NANOSLEEP)
573 MESSAGE(FATAL_ERROR "No sleep function found!")
576 # We need pthreads outside of Windows
577 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
578 IF(NOT HAVE_PTHREAD_H)
579 MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
581 # Some systems need pthread_np.h to get recursive mutexes
582 CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
584 CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
586 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
587 SET(C_FLAGS ${C_FLAGS} -pthread)
588 SET(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
591 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
593 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
596 CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
598 IF(HAVE_PTHREAD_NP_H)
599 CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
600 IF(NOT HAVE_PTHREAD_SETNAME_NP)
601 CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
603 CHECK_C_SOURCE_COMPILES("
605 #include <pthread_np.h>
608 pthread_setname_np(\"testname\");
611 PTHREAD_SETNAME_NP_ONE_PARAM
613 CHECK_C_SOURCE_COMPILES("
615 #include <pthread_np.h>
618 pthread_setname_np(pthread_self(), \"%s\", \"testname\");
621 PTHREAD_SETNAME_NP_THREE_PARAMS
624 CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np "pthread.h;pthread_np.h" HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
626 CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
627 IF(NOT HAVE_PTHREAD_SETNAME_NP)
628 CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
630 CHECK_C_SOURCE_COMPILES("
634 pthread_setname_np(\"testname\");
637 PTHREAD_SETNAME_NP_ONE_PARAM
639 CHECK_C_SOURCE_COMPILES("
643 pthread_setname_np(pthread_self(), \"%s\", \"testname\");
646 PTHREAD_SETNAME_NP_THREE_PARAMS
649 CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np pthread.h HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
652 CHECK_SYMBOL_EXISTS(pthread_mutex_timedlock pthread.h HAVE_PTHREAD_MUTEX_TIMEDLOCK)
654 CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
656 SET(EXTRA_LIBS rt ${EXTRA_LIBS})
660 CHECK_SYMBOL_EXISTS(getopt unistd.h HAVE_GETOPT)
662 # Check for a 64-bit type
663 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
664 IF(NOT HAVE_STDINT_H)
666 CHECK_C_SOURCE_COMPILES("#define _WIN32_WINNT 0x0502
669 int main() {return 0;}" HAVE___INT64)
672 IF(NOT SIZEOF_LONG MATCHES "8")
673 IF(NOT SIZEOF_LONG_LONG MATCHES "8")
674 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
681 SET(COMMON_OBJS common/almalloc.c
687 SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
691 OpenAL32/alExtension.c
693 OpenAL32/alListener.c
698 OpenAL32/sample_cvt.c
700 SET(ALC_OBJS Alc/ALc.c
708 Alc/effects/compressor.c
709 Alc/effects/dedicated.c
710 Alc/effects/distortion.c
712 Alc/effects/equalizer.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 ${FPU_NEON_SWITCH})
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 SET(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
882 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
883 MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
887 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
890 OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
891 IF(ALSOFT_BACKEND_OSS)
893 SET(BACKENDS "${BACKENDS} OSS,")
894 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/oss.c)
896 SET(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
898 SET(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
901 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
902 MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
905 # Check Solaris backend
906 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
907 FIND_PACKAGE(AudioIO)
909 OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
910 IF(ALSOFT_BACKEND_SOLARIS)
912 SET(BACKENDS "${BACKENDS} Solaris,")
913 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/solaris.c)
914 SET(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
917 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
918 MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
921 # Check SndIO backend
922 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
923 FIND_PACKAGE(SoundIO)
925 OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
926 IF(ALSOFT_BACKEND_SNDIO)
928 SET(BACKENDS "${BACKENDS} SndIO (linked),")
929 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/sndio.c)
930 SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
931 SET(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
934 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
935 MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
939 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
942 OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
943 IF(ALSOFT_BACKEND_QSA)
945 SET(BACKENDS "${BACKENDS} QSA (linked),")
946 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/qsa.c)
947 SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
948 SET(INC_PATHS ${INC_PATHS} ${QSA_INCLUDE_DIRS})
951 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
952 MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
955 # Check Windows-only backends
956 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
957 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
958 OPTION(ALSOFT_REQUIRE_MMDEVAPI "Require MMDevApi backend" OFF)
960 # Check MMSystem backend
961 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0502)
963 CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
965 OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
966 IF(ALSOFT_BACKEND_WINMM)
968 SET(BACKENDS "${BACKENDS} WinMM,")
969 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/winmm.c)
970 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
975 # Check DSound backend
978 OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
979 IF(ALSOFT_BACKEND_DSOUND)
981 SET(BACKENDS "${BACKENDS} DirectSound${IS_LINKED},")
982 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/dsound.c)
983 ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
984 SET(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIRS})
988 # Check for MMDevApi backend
989 CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
990 IF(HAVE_MMDEVICEAPI_H)
991 OPTION(ALSOFT_BACKEND_MMDEVAPI "Enable MMDevApi backend" ON)
992 IF(ALSOFT_BACKEND_MMDEVAPI)
994 SET(BACKENDS "${BACKENDS} MMDevApi,")
995 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/mmdevapi.c)
999 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1000 MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
1002 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1003 MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
1005 IF(ALSOFT_REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
1006 MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
1009 # Check PortAudio backend
1010 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1011 FIND_PACKAGE(PortAudio)
1013 OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1014 IF(ALSOFT_BACKEND_PORTAUDIO)
1015 SET(HAVE_PORTAUDIO 1)
1016 SET(BACKENDS "${BACKENDS} PortAudio${IS_LINKED},")
1017 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/portaudio.c)
1018 ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
1019 SET(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
1022 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1023 MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
1026 # Check PulseAudio backend
1027 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1028 FIND_PACKAGE(PulseAudio)
1029 IF(PULSEAUDIO_FOUND)
1030 OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1031 IF(ALSOFT_BACKEND_PULSEAUDIO)
1032 SET(HAVE_PULSEAUDIO 1)
1033 SET(BACKENDS "${BACKENDS} PulseAudio${IS_LINKED},")
1034 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/pulseaudio.c)
1035 ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
1036 SET(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
1039 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1040 MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1043 # Check JACK backend
1044 OPTION(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1047 OPTION(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1048 IF(ALSOFT_BACKEND_JACK)
1050 SET(BACKENDS "${BACKENDS} JACK${IS_LINKED},")
1051 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/jack.c)
1052 ADD_BACKEND_LIBS(${JACK_LIBRARIES})
1053 SET(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1056 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1057 MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
1060 # Check CoreAudio backend
1061 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1062 FIND_LIBRARY(COREAUDIO_FRAMEWORK
1064 PATHS /System/Library/Frameworks
1066 IF(COREAUDIO_FRAMEWORK)
1067 OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1068 IF(ALSOFT_BACKEND_COREAUDIO)
1069 SET(HAVE_COREAUDIO 1)
1070 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/coreaudio.c)
1071 SET(BACKENDS "${BACKENDS} CoreAudio,")
1072 SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
1073 SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
1074 SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1076 # Some versions of OSX may need the AudioToolbox framework. Add it if
1078 FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
1080 PATHS ~/Library/Frameworks
1082 /System/Library/Frameworks
1084 IF(AUDIOTOOLBOX_LIBRARY)
1085 SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1089 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1090 MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1093 # Check for OpenSL (Android) backend
1094 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1095 CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
1096 IF(HAVE_SLES_OPENSLES_ANDROID_H)
1097 CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
1098 IF(HAVE_LIBOPENSLES)
1099 OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1100 IF(ALSOFT_BACKEND_OPENSL)
1102 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/opensl.c)
1103 SET(BACKENDS "${BACKENDS} OpenSL,")
1104 SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
1108 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1109 MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1112 # Optionally enable the Wave Writer backend
1113 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1114 IF(ALSOFT_BACKEND_WAVE)
1116 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/wave.c)
1117 SET(BACKENDS "${BACKENDS} WaveFile,")
1120 # This is always available
1121 SET(BACKENDS "${BACKENDS} Null")
1125 IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1126 # Get the current working branch and its latest abbreviated commit hash
1127 ADD_CUSTOM_TARGET(build_version
1128 ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
1129 -D LIB_VERSION=${LIB_VERSION}
1130 -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1131 -D DST=${OpenAL_BINARY_DIR}/version.h
1132 -P ${OpenAL_SOURCE_DIR}/version.cmake
1133 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1137 SET(GIT_BRANCH "UNKNOWN")
1138 SET(GIT_COMMIT_HASH "unknown")
1140 "${OpenAL_SOURCE_DIR}/version.h.in"
1141 "${OpenAL_BINARY_DIR}/version.h")
1144 SET(NATIVE_SRC_DIR "${OpenAL_SOURCE_DIR}/native-tools/")
1145 SET(NATIVE_BIN_DIR "${OpenAL_BINARY_DIR}/native-tools/")
1146 FILE(MAKE_DIRECTORY "${NATIVE_BIN_DIR}")
1148 SET(BIN2H_COMMAND "${NATIVE_BIN_DIR}bin2h")
1149 SET(BSINCGEN_COMMAND "${NATIVE_BIN_DIR}bsincgen")
1150 ADD_CUSTOM_COMMAND(OUTPUT "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1151 COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" "${NATIVE_SRC_DIR}"
1152 COMMAND ${CMAKE_COMMAND} -E remove "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1153 COMMAND ${CMAKE_COMMAND} --build . --config "Release"
1154 WORKING_DIRECTORY "${NATIVE_BIN_DIR}"
1155 DEPENDS "${NATIVE_SRC_DIR}CMakeLists.txt"
1156 IMPLICIT_DEPENDS C "${NATIVE_SRC_DIR}bin2h.c"
1157 C "${NATIVE_SRC_DIR}bsincgen.c"
1160 ADD_CUSTOM_TARGET(native-tools
1161 DEPENDS "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1165 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" OFF)
1166 if(ALSOFT_EMBED_HRTF_DATA)
1167 MACRO(make_hrtf_header FILENAME VARNAME)
1168 SET(infile "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1169 SET(outfile "${OpenAL_BINARY_DIR}/${FILENAME}.h")
1171 ADD_CUSTOM_COMMAND(OUTPUT "${outfile}"
1172 COMMAND "${BIN2H_COMMAND}" "${infile}" "${outfile}" ${VARNAME}
1173 DEPENDS native-tools "${infile}"
1176 SET(ALC_OBJS ${ALC_OBJS} "${outfile}")
1179 make_hrtf_header(default-44100.mhr "hrtf_default_44100")
1180 make_hrtf_header(default-48000.mhr "hrtf_default_48000")
1183 ADD_CUSTOM_COMMAND(OUTPUT "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1184 COMMAND "${BSINCGEN_COMMAND}" "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1185 DEPENDS native-tools "${NATIVE_SRC_DIR}bsincgen.c"
1188 SET(ALC_OBJS ${ALC_OBJS} "${OpenAL_BINARY_DIR}/bsinc_inc.h")
1191 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1192 add_subdirectory(utils/alsoft-config)
1197 FIND_PACKAGE(SDL_sound)
1198 FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1203 SET(LIBNAME "openal")
1205 SET(LIBNAME "OpenAL32")
1208 # Needed for openal.pc.in
1209 SET(prefix ${CMAKE_INSTALL_PREFIX})
1210 SET(exec_prefix "\${prefix}")
1211 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1212 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1213 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1214 SET(PACKAGE_VERSION "${LIB_VERSION}")
1215 IF(LIBTYPE STREQUAL "STATIC")
1216 SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
1221 "${OpenAL_SOURCE_DIR}/config.h.in"
1222 "${OpenAL_BINARY_DIR}/config.h")
1224 "${OpenAL_SOURCE_DIR}/openal.pc.in"
1225 "${OpenAL_BINARY_DIR}/openal.pc"
1229 # Add a static library with common functions used by multiple targets
1230 ADD_LIBRARY(common STATIC ${COMMON_OBJS})
1231 TARGET_COMPILE_DEFINITIONS(common PRIVATE ${CPP_DEFS})
1232 TARGET_COMPILE_OPTIONS(common PRIVATE ${C_FLAGS})
1236 SET(IMPL_TARGET OpenAL)
1240 # Build main library
1241 IF(LIBTYPE STREQUAL "STATIC")
1242 SET(CPP_DEFS ${CPP_DEFS} AL_LIBTYPE_STATIC)
1243 IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1244 SET(CPP_DEFS ${CPP_DEFS} AL_NO_UID_DEFS)
1246 ADD_LIBRARY(OpenAL STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1248 # Make sure to compile the common code with PIC, since it'll be linked into
1249 # shared libs that needs it.
1250 SET_PROPERTY(TARGET common PROPERTY POSITION_INDEPENDENT_CODE TRUE)
1251 SET(COMMON_LIB common)
1255 SET(SUBSYS_FLAG ${SUBSYS_FLAG} "/SUBSYSTEM:WINDOWS")
1256 ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1257 SET(SUBSYS_FLAG ${SUBSYS_FLAG} "-mwindows")
1261 IF(WIN32 AND ALSOFT_BUILD_ROUTER)
1262 ADD_LIBRARY(OpenAL SHARED router/router.c router/alc.c router/al.c)
1263 TARGET_COMPILE_DEFINITIONS(OpenAL
1264 PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1265 TARGET_COMPILE_OPTIONS(OpenAL PRIVATE ${C_FLAGS})
1266 TARGET_LINK_LIBRARIES(OpenAL PRIVATE ${LINKER_FLAGS} ${COMMON_LIB})
1267 SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "")
1268 SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1269 IF(TARGET build_version)
1270 ADD_DEPENDENCIES(OpenAL build_version)
1274 SET(LIBNAME "soft_oal")
1275 SET(IMPL_TARGET soft_oal)
1278 ADD_LIBRARY(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
1280 SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES PREFIX "")
1283 SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1284 VERSION ${LIB_VERSION}
1285 SOVERSION ${LIB_MAJOR_VERSION}
1287 TARGET_COMPILE_DEFINITIONS(${IMPL_TARGET}
1288 PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1289 TARGET_INCLUDE_DIRECTORIES(${IMPL_TARGET}
1290 PRIVATE "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc" ${INC_PATHS})
1291 TARGET_COMPILE_OPTIONS(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1292 TARGET_LINK_LIBRARIES(${IMPL_TARGET}
1293 PRIVATE ${LINKER_FLAGS} ${COMMON_LIB} ${EXTRA_LIBS} ${MATH_LIB})
1294 IF(TARGET build_version)
1295 ADD_DEPENDENCIES(${IMPL_TARGET} build_version)
1298 IF(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1299 FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1300 FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1301 IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1303 IF(NOT SED_EXECUTABLE)
1304 MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1306 IF(NOT DLLTOOL_EXECUTABLE)
1307 MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1310 SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS
1311 " -Wl,--output-def,OpenAL32.def")
1312 ADD_CUSTOM_COMMAND(TARGET OpenAL POST_BUILD
1313 COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1314 COMMAND "${DLLTOOL_EXECUTABLE}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1315 COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1322 INSTALL(TARGETS OpenAL EXPORT OpenAL
1323 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1324 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1325 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1326 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL
1328 EXPORT(TARGETS OpenAL
1330 FILE OpenALConfig.cmake)
1331 INSTALL(EXPORT OpenAL
1332 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1334 FILE OpenALConfig.cmake)
1335 INSTALL(FILES include/AL/al.h
1339 include/AL/efx-creative.h
1340 include/AL/efx-presets.h
1341 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
1343 INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1344 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1346 INSTALL(TARGETS soft_oal
1347 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1355 message(STATUS "Building DLL router")
1359 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1360 MESSAGE(STATUS " ${BACKENDS}")
1362 MESSAGE(STATUS "Building with support for CPU extensions:")
1363 MESSAGE(STATUS " ${CPU_EXTS}")
1368 MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
1369 MESSAGE(STATUS " This is probably NOT what you want!")
1374 if(ALSOFT_EMBED_HRTF_DATA)
1375 message(STATUS "Embedding HRTF datasets")
1379 # Install alsoft.conf configuration file
1381 INSTALL(FILES alsoftrc.sample
1382 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal
1384 MESSAGE(STATUS "Installing sample configuration")
1388 # Install HRTF definitions
1389 IF(ALSOFT_HRTF_DEFS)
1390 INSTALL(FILES hrtf/default-44100.mhr
1391 hrtf/default-48000.mhr
1392 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf
1394 MESSAGE(STATUS "Installing HRTF definitions")
1398 # Install AmbDec presets
1399 IF(ALSOFT_AMBDEC_PRESETS)
1400 INSTALL(FILES presets/3D7.1.ambdec
1401 presets/hexagon.ambdec
1402 presets/itu5.1.ambdec
1403 presets/itu5.1-nocenter.ambdec
1404 presets/rectangle.ambdec
1405 presets/square.ambdec
1407 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
1409 MESSAGE(STATUS "Installing AmbDec presets")
1414 ADD_EXECUTABLE(openal-info utils/openal-info.c)
1415 TARGET_COMPILE_OPTIONS(openal-info PRIVATE ${C_FLAGS})
1416 TARGET_LINK_LIBRARIES(openal-info PRIVATE ${LINKER_FLAGS} OpenAL)
1418 SET(MAKEHRTF_SRCS utils/makehrtf.c)
1420 SET(MAKEHRTF_SRCS ${MAKEHRTF_SRCS} utils/getopt.c)
1422 ADD_EXECUTABLE(makehrtf ${MAKEHRTF_SRCS})
1423 TARGET_COMPILE_DEFINITIONS(makehrtf PRIVATE ${CPP_DEFS})
1424 TARGET_COMPILE_OPTIONS(makehrtf PRIVATE ${C_FLAGS})
1426 TARGET_LINK_LIBRARIES(makehrtf PRIVATE ${LINKER_FLAGS} m)
1430 INSTALL(TARGETS openal-info makehrtf
1431 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1432 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1433 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1437 MESSAGE(STATUS "Building utility programs")
1438 IF(TARGET alsoft-config)
1439 MESSAGE(STATUS "Building configuration program")
1445 SET(TEST_COMMON_OBJS examples/common/alhelpers.c)
1447 ADD_EXECUTABLE(altonegen examples/altonegen.c ${TEST_COMMON_OBJS})
1448 TARGET_COMPILE_DEFINITIONS(altonegen PRIVATE ${CPP_DEFS})
1449 TARGET_COMPILE_OPTIONS(altonegen PRIVATE ${C_FLAGS})
1450 TARGET_LINK_LIBRARIES(altonegen PRIVATE ${LINKER_FLAGS} common OpenAL ${MATH_LIB})
1453 INSTALL(TARGETS altonegen
1454 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1455 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1456 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1460 MESSAGE(STATUS "Building test programs")
1465 ADD_EXECUTABLE(alrecord examples/alrecord.c)
1466 TARGET_COMPILE_DEFINITIONS(alrecord PRIVATE ${CPP_DEFS})
1467 TARGET_COMPILE_OPTIONS(alrecord PRIVATE ${C_FLAGS})
1468 TARGET_LINK_LIBRARIES(alrecord PRIVATE ${LINKER_FLAGS} common OpenAL)
1471 INSTALL(TARGETS alrecord
1472 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1473 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1474 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1478 MESSAGE(STATUS "Building example programs")
1482 # Add a static library with common functions used by multiple targets
1483 ADD_LIBRARY(ex-common STATIC examples/common/alhelpers.c)
1484 TARGET_COMPILE_DEFINITIONS(ex-common PRIVATE ${CPP_DEFS})
1485 TARGET_COMPILE_OPTIONS(ex-common PRIVATE ${C_FLAGS})
1487 ADD_EXECUTABLE(alplay examples/alplay.c)
1488 TARGET_COMPILE_DEFINITIONS(alplay PRIVATE ${CPP_DEFS})
1489 TARGET_INCLUDE_DIRECTORIES(alplay
1490 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1491 TARGET_COMPILE_OPTIONS(alplay PRIVATE ${C_FLAGS})
1492 TARGET_LINK_LIBRARIES(alplay
1493 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1496 ADD_EXECUTABLE(alstream examples/alstream.c)
1497 TARGET_COMPILE_DEFINITIONS(alstream PRIVATE ${CPP_DEFS})
1498 TARGET_INCLUDE_DIRECTORIES(alstream
1499 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1500 TARGET_COMPILE_OPTIONS(alstream PRIVATE ${C_FLAGS})
1501 TARGET_LINK_LIBRARIES(alstream
1502 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1505 ADD_EXECUTABLE(alreverb examples/alreverb.c)
1506 TARGET_COMPILE_DEFINITIONS(alreverb PRIVATE ${CPP_DEFS})
1507 TARGET_INCLUDE_DIRECTORIES(alreverb
1508 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1509 TARGET_COMPILE_OPTIONS(alreverb PRIVATE ${C_FLAGS})
1510 TARGET_LINK_LIBRARIES(alreverb
1511 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1514 ADD_EXECUTABLE(allatency examples/allatency.c)
1515 TARGET_COMPILE_DEFINITIONS(allatency PRIVATE ${CPP_DEFS})
1516 TARGET_INCLUDE_DIRECTORIES(allatency
1517 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1518 TARGET_COMPILE_OPTIONS(allatency PRIVATE ${C_FLAGS})
1519 TARGET_LINK_LIBRARIES(allatency
1520 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1523 ADD_EXECUTABLE(alloopback examples/alloopback.c)
1524 TARGET_COMPILE_DEFINITIONS(alloopback PRIVATE ${CPP_DEFS})
1525 TARGET_INCLUDE_DIRECTORIES(alloopback
1526 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1527 TARGET_COMPILE_OPTIONS(alloopback PRIVATE ${C_FLAGS})
1528 TARGET_LINK_LIBRARIES(alloopback
1529 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1532 ADD_EXECUTABLE(alhrtf examples/alhrtf.c)
1533 TARGET_COMPILE_DEFINITIONS(alhrtf PRIVATE ${CPP_DEFS})
1534 TARGET_INCLUDE_DIRECTORIES(alhrtf
1535 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1536 TARGET_COMPILE_OPTIONS(alhrtf PRIVATE ${C_FLAGS})
1537 TARGET_LINK_LIBRARIES(alhrtf
1538 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1542 INSTALL(TARGETS alplay alstream alreverb allatency alloopback alhrtf
1543 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1544 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1545 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1549 MESSAGE(STATUS "Building SDL_sound example programs")
1555 IF(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1556 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1559 IF(AVCODEC_VERSION VERSION_LESS "57.64.101")
1560 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1563 IF(AVUTIL_VERSION VERSION_LESS "55.34.101")
1564 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1567 IF(SWSCALE_VERSION VERSION_LESS "4.2.100")
1568 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1571 IF(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1572 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1577 ADD_EXECUTABLE(alffplay examples/alffplay.cpp)
1578 TARGET_COMPILE_DEFINITIONS(alffplay PRIVATE ${CPP_DEFS})
1579 TARGET_INCLUDE_DIRECTORIES(alffplay
1580 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1581 TARGET_COMPILE_OPTIONS(alffplay PRIVATE ${C_FLAGS})
1582 TARGET_LINK_LIBRARIES(alffplay
1583 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} common OpenAL)
1586 INSTALL(TARGETS alffplay
1587 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1588 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1589 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1592 MESSAGE(STATUS "Building SDL+FFmpeg example programs")