Use the correct input channel for the compressor effect
[openal-soft.git] / CMakeLists.txt
bloba7d137775d2364f77ecfe0e921c1182bb229773a
1 # CMake build file list for OpenAL
3 CMAKE_MINIMUM_REQUIRED(VERSION 3.0.2)
5 PROJECT(OpenAL)
7 IF(COMMAND CMAKE_POLICY)
8     CMAKE_POLICY(SET CMP0003 NEW)
9     CMAKE_POLICY(SET CMP0005 NEW)
10     IF(POLICY CMP0020)
11         CMAKE_POLICY(SET CMP0020 NEW)
12     ENDIF(POLICY CMP0020)
13     IF(POLICY CMP0042)
14         CMAKE_POLICY(SET CMP0042 NEW)
15     ENDIF(POLICY CMP0042)
16     IF(POLICY CMP0054)
17         CMAKE_POLICY(SET CMP0054 NEW)
18     ENDIF(POLICY CMP0054)
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}")
58 endif()
60 if(DEFINED LIB_SUFFIX)
61     message(WARNING "LIB_SUFFIX is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
62 endif()
65 SET(CPP_DEFS ) # C pre-process, not C++
66 SET(INC_PATHS )
67 SET(C_FLAGS )
68 SET(LINKER_FLAGS )
69 SET(EXTRA_LIBS )
71 IF(WIN32)
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)
81     IF(MINGW)
82         OPTION(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
83         IF(NOT DLLTOOL)
84             IF(HOST)
85                 SET(DLLTOOL "${HOST}-dlltool")
86             ELSE()
87                 SET(DLLTOOL "dlltool")
88             ENDIF()
89         ENDIF()
90     ENDIF()
91 ENDIF()
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)
98 ENDIF()
100 IF(NOT LIBTYPE)
101     SET(LIBTYPE SHARED)
102 ENDIF()
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}")
109 SET(EXPORT_DECL "")
110 SET(ALIGN_DECL "")
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)
118 IF(HAVE_STD_C11)
119     SET(CMAKE_C_FLAGS "-std=c11 ${CMAKE_C_FLAGS}")
120 ELSE()
121     CHECK_C_COMPILER_FLAG(-std=c99 HAVE_STD_C99)
122     IF(HAVE_STD_C99)
123         SET(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
124     ENDIF()
125 ENDIF()
127 CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD_CXX11)
128 IF(HAVE_STD_CXX11)
129     SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
130 ENDIF()
132 if(NOT WIN32)
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})
141         ELSE()
142             SET(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
143         ENDIF()
144     ENDIF()
145     UNSET(OLD_REQUIRED_FLAGS)
146 ENDIF()
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}")
153 ENDIF()
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
158 IF(MSVC)
159     # TODO: Once we truly require C99, these restrict and inline checks should go
160     # away.
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=")
166     ENDIF()
168     CHECK_C_SOURCE_COMPILES("inline void foo(void) { }
169                              int main() {return 0;}" HAVE_INLINE)
170     IF(NOT 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!")
175         ENDIF()
177         SET(CPP_DEFS ${CPP_DEFS} inline=__inline)
178         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Dinline=__inline")
179     ENDIF()
180 ENDIF()
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.")
195     ENDIF()
197     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
198 ENDIF()
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)
205 ENDIF()
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);
212 int main()
214     return atomic_fetch_add(&foo, 2);
216 HAVE_LIBATOMIC)
217 IF(NOT HAVE_LIBATOMIC)
218     SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
219 ELSE()
220     SET(EXTRA_LIBS atomic ${EXTRA_LIBS})
221 ENDIF()
222 UNSET(OLD_REQUIRED_LIBRARIES)
224 # Include liblog for Android logging
225 CHECK_LIBRARY_EXISTS(log __android_log_print "" HAVE_LIBLOG)
226 IF(HAVE_LIBLOG)
227     SET(EXTRA_LIBS log ${EXTRA_LIBS})
228     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
229 ENDIF()
231 # Check if we have C99 bool
232 CHECK_C_SOURCE_COMPILES(
233 "int main(int argc, char *argv[])
235      volatile _Bool ret;
236      ret = (argc > 1) ? 1 : 0;
237      return ret ? -1 : 0;
238  }"
239 HAVE_C99_BOOL)
241 # Check if we have C11 static_assert
242 CHECK_C_SOURCE_COMPILES(
243 "int main()
245      _Static_assert(sizeof(int) == sizeof(int), \"What\");
246      return 0;
247  }"
248 HAVE_C11_STATIC_ASSERT)
250 # Check if we have C11 alignas
251 CHECK_C_SOURCE_COMPILES(
252 "_Alignas(16) int foo;
253  int main()
255      return 0;
256  }"
257 HAVE_C11_ALIGNAS)
259 # Check if we have C11 _Atomic
260 CHECK_C_SOURCE_COMPILES(
261 "#include <stdatomic.h>
262  int _Atomic foo = ATOMIC_VAR_INIT(0);
263  int main()
265      atomic_fetch_add(&foo, 2);
266      return 0;
267  }"
268 HAVE_C11_ATOMIC)
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."
276         FORCE)
277 ENDIF()
278 IF(NOT CMAKE_DEBUG_POSTFIX)
279     SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
280         "Library postfix for debug builds. Normally left blank."
281         FORCE)
282 ENDIF()
284 IF(MSVC)
285     SET(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE)
286     SET(C_FLAGS ${C_FLAGS} /wd4098)
288     IF(NOT DXSDK_DIR)
289         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
290     ELSE()
291         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
292     ENDIF()
293     IF(DXSDK_DIR)
294         MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
295     ENDIF()
297     OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
298     IF(FORCE_STATIC_VCRT)
299         FOREACH(flag_var
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}}")
304             ENDIF()
305         ENDFOREACH(flag_var)
306     ENDIF()
307 ELSE()
308     SET(C_FLAGS ${C_FLAGS} -Winline -Wall)
309     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
310     IF(HAVE_W_EXTRA)
311         SET(C_FLAGS ${C_FLAGS} -Wextra)
312     ENDIF()
314     IF(ALSOFT_WERROR)
315         SET(C_FLAGS ${C_FLAGS} -Werror)
316     ENDIF()
318     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
319     # instead of NDEBUG)
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}}")
323         ENDIF()
324     ENDFOREACH()
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)
329     ENDIF()
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(
339 "#include <stdlib.h>
340 int main()
342     return 0;
344             HAVE_STATIC_LIBGCC_SWITCH
345         )
346         if(HAVE_STATIC_LIBGCC_SWITCH)
347             SET(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
348         endif()
349         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
350         unset(OLD_REQUIRED_LIBRARIES)
351     endif()
352 ENDIF()
354 # Set visibility/export options if available
355 IF(WIN32)
356     SET(EXPORT_DECL "__declspec(dllexport)")
357     IF(NOT MINGW)
358         SET(ALIGN_DECL "__declspec(align(x))")
359     ELSE()
360         SET(ALIGN_DECL "__declspec(aligned(x))")
361     ENDIF()
362 ELSE()
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\")))")
371     ELSE()
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\")))")
376         ENDIF()
377     ENDIF()
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)
383         ENDIF()
384     ENDIF()
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)))")
390     ENDIF()
392     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
393 ENDIF()
395 CHECK_C_SOURCE_COMPILES("
396 int main()
398     float *ptr;
399     ptr = __builtin_assume_aligned(ptr, 16);
400     return 0;
401 }" HAVE___BUILTIN_ASSUME_ALIGNED)
402 IF(HAVE___BUILTIN_ASSUME_ALIGNED)
403     SET(ASSUME_ALIGNED_DECL "__builtin_assume_aligned(x, y)")
404 ELSE()
405     SET(ASSUME_ALIGNED_DECL "x")
406 ENDIF()
408 SET(SSE_SWITCH "")
409 SET(SSE2_SWITCH "")
410 SET(SSE3_SWITCH "")
411 SET(SSE4_1_SWITCH "")
412 SET(FPU_NEON_SWITCH "")
414 CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
415 IF(HAVE_MSSE_SWITCH)
416     SET(SSE_SWITCH "-msse")
417 ENDIF()
418 CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
419 IF(HAVE_MSSE2_SWITCH)
420     SET(SSE2_SWITCH "-msse2")
421 ENDIF()
422 CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
423 IF(HAVE_MSSE3_SWITCH)
424     SET(SSE3_SWITCH "-msse3")
425 ENDIF()
426 CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
427 IF(HAVE_MSSE4_1_SWITCH)
428     SET(SSE4_1_SWITCH "-msse4.1")
429 ENDIF()
430 CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
431 IF(HAVE_MFPU_NEON_SWITCH)
432     SET(FPU_NEON_SWITCH "-mfpu=neon")
433 ENDIF()
435 SET(FPMATH_SET "0")
436 IF(HAVE_MSSE_SWITCH AND CMAKE_SIZEOF_VOID_P MATCHES "4")
437     OPTION(ALSOFT_ENABLE_SSE_CODEGEN "Enable SSE code generation instead of x87 for 32-bit targets." TRUE)
438     IF(HAVE_MSSE2_SWITCH)
439         OPTION(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
440     ENDIF()
442     IF(HAVE_MSSE2_SWITCH AND ALSOFT_ENABLE_SSE2_CODEGEN)
443         CHECK_C_COMPILER_FLAG("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
444         IF(ALSOFT_ENABLE_SSE2_CODEGEN AND HAVE_MFPMATH_SSE_2)
445             SET(C_FLAGS ${C_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
446             SET(FPMATH_SET 2)
447         ENDIF()
448     ENDIF()
449     IF(ALSOFT_ENABLE_SSE_CODEGEN AND NOT FPMATH_SET)
450         CHECK_C_COMPILER_FLAG("${SSE_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE)
451         IF(ALSOFT_ENABLE_SSE_CODEGEN AND HAVE_MFPMATH_SSE)
452             SET(C_FLAGS ${C_FLAGS} ${SSE_SWITCH} -mfpmath=sse)
453             SET(FPMATH_SET 1)
454         ENDIF()
455     ENDIF()
456 ENDIF()
459 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
460                          int main() {return 0;}" HAVE_GCC_FORMAT)
462 CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
463 CHECK_INCLUDE_FILE(stdalign.h HAVE_STDALIGN_H)
464 CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
465 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
466 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
467 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
468 CHECK_INCLUDE_FILE(intrin.h HAVE_INTRIN_H)
469 CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
470 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
471 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
472 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
473 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
474 IF(NOT HAVE_GUIDDEF_H)
475     CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
476 ENDIF()
478 # Some systems need libm for some of the following math functions to work
479 SET(MATH_LIB )
480 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
481 IF(HAVE_LIBM)
482     SET(MATH_LIB ${MATH_LIB} m)
483     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
484 ENDIF()
486 # Check for the dlopen API (for dynamicly loading backend libs)
487 IF(ALSOFT_DLOPEN)
488     CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
489     IF(HAVE_LIBDL)
490         SET(EXTRA_LIBS dl ${EXTRA_LIBS})
491         SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
492     ENDIF()
494     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
495 ENDIF()
497 # Check for a cpuid intrinsic
498 IF(HAVE_CPUID_H)
499     CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
500         int main()
501         {
502             unsigned int eax, ebx, ecx, edx;
503             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
504         }" HAVE_GCC_GET_CPUID)
505 ENDIF()
506 IF(HAVE_INTRIN_H)
507     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
508         int main()
509         {
510             int regs[4];
511             __cpuid(regs, 0);
512             return regs[0];
513         }" HAVE_CPUID_INTRINSIC)
514     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
515         int main()
516         {
517             unsigned long idx = 0;
518             _BitScanForward64(&idx, 1);
519             return idx;
520         }" HAVE_BITSCANFORWARD64_INTRINSIC)
521     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
522         int main()
523         {
524             unsigned long idx = 0;
525             _BitScanForward(&idx, 1);
526             return idx;
527         }" HAVE_BITSCANFORWARD_INTRINSIC)
528 ENDIF()
530 CHECK_SYMBOL_EXISTS(sysconf          unistd.h HAVE_SYSCONF)
531 CHECK_SYMBOL_EXISTS(aligned_alloc    stdlib.h HAVE_ALIGNED_ALLOC)
532 CHECK_SYMBOL_EXISTS(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
533 CHECK_SYMBOL_EXISTS(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
534 CHECK_SYMBOL_EXISTS(proc_pidpath     libproc.h HAVE_PROC_PIDPATH)
535 CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
536 CHECK_SYMBOL_EXISTS(modff  math.h HAVE_MODFF)
537 CHECK_SYMBOL_EXISTS(log2f  math.h HAVE_LOG2F)
538 CHECK_SYMBOL_EXISTS(cbrtf  math.h HAVE_CBRTF)
540 IF(HAVE_FLOAT_H)
541     CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
542     CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
543 ENDIF()
545 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
546 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
547 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
548 IF(NOT HAVE_STRCASECMP)
549     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
550     IF(NOT HAVE__STRICMP)
551         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
552     ENDIF()
554     SET(CPP_DEFS ${CPP_DEFS} strcasecmp=_stricmp)
555 ENDIF()
557 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
558 IF(NOT HAVE_STRNCASECMP)
559     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
560     IF(NOT HAVE__STRNICMP)
561         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
562     ENDIF()
564     SET(CPP_DEFS ${CPP_DEFS} strncasecmp=_strnicmp)
565 ENDIF()
567 CHECK_SYMBOL_EXISTS(strnlen string.h HAVE_STRNLEN)
568 CHECK_SYMBOL_EXISTS(snprintf stdio.h HAVE_SNPRINTF)
569 IF(NOT HAVE_SNPRINTF)
570     CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
571     IF(NOT HAVE__SNPRINTF)
572         MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
573     ENDIF()
575     SET(CPP_DEFS ${CPP_DEFS} snprintf=_snprintf)
576 ENDIF()
578 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
579 IF(NOT HAVE_ISFINITE)
580     CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
581     IF(NOT HAVE_FINITE)
582         CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
583         IF(NOT HAVE__FINITE)
584             MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
585         ENDIF()
586         SET(CPP_DEFS ${CPP_DEFS} isfinite=_finite)
587     ELSE()
588         SET(CPP_DEFS ${CPP_DEFS} isfinite=finite)
589     ENDIF()
590 ENDIF()
592 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
593 IF(NOT HAVE_ISNAN)
594     CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
595     IF(NOT HAVE__ISNAN)
596         MESSAGE(FATAL_ERROR "No isnan function found, please report!")
597     ENDIF()
599     SET(CPP_DEFS ${CPP_DEFS} isnan=_isnan)
600 ENDIF()
603 # Check if we have Windows headers
604 SET(OLD_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS})
605 SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=0x0502)
606 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H)
607 SET(CMAKE_REQUIRED_DEFINITIONS ${OLD_REQUIRED_DEFINITIONS})
608 UNSET(OLD_REQUIRED_DEFINITIONS)
610 IF(NOT HAVE_WINDOWS_H)
611     CHECK_SYMBOL_EXISTS(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
612     IF(NOT HAVE_GETTIMEOFDAY)
613         MESSAGE(FATAL_ERROR "No timing function found!")
614     ENDIF()
616     CHECK_SYMBOL_EXISTS(nanosleep time.h HAVE_NANOSLEEP)
617     IF(NOT HAVE_NANOSLEEP)
618         MESSAGE(FATAL_ERROR "No sleep function found!")
619     ENDIF()
621     # We need pthreads outside of Windows
622     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
623     IF(NOT HAVE_PTHREAD_H)
624         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
625     ENDIF()
626     # Some systems need pthread_np.h to get recursive mutexes
627     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
629     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
630     IF(HAVE_PTHREAD)
631         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
632         SET(C_FLAGS ${C_FLAGS} -pthread)
633         SET(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
634     ENDIF()
636     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
637     IF(HAVE_LIBPTHREAD)
638         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
639     ENDIF()
641     CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
643     IF(HAVE_PTHREAD_NP_H)
644         CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
645         IF(NOT HAVE_PTHREAD_SETNAME_NP)
646             CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
647         ELSE()
648             CHECK_C_SOURCE_COMPILES("
649 #include <pthread.h>
650 #include <pthread_np.h>
651 int main()
653     pthread_setname_np(\"testname\");
654     return 0;
656                 PTHREAD_SETNAME_NP_ONE_PARAM
657             )
658             CHECK_C_SOURCE_COMPILES("
659 #include <pthread.h>
660 #include <pthread_np.h>
661 int main()
663     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
664     return 0;
666                 PTHREAD_SETNAME_NP_THREE_PARAMS
667             )
668         ENDIF()
669         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np "pthread.h;pthread_np.h" HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
670     ELSE()
671         CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
672         IF(NOT HAVE_PTHREAD_SETNAME_NP)
673             CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
674         ELSE()
675             CHECK_C_SOURCE_COMPILES("
676 #include <pthread.h>
677 int main()
679     pthread_setname_np(\"testname\");
680     return 0;
682                 PTHREAD_SETNAME_NP_ONE_PARAM
683             )
684             CHECK_C_SOURCE_COMPILES("
685 #include <pthread.h>
686 int main()
688     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
689     return 0;
691                 PTHREAD_SETNAME_NP_THREE_PARAMS
692             )
693         ENDIF()
694         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np pthread.h HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
695     ENDIF()
697     CHECK_SYMBOL_EXISTS(pthread_mutex_timedlock pthread.h HAVE_PTHREAD_MUTEX_TIMEDLOCK)
699     CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
700     IF(HAVE_LIBRT)
701         SET(EXTRA_LIBS rt ${EXTRA_LIBS})
702     ENDIF()
703 ENDIF()
705 CHECK_SYMBOL_EXISTS(getopt unistd.h HAVE_GETOPT)
707 # Check for a 64-bit type
708 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
709 IF(NOT HAVE_STDINT_H)
710     IF(HAVE_WINDOWS_H)
711         CHECK_C_SOURCE_COMPILES("#define _WIN32_WINNT 0x0502
712                                  #include <windows.h>
713                                  __int64 foo;
714                                  int main() {return 0;}" HAVE___INT64)
715     ENDIF()
716     IF(NOT HAVE___INT64)
717         IF(NOT SIZEOF_LONG MATCHES "8")
718             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
719                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
720             ENDIF()
721         ENDIF()
722     ENDIF()
723 ENDIF()
726 SET(COMMON_OBJS
727     common/alcomplex.c
728     common/alcomplex.h
729     common/align.h
730     common/almalloc.c
731     common/almalloc.h
732     common/atomic.c
733     common/atomic.h
734     common/bool.h
735     common/math_defs.h
736     common/rwlock.c
737     common/rwlock.h
738     common/static_assert.h
739     common/threads.c
740     common/threads.h
741     common/uintmap.c
742     common/uintmap.h
744 SET(OPENAL_OBJS
745     OpenAL32/Include/bs2b.h
746     OpenAL32/Include/alMain.h
747     OpenAL32/Include/alu.h
749     OpenAL32/Include/alAuxEffectSlot.h
750     OpenAL32/alAuxEffectSlot.c
751     OpenAL32/Include/alBuffer.h
752     OpenAL32/alBuffer.c
753     OpenAL32/Include/alEffect.h
754     OpenAL32/alEffect.c
755     OpenAL32/Include/alError.h
756     OpenAL32/alError.c
757     OpenAL32/alExtension.c
758     OpenAL32/Include/alFilter.h
759     OpenAL32/alFilter.c
760     OpenAL32/Include/alListener.h
761     OpenAL32/alListener.c
762     OpenAL32/Include/alSource.h
763     OpenAL32/alSource.c
764     OpenAL32/alState.c
765     OpenAL32/event.c
766     OpenAL32/Include/sample_cvt.h
767     OpenAL32/sample_cvt.c
769 SET(ALC_OBJS
770     Alc/ALc.c
771     Alc/ALu.c
772     Alc/alconfig.c
773     Alc/alconfig.h
774     Alc/bs2b.c
775     Alc/converter.c
776     Alc/converter.h
777     Alc/inprogext.h
778     Alc/mastering.c
779     Alc/mastering.h
780     Alc/ringbuffer.c
781     Alc/ringbuffer.h
782     Alc/effects/autowah.c
783     Alc/effects/chorus.c
784     Alc/effects/compressor.c
785     Alc/effects/dedicated.c
786     Alc/effects/distortion.c
787     Alc/effects/echo.c
788     Alc/effects/equalizer.c
789     Alc/effects/fshifter.c
790     Alc/effects/modulator.c
791     Alc/effects/null.c
792     Alc/effects/pshifter.c
793     Alc/effects/reverb.c
794     Alc/filters/defs.h
795     Alc/filters/filter.c
796     Alc/filters/nfc.c
797     Alc/filters/nfc.h
798     Alc/filters/splitter.c
799     Alc/filters/splitter.h
800     Alc/helpers.c
801     Alc/alstring.h
802     Alc/compat.h
803     Alc/cpu_caps.h
804     Alc/fpu_modes.h
805     Alc/logging.h
806     Alc/vector.h
807     Alc/hrtf.c
808     Alc/hrtf.h
809     Alc/uhjfilter.c
810     Alc/uhjfilter.h
811     Alc/ambdec.c
812     Alc/ambdec.h
813     Alc/bformatdec.c
814     Alc/bformatdec.h
815     Alc/panning.c
816     Alc/polymorphism.h
817     Alc/mixvoice.c
818     Alc/mixer/defs.h
819     Alc/mixer/mixer_c.c
823 SET(CPU_EXTS "Default")
824 SET(HAVE_SSE        0)
825 SET(HAVE_SSE2       0)
826 SET(HAVE_SSE3       0)
827 SET(HAVE_SSE4_1     0)
828 SET(HAVE_NEON       0)
830 SET(HAVE_ALSA       0)
831 SET(HAVE_OSS        0)
832 SET(HAVE_SOLARIS    0)
833 SET(HAVE_SNDIO      0)
834 SET(HAVE_QSA        0)
835 SET(HAVE_DSOUND     0)
836 SET(HAVE_WASAPI     0)
837 SET(HAVE_WINMM      0)
838 SET(HAVE_PORTAUDIO  0)
839 SET(HAVE_PULSEAUDIO 0)
840 SET(HAVE_COREAUDIO  0)
841 SET(HAVE_OPENSL     0)
842 SET(HAVE_WAVE       0)
843 SET(HAVE_SDL2       0)
845 # Check for SSE support
846 OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
847 CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE_SWITCH}")
848 IF(HAVE_XMMINTRIN_H)
849     OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
850     IF(ALSOFT_CPUEXT_SSE)
851         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
852             SET(HAVE_SSE 1)
853             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer/mixer_sse.c)
854             IF(SSE_SWITCH)
855                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_sse.c PROPERTIES
856                                             COMPILE_FLAGS "${SSE_SWITCH}")
857             ENDIF()
858             SET(CPU_EXTS "${CPU_EXTS}, SSE")
859         ENDIF()
860     ENDIF()
861 ENDIF()
862 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
863     MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
864 ENDIF()
866 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
867 CHECK_INCLUDE_FILE(emmintrin.h HAVE_EMMINTRIN_H "${SSE2_SWITCH}")
868 IF(HAVE_EMMINTRIN_H)
869     OPTION(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
870     IF(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
871         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
872             SET(HAVE_SSE2 1)
873             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer/mixer_sse2.c)
874             IF(SSE2_SWITCH)
875                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_sse2.c PROPERTIES
876                                             COMPILE_FLAGS "${SSE2_SWITCH}")
877             ENDIF()
878             SET(CPU_EXTS "${CPU_EXTS}, SSE2")
879         ENDIF()
880     ENDIF()
881 ENDIF()
882 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
883     MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
884 ENDIF()
886 OPTION(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
887 CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}")
888 IF(HAVE_EMMINTRIN_H)
889     OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
890     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
891         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
892             SET(HAVE_SSE3 1)
893             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer/mixer_sse3.c)
894             IF(SSE2_SWITCH)
895                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_sse3.c PROPERTIES
896                                             COMPILE_FLAGS "${SSE3_SWITCH}")
897             ENDIF()
898             SET(CPU_EXTS "${CPU_EXTS}, SSE3")
899         ENDIF()
900     ENDIF()
901 ENDIF()
902 IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
903     MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
904 ENDIF()
906 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
907 CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}")
908 IF(HAVE_SMMINTRIN_H)
909     OPTION(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
910     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE4_1)
911         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
912             SET(HAVE_SSE4_1 1)
913             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer/mixer_sse41.c)
914             IF(SSE4_1_SWITCH)
915                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_sse41.c PROPERTIES
916                                             COMPILE_FLAGS "${SSE4_1_SWITCH}")
917             ENDIF()
918             SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
919         ENDIF()
920     ENDIF()
921 ENDIF()
922 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
923     MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
924 ENDIF()
926 # Check for ARM Neon support
927 OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
928 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H ${FPU_NEON_SWITCH})
929 IF(HAVE_ARM_NEON_H)
930     OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
931     IF(ALSOFT_CPUEXT_NEON)
932         SET(HAVE_NEON 1)
933         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer/mixer_neon.c)
934         IF(FPU_NEON_SWITCH)
935             SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_neon.c PROPERTIES
936                                         COMPILE_FLAGS "${FPU_NEON_SWITCH}")
937         ENDIF()
938         SET(CPU_EXTS "${CPU_EXTS}, Neon")
939     ENDIF()
940 ENDIF()
941 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
942     MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
943 ENDIF()
946 IF(WIN32 OR HAVE_DLFCN_H)
947     SET(IS_LINKED "")
948     MACRO(ADD_BACKEND_LIBS _LIBS)
949     ENDMACRO()
950 ELSE()
951     SET(IS_LINKED " (linked)")
952     MACRO(ADD_BACKEND_LIBS _LIBS)
953         SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
954     ENDMACRO()
955 ENDIF()
957 SET(BACKENDS "")
958 SET(ALC_OBJS  ${ALC_OBJS}
959     Alc/backends/base.c
960     Alc/backends/base.h
961     # Default backends, always available
962     Alc/backends/loopback.c
963     Alc/backends/null.c
966 # Check ALSA backend
967 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
968 FIND_PACKAGE(ALSA)
969 IF(ALSA_FOUND)
970     OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
971     IF(ALSOFT_BACKEND_ALSA)
972         SET(HAVE_ALSA 1)
973         SET(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
974         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/alsa.c)
975         ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
976         SET(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
977     ENDIF()
978 ENDIF()
979 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
980     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
981 ENDIF()
983 # Check OSS backend
984 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
985 FIND_PACKAGE(OSS)
986 IF(OSS_FOUND)
987     OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
988     IF(ALSOFT_BACKEND_OSS)
989         SET(HAVE_OSS 1)
990         SET(BACKENDS  "${BACKENDS} OSS,")
991         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/oss.c)
992         IF(OSS_LIBRARIES)
993             SET(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
994         ENDIF()
995         SET(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
996     ENDIF()
997 ENDIF()
998 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
999     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
1000 ENDIF()
1002 # Check Solaris backend
1003 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
1004 FIND_PACKAGE(AudioIO)
1005 IF(AUDIOIO_FOUND)
1006     OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
1007     IF(ALSOFT_BACKEND_SOLARIS)
1008         SET(HAVE_SOLARIS 1)
1009         SET(BACKENDS  "${BACKENDS} Solaris,")
1010         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/solaris.c)
1011         SET(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
1012     ENDIF()
1013 ENDIF()
1014 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
1015     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
1016 ENDIF()
1018 # Check SndIO backend
1019 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
1020 FIND_PACKAGE(SoundIO)
1021 IF(SOUNDIO_FOUND)
1022     OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
1023     IF(ALSOFT_BACKEND_SNDIO)
1024         SET(HAVE_SNDIO 1)
1025         SET(BACKENDS  "${BACKENDS} SndIO (linked),")
1026         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sndio.c)
1027         SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
1028         SET(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
1029     ENDIF()
1030 ENDIF()
1031 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
1032     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
1033 ENDIF()
1035 # Check QSA backend
1036 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
1037 FIND_PACKAGE(QSA)
1038 IF(QSA_FOUND)
1039     OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
1040     IF(ALSOFT_BACKEND_QSA)
1041         SET(HAVE_QSA 1)
1042         SET(BACKENDS  "${BACKENDS} QSA (linked),")
1043         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/qsa.c)
1044         SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
1045         SET(INC_PATHS ${INC_PATHS} ${QSA_INCLUDE_DIRS})
1046     ENDIF()
1047 ENDIF()
1048 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
1049     MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
1050 ENDIF()
1052 # Check Windows-only backends
1053 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
1054 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
1055 OPTION(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
1056 IF(HAVE_WINDOWS_H)
1057     SET(OLD_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS})
1058     SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=0x0502)
1060     # Check MMSystem backend
1061     CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
1062     IF(HAVE_MMSYSTEM_H)
1063         CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
1064         IF(HAVE_LIBWINMM)
1065             OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
1066             IF(ALSOFT_BACKEND_WINMM)
1067                 SET(HAVE_WINMM 1)
1068                 SET(BACKENDS  "${BACKENDS} WinMM,")
1069                 SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/winmm.c)
1070                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
1071             ENDIF()
1072         ENDIF()
1073     ENDIF()
1075     # Check DSound backend
1076     FIND_PACKAGE(DSound)
1077     IF(DSOUND_FOUND)
1078         OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
1079         IF(ALSOFT_BACKEND_DSOUND)
1080             SET(HAVE_DSOUND 1)
1081             SET(BACKENDS  "${BACKENDS} DirectSound${IS_LINKED},")
1082             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/dsound.c)
1083             ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
1084             SET(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIRS})
1085         ENDIF()
1086     ENDIF()
1088     # Check for WASAPI backend
1089     CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1090     IF(HAVE_MMDEVICEAPI_H)
1091         OPTION(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
1092         IF(ALSOFT_BACKEND_WASAPI)
1093             SET(HAVE_WASAPI 1)
1094             SET(BACKENDS  "${BACKENDS} WASAPI,")
1095             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wasapi.c)
1096         ENDIF()
1097     ENDIF()
1099     SET(CMAKE_REQUIRED_DEFINITIONS ${OLD_REQUIRED_DEFINITIONS})
1100     UNSET(OLD_REQUIRED_DEFINITIONS)
1101 ENDIF()
1102 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1103     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
1104 ENDIF()
1105 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1106     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
1107 ENDIF()
1108 IF(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
1109     MESSAGE(FATAL_ERROR "Failed to enabled required WASAPI backend")
1110 ENDIF()
1112 # Check PortAudio backend
1113 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1114 FIND_PACKAGE(PortAudio)
1115 IF(PORTAUDIO_FOUND)
1116     OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1117     IF(ALSOFT_BACKEND_PORTAUDIO)
1118         SET(HAVE_PORTAUDIO 1)
1119         SET(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
1120         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/portaudio.c)
1121         ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
1122         SET(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
1123     ENDIF()
1124 ENDIF()
1125 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1126     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
1127 ENDIF()
1129 # Check PulseAudio backend
1130 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1131 FIND_PACKAGE(PulseAudio)
1132 IF(PULSEAUDIO_FOUND)
1133     OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1134     IF(ALSOFT_BACKEND_PULSEAUDIO)
1135         SET(HAVE_PULSEAUDIO 1)
1136         SET(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
1137         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/pulseaudio.c)
1138         ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
1139         SET(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
1140     ENDIF()
1141 ENDIF()
1142 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1143     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1144 ENDIF()
1146 # Check JACK backend
1147 OPTION(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1148 FIND_PACKAGE(JACK)
1149 IF(JACK_FOUND)
1150     OPTION(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1151     IF(ALSOFT_BACKEND_JACK)
1152         SET(HAVE_JACK 1)
1153         SET(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1154         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/jack.c)
1155         ADD_BACKEND_LIBS(${JACK_LIBRARIES})
1156         SET(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1157     ENDIF()
1158 ENDIF()
1159 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1160     MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
1161 ENDIF()
1163 # Check CoreAudio backend
1164 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1165 FIND_LIBRARY(COREAUDIO_FRAMEWORK
1166              NAMES CoreAudio
1167              PATHS /System/Library/Frameworks
1169 IF(COREAUDIO_FRAMEWORK)
1170     OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1171     IF(ALSOFT_BACKEND_COREAUDIO)
1172         SET(HAVE_COREAUDIO 1)
1173         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/coreaudio.c)
1174         SET(BACKENDS  "${BACKENDS} CoreAudio,")
1175         SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
1176         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
1177         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1179         # Some versions of OSX may need the AudioToolbox framework. Add it if
1180         # it's found.
1181         FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
1182                      NAMES AudioToolbox
1183                      PATHS ~/Library/Frameworks
1184                            /Library/Frameworks
1185                            /System/Library/Frameworks
1186                     )
1187         IF(AUDIOTOOLBOX_LIBRARY)
1188             SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1189         ENDIF()
1190     ENDIF()
1191 ENDIF()
1192 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1193     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1194 ENDIF()
1196 # Check for OpenSL (Android) backend
1197 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1198 CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
1199 IF(HAVE_SLES_OPENSLES_ANDROID_H)
1200     CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
1201     IF(HAVE_LIBOPENSLES)
1202         OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1203         IF(ALSOFT_BACKEND_OPENSL)
1204             SET(HAVE_OPENSL 1)
1205             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/opensl.c)
1206             SET(BACKENDS  "${BACKENDS} OpenSL,")
1207             SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
1208         ENDIF()
1209     ENDIF()
1210 ENDIF()
1211 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1212     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1213 ENDIF()
1215 # Check for SDL2 backend
1216 OPTION(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1217 FIND_PACKAGE(SDL2)
1218 IF(SDL2_FOUND)
1219     # Off by default, since it adds a runtime dependency
1220     OPTION(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1221     IF(ALSOFT_BACKEND_SDL2)
1222         SET(HAVE_SDL2 1)
1223         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sdl2.c)
1224         SET(BACKENDS  "${BACKENDS} SDL2,")
1225         SET(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
1226         SET(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
1227     ENDIF()
1228 ENDIF()
1229 IF(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1230     MESSAGE(FATAL_ERROR "Failed to enabled required SDL2 backend")
1231 ENDIF()
1233 # Optionally enable the Wave Writer backend
1234 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1235 IF(ALSOFT_BACKEND_WAVE)
1236     SET(HAVE_WAVE 1)
1237     SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wave.c)
1238     SET(BACKENDS  "${BACKENDS} WaveFile,")
1239 ENDIF()
1241 # This is always available
1242 SET(BACKENDS  "${BACKENDS} Null")
1245 FIND_PACKAGE(Git)
1246 IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1247     # Get the current working branch and its latest abbreviated commit hash
1248     ADD_CUSTOM_TARGET(build_version
1249         ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
1250                          -D LIB_VERSION=${LIB_VERSION}
1251                          -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1252                          -D DST=${OpenAL_BINARY_DIR}/version.h
1253                          -P ${OpenAL_SOURCE_DIR}/version.cmake
1254         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1255         VERBATIM
1256     )
1257 ELSE()
1258     SET(GIT_BRANCH "UNKNOWN")
1259     SET(GIT_COMMIT_HASH "unknown")
1260     CONFIGURE_FILE(
1261         "${OpenAL_SOURCE_DIR}/version.h.in"
1262         "${OpenAL_BINARY_DIR}/version.h")
1263 ENDIF()
1265 SET(NATIVE_SRC_DIR  "${OpenAL_SOURCE_DIR}/native-tools/")
1266 SET(NATIVE_BIN_DIR  "${OpenAL_BINARY_DIR}/native-tools/")
1267 FILE(MAKE_DIRECTORY "${NATIVE_BIN_DIR}")
1269 SET(BIN2H_COMMAND  "${NATIVE_BIN_DIR}bin2h")
1270 SET(BSINCGEN_COMMAND  "${NATIVE_BIN_DIR}bsincgen")
1271 ADD_CUSTOM_COMMAND(OUTPUT "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1272     COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" "${NATIVE_SRC_DIR}"
1273     COMMAND ${CMAKE_COMMAND} -E remove "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1274     COMMAND ${CMAKE_COMMAND} --build . --config "Release"
1275     WORKING_DIRECTORY "${NATIVE_BIN_DIR}"
1276     DEPENDS "${NATIVE_SRC_DIR}CMakeLists.txt"
1277     IMPLICIT_DEPENDS C "${NATIVE_SRC_DIR}bin2h.c"
1278                      C "${NATIVE_SRC_DIR}bsincgen.c"
1279     VERBATIM
1281 ADD_CUSTOM_TARGET(native-tools
1282     DEPENDS "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1283     VERBATIM
1286 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" OFF)
1287 if(ALSOFT_EMBED_HRTF_DATA)
1288     MACRO(make_hrtf_header FILENAME VARNAME)
1289         SET(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1290         SET(outfile  "${OpenAL_BINARY_DIR}/${FILENAME}.h")
1292         ADD_CUSTOM_COMMAND(OUTPUT "${outfile}"
1293             COMMAND "${BIN2H_COMMAND}" "${infile}" "${outfile}" ${VARNAME}
1294             DEPENDS native-tools "${infile}"
1295             VERBATIM
1296         )
1297         SET(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1298     ENDMACRO()
1300     make_hrtf_header(default-44100.mhr "hrtf_default_44100")
1301     make_hrtf_header(default-48000.mhr "hrtf_default_48000")
1302 endif()
1304 ADD_CUSTOM_COMMAND(OUTPUT "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1305     COMMAND "${BSINCGEN_COMMAND}" "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1306     DEPENDS native-tools "${NATIVE_SRC_DIR}bsincgen.c"
1307     VERBATIM
1309 SET(ALC_OBJS  ${ALC_OBJS} "${OpenAL_BINARY_DIR}/bsinc_inc.h")
1312 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1313     add_subdirectory(utils/alsoft-config)
1314 ENDIF()
1315 IF(ALSOFT_EXAMPLES)
1316     IF(NOT SDL2_FOUND)
1317         FIND_PACKAGE(SDL2)
1318     ENDIF()
1319     IF(SDL2_FOUND)
1320         FIND_PACKAGE(SDL_sound)
1321         FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1322     ENDIF()
1323 ENDIF()
1325 IF(NOT WIN32)
1326     SET(LIBNAME "openal")
1327 ELSE()
1328     SET(LIBNAME "OpenAL32")
1329 ENDIF()
1331 # Needed for openal.pc.in
1332 SET(prefix ${CMAKE_INSTALL_PREFIX})
1333 SET(exec_prefix "\${prefix}")
1334 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1335 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1336 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1337 SET(PACKAGE_VERSION "${LIB_VERSION}")
1338 SET(PKG_CONFIG_CFLAGS )
1339 SET(PKG_CONFIG_PRIVATE_LIBS )
1340 IF(LIBTYPE STREQUAL "STATIC")
1341     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1342     FOREACH(FLAG  ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1343         # If this is already a linker flag, or is a full path+file, add it
1344         # as-is. Otherwise, it's a name intended to be dressed as -lname.
1345         IF(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1346             SET(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1347         ELSE()
1348             SET(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1349         ENDIF()
1350     ENDFOREACH()
1351 ENDIF()
1353 # End configuration
1354 CONFIGURE_FILE(
1355     "${OpenAL_SOURCE_DIR}/config.h.in"
1356     "${OpenAL_BINARY_DIR}/config.h")
1357 CONFIGURE_FILE(
1358     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1359     "${OpenAL_BINARY_DIR}/openal.pc"
1360     @ONLY)
1363 # Add a static library with common functions used by multiple targets
1364 ADD_LIBRARY(common STATIC ${COMMON_OBJS})
1365 TARGET_COMPILE_DEFINITIONS(common PRIVATE ${CPP_DEFS})
1366 TARGET_COMPILE_OPTIONS(common PRIVATE ${C_FLAGS})
1369 UNSET(HAS_ROUTER)
1370 SET(IMPL_TARGET OpenAL)
1371 SET(COMMON_LIB )
1372 SET(SUBSYS_FLAG )
1374 # Build main library
1375 IF(LIBTYPE STREQUAL "STATIC")
1376     SET(CPP_DEFS ${CPP_DEFS} AL_LIBTYPE_STATIC)
1377     IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1378         SET(CPP_DEFS ${CPP_DEFS} AL_NO_UID_DEFS)
1379     ENDIF()
1380     ADD_LIBRARY(OpenAL STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1381 ELSE()
1382     # Make sure to compile the common code with PIC, since it'll be linked into
1383     # shared libs that needs it.
1384     SET_PROPERTY(TARGET common PROPERTY POSITION_INDEPENDENT_CODE TRUE)
1385     SET(COMMON_LIB common)
1387     IF(WIN32)
1388         IF(MSVC)
1389             SET(SUBSYS_FLAG ${SUBSYS_FLAG} "/SUBSYSTEM:WINDOWS")
1390         ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1391             SET(SUBSYS_FLAG ${SUBSYS_FLAG} "-mwindows")
1392         ENDIF()
1393     ENDIF()
1395     IF(WIN32 AND ALSOFT_BUILD_ROUTER)
1396         ADD_LIBRARY(OpenAL SHARED router/router.c router/router.h router/alc.c router/al.c)
1397         TARGET_COMPILE_DEFINITIONS(OpenAL
1398             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1399         TARGET_COMPILE_OPTIONS(OpenAL PRIVATE ${C_FLAGS})
1400         TARGET_LINK_LIBRARIES(OpenAL PRIVATE ${LINKER_FLAGS} ${COMMON_LIB})
1401         SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "")
1402         SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1403         IF(TARGET build_version)
1404             ADD_DEPENDENCIES(OpenAL build_version)
1405         ENDIF()
1406         SET(HAS_ROUTER 1)
1408         SET(LIBNAME "soft_oal")
1409         SET(IMPL_TARGET soft_oal)
1410     ENDIF()
1412     ADD_LIBRARY(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
1413     IF(WIN32)
1414         SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES PREFIX "")
1415     ENDIF()
1416 ENDIF()
1417 SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1418     VERSION ${LIB_VERSION}
1419     SOVERSION ${LIB_MAJOR_VERSION}
1421 TARGET_COMPILE_DEFINITIONS(${IMPL_TARGET}
1422     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1423 TARGET_INCLUDE_DIRECTORIES(${IMPL_TARGET}
1424     PRIVATE "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc" ${INC_PATHS})
1425 TARGET_COMPILE_OPTIONS(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1426 TARGET_LINK_LIBRARIES(${IMPL_TARGET}
1427     PRIVATE ${LINKER_FLAGS} ${COMMON_LIB} ${EXTRA_LIBS} ${MATH_LIB})
1428 IF(TARGET build_version)
1429     ADD_DEPENDENCIES(${IMPL_TARGET} build_version)
1430 ENDIF()
1432 IF(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1433     FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1434     FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1435     IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1436         MESSAGE(STATUS "")
1437         IF(NOT SED_EXECUTABLE)
1438             MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1439         ENDIF()
1440         IF(NOT DLLTOOL_EXECUTABLE)
1441             MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1442         ENDIF()
1443     ELSE()
1444         SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS
1445                         " -Wl,--output-def,OpenAL32.def")
1446         ADD_CUSTOM_COMMAND(TARGET OpenAL POST_BUILD
1447             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1448             COMMAND "${DLLTOOL_EXECUTABLE}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1449             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1450             VERBATIM
1451         )
1452     ENDIF()
1453 ENDIF()
1455 IF(ALSOFT_INSTALL)
1456     INSTALL(TARGETS OpenAL EXPORT OpenAL
1457             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1458             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1459             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1460             INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL
1461     )
1462     EXPORT(TARGETS OpenAL
1463            NAMESPACE OpenAL::
1464            FILE OpenALConfig.cmake)
1465     INSTALL(EXPORT OpenAL
1466             DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1467             NAMESPACE OpenAL::
1468             FILE OpenALConfig.cmake)
1469     INSTALL(FILES include/AL/al.h
1470                   include/AL/alc.h
1471                   include/AL/alext.h
1472                   include/AL/efx.h
1473                   include/AL/efx-creative.h
1474                   include/AL/efx-presets.h
1475             DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
1476     )
1477     INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1478             DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1479     IF(TARGET soft_oal)
1480         INSTALL(TARGETS soft_oal
1481                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1482         )
1483     ENDIF()
1484 ENDIF()
1487 if(HAS_ROUTER)
1488     message(STATUS "")
1489     message(STATUS "Building DLL router")
1490 endif()
1492 MESSAGE(STATUS "")
1493 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1494 MESSAGE(STATUS "    ${BACKENDS}")
1495 MESSAGE(STATUS "")
1496 MESSAGE(STATUS "Building with support for CPU extensions:")
1497 MESSAGE(STATUS "    ${CPU_EXTS}")
1498 MESSAGE(STATUS "")
1499 IF(FPMATH_SET)
1500     MESSAGE(STATUS "Building with SSE${FPMATH_SET} codegen")
1501     MESSAGE(STATUS "")
1502 ENDIF()
1504 IF(WIN32)
1505     IF(NOT HAVE_DSOUND)
1506         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
1507         MESSAGE(STATUS "         This is probably NOT what you want!")
1508         MESSAGE(STATUS "")
1509     ENDIF()
1510 ENDIF()
1512 if(ALSOFT_EMBED_HRTF_DATA)
1513     message(STATUS "Embedding HRTF datasets")
1514     message(STATUS "")
1515 endif()
1517 # Install alsoft.conf configuration file
1518 IF(ALSOFT_CONFIG)
1519     INSTALL(FILES alsoftrc.sample
1520             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal
1521     )
1522     MESSAGE(STATUS "Installing sample configuration")
1523     MESSAGE(STATUS "")
1524 ENDIF()
1526 # Install HRTF definitions
1527 IF(ALSOFT_HRTF_DEFS)
1528     INSTALL(FILES hrtf/default-44100.mhr
1529                   hrtf/default-48000.mhr
1530             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf
1531     )
1532     MESSAGE(STATUS "Installing HRTF definitions")
1533     MESSAGE(STATUS "")
1534 ENDIF()
1536 # Install AmbDec presets
1537 IF(ALSOFT_AMBDEC_PRESETS)
1538     INSTALL(FILES presets/3D7.1.ambdec
1539                   presets/hexagon.ambdec
1540                   presets/itu5.1.ambdec
1541                   presets/itu5.1-nocenter.ambdec
1542                   presets/rectangle.ambdec
1543                   presets/square.ambdec
1544                   presets/presets.txt
1545             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
1546     )
1547     MESSAGE(STATUS "Installing AmbDec presets")
1548     MESSAGE(STATUS "")
1549 ENDIF()
1551 IF(ALSOFT_UTILS)
1552     ADD_EXECUTABLE(openal-info utils/openal-info.c)
1553     TARGET_COMPILE_OPTIONS(openal-info PRIVATE ${C_FLAGS})
1554     TARGET_LINK_LIBRARIES(openal-info PRIVATE ${LINKER_FLAGS} OpenAL)
1556     SET(MAKEHRTF_SRCS  utils/makehrtf.c)
1557     IF(NOT HAVE_GETOPT)
1558         SET(MAKEHRTF_SRCS  ${MAKEHRTF_SRCS} utils/getopt.c utils/getopt.h)
1559     ENDIF()
1560     ADD_EXECUTABLE(makehrtf ${MAKEHRTF_SRCS})
1561     TARGET_COMPILE_DEFINITIONS(makehrtf PRIVATE ${CPP_DEFS})
1562     TARGET_COMPILE_OPTIONS(makehrtf PRIVATE ${C_FLAGS})
1563     IF(HAVE_LIBM)
1564         TARGET_LINK_LIBRARIES(makehrtf PRIVATE ${LINKER_FLAGS} m)
1565     ENDIF()
1567     IF(ALSOFT_INSTALL)
1568         INSTALL(TARGETS openal-info makehrtf
1569                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1570                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1571                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1572         )
1573     ENDIF()
1575     MESSAGE(STATUS "Building utility programs")
1576     IF(TARGET alsoft-config)
1577         MESSAGE(STATUS "Building configuration program")
1578     ENDIF()
1579     MESSAGE(STATUS "")
1580 ENDIF()
1582 IF(ALSOFT_TESTS)
1583     SET(TEST_COMMON_OBJS  examples/common/alhelpers.c)
1585     ADD_EXECUTABLE(altonegen examples/altonegen.c ${TEST_COMMON_OBJS})
1586     TARGET_COMPILE_DEFINITIONS(altonegen PRIVATE ${CPP_DEFS})
1587     TARGET_COMPILE_OPTIONS(altonegen PRIVATE ${C_FLAGS})
1588     TARGET_LINK_LIBRARIES(altonegen PRIVATE ${LINKER_FLAGS} common OpenAL ${MATH_LIB})
1590     IF(ALSOFT_INSTALL)
1591         INSTALL(TARGETS altonegen
1592                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1593                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1594                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1595         )
1596     ENDIF()
1598     MESSAGE(STATUS "Building test programs")
1599     MESSAGE(STATUS "")
1600 ENDIF()
1602 IF(ALSOFT_EXAMPLES)
1603     ADD_EXECUTABLE(alrecord examples/alrecord.c)
1604     TARGET_COMPILE_DEFINITIONS(alrecord PRIVATE ${CPP_DEFS})
1605     TARGET_COMPILE_OPTIONS(alrecord PRIVATE ${C_FLAGS})
1606     TARGET_LINK_LIBRARIES(alrecord PRIVATE ${LINKER_FLAGS} common OpenAL)
1608     IF(ALSOFT_INSTALL)
1609         INSTALL(TARGETS alrecord
1610                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1611                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1612                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1613         )
1614     ENDIF()
1616     MESSAGE(STATUS "Building example programs")
1618     IF(SDL2_FOUND)
1619         IF(SDL_SOUND_FOUND)
1620             # Add a static library with common functions used by multiple targets
1621             ADD_LIBRARY(ex-common STATIC examples/common/alhelpers.c)
1622             TARGET_COMPILE_DEFINITIONS(ex-common PRIVATE ${CPP_DEFS})
1623             TARGET_COMPILE_OPTIONS(ex-common PRIVATE ${C_FLAGS})
1625             ADD_EXECUTABLE(alplay examples/alplay.c)
1626             TARGET_COMPILE_DEFINITIONS(alplay PRIVATE ${CPP_DEFS})
1627             TARGET_INCLUDE_DIRECTORIES(alplay
1628                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1629             TARGET_COMPILE_OPTIONS(alplay PRIVATE ${C_FLAGS})
1630             TARGET_LINK_LIBRARIES(alplay
1631                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1632                         OpenAL)
1634             ADD_EXECUTABLE(alstream examples/alstream.c)
1635             TARGET_COMPILE_DEFINITIONS(alstream PRIVATE ${CPP_DEFS})
1636             TARGET_INCLUDE_DIRECTORIES(alstream
1637                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1638             TARGET_COMPILE_OPTIONS(alstream PRIVATE ${C_FLAGS})
1639             TARGET_LINK_LIBRARIES(alstream
1640                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1641                         OpenAL)
1643             ADD_EXECUTABLE(alreverb examples/alreverb.c)
1644             TARGET_COMPILE_DEFINITIONS(alreverb PRIVATE ${CPP_DEFS})
1645             TARGET_INCLUDE_DIRECTORIES(alreverb
1646                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1647             TARGET_COMPILE_OPTIONS(alreverb PRIVATE ${C_FLAGS})
1648             TARGET_LINK_LIBRARIES(alreverb
1649                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1650                         OpenAL)
1652             ADD_EXECUTABLE(almultireverb examples/almultireverb.c)
1653             TARGET_COMPILE_DEFINITIONS(almultireverb PRIVATE ${CPP_DEFS})
1654             TARGET_INCLUDE_DIRECTORIES(almultireverb
1655                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1656             TARGET_COMPILE_OPTIONS(almultireverb PRIVATE ${C_FLAGS})
1657             TARGET_LINK_LIBRARIES(almultireverb
1658                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1659                         OpenAL ${MATH_LIB})
1661             ADD_EXECUTABLE(allatency examples/allatency.c)
1662             TARGET_COMPILE_DEFINITIONS(allatency PRIVATE ${CPP_DEFS})
1663             TARGET_INCLUDE_DIRECTORIES(allatency
1664                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1665             TARGET_COMPILE_OPTIONS(allatency PRIVATE ${C_FLAGS})
1666             TARGET_LINK_LIBRARIES(allatency
1667                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1668                         OpenAL)
1670             ADD_EXECUTABLE(alloopback examples/alloopback.c)
1671             TARGET_COMPILE_DEFINITIONS(alloopback PRIVATE ${CPP_DEFS})
1672             TARGET_INCLUDE_DIRECTORIES(alloopback
1673                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1674             TARGET_COMPILE_OPTIONS(alloopback PRIVATE ${C_FLAGS})
1675             TARGET_LINK_LIBRARIES(alloopback
1676                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1677                         OpenAL ${MATH_LIB})
1679             ADD_EXECUTABLE(alhrtf examples/alhrtf.c)
1680             TARGET_COMPILE_DEFINITIONS(alhrtf PRIVATE ${CPP_DEFS})
1681             TARGET_INCLUDE_DIRECTORIES(alhrtf
1682                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1683             TARGET_COMPILE_OPTIONS(alhrtf PRIVATE ${C_FLAGS})
1684             TARGET_LINK_LIBRARIES(alhrtf
1685                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1686                         OpenAL ${MATH_LIB})
1688             IF(ALSOFT_INSTALL)
1689                 INSTALL(TARGETS alplay alstream alreverb almultireverb allatency alloopback alhrtf
1690                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1691                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1692                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1693                 )
1694             ENDIF()
1696             MESSAGE(STATUS "Building SDL_sound example programs")
1697         ENDIF()
1699         SET(FFVER_OK FALSE)
1700         IF(FFMPEG_FOUND)
1701             SET(FFVER_OK TRUE)
1702             IF(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1703                 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1704                 SET(FFVER_OK FALSE)
1705             ENDIF()
1706             IF(AVCODEC_VERSION VERSION_LESS "57.64.101")
1707                 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1708                 SET(FFVER_OK FALSE)
1709             ENDIF()
1710             IF(AVUTIL_VERSION VERSION_LESS "55.34.101")
1711                 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1712                 SET(FFVER_OK FALSE)
1713             ENDIF()
1714             IF(SWSCALE_VERSION VERSION_LESS "4.2.100")
1715                 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1716                 SET(FFVER_OK FALSE)
1717             ENDIF()
1718             IF(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1719                 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1720                 SET(FFVER_OK FALSE)
1721             ENDIF()
1722         ENDIF()
1723         IF(FFVER_OK)
1724             ADD_EXECUTABLE(alffplay examples/alffplay.cpp)
1725             TARGET_COMPILE_DEFINITIONS(alffplay PRIVATE ${CPP_DEFS})
1726             TARGET_INCLUDE_DIRECTORIES(alffplay
1727                 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1728             TARGET_COMPILE_OPTIONS(alffplay PRIVATE ${C_FLAGS})
1729             TARGET_LINK_LIBRARIES(alffplay
1730                 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} common OpenAL)
1732             IF(ALSOFT_INSTALL)
1733                 INSTALL(TARGETS alffplay
1734                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1735                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1736                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1737                 )
1738             ENDIF()
1739             MESSAGE(STATUS "Building SDL+FFmpeg example programs")
1740         ENDIF()
1741         MESSAGE(STATUS "")
1742     ENDIF()
1743 ENDIF()