Request the device's sample type for SDL2
[openal-soft.git] / CMakeLists.txt
blob0c6196f1f47bb95b1ee5039af986fcb70dcc29d6
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 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
436                          int main() {return 0;}" HAVE_GCC_FORMAT)
438 CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
439 CHECK_INCLUDE_FILE(stdalign.h HAVE_STDALIGN_H)
440 CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
441 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
442 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
443 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
444 CHECK_INCLUDE_FILE(intrin.h HAVE_INTRIN_H)
445 CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
446 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
447 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
448 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
449 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
450 IF(NOT HAVE_GUIDDEF_H)
451     CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
452 ENDIF()
454 # Some systems need libm for some of the following math functions to work
455 SET(MATH_LIB )
456 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
457 IF(HAVE_LIBM)
458     SET(MATH_LIB ${MATH_LIB} m)
459     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
460 ENDIF()
462 # Check for the dlopen API (for dynamicly loading backend libs)
463 IF(ALSOFT_DLOPEN)
464     CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
465     IF(HAVE_LIBDL)
466         SET(EXTRA_LIBS dl ${EXTRA_LIBS})
467         SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
468     ENDIF()
470     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
471 ENDIF()
473 # Check for a cpuid intrinsic
474 IF(HAVE_CPUID_H)
475     CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
476         int main()
477         {
478             unsigned int eax, ebx, ecx, edx;
479             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
480         }" HAVE_GCC_GET_CPUID)
481 ENDIF()
482 IF(HAVE_INTRIN_H)
483     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
484         int main()
485         {
486             int regs[4];
487             __cpuid(regs, 0);
488             return regs[0];
489         }" HAVE_CPUID_INTRINSIC)
490     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
491         int main()
492         {
493             unsigned long idx = 0;
494             _BitScanForward64(&idx, 1);
495             return idx;
496         }" HAVE_BITSCANFORWARD64_INTRINSIC)
497     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
498         int main()
499         {
500             unsigned long idx = 0;
501             _BitScanForward(&idx, 1);
502             return idx;
503         }" HAVE_BITSCANFORWARD_INTRINSIC)
504 ENDIF()
506 CHECK_SYMBOL_EXISTS(sysconf          unistd.h HAVE_SYSCONF)
507 CHECK_SYMBOL_EXISTS(aligned_alloc    stdlib.h HAVE_ALIGNED_ALLOC)
508 CHECK_SYMBOL_EXISTS(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
509 CHECK_SYMBOL_EXISTS(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
510 CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
511 CHECK_SYMBOL_EXISTS(modff  math.h HAVE_MODFF)
512 CHECK_SYMBOL_EXISTS(log2f  math.h HAVE_LOG2F)
513 CHECK_SYMBOL_EXISTS(cbrtf  math.h HAVE_CBRTF)
515 IF(HAVE_FLOAT_H)
516     CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
517     CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
518 ENDIF()
520 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
521 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
522 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
523 IF(NOT HAVE_STRCASECMP)
524     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
525     IF(NOT HAVE__STRICMP)
526         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
527     ENDIF()
529     SET(CPP_DEFS ${CPP_DEFS} strcasecmp=_stricmp)
530 ENDIF()
532 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
533 IF(NOT HAVE_STRNCASECMP)
534     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
535     IF(NOT HAVE__STRNICMP)
536         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
537     ENDIF()
539     SET(CPP_DEFS ${CPP_DEFS} strncasecmp=_strnicmp)
540 ENDIF()
542 CHECK_SYMBOL_EXISTS(strnlen string.h HAVE_STRNLEN)
543 CHECK_SYMBOL_EXISTS(snprintf stdio.h HAVE_SNPRINTF)
544 IF(NOT HAVE_SNPRINTF)
545     CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
546     IF(NOT HAVE__SNPRINTF)
547         MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
548     ENDIF()
550     SET(CPP_DEFS ${CPP_DEFS} snprintf=_snprintf)
551 ENDIF()
553 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
554 IF(NOT HAVE_ISFINITE)
555     CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
556     IF(NOT HAVE_FINITE)
557         CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
558         IF(NOT HAVE__FINITE)
559             MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
560         ENDIF()
561         SET(CPP_DEFS ${CPP_DEFS} isfinite=_finite)
562     ELSE()
563         SET(CPP_DEFS ${CPP_DEFS} isfinite=finite)
564     ENDIF()
565 ENDIF()
567 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
568 IF(NOT HAVE_ISNAN)
569     CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
570     IF(NOT HAVE__ISNAN)
571         MESSAGE(FATAL_ERROR "No isnan function found, please report!")
572     ENDIF()
574     SET(CPP_DEFS ${CPP_DEFS} isnan=_isnan)
575 ENDIF()
578 # Check if we have Windows headers
579 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0502)
580 IF(NOT HAVE_WINDOWS_H)
581     CHECK_SYMBOL_EXISTS(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
582     IF(NOT HAVE_GETTIMEOFDAY)
583         MESSAGE(FATAL_ERROR "No timing function found!")
584     ENDIF()
586     CHECK_SYMBOL_EXISTS(nanosleep time.h HAVE_NANOSLEEP)
587     IF(NOT HAVE_NANOSLEEP)
588         MESSAGE(FATAL_ERROR "No sleep function found!")
589     ENDIF()
591     # We need pthreads outside of Windows
592     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
593     IF(NOT HAVE_PTHREAD_H)
594         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
595     ENDIF()
596     # Some systems need pthread_np.h to get recursive mutexes
597     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
599     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
600     IF(HAVE_PTHREAD)
601         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
602         SET(C_FLAGS ${C_FLAGS} -pthread)
603         SET(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
604     ENDIF()
606     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
607     IF(HAVE_LIBPTHREAD)
608         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
609     ENDIF()
611     CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
613     IF(HAVE_PTHREAD_NP_H)
614         CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
615         IF(NOT HAVE_PTHREAD_SETNAME_NP)
616             CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
617         ELSE()
618             CHECK_C_SOURCE_COMPILES("
619 #include <pthread.h>
620 #include <pthread_np.h>
621 int main()
623     pthread_setname_np(\"testname\");
624     return 0;
626                 PTHREAD_SETNAME_NP_ONE_PARAM
627             )
628             CHECK_C_SOURCE_COMPILES("
629 #include <pthread.h>
630 #include <pthread_np.h>
631 int main()
633     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
634     return 0;
636                 PTHREAD_SETNAME_NP_THREE_PARAMS
637             )
638         ENDIF()
639         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np "pthread.h;pthread_np.h" HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
640     ELSE()
641         CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
642         IF(NOT HAVE_PTHREAD_SETNAME_NP)
643             CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
644         ELSE()
645             CHECK_C_SOURCE_COMPILES("
646 #include <pthread.h>
647 int main()
649     pthread_setname_np(\"testname\");
650     return 0;
652                 PTHREAD_SETNAME_NP_ONE_PARAM
653             )
654             CHECK_C_SOURCE_COMPILES("
655 #include <pthread.h>
656 int main()
658     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
659     return 0;
661                 PTHREAD_SETNAME_NP_THREE_PARAMS
662             )
663         ENDIF()
664         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np pthread.h HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
665     ENDIF()
667     CHECK_SYMBOL_EXISTS(pthread_mutex_timedlock pthread.h HAVE_PTHREAD_MUTEX_TIMEDLOCK)
669     CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
670     IF(HAVE_LIBRT)
671         SET(EXTRA_LIBS rt ${EXTRA_LIBS})
672     ENDIF()
673 ENDIF()
675 CHECK_SYMBOL_EXISTS(getopt unistd.h HAVE_GETOPT)
677 # Check for a 64-bit type
678 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
679 IF(NOT HAVE_STDINT_H)
680     IF(HAVE_WINDOWS_H)
681         CHECK_C_SOURCE_COMPILES("#define _WIN32_WINNT 0x0502
682                                  #include <windows.h>
683                                  __int64 foo;
684                                  int main() {return 0;}" HAVE___INT64)
685     ENDIF()
686     IF(NOT HAVE___INT64)
687         IF(NOT SIZEOF_LONG MATCHES "8")
688             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
689                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
690             ENDIF()
691         ENDIF()
692     ENDIF()
693 ENDIF()
696 SET(COMMON_OBJS  common/almalloc.c
697                  common/atomic.c
698                  common/rwlock.c
699                  common/threads.c
700                  common/uintmap.c
702 SET(OPENAL_OBJS  OpenAL32/alAuxEffectSlot.c
703                  OpenAL32/alBuffer.c
704                  OpenAL32/alEffect.c
705                  OpenAL32/alError.c
706                  OpenAL32/alExtension.c
707                  OpenAL32/alFilter.c
708                  OpenAL32/alListener.c
709                  OpenAL32/alSource.c
710                  OpenAL32/alState.c
711                  OpenAL32/event.c
712                  OpenAL32/sample_cvt.c
714 SET(ALC_OBJS  Alc/ALc.c
715               Alc/ALu.c
716               Alc/alconfig.c
717               Alc/bs2b.c
718               Alc/converter.c
719               Alc/mastering.c
720               Alc/ringbuffer.c
721               Alc/effects/chorus.c
722               Alc/effects/compressor.c
723               Alc/effects/dedicated.c
724               Alc/effects/distortion.c
725               Alc/effects/echo.c
726               Alc/effects/equalizer.c
727               Alc/effects/modulator.c
728               Alc/effects/null.c
729               Alc/effects/reverb.c
730               Alc/helpers.c
731               Alc/hrtf.c
732               Alc/uhjfilter.c
733               Alc/ambdec.c
734               Alc/bformatdec.c
735               Alc/nfcfilter.c
736               Alc/panning.c
737               Alc/mixer.c
738               Alc/mixer_c.c
742 SET(CPU_EXTS "Default")
743 SET(HAVE_SSE        0)
744 SET(HAVE_SSE2       0)
745 SET(HAVE_SSE3       0)
746 SET(HAVE_SSE4_1     0)
747 SET(HAVE_NEON       0)
749 SET(HAVE_ALSA       0)
750 SET(HAVE_OSS        0)
751 SET(HAVE_SOLARIS    0)
752 SET(HAVE_SNDIO      0)
753 SET(HAVE_QSA        0)
754 SET(HAVE_DSOUND     0)
755 SET(HAVE_MMDEVAPI   0)
756 SET(HAVE_WINMM      0)
757 SET(HAVE_PORTAUDIO  0)
758 SET(HAVE_PULSEAUDIO 0)
759 SET(HAVE_COREAUDIO  0)
760 SET(HAVE_OPENSL     0)
761 SET(HAVE_WAVE       0)
762 SET(HAVE_SDL2       0)
764 # Check for SSE support
765 OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
766 CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE_SWITCH}")
767 IF(HAVE_XMMINTRIN_H)
768     OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
769     IF(ALSOFT_CPUEXT_SSE)
770         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
771             SET(HAVE_SSE 1)
772             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse.c)
773             IF(SSE_SWITCH)
774                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse.c PROPERTIES
775                                             COMPILE_FLAGS "${SSE_SWITCH}")
776             ENDIF()
777             SET(CPU_EXTS "${CPU_EXTS}, SSE")
778         ENDIF()
779     ENDIF()
780 ENDIF()
781 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
782     MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
783 ENDIF()
785 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
786 CHECK_INCLUDE_FILE(emmintrin.h HAVE_EMMINTRIN_H "${SSE2_SWITCH}")
787 IF(HAVE_EMMINTRIN_H)
788     OPTION(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
789     IF(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
790         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
791             SET(HAVE_SSE2 1)
792             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse2.c)
793             IF(SSE2_SWITCH)
794                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse2.c PROPERTIES
795                                             COMPILE_FLAGS "${SSE2_SWITCH}")
796             ENDIF()
797             SET(CPU_EXTS "${CPU_EXTS}, SSE2")
798         ENDIF()
799     ENDIF()
800 ENDIF()
801 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
802     MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
803 ENDIF()
805 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE3 support" OFF)
806 CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}")
807 IF(HAVE_EMMINTRIN_H)
808     OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
809     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
810         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
811             SET(HAVE_SSE3 1)
812             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse3.c)
813             IF(SSE2_SWITCH)
814                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse3.c PROPERTIES
815                                             COMPILE_FLAGS "${SSE3_SWITCH}")
816             ENDIF()
817             SET(CPU_EXTS "${CPU_EXTS}, SSE3")
818         ENDIF()
819     ENDIF()
820 ENDIF()
821 IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
822     MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
823 ENDIF()
825 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
826 CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}")
827 IF(HAVE_SMMINTRIN_H)
828     OPTION(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
829     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE4_1)
830         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
831             SET(HAVE_SSE4_1 1)
832             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse41.c)
833             IF(SSE4_1_SWITCH)
834                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse41.c PROPERTIES
835                                             COMPILE_FLAGS "${SSE4_1_SWITCH}")
836             ENDIF()
837             SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
838         ENDIF()
839     ENDIF()
840 ENDIF()
841 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
842     MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
843 ENDIF()
845 # Check for ARM Neon support
846 OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
847 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H ${FPU_NEON_SWITCH})
848 IF(HAVE_ARM_NEON_H)
849     OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
850     IF(ALSOFT_CPUEXT_NEON)
851         SET(HAVE_NEON 1)
852         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_neon.c)
853         IF(FPU_NEON_SWITCH)
854             SET_SOURCE_FILES_PROPERTIES(Alc/mixer_neon.c PROPERTIES
855                                         COMPILE_FLAGS "${FPU_NEON_SWITCH}")
856         ENDIF()
857         SET(CPU_EXTS "${CPU_EXTS}, Neon")
858     ENDIF()
859 ENDIF()
860 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
861     MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
862 ENDIF()
865 IF(WIN32 OR HAVE_DLFCN_H)
866     SET(IS_LINKED "")
867     MACRO(ADD_BACKEND_LIBS _LIBS)
868     ENDMACRO()
869 ELSE()
870     SET(IS_LINKED " (linked)")
871     MACRO(ADD_BACKEND_LIBS _LIBS)
872         SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
873     ENDMACRO()
874 ENDIF()
876 SET(BACKENDS "")
877 SET(ALC_OBJS  ${ALC_OBJS}
878               Alc/backends/base.c
879               # Default backends, always available
880               Alc/backends/loopback.c
881               Alc/backends/null.c
884 # Check ALSA backend
885 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
886 FIND_PACKAGE(ALSA)
887 IF(ALSA_FOUND)
888     OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
889     IF(ALSOFT_BACKEND_ALSA)
890         SET(HAVE_ALSA 1)
891         SET(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
892         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/alsa.c)
893         ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
894         SET(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
895     ENDIF()
896 ENDIF()
897 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
898     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
899 ENDIF()
901 # Check OSS backend
902 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
903 FIND_PACKAGE(OSS)
904 IF(OSS_FOUND)
905     OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
906     IF(ALSOFT_BACKEND_OSS)
907         SET(HAVE_OSS 1)
908         SET(BACKENDS  "${BACKENDS} OSS,")
909         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/oss.c)
910         IF(OSS_LIBRARIES)
911             SET(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
912         ENDIF()
913         SET(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
914     ENDIF()
915 ENDIF()
916 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
917     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
918 ENDIF()
920 # Check Solaris backend
921 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
922 FIND_PACKAGE(AudioIO)
923 IF(AUDIOIO_FOUND)
924     OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
925     IF(ALSOFT_BACKEND_SOLARIS)
926         SET(HAVE_SOLARIS 1)
927         SET(BACKENDS  "${BACKENDS} Solaris,")
928         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/solaris.c)
929         SET(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
930     ENDIF()
931 ENDIF()
932 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
933     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
934 ENDIF()
936 # Check SndIO backend
937 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
938 FIND_PACKAGE(SoundIO)
939 IF(SOUNDIO_FOUND)
940     OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
941     IF(ALSOFT_BACKEND_SNDIO)
942         SET(HAVE_SNDIO 1)
943         SET(BACKENDS  "${BACKENDS} SndIO (linked),")
944         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sndio.c)
945         SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
946         SET(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
947     ENDIF()
948 ENDIF()
949 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
950     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
951 ENDIF()
953 # Check QSA backend
954 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
955 FIND_PACKAGE(QSA)
956 IF(QSA_FOUND)
957     OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
958     IF(ALSOFT_BACKEND_QSA)
959         SET(HAVE_QSA 1)
960         SET(BACKENDS  "${BACKENDS} QSA (linked),")
961         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/qsa.c)
962         SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
963         SET(INC_PATHS ${INC_PATHS} ${QSA_INCLUDE_DIRS})
964     ENDIF()
965 ENDIF()
966 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
967     MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
968 ENDIF()
970 # Check Windows-only backends
971 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
972 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
973 OPTION(ALSOFT_REQUIRE_MMDEVAPI "Require MMDevApi backend" OFF)
974 IF(HAVE_WINDOWS_H)
975     # Check MMSystem backend
976     CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0502)
977     IF(HAVE_MMSYSTEM_H)
978         CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
979         IF(HAVE_LIBWINMM)
980             OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
981             IF(ALSOFT_BACKEND_WINMM)
982                 SET(HAVE_WINMM 1)
983                 SET(BACKENDS  "${BACKENDS} WinMM,")
984                 SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/winmm.c)
985                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
986             ENDIF()
987         ENDIF()
988     ENDIF()
990     # Check DSound backend
991     FIND_PACKAGE(DSound)
992     IF(DSOUND_FOUND)
993         OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
994         IF(ALSOFT_BACKEND_DSOUND)
995             SET(HAVE_DSOUND 1)
996             SET(BACKENDS  "${BACKENDS} DirectSound${IS_LINKED},")
997             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/dsound.c)
998             ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
999             SET(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIRS})
1000         ENDIF()
1001     ENDIF()
1003     # Check for MMDevApi backend
1004     CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1005     IF(HAVE_MMDEVICEAPI_H)
1006         OPTION(ALSOFT_BACKEND_MMDEVAPI "Enable MMDevApi backend" ON)
1007         IF(ALSOFT_BACKEND_MMDEVAPI)
1008             SET(HAVE_MMDEVAPI 1)
1009             SET(BACKENDS  "${BACKENDS} MMDevApi,")
1010             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/mmdevapi.c)
1011         ENDIF()
1012     ENDIF()
1013 ENDIF()
1014 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1015     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
1016 ENDIF()
1017 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1018     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
1019 ENDIF()
1020 IF(ALSOFT_REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
1021     MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
1022 ENDIF()
1024 # Check PortAudio backend
1025 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1026 FIND_PACKAGE(PortAudio)
1027 IF(PORTAUDIO_FOUND)
1028     OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1029     IF(ALSOFT_BACKEND_PORTAUDIO)
1030         SET(HAVE_PORTAUDIO 1)
1031         SET(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
1032         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/portaudio.c)
1033         ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
1034         SET(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
1035     ENDIF()
1036 ENDIF()
1037 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1038     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
1039 ENDIF()
1041 # Check PulseAudio backend
1042 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1043 FIND_PACKAGE(PulseAudio)
1044 IF(PULSEAUDIO_FOUND)
1045     OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1046     IF(ALSOFT_BACKEND_PULSEAUDIO)
1047         SET(HAVE_PULSEAUDIO 1)
1048         SET(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
1049         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/pulseaudio.c)
1050         ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
1051         SET(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
1052     ENDIF()
1053 ENDIF()
1054 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1055     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1056 ENDIF()
1058 # Check JACK backend
1059 OPTION(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1060 FIND_PACKAGE(JACK)
1061 IF(JACK_FOUND)
1062     OPTION(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1063     IF(ALSOFT_BACKEND_JACK)
1064         SET(HAVE_JACK 1)
1065         SET(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1066         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/jack.c)
1067         ADD_BACKEND_LIBS(${JACK_LIBRARIES})
1068         SET(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1069     ENDIF()
1070 ENDIF()
1071 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1072     MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
1073 ENDIF()
1075 # Check CoreAudio backend
1076 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1077 FIND_LIBRARY(COREAUDIO_FRAMEWORK
1078              NAMES CoreAudio
1079              PATHS /System/Library/Frameworks
1081 IF(COREAUDIO_FRAMEWORK)
1082     OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1083     IF(ALSOFT_BACKEND_COREAUDIO)
1084         SET(HAVE_COREAUDIO 1)
1085         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/coreaudio.c)
1086         SET(BACKENDS  "${BACKENDS} CoreAudio,")
1087         SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
1088         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
1089         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1091         # Some versions of OSX may need the AudioToolbox framework. Add it if
1092         # it's found.
1093         FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
1094                      NAMES AudioToolbox
1095                      PATHS ~/Library/Frameworks
1096                            /Library/Frameworks
1097                            /System/Library/Frameworks
1098                     )
1099         IF(AUDIOTOOLBOX_LIBRARY)
1100             SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1101         ENDIF()
1102     ENDIF()
1103 ENDIF()
1104 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1105     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1106 ENDIF()
1108 # Check for OpenSL (Android) backend
1109 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1110 CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
1111 IF(HAVE_SLES_OPENSLES_ANDROID_H)
1112     CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
1113     IF(HAVE_LIBOPENSLES)
1114         OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1115         IF(ALSOFT_BACKEND_OPENSL)
1116             SET(HAVE_OPENSL 1)
1117             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/opensl.c)
1118             SET(BACKENDS  "${BACKENDS} OpenSL,")
1119             SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
1120         ENDIF()
1121     ENDIF()
1122 ENDIF()
1123 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1124     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1125 ENDIF()
1127 # Check for SDL2 backend
1128 OPTION(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1129 FIND_PACKAGE(SDL2)
1130 IF(SDL2_FOUND)
1131     # Off by default, since it adds a runtime dependency
1132     OPTION(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1133     IF(ALSOFT_BACKEND_SDL2)
1134         SET(HAVE_SDL2 1)
1135         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sdl2.c)
1136         SET(BACKENDS  "${BACKENDS} SDL2,")
1137         SET(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
1138     ENDIF()
1139 ENDIF()
1140 IF(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1141     MESSAGE(FATAL_ERROR "Failed to enabled required SDL2 backend")
1142 ENDIF()
1144 # Optionally enable the Wave Writer backend
1145 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1146 IF(ALSOFT_BACKEND_WAVE)
1147     SET(HAVE_WAVE 1)
1148     SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wave.c)
1149     SET(BACKENDS  "${BACKENDS} WaveFile,")
1150 ENDIF()
1152 # This is always available
1153 SET(BACKENDS  "${BACKENDS} Null")
1156 FIND_PACKAGE(Git)
1157 IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1158     # Get the current working branch and its latest abbreviated commit hash
1159     ADD_CUSTOM_TARGET(build_version
1160         ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
1161                          -D LIB_VERSION=${LIB_VERSION}
1162                          -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1163                          -D DST=${OpenAL_BINARY_DIR}/version.h
1164                          -P ${OpenAL_SOURCE_DIR}/version.cmake
1165         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1166         VERBATIM
1167     )
1168 ELSE()
1169     SET(GIT_BRANCH "UNKNOWN")
1170     SET(GIT_COMMIT_HASH "unknown")
1171     CONFIGURE_FILE(
1172         "${OpenAL_SOURCE_DIR}/version.h.in"
1173         "${OpenAL_BINARY_DIR}/version.h")
1174 ENDIF()
1176 SET(NATIVE_SRC_DIR  "${OpenAL_SOURCE_DIR}/native-tools/")
1177 SET(NATIVE_BIN_DIR  "${OpenAL_BINARY_DIR}/native-tools/")
1178 FILE(MAKE_DIRECTORY "${NATIVE_BIN_DIR}")
1180 SET(BIN2H_COMMAND  "${NATIVE_BIN_DIR}bin2h")
1181 SET(BSINCGEN_COMMAND  "${NATIVE_BIN_DIR}bsincgen")
1182 ADD_CUSTOM_COMMAND(OUTPUT "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1183     COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" "${NATIVE_SRC_DIR}"
1184     COMMAND ${CMAKE_COMMAND} -E remove "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1185     COMMAND ${CMAKE_COMMAND} --build . --config "Release"
1186     WORKING_DIRECTORY "${NATIVE_BIN_DIR}"
1187     DEPENDS "${NATIVE_SRC_DIR}CMakeLists.txt"
1188     IMPLICIT_DEPENDS C "${NATIVE_SRC_DIR}bin2h.c"
1189                      C "${NATIVE_SRC_DIR}bsincgen.c"
1190     VERBATIM
1192 ADD_CUSTOM_TARGET(native-tools
1193     DEPENDS "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1194     VERBATIM
1197 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" OFF)
1198 if(ALSOFT_EMBED_HRTF_DATA)
1199     MACRO(make_hrtf_header FILENAME VARNAME)
1200         SET(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1201         SET(outfile  "${OpenAL_BINARY_DIR}/${FILENAME}.h")
1203         ADD_CUSTOM_COMMAND(OUTPUT "${outfile}"
1204             COMMAND "${BIN2H_COMMAND}" "${infile}" "${outfile}" ${VARNAME}
1205             DEPENDS native-tools "${infile}"
1206             VERBATIM
1207         )
1208         SET(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1209     ENDMACRO()
1211     make_hrtf_header(default-44100.mhr "hrtf_default_44100")
1212     make_hrtf_header(default-48000.mhr "hrtf_default_48000")
1213 endif()
1215 ADD_CUSTOM_COMMAND(OUTPUT "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1216     COMMAND "${BSINCGEN_COMMAND}" "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1217     DEPENDS native-tools "${NATIVE_SRC_DIR}bsincgen.c"
1218     VERBATIM
1220 SET(ALC_OBJS  ${ALC_OBJS} "${OpenAL_BINARY_DIR}/bsinc_inc.h")
1223 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1224     add_subdirectory(utils/alsoft-config)
1225 ENDIF()
1226 IF(ALSOFT_EXAMPLES)
1227     IF(NOT SDL2_FOUND)
1228         FIND_PACKAGE(SDL2)
1229     ENDIF()
1230     IF(SDL2_FOUND)
1231         FIND_PACKAGE(SDL_sound)
1232         FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1233     ENDIF()
1234 ENDIF()
1236 IF(NOT WIN32)
1237     SET(LIBNAME "openal")
1238 ELSE()
1239     SET(LIBNAME "OpenAL32")
1240 ENDIF()
1242 # Needed for openal.pc.in
1243 SET(prefix ${CMAKE_INSTALL_PREFIX})
1244 SET(exec_prefix "\${prefix}")
1245 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1246 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1247 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1248 SET(PACKAGE_VERSION "${LIB_VERSION}")
1249 IF(LIBTYPE STREQUAL "STATIC")
1250     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
1251 ENDIF()
1253 # End configuration
1254 CONFIGURE_FILE(
1255     "${OpenAL_SOURCE_DIR}/config.h.in"
1256     "${OpenAL_BINARY_DIR}/config.h")
1257 CONFIGURE_FILE(
1258     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1259     "${OpenAL_BINARY_DIR}/openal.pc"
1260     @ONLY)
1263 # Add a static library with common functions used by multiple targets
1264 ADD_LIBRARY(common STATIC ${COMMON_OBJS})
1265 TARGET_COMPILE_DEFINITIONS(common PRIVATE ${CPP_DEFS})
1266 TARGET_COMPILE_OPTIONS(common PRIVATE ${C_FLAGS})
1269 UNSET(HAS_ROUTER)
1270 SET(IMPL_TARGET OpenAL)
1271 SET(COMMON_LIB )
1272 SET(SUBSYS_FLAG )
1274 # Build main library
1275 IF(LIBTYPE STREQUAL "STATIC")
1276     SET(CPP_DEFS ${CPP_DEFS} AL_LIBTYPE_STATIC)
1277     IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1278         SET(CPP_DEFS ${CPP_DEFS} AL_NO_UID_DEFS)
1279     ENDIF()
1280     ADD_LIBRARY(OpenAL STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1281 ELSE()
1282     # Make sure to compile the common code with PIC, since it'll be linked into
1283     # shared libs that needs it.
1284     SET_PROPERTY(TARGET common PROPERTY POSITION_INDEPENDENT_CODE TRUE)
1285     SET(COMMON_LIB common)
1287     IF(WIN32)
1288         IF(MSVC)
1289             SET(SUBSYS_FLAG ${SUBSYS_FLAG} "/SUBSYSTEM:WINDOWS")
1290         ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1291             SET(SUBSYS_FLAG ${SUBSYS_FLAG} "-mwindows")
1292         ENDIF()
1293     ENDIF()
1295     IF(WIN32 AND ALSOFT_BUILD_ROUTER)
1296         ADD_LIBRARY(OpenAL SHARED router/router.c router/alc.c router/al.c)
1297         TARGET_COMPILE_DEFINITIONS(OpenAL
1298             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1299         TARGET_COMPILE_OPTIONS(OpenAL PRIVATE ${C_FLAGS})
1300         TARGET_LINK_LIBRARIES(OpenAL PRIVATE ${LINKER_FLAGS} ${COMMON_LIB})
1301         SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "")
1302         SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1303         IF(TARGET build_version)
1304             ADD_DEPENDENCIES(OpenAL build_version)
1305         ENDIF()
1306         SET(HAS_ROUTER 1)
1308         SET(LIBNAME "soft_oal")
1309         SET(IMPL_TARGET soft_oal)
1310     ENDIF()
1312     ADD_LIBRARY(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
1313     IF(WIN32)
1314         SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES PREFIX "")
1315     ENDIF()
1316 ENDIF()
1317 SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1318     VERSION ${LIB_VERSION}
1319     SOVERSION ${LIB_MAJOR_VERSION}
1321 TARGET_COMPILE_DEFINITIONS(${IMPL_TARGET}
1322     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1323 TARGET_INCLUDE_DIRECTORIES(${IMPL_TARGET}
1324     PRIVATE "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc" ${INC_PATHS})
1325 TARGET_COMPILE_OPTIONS(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1326 TARGET_LINK_LIBRARIES(${IMPL_TARGET}
1327     PRIVATE ${LINKER_FLAGS} ${COMMON_LIB} ${EXTRA_LIBS} ${MATH_LIB})
1328 IF(TARGET build_version)
1329     ADD_DEPENDENCIES(${IMPL_TARGET} build_version)
1330 ENDIF()
1332 IF(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1333     FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1334     FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1335     IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1336         MESSAGE(STATUS "")
1337         IF(NOT SED_EXECUTABLE)
1338             MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1339         ENDIF()
1340         IF(NOT DLLTOOL_EXECUTABLE)
1341             MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1342         ENDIF()
1343     ELSE()
1344         SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS
1345                         " -Wl,--output-def,OpenAL32.def")
1346         ADD_CUSTOM_COMMAND(TARGET OpenAL POST_BUILD
1347             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1348             COMMAND "${DLLTOOL_EXECUTABLE}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1349             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1350             VERBATIM
1351         )
1352     ENDIF()
1353 ENDIF()
1355 IF(ALSOFT_INSTALL)
1356     INSTALL(TARGETS OpenAL EXPORT OpenAL
1357             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1358             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1359             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1360             INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL
1361     )
1362     EXPORT(TARGETS OpenAL
1363            NAMESPACE OpenAL::
1364            FILE OpenALConfig.cmake)
1365     INSTALL(EXPORT OpenAL
1366             DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1367             NAMESPACE OpenAL::
1368             FILE OpenALConfig.cmake)
1369     INSTALL(FILES include/AL/al.h
1370                   include/AL/alc.h
1371                   include/AL/alext.h
1372                   include/AL/efx.h
1373                   include/AL/efx-creative.h
1374                   include/AL/efx-presets.h
1375             DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
1376     )
1377     INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1378             DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1379     IF(TARGET soft_oal)
1380         INSTALL(TARGETS soft_oal
1381                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1382         )
1383     ENDIF()
1384 ENDIF()
1387 if(HAS_ROUTER)
1388     message(STATUS "")
1389     message(STATUS "Building DLL router")
1390 endif()
1392 MESSAGE(STATUS "")
1393 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1394 MESSAGE(STATUS "    ${BACKENDS}")
1395 MESSAGE(STATUS "")
1396 MESSAGE(STATUS "Building with support for CPU extensions:")
1397 MESSAGE(STATUS "    ${CPU_EXTS}")
1398 MESSAGE(STATUS "")
1400 IF(WIN32)
1401     IF(NOT HAVE_DSOUND)
1402         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
1403         MESSAGE(STATUS "         This is probably NOT what you want!")
1404         MESSAGE(STATUS "")
1405     ENDIF()
1406 ENDIF()
1408 if(ALSOFT_EMBED_HRTF_DATA)
1409     message(STATUS "Embedding HRTF datasets")
1410     message(STATUS "")
1411 endif()
1413 # Install alsoft.conf configuration file
1414 IF(ALSOFT_CONFIG)
1415     INSTALL(FILES alsoftrc.sample
1416             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal
1417     )
1418     MESSAGE(STATUS "Installing sample configuration")
1419     MESSAGE(STATUS "")
1420 ENDIF()
1422 # Install HRTF definitions
1423 IF(ALSOFT_HRTF_DEFS)
1424     INSTALL(FILES hrtf/default-44100.mhr
1425                   hrtf/default-48000.mhr
1426             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf
1427     )
1428     MESSAGE(STATUS "Installing HRTF definitions")
1429     MESSAGE(STATUS "")
1430 ENDIF()
1432 # Install AmbDec presets
1433 IF(ALSOFT_AMBDEC_PRESETS)
1434     INSTALL(FILES presets/3D7.1.ambdec
1435                   presets/hexagon.ambdec
1436                   presets/itu5.1.ambdec
1437                   presets/itu5.1-nocenter.ambdec
1438                   presets/rectangle.ambdec
1439                   presets/square.ambdec
1440                   presets/presets.txt
1441             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
1442     )
1443     MESSAGE(STATUS "Installing AmbDec presets")
1444     MESSAGE(STATUS "")
1445 ENDIF()
1447 IF(ALSOFT_UTILS)
1448     ADD_EXECUTABLE(openal-info utils/openal-info.c)
1449     TARGET_COMPILE_OPTIONS(openal-info PRIVATE ${C_FLAGS})
1450     TARGET_LINK_LIBRARIES(openal-info PRIVATE ${LINKER_FLAGS} OpenAL)
1452     SET(MAKEHRTF_SRCS  utils/makehrtf.c)
1453     IF(NOT HAVE_GETOPT)
1454         SET(MAKEHRTF_SRCS  ${MAKEHRTF_SRCS} utils/getopt.c)
1455     ENDIF()
1456     ADD_EXECUTABLE(makehrtf ${MAKEHRTF_SRCS})
1457     TARGET_COMPILE_DEFINITIONS(makehrtf PRIVATE ${CPP_DEFS})
1458     TARGET_COMPILE_OPTIONS(makehrtf PRIVATE ${C_FLAGS})
1459     IF(HAVE_LIBM)
1460         TARGET_LINK_LIBRARIES(makehrtf PRIVATE ${LINKER_FLAGS} m)
1461     ENDIF()
1463     IF(ALSOFT_INSTALL)
1464         INSTALL(TARGETS openal-info makehrtf
1465                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1466                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1467                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1468         )
1469     ENDIF()
1471     MESSAGE(STATUS "Building utility programs")
1472     IF(TARGET alsoft-config)
1473         MESSAGE(STATUS "Building configuration program")
1474     ENDIF()
1475     MESSAGE(STATUS "")
1476 ENDIF()
1478 IF(ALSOFT_TESTS)
1479     SET(TEST_COMMON_OBJS  examples/common/alhelpers.c)
1481     ADD_EXECUTABLE(altonegen examples/altonegen.c ${TEST_COMMON_OBJS})
1482     TARGET_COMPILE_DEFINITIONS(altonegen PRIVATE ${CPP_DEFS})
1483     TARGET_COMPILE_OPTIONS(altonegen PRIVATE ${C_FLAGS})
1484     TARGET_LINK_LIBRARIES(altonegen PRIVATE ${LINKER_FLAGS} common OpenAL ${MATH_LIB})
1486     IF(ALSOFT_INSTALL)
1487         INSTALL(TARGETS altonegen
1488                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1489                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1490                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1491         )
1492     ENDIF()
1494     MESSAGE(STATUS "Building test programs")
1495     MESSAGE(STATUS "")
1496 ENDIF()
1498 IF(ALSOFT_EXAMPLES)
1499     ADD_EXECUTABLE(alrecord examples/alrecord.c)
1500     TARGET_COMPILE_DEFINITIONS(alrecord PRIVATE ${CPP_DEFS})
1501     TARGET_COMPILE_OPTIONS(alrecord PRIVATE ${C_FLAGS})
1502     TARGET_LINK_LIBRARIES(alrecord PRIVATE ${LINKER_FLAGS} common OpenAL)
1504     IF(ALSOFT_INSTALL)
1505         INSTALL(TARGETS alrecord
1506                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1507                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1508                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1509         )
1510     ENDIF()
1512     MESSAGE(STATUS "Building example programs")
1514     IF(SDL2_FOUND)
1515         IF(SDL_SOUND_FOUND)
1516             # Add a static library with common functions used by multiple targets
1517             ADD_LIBRARY(ex-common STATIC examples/common/alhelpers.c)
1518             TARGET_COMPILE_DEFINITIONS(ex-common PRIVATE ${CPP_DEFS})
1519             TARGET_COMPILE_OPTIONS(ex-common PRIVATE ${C_FLAGS})
1521             ADD_EXECUTABLE(alplay examples/alplay.c)
1522             TARGET_COMPILE_DEFINITIONS(alplay PRIVATE ${CPP_DEFS})
1523             TARGET_INCLUDE_DIRECTORIES(alplay
1524                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1525             TARGET_COMPILE_OPTIONS(alplay PRIVATE ${C_FLAGS})
1526             TARGET_LINK_LIBRARIES(alplay
1527                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1528                         OpenAL)
1530             ADD_EXECUTABLE(alstream examples/alstream.c)
1531             TARGET_COMPILE_DEFINITIONS(alstream PRIVATE ${CPP_DEFS})
1532             TARGET_INCLUDE_DIRECTORIES(alstream
1533                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1534             TARGET_COMPILE_OPTIONS(alstream PRIVATE ${C_FLAGS})
1535             TARGET_LINK_LIBRARIES(alstream
1536                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1537                         OpenAL)
1539             ADD_EXECUTABLE(alreverb examples/alreverb.c)
1540             TARGET_COMPILE_DEFINITIONS(alreverb PRIVATE ${CPP_DEFS})
1541             TARGET_INCLUDE_DIRECTORIES(alreverb
1542                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1543             TARGET_COMPILE_OPTIONS(alreverb PRIVATE ${C_FLAGS})
1544             TARGET_LINK_LIBRARIES(alreverb
1545                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1546                         OpenAL)
1548             ADD_EXECUTABLE(almultireverb examples/almultireverb.c)
1549             TARGET_COMPILE_DEFINITIONS(almultireverb PRIVATE ${CPP_DEFS})
1550             TARGET_INCLUDE_DIRECTORIES(almultireverb
1551                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1552             TARGET_COMPILE_OPTIONS(almultireverb PRIVATE ${C_FLAGS})
1553             TARGET_LINK_LIBRARIES(almultireverb
1554                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1555                         OpenAL ${MATH_LIB})
1557             ADD_EXECUTABLE(allatency examples/allatency.c)
1558             TARGET_COMPILE_DEFINITIONS(allatency PRIVATE ${CPP_DEFS})
1559             TARGET_INCLUDE_DIRECTORIES(allatency
1560                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1561             TARGET_COMPILE_OPTIONS(allatency PRIVATE ${C_FLAGS})
1562             TARGET_LINK_LIBRARIES(allatency
1563                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1564                         OpenAL)
1566             ADD_EXECUTABLE(alloopback examples/alloopback.c)
1567             TARGET_COMPILE_DEFINITIONS(alloopback PRIVATE ${CPP_DEFS})
1568             TARGET_INCLUDE_DIRECTORIES(alloopback
1569                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1570             TARGET_COMPILE_OPTIONS(alloopback PRIVATE ${C_FLAGS})
1571             TARGET_LINK_LIBRARIES(alloopback
1572                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1573                         OpenAL ${MATH_LIB})
1575             ADD_EXECUTABLE(alhrtf examples/alhrtf.c)
1576             TARGET_COMPILE_DEFINITIONS(alhrtf PRIVATE ${CPP_DEFS})
1577             TARGET_INCLUDE_DIRECTORIES(alhrtf
1578                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1579             TARGET_COMPILE_OPTIONS(alhrtf PRIVATE ${C_FLAGS})
1580             TARGET_LINK_LIBRARIES(alhrtf
1581                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1582                         OpenAL ${MATH_LIB})
1584             IF(ALSOFT_INSTALL)
1585                 INSTALL(TARGETS alplay alstream alreverb almultireverb allatency alloopback alhrtf
1586                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1587                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1588                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1589                 )
1590             ENDIF()
1592             MESSAGE(STATUS "Building SDL_sound example programs")
1593         ENDIF()
1595         SET(FFVER_OK FALSE)
1596         IF(FFMPEG_FOUND)
1597             SET(FFVER_OK TRUE)
1598             IF(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1599                 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1600                 SET(FFVER_OK FALSE)
1601             ENDIF()
1602             IF(AVCODEC_VERSION VERSION_LESS "57.64.101")
1603                 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1604                 SET(FFVER_OK FALSE)
1605             ENDIF()
1606             IF(AVUTIL_VERSION VERSION_LESS "55.34.101")
1607                 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1608                 SET(FFVER_OK FALSE)
1609             ENDIF()
1610             IF(SWSCALE_VERSION VERSION_LESS "4.2.100")
1611                 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1612                 SET(FFVER_OK FALSE)
1613             ENDIF()
1614             IF(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1615                 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1616                 SET(FFVER_OK FALSE)
1617             ENDIF()
1618         ENDIF()
1619         IF(FFVER_OK)
1620             ADD_EXECUTABLE(alffplay examples/alffplay.cpp)
1621             TARGET_COMPILE_DEFINITIONS(alffplay PRIVATE ${CPP_DEFS})
1622             TARGET_INCLUDE_DIRECTORIES(alffplay
1623                 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1624             TARGET_COMPILE_OPTIONS(alffplay PRIVATE ${C_FLAGS})
1625             TARGET_LINK_LIBRARIES(alffplay
1626                 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} common OpenAL)
1628             IF(ALSOFT_INSTALL)
1629                 INSTALL(TARGETS alffplay
1630                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1631                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1632                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1633                 )
1634             ENDIF()
1635             MESSAGE(STATUS "Building SDL+FFmpeg example programs")
1636         ENDIF()
1637         MESSAGE(STATUS "")
1638     ENDIF()
1639 ENDIF()