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")
66 ADD_DEFINITIONS("-D_WIN32 -D_WIN32_WINNT=0x0502")
68 OPTION(ALSOFT_BUILD_ROUTER "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)" OFF)
70 # This option is mainly for static linking OpenAL Soft into another project
71 # that already defines the IDs. It is up to that project to ensure all
72 # required IDs are defined.
73 OPTION(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
76 OPTION(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
79 SET(DLLTOOL "${HOST}-dlltool")
81 SET(DLLTOOL "dlltool")
91 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
92 IF ("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
93 ADD_DEFINITIONS("-I/usr/include")
94 SET(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} -L/usr/lib")
101 SET(LIB_MAJOR_VERSION "1")
102 SET(LIB_MINOR_VERSION "18")
103 SET(LIB_REVISION "2")
104 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
110 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
111 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
114 CHECK_C_COMPILER_FLAG(-std=c11 HAVE_STD_C11)
116 SET(CMAKE_C_FLAGS "-std=c11 ${CMAKE_C_FLAGS}")
118 CHECK_C_COMPILER_FLAG(-std=c99 HAVE_STD_C99)
120 SET(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
124 CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD_CXX11)
126 SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
130 # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
131 CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
132 IF(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
133 SET(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
134 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
135 CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
136 IF(NOT HAVE_POSIX_MEMALIGN_POSIX)
137 SET(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
139 ADD_DEFINITIONS(-D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600)
142 UNSET(OLD_REQUIRED_FLAGS)
145 # Set defines for large file support
146 CHECK_FILE_OFFSET_BITS()
147 IF(_FILE_OFFSET_BITS)
148 ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS})
149 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
151 ADD_DEFINITIONS(-D_LARGEFILE_SOURCE -D_LARGE_FILES)
152 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_LARGEFILE_SOURCE -D_LARGE_FILES")
154 # MSVC may need workarounds for C99 restrict and inline
156 # TODO: Once we truly require C99, these restrict and inline checks should go
158 CHECK_C_SOURCE_COMPILES("int *restrict foo;
159 int main() {return 0;}" HAVE_RESTRICT)
160 IF(NOT HAVE_RESTRICT)
161 ADD_DEFINITIONS("-Drestrict=")
162 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Drestrict=")
165 CHECK_C_SOURCE_COMPILES("inline void foo(void) { }
166 int main() {return 0;}" HAVE_INLINE)
168 CHECK_C_SOURCE_COMPILES("__inline void foo(void) { }
169 int main() {return 0;}" HAVE___INLINE)
170 IF(NOT HAVE___INLINE)
171 MESSAGE(FATAL_ERROR "No inline keyword found, please report!")
174 ADD_DEFINITIONS(-Dinline=__inline)
175 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Dinline=__inline")
179 # Make sure we have C99-style inline semantics with GCC (4.3 or newer).
180 IF(CMAKE_COMPILER_IS_GNUCC)
181 SET(CMAKE_C_FLAGS "-fno-gnu89-inline ${CMAKE_C_FLAGS}")
183 SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
184 # Force no inlining for the next test.
185 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -fno-inline")
187 CHECK_C_SOURCE_COMPILES("extern inline int foo() { return 0; }
188 int main() {return foo();}" INLINE_IS_C99)
189 IF(NOT INLINE_IS_C99)
190 MESSAGE(FATAL_ERROR "Your compiler does not seem to have C99 inline semantics!
191 Please update your compiler for better C99 compliance.")
194 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
197 # Check if we have a proper timespec declaration
198 CHECK_STRUCT_HAS_MEMBER("struct timespec" tv_sec time.h HAVE_STRUCT_TIMESPEC)
199 IF(HAVE_STRUCT_TIMESPEC)
200 # Define it here so we don't have to include config.h for it
201 ADD_DEFINITIONS("-DHAVE_STRUCT_TIMESPEC")
204 # Some systems may need libatomic for C11 atomic functions to work
205 SET(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
206 SET(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
207 CHECK_C_SOURCE_COMPILES("#include <stdatomic.h>
208 int _Atomic foo = ATOMIC_VAR_INIT(0);
211 return atomic_fetch_add(&foo, 2);
214 IF(NOT HAVE_LIBATOMIC)
215 SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
217 SET(EXTRA_LIBS atomic ${EXTRA_LIBS})
219 UNSET(OLD_REQUIRED_LIBRARIES)
221 # Include liblog for Android logging
222 CHECK_LIBRARY_EXISTS(log __android_log_print "" HAVE_LIBLOG)
224 SET(EXTRA_LIBS log ${EXTRA_LIBS})
225 SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
228 # Check if we have C99 variable length arrays
229 CHECK_C_SOURCE_COMPILES(
230 "int main(int argc, char *argv[])
232 volatile int tmp[argc];
238 # Check if we have C99 bool
239 CHECK_C_SOURCE_COMPILES(
240 "int main(int argc, char *argv[])
243 ret = (argc > 1) ? 1 : 0;
248 # Check if we have C11 static_assert
249 CHECK_C_SOURCE_COMPILES(
252 _Static_assert(sizeof(int) == sizeof(int), \"What\");
255 HAVE_C11_STATIC_ASSERT)
257 # Check if we have C11 alignas
258 CHECK_C_SOURCE_COMPILES(
259 "_Alignas(16) int foo;
266 # Check if we have C11 _Atomic
267 CHECK_C_SOURCE_COMPILES(
268 "#include <stdatomic.h>
269 int _Atomic foo = ATOMIC_VAR_INIT(0);
272 atomic_fetch_add(&foo, 2);
277 # Add definitions, compiler switches, etc.
278 INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_SOURCE_DIR}/common" "${OpenAL_BINARY_DIR}")
280 IF(NOT CMAKE_BUILD_TYPE)
281 SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
282 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
285 IF(NOT CMAKE_DEBUG_POSTFIX)
286 SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
287 "Library postfix for debug builds. Normally left blank."
293 ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
294 ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
295 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} /wd4098")
298 STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
300 STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
303 MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
306 OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
307 IF(FORCE_STATIC_VCRT)
309 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
310 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
311 IF(${flag_var} MATCHES "/MD")
312 STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
317 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Winline -Wall")
318 CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
320 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wextra")
324 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror")
327 # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
329 FOREACH(flag_var CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
330 IF(${flag_var} MATCHES "-DNDEBUG")
331 STRING(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
335 CHECK_C_COMPILER_FLAG(-fno-math-errno HAVE_FNO_MATH_ERRNO)
336 IF(HAVE_FNO_MATH_ERRNO)
337 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fno-math-errno")
340 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
341 int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
343 option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
344 if(ALSOFT_STATIC_LIBGCC)
345 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
346 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
347 check_c_source_compiles(
353 HAVE_STATIC_LIBGCC_SWITCH
355 if(HAVE_STATIC_LIBGCC_SWITCH)
356 set(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} -static-libgcc")
358 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
359 unset(OLD_REQUIRED_LIBRARIES)
363 # Set visibility/export options if available
365 SET(EXPORT_DECL "__declspec(dllexport)")
367 SET(ALIGN_DECL "__declspec(align(x))")
369 SET(ALIGN_DECL "__declspec(aligned(x))")
372 SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
373 # Yes GCC, really don't accept visibility modes you don't support
374 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
376 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
377 int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
378 IF(HAVE_GCC_PROTECTED_VISIBILITY)
379 SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
381 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
382 int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
383 IF(HAVE_GCC_DEFAULT_VISIBILITY)
384 SET(EXPORT_DECL "__attribute__((visibility(\"default\")))")
388 IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
389 CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
390 IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
391 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
395 CHECK_C_SOURCE_COMPILES("int foo __attribute__((aligned(16)));
396 int main() {return 0;}" HAVE_ATTRIBUTE_ALIGNED)
397 IF(HAVE_ATTRIBUTE_ALIGNED)
398 SET(ALIGN_DECL "__attribute__((aligned(x)))")
401 SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
404 CHECK_C_SOURCE_COMPILES("
408 ptr = __builtin_assume_aligned(ptr, 16);
410 }" HAVE___BUILTIN_ASSUME_ALIGNED)
411 IF(HAVE___BUILTIN_ASSUME_ALIGNED)
412 SET(ASSUME_ALIGNED_DECL "__builtin_assume_aligned(x, y)")
414 SET(ASSUME_ALIGNED_DECL "x")
420 SET(SSE4_1_SWITCH "")
421 SET(FPU_NEON_SWITCH "")
423 CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
425 SET(SSE_SWITCH "-msse")
427 CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
428 IF(HAVE_MSSE2_SWITCH)
429 SET(SSE2_SWITCH "-msse2")
431 CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
432 IF(HAVE_MSSE3_SWITCH)
433 SET(SSE3_SWITCH "-msse3")
435 CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
436 IF(HAVE_MSSE4_1_SWITCH)
437 SET(SSE4_1_SWITCH "-msse4.1")
439 CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
440 IF(HAVE_MFPU_NEON_SWITCH)
441 SET(FPU_NEON_SWITCH "-mfpu=neon")
444 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
445 int main() {return 0;}" HAVE_GCC_FORMAT)
447 CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
448 CHECK_INCLUDE_FILE(stdalign.h HAVE_STDALIGN_H)
449 CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
450 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
451 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
452 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
453 CHECK_INCLUDE_FILE(intrin.h HAVE_INTRIN_H)
454 CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
455 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
456 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
457 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
458 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
459 IF(NOT HAVE_GUIDDEF_H)
460 CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
463 # Some systems need libm for some of the following math functions to work
464 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
466 SET(EXTRA_LIBS m ${EXTRA_LIBS})
467 SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
470 # Check for the dlopen API (for dynamicly loading backend libs)
472 CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
474 SET(EXTRA_LIBS dl ${EXTRA_LIBS})
475 SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
478 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
481 # Check for a cpuid intrinsic
483 CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
486 unsigned int eax, ebx, ecx, edx;
487 return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
488 }" HAVE_GCC_GET_CPUID)
491 CHECK_C_SOURCE_COMPILES("#include <intrin.h>
497 }" HAVE_CPUID_INTRINSIC)
500 CHECK_SYMBOL_EXISTS(aligned_alloc stdlib.h HAVE_ALIGNED_ALLOC)
501 CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
502 CHECK_SYMBOL_EXISTS(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
503 CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
504 CHECK_SYMBOL_EXISTS(modff math.h HAVE_MODFF)
505 CHECK_SYMBOL_EXISTS(log2f math.h HAVE_LOG2F)
507 CHECK_SYMBOL_EXISTS(alloca malloc.h HAVE_ALLOCA)
509 MESSAGE(FATAL_ERROR "No alloca function found, please report!")
514 CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
515 CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
518 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
519 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
520 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
521 IF(NOT HAVE_STRCASECMP)
522 CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
523 IF(NOT HAVE__STRICMP)
524 MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
527 ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
530 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
531 IF(NOT HAVE_STRNCASECMP)
532 CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
533 IF(NOT HAVE__STRNICMP)
534 MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
537 ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
540 CHECK_SYMBOL_EXISTS(strnlen string.h HAVE_STRNLEN)
541 CHECK_SYMBOL_EXISTS(snprintf stdio.h HAVE_SNPRINTF)
542 IF(NOT HAVE_SNPRINTF)
543 CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
544 IF(NOT HAVE__SNPRINTF)
545 MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
548 ADD_DEFINITIONS(-Dsnprintf=_snprintf)
551 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
552 IF(NOT HAVE_ISFINITE)
553 CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
555 CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
557 MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
559 ADD_DEFINITIONS(-Disfinite=_finite)
561 ADD_DEFINITIONS(-Disfinite=finite)
565 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
567 CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
569 MESSAGE(FATAL_ERROR "No isnan function found, please report!")
572 ADD_DEFINITIONS(-Disnan=_isnan)
576 # Check if we have Windows headers
577 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0502)
578 IF(NOT HAVE_WINDOWS_H)
579 CHECK_SYMBOL_EXISTS(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
580 IF(NOT HAVE_GETTIMEOFDAY)
581 MESSAGE(FATAL_ERROR "No timing function found!")
584 CHECK_SYMBOL_EXISTS(nanosleep time.h HAVE_NANOSLEEP)
585 IF(NOT HAVE_NANOSLEEP)
586 MESSAGE(FATAL_ERROR "No sleep function found!")
589 # We need pthreads outside of Windows
590 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
591 IF(NOT HAVE_PTHREAD_H)
592 MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
594 # Some systems need pthread_np.h to get recursive mutexes
595 CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
597 CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
599 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pthread")
600 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
601 SET(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} -pthread")
604 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
606 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
609 CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
611 IF(HAVE_PTHREAD_NP_H)
612 CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
613 IF(NOT HAVE_PTHREAD_SETNAME_NP)
614 CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
616 CHECK_C_SOURCE_COMPILES("
618 #include <pthread_np.h>
621 pthread_setname_np(\"testname\");
624 PTHREAD_SETNAME_NP_ONE_PARAM
626 CHECK_C_SOURCE_COMPILES("
628 #include <pthread_np.h>
631 pthread_setname_np(pthread_self(), \"%s\", \"testname\");
634 PTHREAD_SETNAME_NP_THREE_PARAMS
637 CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np "pthread.h;pthread_np.h" HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
639 CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
640 IF(NOT HAVE_PTHREAD_SETNAME_NP)
641 CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
643 CHECK_C_SOURCE_COMPILES("
647 pthread_setname_np(\"testname\");
650 PTHREAD_SETNAME_NP_ONE_PARAM
652 CHECK_C_SOURCE_COMPILES("
656 pthread_setname_np(pthread_self(), \"%s\", \"testname\");
659 PTHREAD_SETNAME_NP_THREE_PARAMS
662 CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np pthread.h HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
665 CHECK_SYMBOL_EXISTS(pthread_mutex_timedlock pthread.h HAVE_PTHREAD_MUTEX_TIMEDLOCK)
667 CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
669 SET(EXTRA_LIBS rt ${EXTRA_LIBS})
673 CHECK_SYMBOL_EXISTS(getopt unistd.h HAVE_GETOPT)
675 # Check for a 64-bit type
676 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
677 IF(NOT HAVE_STDINT_H)
679 CHECK_C_SOURCE_COMPILES("#define _WIN32_WINNT 0x0502
682 int main() {return 0;}" HAVE___INT64)
685 IF(NOT SIZEOF_LONG MATCHES "8")
686 IF(NOT SIZEOF_LONG_LONG MATCHES "8")
687 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
694 SET(COMMON_OBJS common/almalloc.c
700 SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
704 OpenAL32/alExtension.c
706 OpenAL32/alListener.c
710 OpenAL32/sample_cvt.c
712 SET(ALC_OBJS Alc/ALc.c
720 Alc/effects/compressor.c
721 Alc/effects/dedicated.c
722 Alc/effects/distortion.c
724 Alc/effects/equalizer.c
725 Alc/effects/flanger.c
726 Alc/effects/modulator.c
741 SET(CPU_EXTS "Default")
756 SET(HAVE_PORTAUDIO 0)
757 SET(HAVE_PULSEAUDIO 0)
758 SET(HAVE_COREAUDIO 0)
762 # Check for SSE support
763 OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
764 CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE_SWITCH}")
766 OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
767 IF(ALSOFT_CPUEXT_SSE)
768 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
770 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse.c)
772 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse.c PROPERTIES
773 COMPILE_FLAGS "${SSE_SWITCH}")
775 SET(CPU_EXTS "${CPU_EXTS}, SSE")
779 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
780 MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
783 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
784 CHECK_INCLUDE_FILE(emmintrin.h HAVE_EMMINTRIN_H "${SSE2_SWITCH}")
786 OPTION(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
787 IF(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
788 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
790 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse2.c)
792 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse2.c PROPERTIES
793 COMPILE_FLAGS "${SSE2_SWITCH}")
795 SET(CPU_EXTS "${CPU_EXTS}, SSE2")
799 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
800 MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
803 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE3 support" OFF)
804 CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}")
806 OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
807 IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
808 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
810 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse3.c)
812 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse3.c PROPERTIES
813 COMPILE_FLAGS "${SSE3_SWITCH}")
815 SET(CPU_EXTS "${CPU_EXTS}, SSE3")
819 IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
820 MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
823 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
824 CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}")
826 OPTION(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
827 IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE4_1)
828 IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
830 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse41.c)
832 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse41.c PROPERTIES
833 COMPILE_FLAGS "${SSE4_1_SWITCH}")
835 SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
839 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
840 MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
843 # Check for ARM Neon support
844 OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
845 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H)
847 OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
848 IF(ALSOFT_CPUEXT_NEON)
850 SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_neon.c)
852 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_neon.c PROPERTIES
853 COMPILE_FLAGS "${FPU_NEON_SWITCH}")
855 SET(CPU_EXTS "${CPU_EXTS}, Neon")
858 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
859 MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
863 IF(WIN32 OR HAVE_DLFCN_H)
865 MACRO(ADD_BACKEND_LIBS _LIBS)
868 SET(IS_LINKED " (linked)")
869 MACRO(ADD_BACKEND_LIBS _LIBS)
870 SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
875 SET(ALC_OBJS ${ALC_OBJS}
877 # Default backends, always available
878 Alc/backends/loopback.c
883 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
886 OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
887 IF(ALSOFT_BACKEND_ALSA)
889 SET(BACKENDS "${BACKENDS} ALSA${IS_LINKED},")
890 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/alsa.c)
891 ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
894 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
895 MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
899 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
902 OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
903 IF(ALSOFT_BACKEND_OSS)
905 SET(BACKENDS "${BACKENDS} OSS,")
906 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/oss.c)
908 SET(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
912 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
913 MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
916 # Check Solaris backend
917 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
918 FIND_PACKAGE(AudioIO)
920 OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
921 IF(ALSOFT_BACKEND_SOLARIS)
923 SET(BACKENDS "${BACKENDS} Solaris,")
924 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/solaris.c)
927 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
928 MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
931 # Check SndIO backend
932 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
933 FIND_PACKAGE(SoundIO)
935 OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
936 IF(ALSOFT_BACKEND_SNDIO)
938 SET(BACKENDS "${BACKENDS} SndIO (linked),")
939 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/sndio.c)
940 SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
943 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
944 MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
948 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
951 OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
952 IF(ALSOFT_BACKEND_QSA)
954 SET(BACKENDS "${BACKENDS} QSA (linked),")
955 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/qsa.c)
956 SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
959 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
960 MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
963 # Check Windows-only backends
964 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
965 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
966 OPTION(ALSOFT_REQUIRE_MMDEVAPI "Require MMDevApi backend" OFF)
968 # Check MMSystem backend
969 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0502)
971 CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
973 OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
974 IF(ALSOFT_BACKEND_WINMM)
976 SET(BACKENDS "${BACKENDS} WinMM,")
977 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/winmm.c)
978 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
983 # Check DSound backend
986 OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
987 IF(ALSOFT_BACKEND_DSOUND)
989 SET(BACKENDS "${BACKENDS} DirectSound${IS_LINKED},")
990 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/dsound.c)
991 ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
995 # Check for MMDevApi backend
996 CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
997 IF(HAVE_MMDEVICEAPI_H)
998 OPTION(ALSOFT_BACKEND_MMDEVAPI "Enable MMDevApi backend" ON)
999 IF(ALSOFT_BACKEND_MMDEVAPI)
1000 SET(HAVE_MMDEVAPI 1)
1001 SET(BACKENDS "${BACKENDS} MMDevApi,")
1002 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/mmdevapi.c)
1006 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1007 MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
1009 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1010 MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
1012 IF(ALSOFT_REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
1013 MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
1016 # Check PortAudio backend
1017 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1018 FIND_PACKAGE(PortAudio)
1020 OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1021 IF(ALSOFT_BACKEND_PORTAUDIO)
1022 SET(HAVE_PORTAUDIO 1)
1023 SET(BACKENDS "${BACKENDS} PortAudio${IS_LINKED},")
1024 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/portaudio.c)
1025 ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
1028 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1029 MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
1032 # Check PulseAudio backend
1033 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1034 FIND_PACKAGE(PulseAudio)
1035 IF(PULSEAUDIO_FOUND)
1036 OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1037 IF(ALSOFT_BACKEND_PULSEAUDIO)
1038 SET(HAVE_PULSEAUDIO 1)
1039 SET(BACKENDS "${BACKENDS} PulseAudio${IS_LINKED},")
1040 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/pulseaudio.c)
1041 ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
1044 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1045 MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1048 # Check JACK backend
1049 OPTION(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1052 OPTION(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1053 IF(ALSOFT_BACKEND_JACK)
1055 SET(BACKENDS "${BACKENDS} JACK${IS_LINKED},")
1056 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/jack.c)
1057 ADD_BACKEND_LIBS(${JACK_LIBRARIES})
1060 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1061 MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
1064 # Check CoreAudio backend
1065 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1066 FIND_LIBRARY(COREAUDIO_FRAMEWORK
1068 PATHS /System/Library/Frameworks
1070 IF(COREAUDIO_FRAMEWORK)
1071 OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1072 IF(ALSOFT_BACKEND_COREAUDIO)
1073 SET(HAVE_COREAUDIO 1)
1074 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/coreaudio.c)
1075 SET(BACKENDS "${BACKENDS} CoreAudio,")
1076 SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
1077 SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
1078 SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1080 # Some versions of OSX may need the AudioToolbox framework. Add it if
1082 FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
1084 PATHS ~/Library/Frameworks
1086 /System/Library/Frameworks
1088 IF(AUDIOTOOLBOX_LIBRARY)
1089 SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1093 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1094 MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1097 # Check for OpenSL (Android) backend
1098 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1099 CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
1100 IF(HAVE_SLES_OPENSLES_ANDROID_H)
1101 CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
1102 IF(HAVE_LIBOPENSLES)
1103 OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1104 IF(ALSOFT_BACKEND_OPENSL)
1106 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/opensl.c)
1107 SET(BACKENDS "${BACKENDS} OpenSL,")
1108 SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
1112 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1113 MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1116 # Optionally enable the Wave Writer backend
1117 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1118 IF(ALSOFT_BACKEND_WAVE)
1120 SET(ALC_OBJS ${ALC_OBJS} Alc/backends/wave.c)
1121 SET(BACKENDS "${BACKENDS} WaveFile,")
1124 # This is always available
1125 SET(BACKENDS "${BACKENDS} Null")
1129 IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1130 # Get the current working branch and its latest abbreviated commit hash
1131 ADD_CUSTOM_TARGET(build_version
1132 ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
1133 -D LIB_VERSION=${LIB_VERSION}
1134 -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1135 -D DST=${OpenAL_BINARY_DIR}/version.h
1136 -P ${OpenAL_SOURCE_DIR}/version.cmake
1137 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1141 SET(GIT_BRANCH "UNKNOWN")
1142 SET(GIT_COMMIT_HASH "unknown")
1144 "${OpenAL_SOURCE_DIR}/version.h.in"
1145 "${OpenAL_BINARY_DIR}/version.h")
1148 SET(NATIVE_SRC_DIR "${OpenAL_SOURCE_DIR}/native-tools/")
1149 SET(NATIVE_BIN_DIR "${OpenAL_BINARY_DIR}/native-tools/")
1150 FILE(MAKE_DIRECTORY "${NATIVE_BIN_DIR}")
1152 SET(BIN2H_COMMAND "${NATIVE_BIN_DIR}bin2h")
1153 SET(BSINCGEN_COMMAND "${NATIVE_BIN_DIR}bsincgen")
1154 ADD_CUSTOM_COMMAND(OUTPUT "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1155 COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" "${NATIVE_SRC_DIR}"
1156 COMMAND ${CMAKE_COMMAND} -E remove "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1157 COMMAND ${CMAKE_COMMAND} --build . --config "Release"
1158 WORKING_DIRECTORY "${NATIVE_BIN_DIR}"
1159 DEPENDS "${NATIVE_SRC_DIR}CMakeLists.txt"
1160 IMPLICIT_DEPENDS C "${NATIVE_SRC_DIR}bin2h.c"
1161 C "${NATIVE_SRC_DIR}bsincgen.c"
1164 ADD_CUSTOM_TARGET(native-tools
1165 DEPENDS "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1169 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" OFF)
1170 if(ALSOFT_EMBED_HRTF_DATA)
1171 MACRO(make_hrtf_header FILENAME VARNAME)
1172 SET(infile "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1173 SET(outfile "${OpenAL_BINARY_DIR}/${FILENAME}.h")
1175 ADD_CUSTOM_COMMAND(OUTPUT "${outfile}"
1176 COMMAND "${BIN2H_COMMAND}" "${infile}" "${outfile}" ${VARNAME}
1177 DEPENDS native-tools "${infile}"
1180 SET(ALC_OBJS ${ALC_OBJS} "${outfile}")
1183 make_hrtf_header(default-44100.mhr "hrtf_default_44100")
1184 make_hrtf_header(default-48000.mhr "hrtf_default_48000")
1187 ADD_CUSTOM_COMMAND(OUTPUT "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1188 COMMAND "${BSINCGEN_COMMAND}" "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1189 DEPENDS native-tools "${NATIVE_SRC_DIR}bsincgen.c"
1192 SET(ALC_OBJS ${ALC_OBJS} "${OpenAL_BINARY_DIR}/bsinc_inc.h")
1195 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1196 add_subdirectory(utils/alsoft-config)
1201 FIND_PACKAGE(SDL_sound)
1202 FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1206 IF(LIBTYPE STREQUAL "STATIC")
1207 ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC)
1208 SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
1212 SET(LIBNAME "openal")
1214 SET(LIBNAME "OpenAL32")
1217 # Needed for openal.pc.in
1218 SET(prefix ${CMAKE_INSTALL_PREFIX})
1219 SET(exec_prefix "\${prefix}")
1220 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1221 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1222 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1223 SET(PACKAGE_VERSION "${LIB_VERSION}")
1227 "${OpenAL_SOURCE_DIR}/config.h.in"
1228 "${OpenAL_BINARY_DIR}/config.h")
1230 "${OpenAL_SOURCE_DIR}/openal.pc.in"
1231 "${OpenAL_BINARY_DIR}/openal.pc"
1234 MACRO(ADD_INCLUDE_DIRS TRGT TESTVAR INCVAR)
1236 SET_PROPERTY(TARGET ${TRGT} APPEND PROPERTY INCLUDE_DIRECTORIES ${${INCVAR}})
1241 SET(IMPL_TARGET OpenAL)
1243 # Build main library
1244 IF(LIBTYPE STREQUAL "STATIC")
1245 ADD_LIBRARY(OpenAL STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1247 IF(WIN32 AND ALSOFT_BUILD_ROUTER)
1248 ADD_LIBRARY(OpenAL SHARED router/router.c router/alc.c router/al.c ${COMMON_OBJS})
1249 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1250 SET_PROPERTY(TARGET OpenAL APPEND PROPERTY
1251 COMPILE_DEFINITIONS AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES
1253 SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS ${EXTRA_LDFLAGS})
1255 SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:WINDOWS")
1256 ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1257 SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS " -mwindows")
1259 SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "")
1260 SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1261 IF(TARGET build_version)
1262 ADD_DEPENDENCIES(OpenAL build_version)
1266 SET(LIBNAME "soft_oal")
1267 SET(IMPL_TARGET soft_oal)
1270 ADD_LIBRARY(${IMPL_TARGET} SHARED ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1272 SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES PREFIX "")
1275 SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1276 VERSION ${LIB_VERSION}
1277 SOVERSION ${LIB_MAJOR_VERSION}
1279 SET_PROPERTY(TARGET ${IMPL_TARGET} APPEND PROPERTY INCLUDE_DIRECTORIES
1280 "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc"
1282 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_ALSA ALSA_INCLUDE_DIRS)
1283 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_OSS OSS_INCLUDE_DIRS)
1284 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_SOLARIS AUDIOIO_INCLUDE_DIRS)
1285 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_SNDIO SOUNDIO_INCLUDE_DIRS)
1286 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_QSA QSA_INCLUDE_DIRS)
1287 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_DSOUND DSOUND_INCLUDE_DIRS)
1288 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_PORTAUDIO PORTAUDIO_INCLUDE_DIRS)
1289 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_PULSEAUDIO PULSEAUDIO_INCLUDE_DIRS)
1290 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_JACK JACK_INCLUDE_DIRS)
1291 SET_PROPERTY(TARGET ${IMPL_TARGET} APPEND PROPERTY
1292 COMPILE_DEFINITIONS AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES
1294 IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1295 SET_PROPERTY(TARGET ${IMPL_TARGET} APPEND PROPERTY COMPILE_DEFINITIONS AL_NO_UID_DEFS)
1297 SET_PROPERTY(TARGET ${IMPL_TARGET} APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1298 SET_PROPERTY(TARGET ${IMPL_TARGET} APPEND_STRING PROPERTY LINK_FLAGS ${EXTRA_LDFLAGS})
1300 TARGET_LINK_LIBRARIES(${IMPL_TARGET} ${EXTRA_LIBS})
1301 IF(TARGET build_version)
1302 ADD_DEPENDENCIES(${IMPL_TARGET} build_version)
1307 SET_PROPERTY(TARGET ${IMPL_TARGET} APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:WINDOWS")
1308 ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1309 SET_PROPERTY(TARGET ${IMPL_TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -mwindows")
1312 if(NOT LIBTYPE STREQUAL "STATIC")
1313 IF(MINGW AND ALSOFT_BUILD_IMPORT_LIB)
1314 FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1315 FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1316 IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1318 IF(NOT SED_EXECUTABLE)
1319 MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1321 IF(NOT DLLTOOL_EXECUTABLE)
1322 MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1325 SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS
1326 " -Wl,--output-def,OpenAL32.def")
1327 ADD_CUSTOM_COMMAND(TARGET OpenAL POST_BUILD
1328 COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1329 COMMAND "${DLLTOOL_EXECUTABLE}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1330 COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1339 INSTALL(TARGETS OpenAL EXPORT OpenAL
1340 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1341 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1342 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1343 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL
1345 EXPORT(TARGETS OpenAL
1347 FILE OpenALConfig.cmake)
1348 INSTALL(EXPORT OpenAL
1349 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1351 FILE OpenALConfig.cmake)
1352 INSTALL(FILES include/AL/al.h
1356 include/AL/efx-creative.h
1357 include/AL/efx-presets.h
1358 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
1360 INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1361 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1363 INSTALL(TARGETS soft_oal
1364 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1372 message(STATUS "Building DLL router")
1376 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1377 MESSAGE(STATUS " ${BACKENDS}")
1379 MESSAGE(STATUS "Building with support for CPU extensions:")
1380 MESSAGE(STATUS " ${CPU_EXTS}")
1385 MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
1386 MESSAGE(STATUS " This is probably NOT what you want!")
1391 if(ALSOFT_EMBED_HRTF_DATA)
1392 message(STATUS "Embedding HRTF datasets")
1396 # Install alsoft.conf configuration file
1398 INSTALL(FILES alsoftrc.sample
1399 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal
1401 MESSAGE(STATUS "Installing sample configuration")
1405 # Install HRTF definitions
1406 IF(ALSOFT_HRTF_DEFS)
1407 INSTALL(FILES hrtf/default-44100.mhr
1408 hrtf/default-48000.mhr
1409 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf
1411 MESSAGE(STATUS "Installing HRTF definitions")
1415 # Install AmbDec presets
1416 IF(ALSOFT_AMBDEC_PRESETS)
1417 INSTALL(FILES presets/3D7.1.ambdec
1418 presets/hexagon.ambdec
1419 presets/itu5.1.ambdec
1420 presets/itu5.1-nocenter.ambdec
1421 presets/rectangle.ambdec
1422 presets/square.ambdec
1424 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
1426 MESSAGE(STATUS "Installing AmbDec presets")
1431 ADD_EXECUTABLE(openal-info utils/openal-info.c)
1432 SET_PROPERTY(TARGET openal-info APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1433 TARGET_LINK_LIBRARIES(openal-info OpenAL)
1435 SET(MAKEHRTF_SRCS utils/makehrtf.c)
1437 SET(MAKEHRTF_SRCS ${MAKEHRTF_SRCS} utils/getopt.c)
1439 ADD_EXECUTABLE(makehrtf ${MAKEHRTF_SRCS})
1440 SET_PROPERTY(TARGET makehrtf APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1442 TARGET_LINK_LIBRARIES(makehrtf m)
1446 INSTALL(TARGETS openal-info makehrtf
1447 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1448 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1449 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1453 MESSAGE(STATUS "Building utility programs")
1454 IF(TARGET alsoft-config)
1455 MESSAGE(STATUS "Building configuration program")
1461 SET(TEST_COMMON_OBJS examples/common/alhelpers.c)
1463 ADD_EXECUTABLE(altonegen examples/altonegen.c ${COMMON_OBJS} ${TEST_COMMON_OBJS})
1464 TARGET_LINK_LIBRARIES(altonegen OpenAL)
1465 SET_PROPERTY(TARGET altonegen APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1468 INSTALL(TARGETS altonegen
1469 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1470 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1471 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1475 MESSAGE(STATUS "Building test programs")
1480 ADD_EXECUTABLE(alrecord examples/alrecord.c ${COMMON_OBJS})
1481 TARGET_LINK_LIBRARIES(alrecord OpenAL)
1482 SET_PROPERTY(TARGET alrecord APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1485 INSTALL(TARGETS alrecord
1486 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1487 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1488 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1492 MESSAGE(STATUS "Building example programs")
1496 SET(EX_COMMON_OBJS examples/common/alhelpers.c)
1498 ADD_EXECUTABLE(alstream examples/alstream.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1499 TARGET_LINK_LIBRARIES(alstream ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} OpenAL)
1500 SET_PROPERTY(TARGET alstream APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1501 SET_PROPERTY(TARGET alstream APPEND PROPERTY
1502 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1505 ADD_EXECUTABLE(alreverb examples/alreverb.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1506 TARGET_LINK_LIBRARIES(alreverb ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} OpenAL)
1507 SET_PROPERTY(TARGET alreverb APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1508 SET_PROPERTY(TARGET alreverb APPEND PROPERTY
1509 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1512 ADD_EXECUTABLE(allatency examples/allatency.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1513 TARGET_LINK_LIBRARIES(allatency ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} OpenAL)
1514 SET_PROPERTY(TARGET allatency APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1515 SET_PROPERTY(TARGET allatency APPEND PROPERTY
1516 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1519 ADD_EXECUTABLE(alloopback examples/alloopback.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1520 TARGET_LINK_LIBRARIES(alloopback ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} OpenAL)
1521 SET_PROPERTY(TARGET alloopback APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1522 SET_PROPERTY(TARGET alloopback APPEND PROPERTY
1523 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1526 ADD_EXECUTABLE(alhrtf examples/alhrtf.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1527 TARGET_LINK_LIBRARIES(alhrtf ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} OpenAL)
1528 SET_PROPERTY(TARGET alhrtf APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1529 SET_PROPERTY(TARGET alhrtf APPEND PROPERTY
1530 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1534 INSTALL(TARGETS alstream alreverb allatency alloopback alhrtf
1535 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1536 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1537 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1541 MESSAGE(STATUS "Building SDL_sound example programs")
1547 IF(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1548 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1551 IF(AVCODEC_VERSION VERSION_LESS "57.64.101")
1552 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1555 IF(AVUTIL_VERSION VERSION_LESS "55.34.101")
1556 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1559 IF(SWSCALE_VERSION VERSION_LESS "4.2.100")
1560 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1563 IF(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1564 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1569 ADD_EXECUTABLE(alffplay examples/alffplay.cpp ${COMMON_OBJS})
1570 TARGET_LINK_LIBRARIES(alffplay ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} OpenAL)
1571 SET_PROPERTY(TARGET alffplay APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1572 SET_PROPERTY(TARGET alffplay APPEND PROPERTY
1573 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS}
1577 INSTALL(TARGETS alffplay
1578 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1579 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1580 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1583 MESSAGE(STATUS "Building SDL+FFmpeg example programs")