1 # CMake build file list for OpenAL
3 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5)
7 IF(COMMAND CMAKE_POLICY)
8 CMAKE_POLICY(SET CMP0003 NEW)
9 CMAKE_POLICY(SET CMP0005 NEW)
11 CMAKE_POLICY(SET CMP0042 NEW)
14 CMAKE_POLICY(SET CMP0054 NEW)
16 ENDIF(COMMAND CMAKE_POLICY)
18 SET(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
20 INCLUDE(CheckFunctionExists)
21 INCLUDE(CheckLibraryExists)
22 INCLUDE(CheckSharedFunctionExists)
23 INCLUDE(CheckIncludeFile)
24 INCLUDE(CheckIncludeFiles)
25 INCLUDE(CheckSymbolExists)
26 INCLUDE(CheckCCompilerFlag)
27 INCLUDE(CheckCXXCompilerFlag)
28 INCLUDE(CheckCSourceCompiles)
29 INCLUDE(CheckTypeSize)
30 include(CheckStructHasMember)
31 include(CheckFileOffsetBits)
32 include(GNUInstallDirs)
34 SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
37 OPTION(ALSOFT_DLOPEN "Check for the dlopen API for loading optional libs" ON)
39 OPTION(ALSOFT_WERROR "Treat compile warnings as errors" OFF)
41 OPTION(ALSOFT_UTILS "Build and install utility programs" ON)
42 OPTION(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
44 OPTION(ALSOFT_EXAMPLES "Build and install example programs" ON)
45 OPTION(ALSOFT_TESTS "Build and install test programs" ON)
47 OPTION(ALSOFT_CONFIG "Install alsoft.conf sample configuration file" ON)
48 OPTION(ALSOFT_HRTF_DEFS "Install HRTF definition files" ON)
49 OPTION(ALSOFT_AMBDEC_PRESETS "Install AmbDec preset files" ON)
50 OPTION(ALSOFT_INSTALL "Install headers and libraries" ON)
52 if(DEFINED SHARE_INSTALL_DIR)
53 message(WARNING "SHARE_INSTALL_DIR is deprecated. Use the variables provided by the GNUInstallDirs module instead")
54 set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
57 if(DEFINED LIB_SUFFIX)
58 message(WARNING "LIB_SUFFIX is deprecated. Use the variables provided by the GNUInstallDirs module instead")
66 ADD_DEFINITIONS("-D_WIN32 -D_WIN32_WINNT=0x0502")
68 # This option is mainly for static linking OpenAL Soft into another project
69 # that already defines the IDs. It is up to that project to ensure all
70 # required IDs are defined.
71 OPTION(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
74 OPTION(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
77 SET(DLLTOOL "${HOST}-dlltool")
79 SET(DLLTOOL "dlltool")
86 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
87 IF ("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
88 ADD_DEFINITIONS("-I/usr/include")
89 SET(EXTRA_LIBS ${EXTRA_LIBS} -L/usr/lib)
96 SET(LIB_MAJOR_VERSION "1")
97 SET(LIB_MINOR_VERSION "17")
99 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
105 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
106 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
109 CHECK_C_COMPILER_FLAG(-std=c11 HAVE_STD_C11)
111 SET(CMAKE_C_FLAGS "-std=c11 ${CMAKE_C_FLAGS}")
113 CHECK_C_COMPILER_FLAG(-std=c99 HAVE_STD_C99)
115 SET(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
119 CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD_CXX11)
121 SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
125 # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
126 CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
127 IF(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
128 SET(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
129 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=500")
130 CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
131 IF(NOT HAVE_POSIX_MEMALIGN_POSIX)
132 SET(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
134 ADD_DEFINITIONS(-D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=500)
137 UNSET(OLD_REQUIRED_FLAGS)
140 # Set defines for large file support
141 CHECK_FILE_OFFSET_BITS()
142 IF(_FILE_OFFSET_BITS)
143 ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS})
144 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
146 ADD_DEFINITIONS(-D_LARGEFILE_SOURCE -D_LARGE_FILES)
147 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_LARGEFILE_SOURCE -D_LARGE_FILES")
149 # MSVC may need workarounds for C99 restrict and inline
151 # TODO: Once we truly require C99, these restrict and inline checks should go
153 CHECK_C_SOURCE_COMPILES("int *restrict foo;
154 int main() {return 0;}" HAVE_RESTRICT)
155 IF(NOT HAVE_RESTRICT)
156 ADD_DEFINITIONS("-Drestrict=")
157 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Drestrict=")
160 CHECK_C_SOURCE_COMPILES("inline void foo(void) { }
161 int main() {return 0;}" HAVE_INLINE)
163 CHECK_C_SOURCE_COMPILES("__inline void foo(void) { }
164 int main() {return 0;}" HAVE___INLINE)
165 IF(NOT HAVE___INLINE)
166 MESSAGE(FATAL_ERROR "No inline keyword found, please report!")
169 ADD_DEFINITIONS(-Dinline=__inline)
170 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Dinline=__inline")
174 # Make sure we have C99-style inline semantics with GCC (4.3 or newer).
175 IF(CMAKE_COMPILER_IS_GNUCC)
176 SET(CMAKE_C_FLAGS "-fno-gnu89-inline ${CMAKE_C_FLAGS}")
178 SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
179 # Force no inlining for the next test.
180 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -fno-inline")
182 CHECK_C_SOURCE_COMPILES("extern inline int foo() { return 0; }
183 int main() {return foo();}" INLINE_IS_C99)
184 IF(NOT INLINE_IS_C99)
185 MESSAGE(FATAL_ERROR "Your compiler does not seem to have C99 inline semantics!
186 Please update your compiler for better C99 compliance.")
189 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
192 # Check if we have a proper timespec declaration
193 CHECK_STRUCT_HAS_MEMBER("struct timespec" tv_sec time.h HAVE_STRUCT_TIMESPEC)
194 IF(HAVE_STRUCT_TIMESPEC)
195 # Define it here so we don't have to include config.h for it
196 ADD_DEFINITIONS("-DHAVE_STRUCT_TIMESPEC")
199 # Some systems may need libatomic for C11 atomic functions to work
200 SET(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
201 SET(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
202 CHECK_C_SOURCE_COMPILES("#include <stdatomic.h>
203 int _Atomic foo = ATOMIC_VAR_INIT(0);
206 return atomic_fetch_add(&foo, 2);
209 IF(NOT HAVE_LIBATOMIC)
210 SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
212 SET(EXTRA_LIBS atomic ${EXTRA_LIBS})
214 UNSET(OLD_REQUIRED_LIBRARIES)
216 # Include liblog for Android logging
217 CHECK_LIBRARY_EXISTS(log __android_log_print "" HAVE_LIBLOG)
219 SET(EXTRA_LIBS log ${EXTRA_LIBS})
220 SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
223 # Check if we have C99 variable length arrays
224 CHECK_C_SOURCE_COMPILES(
225 "int main(int argc, char *argv[])
227 volatile int tmp[argc];
233 # Check if we have C99 bool
234 CHECK_C_SOURCE_COMPILES(
235 "int main(int argc, char *argv[])
238 ret = (argc > 1) ? 1 : 0;
243 # Check if we have C11 static_assert
244 CHECK_C_SOURCE_COMPILES(
247 _Static_assert(sizeof(int) == sizeof(int), \"What\");
250 HAVE_C11_STATIC_ASSERT)
252 # Check if we have C11 alignas
253 CHECK_C_SOURCE_COMPILES(
254 "_Alignas(16) int foo;
261 # Check if we have C11 _Atomic
262 CHECK_C_SOURCE_COMPILES(
263 "#include <stdatomic.h>
264 const int _Atomic foo = ATOMIC_VAR_INIT(~0);
265 int _Atomic bar = ATOMIC_VAR_INIT(0);
268 atomic_fetch_add(&bar, 2);
269 return atomic_load(&foo);
273 # Add definitions, compiler switches, etc.
274 INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_BINARY_DIR}")
275 IF(CMAKE_VERSION VERSION_LESS "2.8.8")
276 INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc")
277 IF(WIN32 AND ALSOFT_NO_UID_DEFS)
278 ADD_DEFINITIONS("-DAL_NO_UID_DEFS")
282 IF(NOT CMAKE_BUILD_TYPE)
283 SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
284 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
287 IF(NOT CMAKE_DEBUG_POSTFIX)
288 SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
289 "Library postfix for debug builds. Normally left blank."
295 ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
296 ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
297 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} /wd4098")
300 STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
302 STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
305 MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
308 OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
309 IF(FORCE_STATIC_VCRT)
311 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
312 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
313 IF(${flag_var} MATCHES "/MD")
314 STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
319 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Winline -Wall")
320 CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
322 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wextra")
326 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror")
329 # Force enable -fPIC for CMake versions before 2.8.9 (later versions have
330 # the POSITION_INDEPENDENT_CODE target property). The static common library
331 # will be linked into the dynamic openal library, which requires all its
332 # code to be position-independent.
333 IF(CMAKE_VERSION VERSION_LESS "2.8.9" AND NOT WIN32)
334 CHECK_C_COMPILER_FLAG(-fPIC HAVE_FPIC_SWITCH)
336 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC")
340 # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
342 FOREACH(flag_var CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
343 IF(${flag_var} MATCHES "-DNDEBUG")
344 STRING(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
348 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
349 int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
351 option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
352 if(ALSOFT_STATIC_LIBGCC)
353 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
354 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
355 check_c_source_compiles(
361 HAVE_STATIC_LIBGCC_SWITCH
363 if(HAVE_STATIC_LIBGCC_SWITCH)
364 set(EXTRA_LIBS ${EXTRA_LIBS} -static-libgcc)
366 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
367 unset(OLD_REQUIRED_LIBRARIES)
371 # Set visibility/export options if available
374 SET(EXPORT_DECL "__declspec(dllexport)")
376 SET(ALIGN_DECL "__declspec(align(x))")
378 SET(ALIGN_DECL "__declspec(aligned(x))")
381 SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
382 # Yes GCC, really don't accept visibility modes you don't support
383 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
385 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
386 int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
387 IF(HAVE_GCC_PROTECTED_VISIBILITY)
388 SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
390 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
391 int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
392 IF(HAVE_GCC_DEFAULT_VISIBILITY)
393 SET(EXPORT_DECL "__attribute__((visibility(\"default\")))")
397 IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
398 CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
399 IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
400 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
401 SET(HIDDEN_DECL "__attribute__((visibility(\"hidden\")))")
405 CHECK_C_SOURCE_COMPILES("int foo __attribute__((aligned(16)));
406 int main() {return 0;}" HAVE_ATTRIBUTE_ALIGNED)
407 IF(HAVE_ATTRIBUTE_ALIGNED)
408 SET(ALIGN_DECL "__attribute__((aligned(x)))")
411 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
417 SET(SSE4_1_SWITCH "")
418 SET(FPU_NEON_SWITCH "")
420 CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
422 SET(SSE_SWITCH "-msse")
424 CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
425 IF(HAVE_MSSE2_SWITCH)
426 SET(SSE2_SWITCH "-msse2")
428 CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
429 IF(HAVE_MSSE3_SWITCH)
430 SET(SSE3_SWITCH "-msse3")
432 CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
433 IF(HAVE_MSSE4_1_SWITCH)
434 SET(SSE4_1_SWITCH "-msse4.1")
436 CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
437 IF(HAVE_MFPU_NEON_SWITCH)
438 SET(FPU_NEON_SWITCH "-mfpu=neon")
442 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
443 int main() {return 0;}" HAVE_GCC_FORMAT)
445 CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
446 CHECK_INCLUDE_FILE(stdalign.h HAVE_STDALIGN_H)
447 CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
448 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
449 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
450 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
451 CHECK_INCLUDE_FILE(intrin.h HAVE_INTRIN_H)
452 CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
453 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
454 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
455 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
456 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
457 IF(NOT HAVE_GUIDDEF_H)
458 CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
461 # Some systems need libm for some of the following math functions to work
462 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
464 SET(EXTRA_LIBS m ${EXTRA_LIBS})
465 SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
468 # Check for the dlopen API (for dynamicly loading backend libs)
470 CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
472 SET(EXTRA_LIBS dl ${EXTRA_LIBS})
473 SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
476 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
479 # Check for a cpuid intrinsic
481 CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
484 unsigned int eax, ebx, ecx, edx;
485 return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
486 }" HAVE_GCC_GET_CPUID)
489 CHECK_C_SOURCE_COMPILES("#include <intrin.h>
495 }" HAVE_CPUID_INTRINSIC)
498 CHECK_SYMBOL_EXISTS(aligned_alloc stdlib.h HAVE_ALIGNED_ALLOC)
499 CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
500 CHECK_SYMBOL_EXISTS(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
501 CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
502 CHECK_SYMBOL_EXISTS(modff math.h HAVE_MODFF)
504 CHECK_SYMBOL_EXISTS(alloca malloc.h HAVE_ALLOCA)
506 MESSAGE(FATAL_ERROR "No alloca function found, please report!")
511 CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
512 CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
515 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
516 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
517 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
518 IF(NOT HAVE_STRCASECMP)
519 CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
520 IF(NOT HAVE__STRICMP)
521 MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
524 ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
527 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
528 IF(NOT HAVE_STRNCASECMP)
529 CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
530 IF(NOT HAVE__STRNICMP)
531 MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
534 ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
537 CHECK_SYMBOL_EXISTS(strnlen string.h HAVE_STRNLEN)
538 CHECK_SYMBOL_EXISTS(snprintf stdio.h HAVE_SNPRINTF)
539 IF(NOT HAVE_SNPRINTF)
540 CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
541 IF(NOT HAVE__SNPRINTF)
542 MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
545 ADD_DEFINITIONS(-Dsnprintf=_snprintf)
548 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
549 IF(NOT HAVE_ISFINITE)
550 CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
552 CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
554 MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
556 ADD_DEFINITIONS(-Disfinite=_finite)
558 ADD_DEFINITIONS(-Disfinite=finite)
562 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
564 CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
566 MESSAGE(FATAL_ERROR "No isnan function found, please report!")
569 ADD_DEFINITIONS(-Disnan=_isnan)
573 # Check if we have Windows headers
574 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0502)
575 IF(NOT HAVE_WINDOWS_H)
576 CHECK_SYMBOL_EXISTS(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
577 IF(NOT HAVE_GETTIMEOFDAY)
578 MESSAGE(FATAL_ERROR "No timing function found!")
581 CHECK_SYMBOL_EXISTS(nanosleep time.h HAVE_NANOSLEEP)
582 IF(NOT HAVE_NANOSLEEP)
583 MESSAGE(FATAL_ERROR "No sleep function found!")
586 # We need pthreads outside of Windows
587 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
588 IF(NOT HAVE_PTHREAD_H)
589 MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
591 # Some systems need pthread_np.h to get recursive mutexes
592 CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
594 CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
596 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pthread")
597 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
598 SET(EXTRA_LIBS ${EXTRA_LIBS} -pthread)
601 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
603 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
606 CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
608 IF(HAVE_PTHREAD_NP_H)
609 CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
610 IF(NOT HAVE_PTHREAD_SETNAME_NP)
611 CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
613 CHECK_C_SOURCE_COMPILES("
615 #include <pthread_np.h>
618 pthread_setname_np(\"testname\");
621 PTHREAD_SETNAME_NP_ONE_PARAM
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
640 CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np pthread.h HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
643 CHECK_SYMBOL_EXISTS(pthread_mutex_timedlock pthread.h HAVE_PTHREAD_MUTEX_TIMEDLOCK)
645 CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
647 SET(EXTRA_LIBS rt ${EXTRA_LIBS})
651 # Check for a 64-bit type
652 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
653 IF(NOT HAVE_STDINT_H)
655 CHECK_C_SOURCE_COMPILES("#define _WIN32_WINNT 0x0502
658 int main() {return 0;}" HAVE___INT64)
661 IF(NOT SIZEOF_LONG MATCHES "8")
662 IF(NOT SIZEOF_LONG_LONG MATCHES "8")
663 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
670 SET(COMMON_OBJS common/almalloc.c
676 SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
680 OpenAL32/alExtension.c
682 OpenAL32/alListener.c
686 OpenAL32/sample_cvt.c
688 SET(ALC_OBJS Alc/ALc.c
694 Alc/effects/compressor.c
695 Alc/effects/dedicated.c
696 Alc/effects/distortion.c
698 Alc/effects/equalizer.c
699 Alc/effects/flanger.c
700 Alc/effects/modulator.c
715 SET(CPU_EXTS "Default")
730 SET(HAVE_PORTAUDIO 0)
731 SET(HAVE_PULSEAUDIO 0)
732 SET(HAVE_COREAUDIO 0)
736 # Check for SSE support
737 OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
738 CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE_SWITCH}")
740 OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
741 IF(ALSOFT_CPUEXT_SSE)
742 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
744 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse.c)
746 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse.c PROPERTIES
747 COMPILE_FLAGS "${SSE_SWITCH}")
749 SET(CPU_EXTS "${CPU_EXTS}, SSE")
753 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
754 MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
757 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
758 CHECK_INCLUDE_FILE(emmintrin.h HAVE_EMMINTRIN_H "${SSE2_SWITCH}")
760 OPTION(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
761 IF(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
762 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
764 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse2.c)
766 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse2.c PROPERTIES
767 COMPILE_FLAGS "${SSE2_SWITCH}")
769 SET(CPU_EXTS "${CPU_EXTS}, SSE2")
773 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
774 MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
777 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE3 support" OFF)
778 CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}")
780 OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
781 IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
782 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
784 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse3.c)
786 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse3.c PROPERTIES
787 COMPILE_FLAGS "${SSE3_SWITCH}")
789 SET(CPU_EXTS "${CPU_EXTS}, SSE3")
793 IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
794 MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
797 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
798 CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}")
800 OPTION(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
801 IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE4_1)
802 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
804 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse41.c)
806 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse41.c PROPERTIES
807 COMPILE_FLAGS "${SSE4_1_SWITCH}")
809 SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
813 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
814 MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
817 # Check for ARM Neon support
818 OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
819 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H)
821 OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
822 IF(ALSOFT_CPUEXT_NEON)
824 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_neon.c)
826 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_neon.c PROPERTIES
827 COMPILE_FLAGS "${FPU_NEON_SWITCH}")
829 SET(CPU_EXTS "${CPU_EXTS}, Neon")
832 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
833 MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
837 IF(WIN32 OR HAVE_DLFCN_H)
839 MACRO(ADD_BACKEND_LIBS _LIBS)
842 SET(IS_LINKED " (linked)")
843 MACRO(ADD_BACKEND_LIBS _LIBS)
844 SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
849 SET(ALC_OBJS ${ALC_OBJS}
851 # Default backends, always available
852 Alc/backends/loopback.c
857 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
860 OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
861 IF(ALSOFT_BACKEND_ALSA)
863 SET(BACKENDS "${BACKENDS} ALSA${IS_LINKED},")
864 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/alsa.c)
865 ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
866 IF(CMAKE_VERSION VERSION_LESS "2.8.8")
867 INCLUDE_DIRECTORIES(${ALSA_INCLUDE_DIRS})
871 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
872 MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
876 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
879 OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
880 IF(ALSOFT_BACKEND_OSS)
882 SET(BACKENDS "${BACKENDS} OSS,")
883 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/oss.c)
884 IF(CMAKE_VERSION VERSION_LESS "2.8.8")
885 INCLUDE_DIRECTORIES(${OSS_INCLUDE_DIRS})
889 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
890 MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
893 # Check Solaris backend
894 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
895 FIND_PACKAGE(AudioIO)
897 OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
898 IF(ALSOFT_BACKEND_SOLARIS)
900 SET(BACKENDS "${BACKENDS} Solaris,")
901 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/solaris.c)
902 IF(CMAKE_VERSION VERSION_LESS "2.8.8")
903 INCLUDE_DIRECTORIES(${AUDIOIO_INCLUDE_DIRS})
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})
921 IF(CMAKE_VERSION VERSION_LESS "2.8.8")
922 INCLUDE_DIRECTORIES(${SOUNDIO_INCLUDE_DIRS})
926 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
927 MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
931 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
934 OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
935 IF(ALSOFT_BACKEND_QSA)
937 SET(BACKENDS "${BACKENDS} QSA (linked),")
938 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/qsa.c)
939 SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
940 IF(CMAKE_VERSION VERSION_LESS "2.8.8")
941 INCLUDE_DIRECTORIES(${QSA_INCLUDE_DIRS})
945 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
946 MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
949 # Check Windows-only backends
950 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
951 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
952 OPTION(ALSOFT_REQUIRE_MMDEVAPI "Require MMDevApi backend" OFF)
954 # Check MMSystem backend
955 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0502)
957 CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
959 OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
960 IF(ALSOFT_BACKEND_WINMM)
962 SET(BACKENDS "${BACKENDS} WinMM,")
963 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/winmm.c)
964 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
969 # Check DSound backend
972 OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
973 IF(ALSOFT_BACKEND_DSOUND)
975 SET(BACKENDS "${BACKENDS} DirectSound${IS_LINKED},")
976 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/dsound.c)
977 ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
978 IF(CMAKE_VERSION VERSION_LESS "2.8.8")
979 INCLUDE_DIRECTORIES(${DSOUND_INCLUDE_DIRS})
984 # Check for MMDevApi backend
985 CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
986 IF(HAVE_MMDEVICEAPI_H)
987 OPTION(ALSOFT_BACKEND_MMDEVAPI "Enable MMDevApi backend" ON)
988 IF(ALSOFT_BACKEND_MMDEVAPI)
990 SET(BACKENDS "${BACKENDS} MMDevApi,")
991 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/mmdevapi.c)
995 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
996 MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
998 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
999 MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
1001 IF(ALSOFT_REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
1002 MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
1005 # Check PortAudio backend
1006 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1007 FIND_PACKAGE(PortAudio)
1009 OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1010 IF(ALSOFT_BACKEND_PORTAUDIO)
1011 SET(HAVE_PORTAUDIO 1)
1012 SET(BACKENDS "${BACKENDS} PortAudio${IS_LINKED},")
1013 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/portaudio.c)
1014 ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
1015 IF(CMAKE_VERSION VERSION_LESS "2.8.8")
1016 INCLUDE_DIRECTORIES(${PORTAUDIO_INCLUDE_DIRS})
1020 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1021 MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
1024 # Check PulseAudio backend
1025 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1026 FIND_PACKAGE(PulseAudio)
1027 IF(PULSEAUDIO_FOUND)
1028 OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1029 IF(ALSOFT_BACKEND_PULSEAUDIO)
1030 SET(HAVE_PULSEAUDIO 1)
1031 SET(BACKENDS "${BACKENDS} PulseAudio${IS_LINKED},")
1032 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/pulseaudio.c)
1033 ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
1034 IF(CMAKE_VERSION VERSION_LESS "2.8.8")
1035 INCLUDE_DIRECTORIES(${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 IF(CMAKE_VERSION VERSION_LESS "2.8.8")
1054 INCLUDE_DIRECTORIES(${JACK_INCLUDE_DIRS})
1058 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1059 MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
1062 # Check CoreAudio backend
1063 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1064 FIND_LIBRARY(COREAUDIO_FRAMEWORK
1066 PATHS /System/Library/Frameworks
1068 IF(COREAUDIO_FRAMEWORK)
1069 OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1070 IF(ALSOFT_BACKEND_COREAUDIO)
1071 SET(HAVE_COREAUDIO 1)
1072 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/coreaudio.c)
1073 SET(BACKENDS "${BACKENDS} CoreAudio,")
1074 SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
1075 SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
1076 SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1078 # Some versions of OSX may need the AudioToolbox framework. Add it if
1080 FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
1082 PATHS ~/Library/Frameworks
1084 /System/Library/Frameworks
1086 IF(AUDIOTOOLBOX_LIBRARY)
1087 SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1091 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1092 MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1095 # Check for OpenSL (Android) backend
1096 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1097 CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
1098 IF(HAVE_SLES_OPENSLES_ANDROID_H)
1099 CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
1100 IF(HAVE_LIBOPENSLES)
1101 OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1102 IF(ALSOFT_BACKEND_OPENSL)
1104 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/opensl.c)
1105 SET(BACKENDS "${BACKENDS} OpenSL,")
1106 SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
1110 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1111 MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1114 # Optionally enable the Wave Writer backend
1115 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1116 IF(ALSOFT_BACKEND_WAVE)
1118 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/wave.c)
1119 SET(BACKENDS "${BACKENDS} WaveFile,")
1122 # This is always available
1123 SET(BACKENDS "${BACKENDS} Null")
1125 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" OFF)
1126 if(ALSOFT_EMBED_HRTF_DATA)
1128 set(ALC_OBJS ${ALC_OBJS} Alc/hrtf_res.rc)
1130 macro(add_custom_binary FILENAME BIN_NAME)
1131 set(outfile ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${FILENAME}${CMAKE_C_OUTPUT_EXTENSION})
1132 set(stubsrcfile ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${FILENAME}.stub.c)
1133 set(stubfile ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${FILENAME}.stub${CMAKE_C_OUTPUT_EXTENSION})
1134 add_custom_command(OUTPUT ${outfile}
1135 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hrtf/${FILENAME}"
1136 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/hrtf"
1137 COMMAND touch "${stubsrcfile}"
1138 COMMAND "${CMAKE_C_COMPILER}" -o "${stubfile}" -c "${stubsrcfile}"
1139 COMMAND "${CMAKE_LINKER}" -r -o "${outfile}" -sectcreate binary ${BIN_NAME} ${FILENAME} "${stubfile}"
1140 COMMAND rm "${stubsrcfile}" "${stubfile}"
1141 COMMENT "Generating ${FILENAME}${CMAKE_C_OUTPUT_EXTENSION}"
1144 set(ALC_OBJS ${ALC_OBJS} ${outfile})
1146 add_custom_binary(default-44100.mhr "default_44100")
1147 add_custom_binary(default-48000.mhr "default_48000")
1149 set(FILENAMES default-44100.mhr default-48000.mhr)
1150 foreach(FILENAME ${FILENAMES})
1151 set(outfile ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${FILENAME}${CMAKE_C_OUTPUT_EXTENSION})
1152 add_custom_command(OUTPUT ${outfile}
1153 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hrtf/${FILENAME}"
1154 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/hrtf"
1155 COMMAND "${CMAKE_LINKER}" -r -b binary -o "${outfile}" ${FILENAME}
1156 COMMAND "${CMAKE_OBJCOPY}" --rename-section .data=.rodata,alloc,load,readonly,data,contents "${outfile}" "${outfile}"
1157 COMMENT "Generating ${FILENAME}${CMAKE_C_OUTPUT_EXTENSION}"
1160 set(ALC_OBJS ${ALC_OBJS} ${outfile})
1168 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1169 add_subdirectory(utils/alsoft-config)
1174 FIND_PACKAGE(SDL_sound)
1175 IF(SDL_SOUND_FOUND AND CMAKE_VERSION VERSION_LESS "2.8.8")
1176 INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1178 FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1179 IF(FFMPEG_FOUND AND CMAKE_VERSION VERSION_LESS "2.8.8")
1180 INCLUDE_DIRECTORIES(${FFMPEG_INCLUDE_DIRS})
1185 IF(LIBTYPE STREQUAL "STATIC")
1186 ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC)
1187 SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
1191 IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1192 # Get the current working branch and its latest abbreviated commit hash
1193 ADD_CUSTOM_TARGET(build_version
1194 ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
1195 -D LIB_VERSION=${LIB_VERSION}
1196 -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1197 -D DST=${OpenAL_BINARY_DIR}/version.h
1198 -P ${OpenAL_SOURCE_DIR}/version.cmake
1199 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1203 SET(GIT_BRANCH "UNKNOWN")
1204 SET(GIT_COMMIT_HASH "unknown")
1206 "${OpenAL_SOURCE_DIR}/version.h.in"
1207 "${OpenAL_BINARY_DIR}/version.h")
1210 # Needed for openal.pc.in
1211 SET(prefix ${CMAKE_INSTALL_PREFIX})
1212 SET(exec_prefix "\${prefix}")
1213 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1214 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1215 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1216 SET(PACKAGE_VERSION "${LIB_VERSION}")
1220 "${OpenAL_SOURCE_DIR}/config.h.in"
1221 "${OpenAL_BINARY_DIR}/config.h")
1223 "${OpenAL_SOURCE_DIR}/openal.pc.in"
1224 "${OpenAL_BINARY_DIR}/openal.pc"
1227 # Build a common library with reusable helpers
1228 ADD_LIBRARY(common STATIC ${COMMON_OBJS})
1229 SET_PROPERTY(TARGET common APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1230 IF(NOT LIBTYPE STREQUAL "STATIC")
1231 SET_PROPERTY(TARGET common PROPERTY POSITION_INDEPENDENT_CODE TRUE)
1234 # Build main library
1235 IF(LIBTYPE STREQUAL "STATIC")
1236 ADD_LIBRARY(${LIBNAME} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1238 ADD_LIBRARY(${LIBNAME} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
1240 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1241 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY COMPILE_DEFINITIONS AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES)
1242 IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1243 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY COMPILE_DEFINITIONS AL_NO_UID_DEFS)
1245 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc")
1247 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${ALSA_INCLUDE_DIRS})
1250 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${OSS_INCLUDE_DIRS})
1253 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${AUDIOIO_INCLUDE_DIRS})
1256 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${SOUNDIO_INCLUDE_DIRS})
1259 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${QSA_INCLUDE_DIRS})
1262 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${DSOUND_INCLUDE_DIRS})
1265 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${PORTAUDIO_INCLUDE_DIRS})
1268 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${PULSEAUDIO_INCLUDE_DIRS})
1271 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${JACK_INCLUDE_DIRS})
1275 SET_PROPERTY(TARGET ${LIBNAME} APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:WINDOWS")
1276 ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1277 SET_PROPERTY(TARGET ${LIBNAME} APPEND_STRING PROPERTY LINK_FLAGS " -mwindows")
1281 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
1282 SOVERSION ${LIB_MAJOR_VERSION})
1283 IF(WIN32 AND NOT LIBTYPE STREQUAL "STATIC")
1284 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
1286 IF(MINGW AND ALSOFT_BUILD_IMPORT_LIB)
1287 FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1288 FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1289 IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1291 IF(NOT SED_EXECUTABLE)
1292 MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1294 IF(NOT DLLTOOL_EXECUTABLE)
1295 MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1298 SET_PROPERTY(TARGET ${LIBNAME} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--output-def,${LIBNAME}.def")
1299 ADD_CUSTOM_COMMAND(TARGET ${LIBNAME} POST_BUILD
1300 COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" ${LIBNAME}.def
1301 COMMAND "${DLLTOOL_EXECUTABLE}" -d ${LIBNAME}.def -l ${LIBNAME}.lib -D ${LIBNAME}.dll
1302 COMMENT "Stripping ordinals from ${LIBNAME}.def and generating ${LIBNAME}.lib..."
1309 TARGET_LINK_LIBRARIES(${LIBNAME} common ${EXTRA_LIBS})
1310 IF(TARGET build_version)
1311 ADD_DEPENDENCIES(${LIBNAME} build_version)
1315 # Add an install target here
1316 INSTALL(TARGETS ${LIBNAME}
1317 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1318 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1319 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1321 INSTALL(FILES include/AL/al.h
1325 include/AL/efx-creative.h
1326 include/AL/efx-presets.h
1327 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
1329 INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1330 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1335 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1336 MESSAGE(STATUS " ${BACKENDS}")
1338 MESSAGE(STATUS "Building with support for CPU extensions:")
1339 MESSAGE(STATUS " ${CPU_EXTS}")
1344 MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
1345 MESSAGE(STATUS " This is probably NOT what you want!")
1350 if(ALSOFT_EMBED_HRTF_DATA)
1351 message(STATUS "Embedding HRTF datasets")
1355 # Install alsoft.conf configuration file
1357 INSTALL(FILES alsoftrc.sample
1358 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal
1360 MESSAGE(STATUS "Installing sample configuration")
1364 # Install HRTF definitions
1365 IF(ALSOFT_HRTF_DEFS)
1366 INSTALL(FILES hrtf/default-44100.mhr
1367 hrtf/default-48000.mhr
1368 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf
1370 MESSAGE(STATUS "Installing HRTF definitions")
1374 # Install AmbDec presets
1375 IF(ALSOFT_AMBDEC_PRESETS)
1376 INSTALL(FILES presets/3D7.1.ambdec
1377 presets/hexagon.ambdec
1378 presets/itu5.1.ambdec
1379 presets/rectangle.ambdec
1380 presets/square.ambdec
1382 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
1384 MESSAGE(STATUS "Installing AmbDec presets")
1389 ADD_EXECUTABLE(openal-info utils/openal-info.c)
1390 SET_PROPERTY(TARGET openal-info APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1391 TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
1393 ADD_EXECUTABLE(makehrtf utils/makehrtf.c)
1394 SET_PROPERTY(TARGET makehrtf APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1396 TARGET_LINK_LIBRARIES(makehrtf m)
1399 ADD_EXECUTABLE(bsincgen utils/bsincgen.c)
1400 SET_PROPERTY(TARGET bsincgen APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1402 TARGET_LINK_LIBRARIES(bsincgen m)
1406 INSTALL(TARGETS openal-info makehrtf bsincgen
1407 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1408 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1409 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1413 MESSAGE(STATUS "Building utility programs")
1414 IF(TARGET alsoft-config)
1415 MESSAGE(STATUS "Building configuration program")
1421 ADD_LIBRARY(test-common STATIC examples/common/alhelpers.c)
1422 SET_PROPERTY(TARGET test-common APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1424 ADD_EXECUTABLE(altonegen examples/altonegen.c)
1425 TARGET_LINK_LIBRARIES(altonegen test-common ${LIBNAME})
1426 SET_PROPERTY(TARGET altonegen APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1429 INSTALL(TARGETS altonegen
1430 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1431 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1432 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1436 MESSAGE(STATUS "Building test programs")
1443 ADD_LIBRARY(ex-common STATIC examples/common/alhelpers.c
1444 examples/common/sdl_sound.c)
1445 SET_PROPERTY(TARGET ex-common APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1446 SET_PROPERTY(TARGET ex-common APPEND PROPERTY
1447 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1450 ADD_EXECUTABLE(alstream examples/alstream.c)
1451 TARGET_LINK_LIBRARIES(alstream ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1453 SET_PROPERTY(TARGET alstream APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1454 SET_PROPERTY(TARGET alstream APPEND PROPERTY
1455 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1458 ADD_EXECUTABLE(alreverb examples/alreverb.c)
1459 TARGET_LINK_LIBRARIES(alreverb ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1461 SET_PROPERTY(TARGET alreverb APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1462 SET_PROPERTY(TARGET alreverb APPEND PROPERTY
1463 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1466 ADD_EXECUTABLE(allatency examples/allatency.c)
1467 TARGET_LINK_LIBRARIES(allatency ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1469 SET_PROPERTY(TARGET allatency APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1470 SET_PROPERTY(TARGET allatency APPEND PROPERTY
1471 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1474 ADD_EXECUTABLE(alloopback examples/alloopback.c)
1475 TARGET_LINK_LIBRARIES(alloopback ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1477 SET_PROPERTY(TARGET alloopback APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1478 SET_PROPERTY(TARGET alloopback APPEND PROPERTY
1479 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1482 ADD_EXECUTABLE(alhrtf examples/alhrtf.c)
1483 TARGET_LINK_LIBRARIES(alhrtf ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1485 SET_PROPERTY(TARGET alhrtf APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1486 SET_PROPERTY(TARGET alhrtf APPEND PROPERTY
1487 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1491 INSTALL(TARGETS alstream alreverb allatency alloopback alhrtf
1492 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1493 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1494 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1502 IF(AVFORMAT_VERSION VERSION_LESS "55.33.100")
1503 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 55.33.100)")
1506 IF(AVCODEC_VERSION VERSION_LESS "55.52.102")
1507 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 55.52.102)")
1510 IF(AVUTIL_VERSION VERSION_LESS "52.66.100")
1511 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 52.66.100)")
1514 IF(SWSCALE_VERSION VERSION_LESS "2.5.102")
1515 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 2.5.102)")
1518 IF(SWRESAMPLE_VERSION VERSION_LESS "0.18.100")
1519 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 0.18.100)")
1523 IF(FFVER_OK AND NOT MSVC)
1524 ADD_EXECUTABLE(alffplay examples/alffplay.c)
1525 TARGET_LINK_LIBRARIES(alffplay common ${SDL2_LIBRARY} ${LIBNAME} ${FFMPEG_LIBRARIES})
1526 SET_PROPERTY(TARGET alffplay APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1527 SET_PROPERTY(TARGET alffplay APPEND PROPERTY
1528 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS}
1532 INSTALL(TARGETS alffplay
1533 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1534 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1535 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1538 MESSAGE(STATUS "Building SDL and FFmpeg example programs")
1540 MESSAGE(STATUS "Building SDL example programs")