Improve construction and destruction of ALvoices
[openal-soft.git] / CMakeLists.txt
blob71e20eecf9084f8783bc1df27252133d9bf6d3d3
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     IF(POLICY CMP0075)
20         CMAKE_POLICY(SET CMP0075 NEW)
21     ENDIF(POLICY CMP0075)
22 ENDIF(COMMAND CMAKE_POLICY)
24 SET(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
26 INCLUDE(CheckFunctionExists)
27 INCLUDE(CheckLibraryExists)
28 INCLUDE(CheckSharedFunctionExists)
29 INCLUDE(CheckIncludeFile)
30 INCLUDE(CheckIncludeFiles)
31 INCLUDE(CheckSymbolExists)
32 INCLUDE(CheckCCompilerFlag)
33 INCLUDE(CheckCXXCompilerFlag)
34 INCLUDE(CheckCSourceCompiles)
35 INCLUDE(CheckCXXSourceCompiles)
36 INCLUDE(CheckTypeSize)
37 include(CheckStructHasMember)
38 include(CheckFileOffsetBits)
39 include(GNUInstallDirs)
41 SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
44 OPTION(ALSOFT_DLOPEN  "Check for the dlopen API for loading optional libs"  ON)
46 OPTION(ALSOFT_WERROR  "Treat compile warnings as errors"      OFF)
48 OPTION(ALSOFT_UTILS          "Build and install utility programs"         ON)
49 OPTION(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
51 OPTION(ALSOFT_EXAMPLES  "Build and install example programs"  ON)
52 OPTION(ALSOFT_TESTS     "Build and install test programs"     ON)
54 OPTION(ALSOFT_CONFIG "Install alsoft.conf sample configuration file" ON)
55 OPTION(ALSOFT_HRTF_DEFS "Install HRTF definition files" ON)
56 OPTION(ALSOFT_AMBDEC_PRESETS "Install AmbDec preset files" ON)
57 OPTION(ALSOFT_INSTALL "Install headers and libraries" ON)
59 if(DEFINED SHARE_INSTALL_DIR)
60     message(WARNING "SHARE_INSTALL_DIR is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
61     set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
62 endif()
64 if(DEFINED LIB_SUFFIX)
65     message(WARNING "LIB_SUFFIX is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
66 endif()
69 SET(CPP_DEFS ) # C pre-process, not C++
70 SET(INC_PATHS )
71 SET(C_FLAGS )
72 SET(LINKER_FLAGS )
73 SET(EXTRA_LIBS )
75 IF(WIN32)
76     SET(CPP_DEFS ${CPP_DEFS} _WIN32 _WIN32_WINNT=0x0502)
78     OPTION(ALSOFT_BUILD_ROUTER  "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)"  OFF)
80     # This option is mainly for static linking OpenAL Soft into another project
81     # that already defines the IDs. It is up to that project to ensure all
82     # required IDs are defined.
83     OPTION(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
85     IF(MINGW)
86         OPTION(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
87         IF(NOT DLLTOOL)
88             IF(HOST)
89                 SET(DLLTOOL "${HOST}-dlltool")
90             ELSE()
91                 SET(DLLTOOL "dlltool")
92             ENDIF()
93         ENDIF()
94     ENDIF()
95 ENDIF()
98 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
99 IF ("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
100     SET(INC_PATHS ${INC_PATHS} /usr/include)
101     SET(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
102 ENDIF()
104 IF(NOT LIBTYPE)
105     SET(LIBTYPE SHARED)
106 ENDIF()
108 SET(LIB_MAJOR_VERSION "1")
109 SET(LIB_MINOR_VERSION "19")
110 SET(LIB_REVISION "1")
111 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
113 SET(EXPORT_DECL "")
114 SET(ALIGN_DECL "")
117 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
118 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
121 CHECK_C_COMPILER_FLAG(-std=c11 HAVE_STD_C11)
122 IF(HAVE_STD_C11)
123     SET(CMAKE_C_FLAGS "-std=c11 ${CMAKE_C_FLAGS}")
124 ELSE()
125     CHECK_C_COMPILER_FLAG(-std=c99 HAVE_STD_C99)
126     IF(HAVE_STD_C99)
127         SET(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
128     ENDIF()
129 ENDIF()
131 CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD_CXX11)
132 IF(HAVE_STD_CXX11)
133     SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
134 ENDIF()
136 if(NOT WIN32)
137     # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
138     CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
139     IF(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
140         SET(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
141         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
142         CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
143         IF(NOT HAVE_POSIX_MEMALIGN_POSIX)
144             SET(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
145         ELSE()
146             SET(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
147         ENDIF()
148     ENDIF()
149     UNSET(OLD_REQUIRED_FLAGS)
150 ENDIF()
152 # Set defines for large file support. Don't set this for Android targets. See:
153 # https://android-developers.googleblog.com/2017/09/introducing-android-native-development.html
154 IF(NOT ANDROID)
155     CHECK_FILE_OFFSET_BITS()
156     IF(_FILE_OFFSET_BITS)
157         SET(CPP_DEFS ${CPP_DEFS} "_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
158         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
159     ENDIF()
160     SET(CPP_DEFS ${CPP_DEFS} _LARGEFILE_SOURCE _LARGE_FILES)
161     SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_LARGEFILE_SOURCE -D_LARGE_FILES")
162 ENDIF()
164 # C99 has restrict, but C++ does not, so we can only utilize __restrict.
165 SET(RESTRICT_DECL )
166 CHECK_C_SOURCE_COMPILES("int *__restrict foo;
167                          int main() {return 0;}" HAVE___RESTRICT)
168 IF(HAVE___RESTRICT)
169     SET(RESTRICT_DECL "__restrict")
170 ENDIF()
172 # MSVC may need workarounds for C99 inline
173 IF(MSVC)
174     # TODO: Once we truly require C99, this inline check should go away.
175     CHECK_C_SOURCE_COMPILES("inline void foo(void) { }
176                              int main() {return 0;}" HAVE_INLINE)
177     IF(NOT HAVE_INLINE)
178         CHECK_C_SOURCE_COMPILES("__inline void foo(void) { }
179                                  int main() {return 0;}" HAVE___INLINE)
180         IF(NOT HAVE___INLINE)
181             MESSAGE(FATAL_ERROR "No inline keyword found, please report!")
182         ENDIF()
184         SET(CPP_DEFS ${CPP_DEFS} inline=__inline)
185         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Dinline=__inline")
186     ENDIF()
187 ENDIF()
189 # Make sure we have C99-style inline semantics with GCC (4.3 or newer).
190 IF(CMAKE_COMPILER_IS_GNUCC)
191     SET(CMAKE_C_FLAGS "-fno-gnu89-inline ${CMAKE_C_FLAGS}")
193     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
194     # Force no inlining for the next test.
195     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -fno-inline")
197     CHECK_C_SOURCE_COMPILES("extern inline int foo() { return 0; }
198                              int main() {return foo();}" INLINE_IS_C99)
199     IF(NOT INLINE_IS_C99)
200         MESSAGE(FATAL_ERROR "Your compiler does not seem to have C99 inline semantics!
201                              Please update your compiler for better C99 compliance.")
202     ENDIF()
204     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
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 # Add definitions, compiler switches, etc.
232 INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_SOURCE_DIR}/common" "${OpenAL_BINARY_DIR}")
234 IF(NOT CMAKE_BUILD_TYPE)
235     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
236         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
237         FORCE)
238 ENDIF()
239 IF(NOT CMAKE_DEBUG_POSTFIX)
240     SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
241         "Library postfix for debug builds. Normally left blank."
242         FORCE)
243 ENDIF()
245 IF(MSVC)
246     SET(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE NOMINMAX)
247     SET(C_FLAGS ${C_FLAGS} /wd4065 /wd4098 /wd4200)
249     IF(NOT DXSDK_DIR)
250         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
251     ELSE()
252         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
253     ENDIF()
254     IF(DXSDK_DIR)
255         MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
256     ENDIF()
258     OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
259     IF(FORCE_STATIC_VCRT)
260         FOREACH(flag_var
261                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
262                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
263             IF(${flag_var} MATCHES "/MD")
264                 STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
265             ENDIF()
266         ENDFOREACH(flag_var)
267     ENDIF()
268 ELSE()
269     SET(C_FLAGS ${C_FLAGS} -Winline -Wall)
270     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
271     IF(HAVE_W_EXTRA)
272         SET(C_FLAGS ${C_FLAGS} -Wextra)
273     ENDIF()
275     IF(ALSOFT_WERROR)
276         SET(C_FLAGS ${C_FLAGS} -Werror)
277     ENDIF()
279     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
280     # instead of NDEBUG)
281     FOREACH(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
282         IF(${flag_var} MATCHES "-DNDEBUG")
283             STRING(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
284         ENDIF()
285     ENDFOREACH()
287     CHECK_C_COMPILER_FLAG(-fno-math-errno HAVE_FNO_MATH_ERRNO)
288     IF(HAVE_FNO_MATH_ERRNO)
289         SET(C_FLAGS ${C_FLAGS} -fno-math-errno)
290     ENDIF()
292     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
293                              int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
295     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
296     if(ALSOFT_STATIC_LIBGCC)
297         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
298         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
299         check_c_source_compiles(
300 "#include <stdlib.h>
301 int main()
303     return 0;
305             HAVE_STATIC_LIBGCC_SWITCH
306         )
307         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
308         unset(OLD_REQUIRED_LIBRARIES)
310         if(NOT HAVE_STATIC_LIBGCC_SWITCH)
311             message(FATAL_ERROR "Cannot static link libgcc")
312         endif()
313         set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
314     endif()
316     option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
317     if(ALSOFT_STATIC_STDCXX)
318         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
319         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
320         check_cxx_source_compiles(
321 "#include <cstdlib>
322 int main()
324     return 0;
326             HAVE_STATIC_LIBSTDCXX_SWITCH
327         )
328         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
329         unset(OLD_REQUIRED_LIBRARIES)
331         if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
332             message(FATAL_ERROR "Cannot static link libstdc++")
333         endif()
334         set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
335     endif()
337     if(WIN32)
338         option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
339         if(ALSOFT_STATIC_WINPTHREAD)
340             set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
341             set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
342             check_cxx_source_compiles(
343 "#include <cstdlib>
344 int main()
346     return 0;
348                 HAVE_STATIC_LIBWINPTHREAD_SWITCH
349             )
350             set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
351             unset(OLD_REQUIRED_LIBRARIES)
353             if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
354                 message(FATAL_ERROR "Cannot static link libwinpthread")
355             endif()
356             set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
357         endif()
358     endif()
359 ENDIF()
361 # Set visibility/export options if available
362 IF(WIN32)
363     SET(EXPORT_DECL "__declspec(dllexport)")
364     IF(NOT MINGW)
365         SET(ALIGN_DECL "__declspec(align(x))")
366     ELSE()
367         SET(ALIGN_DECL "__declspec(aligned(x))")
368     ENDIF()
369 ELSE()
370     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
371     # Yes GCC, really don't accept visibility modes you don't support
372     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
374     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
375                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
376     IF(HAVE_GCC_PROTECTED_VISIBILITY)
377         SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
378     ELSE()
379         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
380                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
381         IF(HAVE_GCC_DEFAULT_VISIBILITY)
382             SET(EXPORT_DECL "__attribute__((visibility(\"default\")))")
383         ENDIF()
384     ENDIF()
386     IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
387         CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
388         IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
389             SET(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
390         ENDIF()
391     ENDIF()
393     CHECK_C_SOURCE_COMPILES("int foo __attribute__((aligned(16)));
394                              int main() {return 0;}" HAVE_ATTRIBUTE_ALIGNED)
395     IF(HAVE_ATTRIBUTE_ALIGNED)
396         SET(ALIGN_DECL "__attribute__((aligned(x)))")
397     ENDIF()
399     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
400 ENDIF()
402 SET(SSE_SWITCH "")
403 SET(SSE2_SWITCH "")
404 SET(SSE3_SWITCH "")
405 SET(SSE4_1_SWITCH "")
406 SET(FPU_NEON_SWITCH "")
408 CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
409 IF(HAVE_MSSE_SWITCH)
410     SET(SSE_SWITCH "-msse")
411 ENDIF()
412 CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
413 IF(HAVE_MSSE2_SWITCH)
414     SET(SSE2_SWITCH "-msse2")
415 ENDIF()
416 CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
417 IF(HAVE_MSSE3_SWITCH)
418     SET(SSE3_SWITCH "-msse3")
419 ENDIF()
420 CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
421 IF(HAVE_MSSE4_1_SWITCH)
422     SET(SSE4_1_SWITCH "-msse4.1")
423 ENDIF()
424 CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
425 IF(HAVE_MFPU_NEON_SWITCH)
426     SET(FPU_NEON_SWITCH "-mfpu=neon")
427 ENDIF()
429 SET(FPMATH_SET "0")
430 IF(CMAKE_SIZEOF_VOID_P MATCHES "4")
431     IF(SSE_SWITCH OR MSVC)
432         OPTION(ALSOFT_ENABLE_SSE_CODEGEN "Enable SSE code generation instead of x87 for 32-bit targets." TRUE)
433     ENDIF()
434     IF(SSE2_SWITCH OR MSVC)
435         OPTION(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
436     ENDIF()
438     IF(ALSOFT_ENABLE_SSE2_CODEGEN)
439         IF(SSE2_SWITCH)
440             CHECK_C_COMPILER_FLAG("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
441             IF(HAVE_MFPMATH_SSE_2)
442                 SET(C_FLAGS ${C_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
443                 SET(FPMATH_SET 2)
444             ENDIF()
445         ELSEIF(MSVC)
446             CHECK_C_COMPILER_FLAG("/arch:SSE2" HAVE_ARCH_SSE2)
447             IF(HAVE_ARCH_SSE2)
448                 SET(C_FLAGS ${C_FLAGS} "/arch:SSE2")
449                 SET(FPMATH_SET 2)
450             ENDIF()
451         ENDIF()
452     ENDIF()
453     IF(ALSOFT_ENABLE_SSE_CODEGEN AND NOT FPMATH_SET)
454         IF(SSE_SWITCH)
455             CHECK_C_COMPILER_FLAG("${SSE_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE)
456             IF(HAVE_MFPMATH_SSE)
457                 SET(C_FLAGS ${C_FLAGS} ${SSE_SWITCH} -mfpmath=sse)
458                 SET(FPMATH_SET 1)
459             ENDIF()
460         ELSEIF(MSVC)
461             CHECK_C_COMPILER_FLAG("/arch:SSE" HAVE_ARCH_SSE)
462             IF(HAVE_ARCH_SSE)
463                 SET(C_FLAGS ${C_FLAGS} "/arch:SSE")
464                 SET(FPMATH_SET 1)
465             ENDIF()
466         ENDIF()
467     ENDIF()
468 ENDIF()
471 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
472                          int main() {return 0;}" HAVE_GCC_FORMAT)
474 CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
475 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
476 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
477 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
478 CHECK_INCLUDE_FILE(intrin.h HAVE_INTRIN_H)
479 CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
480 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
481 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
482 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
483 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
484 IF(NOT HAVE_GUIDDEF_H)
485     CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
486 ENDIF()
488 # Some systems need libm for some of the following math functions to work
489 SET(MATH_LIB )
490 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
491 IF(HAVE_LIBM)
492     SET(MATH_LIB ${MATH_LIB} m)
493     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
494 ENDIF()
496 # Check for the dlopen API (for dynamicly loading backend libs)
497 IF(ALSOFT_DLOPEN)
498     CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
499     IF(HAVE_LIBDL)
500         SET(EXTRA_LIBS dl ${EXTRA_LIBS})
501         SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
502     ENDIF()
504     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
505 ENDIF()
507 # Check for a cpuid intrinsic
508 IF(HAVE_CPUID_H)
509     CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
510         int main()
511         {
512             unsigned int eax, ebx, ecx, edx;
513             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
514         }" HAVE_GCC_GET_CPUID)
515 ENDIF()
516 IF(HAVE_INTRIN_H)
517     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
518         int main()
519         {
520             int regs[4];
521             __cpuid(regs, 0);
522             return regs[0];
523         }" HAVE_CPUID_INTRINSIC)
524     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
525         int main()
526         {
527             unsigned long idx = 0;
528             _BitScanForward64(&idx, 1);
529             return idx;
530         }" HAVE_BITSCANFORWARD64_INTRINSIC)
531     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
532         int main()
533         {
534             unsigned long idx = 0;
535             _BitScanForward(&idx, 1);
536             return idx;
537         }" HAVE_BITSCANFORWARD_INTRINSIC)
538 ENDIF()
540 CHECK_SYMBOL_EXISTS(sysconf          unistd.h HAVE_SYSCONF)
541 CHECK_SYMBOL_EXISTS(aligned_alloc    stdlib.h HAVE_ALIGNED_ALLOC)
542 CHECK_SYMBOL_EXISTS(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
543 CHECK_SYMBOL_EXISTS(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
544 CHECK_SYMBOL_EXISTS(proc_pidpath     libproc.h HAVE_PROC_PIDPATH)
546 IF(HAVE_FLOAT_H)
547     CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
548     CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
549 ENDIF()
551 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
552 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
553 IF(NOT HAVE_STRCASECMP)
554     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
555     IF(NOT HAVE__STRICMP)
556         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
557     ENDIF()
559     SET(CPP_DEFS ${CPP_DEFS} strcasecmp=_stricmp)
560 ENDIF()
562 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
563 IF(NOT HAVE_STRNCASECMP)
564     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
565     IF(NOT HAVE__STRNICMP)
566         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
567     ENDIF()
569     SET(CPP_DEFS ${CPP_DEFS} strncasecmp=_strnicmp)
570 ENDIF()
573 # Check if we have Windows headers
574 SET(OLD_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS})
575 SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=0x0502)
576 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H)
577 SET(CMAKE_REQUIRED_DEFINITIONS ${OLD_REQUIRED_DEFINITIONS})
578 UNSET(OLD_REQUIRED_DEFINITIONS)
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     ELSE()
640         CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
641         IF(NOT HAVE_PTHREAD_SETNAME_NP)
642             CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
643         ELSE()
644             CHECK_C_SOURCE_COMPILES("
645 #include <pthread.h>
646 int main()
648     pthread_setname_np(\"testname\");
649     return 0;
651                 PTHREAD_SETNAME_NP_ONE_PARAM
652             )
653             CHECK_C_SOURCE_COMPILES("
654 #include <pthread.h>
655 int main()
657     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
658     return 0;
660                 PTHREAD_SETNAME_NP_THREE_PARAMS
661             )
662         ENDIF()
663     ENDIF()
665     CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
666     IF(HAVE_LIBRT)
667         SET(EXTRA_LIBS rt ${EXTRA_LIBS})
668     ENDIF()
669 ENDIF()
671 CHECK_SYMBOL_EXISTS(getopt unistd.h HAVE_GETOPT)
673 # Check for a 64-bit type
674 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
675 IF(NOT HAVE_STDINT_H)
676     IF(HAVE_WINDOWS_H)
677         CHECK_C_SOURCE_COMPILES("#define _WIN32_WINNT 0x0502
678                                  #include <windows.h>
679                                  __int64 foo;
680                                  int main() {return 0;}" HAVE___INT64)
681     ENDIF()
682     IF(NOT HAVE___INT64)
683         IF(NOT SIZEOF_LONG MATCHES "8")
684             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
685                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
686             ENDIF()
687         ENDIF()
688     ENDIF()
689 ENDIF()
692 SET(COMMON_OBJS
693     common/alcomplex.cpp
694     common/alcomplex.h
695     common/almalloc.cpp
696     common/almalloc.h
697     common/atomic.h
698     common/math_defs.h
699     common/threads.cpp
700     common/threads.h
701     common/vecmat.cpp
702     common/vecmat.h
704 SET(OPENAL_OBJS
705     OpenAL32/Include/alMain.h
706     OpenAL32/Include/alu.h
708     OpenAL32/Include/alAuxEffectSlot.h
709     OpenAL32/alAuxEffectSlot.cpp
710     OpenAL32/Include/alBuffer.h
711     OpenAL32/alBuffer.cpp
712     OpenAL32/Include/alEffect.h
713     OpenAL32/alEffect.cpp
714     OpenAL32/Include/alError.h
715     OpenAL32/alError.cpp
716     OpenAL32/alExtension.cpp
717     OpenAL32/Include/alFilter.h
718     OpenAL32/alFilter.cpp
719     OpenAL32/Include/alListener.h
720     OpenAL32/alListener.cpp
721     OpenAL32/Include/alSource.h
722     OpenAL32/alSource.cpp
723     OpenAL32/alState.cpp
724     OpenAL32/event.cpp
725     OpenAL32/Include/sample_cvt.h
726     OpenAL32/sample_cvt.cpp
728 SET(ALC_OBJS
729     Alc/alc.cpp
730     Alc/alu.cpp
731     Alc/alconfig.cpp
732     Alc/alconfig.h
733     Alc/alcontext.h
734     Alc/bs2b.cpp
735     Alc/bs2b.h
736     Alc/converter.cpp
737     Alc/converter.h
738     Alc/inprogext.h
739     Alc/mastering.cpp
740     Alc/mastering.h
741     Alc/ringbuffer.cpp
742     Alc/ringbuffer.h
743     Alc/effects/autowah.cpp
744     Alc/effects/chorus.cpp
745     Alc/effects/compressor.cpp
746     Alc/effects/dedicated.cpp
747     Alc/effects/distortion.cpp
748     Alc/effects/echo.cpp
749     Alc/effects/equalizer.cpp
750     Alc/effects/fshifter.cpp
751     Alc/effects/modulator.cpp
752     Alc/effects/null.cpp
753     Alc/effects/pshifter.cpp
754     Alc/effects/reverb.cpp
755     Alc/filters/defs.h
756     Alc/filters/filter.cpp
757     Alc/filters/nfc.cpp
758     Alc/filters/nfc.h
759     Alc/filters/splitter.cpp
760     Alc/filters/splitter.h
761     Alc/helpers.cpp
762     Alc/compat.h
763     Alc/cpu_caps.h
764     Alc/fpu_modes.h
765     Alc/logging.h
766     Alc/vector.h
767     Alc/hrtf.cpp
768     Alc/hrtf.h
769     Alc/uhjfilter.cpp
770     Alc/uhjfilter.h
771     Alc/ambdec.cpp
772     Alc/ambdec.h
773     Alc/bformatdec.cpp
774     Alc/bformatdec.h
775     Alc/panning.cpp
776     Alc/polymorphism.h
777     Alc/mixvoice.cpp
778     Alc/mixer/defs.h
779     Alc/mixer/mixer_c.cpp
783 SET(CPU_EXTS "Default")
784 SET(HAVE_SSE        0)
785 SET(HAVE_SSE2       0)
786 SET(HAVE_SSE3       0)
787 SET(HAVE_SSE4_1     0)
788 SET(HAVE_NEON       0)
790 SET(HAVE_ALSA       0)
791 SET(HAVE_OSS        0)
792 SET(HAVE_SOLARIS    0)
793 SET(HAVE_SNDIO      0)
794 SET(HAVE_QSA        0)
795 SET(HAVE_DSOUND     0)
796 SET(HAVE_WASAPI     0)
797 SET(HAVE_WINMM      0)
798 SET(HAVE_PORTAUDIO  0)
799 SET(HAVE_PULSEAUDIO 0)
800 SET(HAVE_COREAUDIO  0)
801 SET(HAVE_OPENSL     0)
802 SET(HAVE_WAVE       0)
803 SET(HAVE_SDL2       0)
805 # Check for SSE support
806 OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
807 CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE_SWITCH}")
808 IF(HAVE_XMMINTRIN_H)
809     OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
810     IF(ALSOFT_CPUEXT_SSE)
811         SET(HAVE_SSE 1)
812         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer/mixer_sse.cpp)
813         IF(SSE_SWITCH)
814             SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_sse.cpp PROPERTIES
815                                         COMPILE_FLAGS "${SSE_SWITCH}")
816         ENDIF()
817         SET(CPU_EXTS "${CPU_EXTS}, SSE")
818     ENDIF()
819 ENDIF()
820 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
821     MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
822 ENDIF()
824 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
825 CHECK_INCLUDE_FILE(emmintrin.h HAVE_EMMINTRIN_H "${SSE2_SWITCH}")
826 IF(HAVE_EMMINTRIN_H)
827     OPTION(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
828     IF(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
829         SET(HAVE_SSE2 1)
830         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer/mixer_sse2.cpp)
831         IF(SSE2_SWITCH)
832             SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_sse2.cpp PROPERTIES
833                                         COMPILE_FLAGS "${SSE2_SWITCH}")
834         ENDIF()
835         SET(CPU_EXTS "${CPU_EXTS}, SSE2")
836     ENDIF()
837 ENDIF()
838 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
839     MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
840 ENDIF()
842 OPTION(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
843 CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}")
844 IF(HAVE_EMMINTRIN_H)
845     OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
846     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
847         SET(HAVE_SSE3 1)
848         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer/mixer_sse3.cpp)
849         IF(SSE2_SWITCH)
850             SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_sse3.cpp PROPERTIES
851                                         COMPILE_FLAGS "${SSE3_SWITCH}")
852         ENDIF()
853         SET(CPU_EXTS "${CPU_EXTS}, SSE3")
854     ENDIF()
855 ENDIF()
856 IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
857     MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
858 ENDIF()
860 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
861 CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}")
862 IF(HAVE_SMMINTRIN_H)
863     OPTION(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
864     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE4_1)
865         SET(HAVE_SSE4_1 1)
866         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer/mixer_sse41.cpp)
867         IF(SSE4_1_SWITCH)
868             SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_sse41.cpp PROPERTIES
869                                         COMPILE_FLAGS "${SSE4_1_SWITCH}")
870         ENDIF()
871         SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
872     ENDIF()
873 ENDIF()
874 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
875     MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
876 ENDIF()
878 # Check for ARM Neon support
879 OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
880 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H ${FPU_NEON_SWITCH})
881 IF(HAVE_ARM_NEON_H)
882     OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
883     IF(ALSOFT_CPUEXT_NEON)
884         SET(HAVE_NEON 1)
885         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer/mixer_neon.cpp)
886         IF(FPU_NEON_SWITCH)
887             SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_neon.cpp PROPERTIES
888                                         COMPILE_FLAGS "${FPU_NEON_SWITCH}")
889         ENDIF()
890         SET(CPU_EXTS "${CPU_EXTS}, Neon")
891     ENDIF()
892 ENDIF()
893 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
894     MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
895 ENDIF()
898 IF(WIN32 OR HAVE_DLFCN_H)
899     SET(IS_LINKED "")
900     MACRO(ADD_BACKEND_LIBS _LIBS)
901     ENDMACRO()
902 ELSE()
903     SET(IS_LINKED " (linked)")
904     MACRO(ADD_BACKEND_LIBS _LIBS)
905         SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
906     ENDMACRO()
907 ENDIF()
909 SET(BACKENDS "")
910 SET(ALC_OBJS  ${ALC_OBJS}
911     Alc/backends/base.cpp
912     Alc/backends/base.h
913     # Default backends, always available
914     Alc/backends/loopback.cpp
915     Alc/backends/loopback.h
916     Alc/backends/null.cpp
917     Alc/backends/null.h
920 # Check ALSA backend
921 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
922 FIND_PACKAGE(ALSA)
923 IF(ALSA_FOUND)
924     OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
925     IF(ALSOFT_BACKEND_ALSA)
926         SET(HAVE_ALSA 1)
927         SET(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
928         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/alsa.cpp Alc/backends/alsa.h)
929         ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
930         SET(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
931     ENDIF()
932 ENDIF()
933 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
934     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
935 ENDIF()
937 # Check OSS backend
938 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
939 FIND_PACKAGE(OSS)
940 IF(OSS_FOUND)
941     OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
942     IF(ALSOFT_BACKEND_OSS)
943         SET(HAVE_OSS 1)
944         SET(BACKENDS  "${BACKENDS} OSS,")
945         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/oss.cpp Alc/backends/oss.h)
946         IF(OSS_LIBRARIES)
947             SET(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
948         ENDIF()
949         SET(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
950     ENDIF()
951 ENDIF()
952 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
953     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
954 ENDIF()
956 # Check Solaris backend
957 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
958 FIND_PACKAGE(AudioIO)
959 IF(AUDIOIO_FOUND)
960     OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
961     IF(ALSOFT_BACKEND_SOLARIS)
962         SET(HAVE_SOLARIS 1)
963         SET(BACKENDS  "${BACKENDS} Solaris,")
964         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/solaris.cpp Alc/backends/solaris.h)
965         SET(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
966     ENDIF()
967 ENDIF()
968 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
969     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
970 ENDIF()
972 # Check SndIO backend
973 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
974 FIND_PACKAGE(SoundIO)
975 IF(SOUNDIO_FOUND)
976     OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
977     IF(ALSOFT_BACKEND_SNDIO)
978         SET(HAVE_SNDIO 1)
979         SET(BACKENDS  "${BACKENDS} SndIO (linked),")
980         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sndio.cpp Alc/backends/sndio.h)
981         SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
982         SET(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
983     ENDIF()
984 ENDIF()
985 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
986     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
987 ENDIF()
989 # Check QSA backend
990 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
991 FIND_PACKAGE(QSA)
992 IF(QSA_FOUND)
993     OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
994     IF(ALSOFT_BACKEND_QSA)
995         SET(HAVE_QSA 1)
996         SET(BACKENDS  "${BACKENDS} QSA (linked),")
997         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/qsa.cpp Alc/backends/qsa.h)
998         SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
999         SET(INC_PATHS ${INC_PATHS} ${QSA_INCLUDE_DIRS})
1000     ENDIF()
1001 ENDIF()
1002 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
1003     MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
1004 ENDIF()
1006 # Check Windows-only backends
1007 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
1008 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
1009 OPTION(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
1010 IF(HAVE_WINDOWS_H)
1011     SET(OLD_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS})
1012     SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=0x0502)
1014     # Check MMSystem backend
1015     CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
1016     IF(HAVE_MMSYSTEM_H)
1017         CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
1018         IF(HAVE_LIBWINMM)
1019             OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
1020             IF(ALSOFT_BACKEND_WINMM)
1021                 SET(HAVE_WINMM 1)
1022                 SET(BACKENDS  "${BACKENDS} WinMM,")
1023                 SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/winmm.cpp Alc/backends/winmm.h)
1024                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
1025             ENDIF()
1026         ENDIF()
1027     ENDIF()
1029     # Check DSound backend
1030     FIND_PACKAGE(DSound)
1031     IF(DSOUND_FOUND)
1032         OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
1033         IF(ALSOFT_BACKEND_DSOUND)
1034             SET(HAVE_DSOUND 1)
1035             SET(BACKENDS  "${BACKENDS} DirectSound${IS_LINKED},")
1036             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/dsound.cpp Alc/backends/dsound.h)
1037             ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
1038             SET(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIRS})
1039         ENDIF()
1040     ENDIF()
1042     # Check for WASAPI backend
1043     CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1044     IF(HAVE_MMDEVICEAPI_H)
1045         OPTION(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
1046         IF(ALSOFT_BACKEND_WASAPI)
1047             SET(HAVE_WASAPI 1)
1048             SET(BACKENDS  "${BACKENDS} WASAPI,")
1049             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wasapi.cpp Alc/backends/wasapi.h)
1050         ENDIF()
1051     ENDIF()
1053     SET(CMAKE_REQUIRED_DEFINITIONS ${OLD_REQUIRED_DEFINITIONS})
1054     UNSET(OLD_REQUIRED_DEFINITIONS)
1055 ENDIF()
1056 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1057     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
1058 ENDIF()
1059 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1060     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
1061 ENDIF()
1062 IF(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
1063     MESSAGE(FATAL_ERROR "Failed to enabled required WASAPI backend")
1064 ENDIF()
1066 # Check PortAudio backend
1067 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1068 FIND_PACKAGE(PortAudio)
1069 IF(PORTAUDIO_FOUND)
1070     OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1071     IF(ALSOFT_BACKEND_PORTAUDIO)
1072         SET(HAVE_PORTAUDIO 1)
1073         SET(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
1074         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/portaudio.cpp Alc/backends/portaudio.h)
1075         ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
1076         SET(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
1077     ENDIF()
1078 ENDIF()
1079 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1080     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
1081 ENDIF()
1083 # Check PulseAudio backend
1084 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1085 FIND_PACKAGE(PulseAudio)
1086 IF(PULSEAUDIO_FOUND)
1087     OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1088     IF(ALSOFT_BACKEND_PULSEAUDIO)
1089         SET(HAVE_PULSEAUDIO 1)
1090         SET(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
1091         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/pulseaudio.cpp Alc/backends/pulseaudio.h)
1092         ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
1093         SET(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
1094     ENDIF()
1095 ENDIF()
1096 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1097     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1098 ENDIF()
1100 # Check JACK backend
1101 OPTION(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1102 FIND_PACKAGE(JACK)
1103 IF(JACK_FOUND)
1104     OPTION(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1105     IF(ALSOFT_BACKEND_JACK)
1106         SET(HAVE_JACK 1)
1107         SET(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1108         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/jack.cpp Alc/backends/jack.h)
1109         ADD_BACKEND_LIBS(${JACK_LIBRARIES})
1110         SET(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1111     ENDIF()
1112 ENDIF()
1113 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1114     MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
1115 ENDIF()
1117 # Check CoreAudio backend
1118 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1119 FIND_LIBRARY(COREAUDIO_FRAMEWORK
1120              NAMES CoreAudio
1121              PATHS /System/Library/Frameworks
1123 IF(COREAUDIO_FRAMEWORK)
1124     OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1125     IF(ALSOFT_BACKEND_COREAUDIO)
1126         SET(HAVE_COREAUDIO 1)
1127         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/coreaudio.cpp Alc/backends/coreaudio.h)
1128         SET(BACKENDS  "${BACKENDS} CoreAudio,")
1129         SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
1130         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
1131         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1133         # Some versions of OSX may need the AudioToolbox framework. Add it if
1134         # it's found.
1135         FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
1136                      NAMES AudioToolbox
1137                      PATHS ~/Library/Frameworks
1138                            /Library/Frameworks
1139                            /System/Library/Frameworks
1140                     )
1141         IF(AUDIOTOOLBOX_LIBRARY)
1142             SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1143         ENDIF()
1144     ENDIF()
1145 ENDIF()
1146 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1147     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1148 ENDIF()
1150 # Check for OpenSL (Android) backend
1151 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1152 CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
1153 IF(HAVE_SLES_OPENSLES_ANDROID_H)
1154     CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
1155     IF(HAVE_LIBOPENSLES)
1156         OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1157         IF(ALSOFT_BACKEND_OPENSL)
1158             SET(HAVE_OPENSL 1)
1159             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/opensl.cpp Alc/backends/opensl.h)
1160             SET(BACKENDS  "${BACKENDS} OpenSL,")
1161             SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
1162         ENDIF()
1163     ENDIF()
1164 ENDIF()
1165 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1166     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1167 ENDIF()
1169 # Check for SDL2 backend
1170 OPTION(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1171 FIND_PACKAGE(SDL2)
1172 IF(SDL2_FOUND)
1173     # Off by default, since it adds a runtime dependency
1174     OPTION(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1175     IF(ALSOFT_BACKEND_SDL2)
1176         SET(HAVE_SDL2 1)
1177         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sdl2.cpp Alc/backends/sdl2.h)
1178         SET(BACKENDS  "${BACKENDS} SDL2,")
1179         SET(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
1180         SET(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
1181     ENDIF()
1182 ENDIF()
1183 IF(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1184     MESSAGE(FATAL_ERROR "Failed to enabled required SDL2 backend")
1185 ENDIF()
1187 # Optionally enable the Wave Writer backend
1188 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1189 IF(ALSOFT_BACKEND_WAVE)
1190     SET(HAVE_WAVE 1)
1191     SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wave.cpp Alc/backends/wave.h)
1192     SET(BACKENDS  "${BACKENDS} WaveFile,")
1193 ENDIF()
1195 # This is always available
1196 SET(BACKENDS  "${BACKENDS} Null")
1199 FIND_PACKAGE(Git)
1200 IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1201     # Get the current working branch and its latest abbreviated commit hash
1202     ADD_CUSTOM_TARGET(build_version
1203         ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
1204                          -D LIB_VERSION=${LIB_VERSION}
1205                          -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1206                          -D DST=${OpenAL_BINARY_DIR}/version.h
1207                          -P ${OpenAL_SOURCE_DIR}/version.cmake
1208         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1209         VERBATIM
1210     )
1211 ELSE()
1212     SET(GIT_BRANCH "UNKNOWN")
1213     SET(GIT_COMMIT_HASH "unknown")
1214     CONFIGURE_FILE(
1215         "${OpenAL_SOURCE_DIR}/version.h.in"
1216         "${OpenAL_BINARY_DIR}/version.h")
1217 ENDIF()
1219 SET(NATIVE_SRC_DIR  "${OpenAL_SOURCE_DIR}/native-tools/")
1220 SET(NATIVE_BIN_DIR  "${OpenAL_BINARY_DIR}/native-tools/")
1221 FILE(MAKE_DIRECTORY "${NATIVE_BIN_DIR}")
1223 SET(BIN2H_COMMAND  "${NATIVE_BIN_DIR}bin2h")
1224 SET(BSINCGEN_COMMAND  "${NATIVE_BIN_DIR}bsincgen")
1225 ADD_CUSTOM_COMMAND(OUTPUT "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1226     COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" "${NATIVE_SRC_DIR}"
1227     COMMAND ${CMAKE_COMMAND} -E remove "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1228     COMMAND ${CMAKE_COMMAND} --build . --config "Release"
1229     WORKING_DIRECTORY "${NATIVE_BIN_DIR}"
1230     DEPENDS "${NATIVE_SRC_DIR}CMakeLists.txt"
1231     IMPLICIT_DEPENDS C "${NATIVE_SRC_DIR}bin2h.c"
1232                      C "${NATIVE_SRC_DIR}bsincgen.c"
1233     VERBATIM
1235 ADD_CUSTOM_TARGET(native-tools
1236     DEPENDS "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1237     VERBATIM
1240 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1241 if(ALSOFT_EMBED_HRTF_DATA)
1242     MACRO(make_hrtf_header FILENAME VARNAME)
1243         SET(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1244         SET(outfile  "${OpenAL_BINARY_DIR}/${FILENAME}.h")
1246         ADD_CUSTOM_COMMAND(OUTPUT "${outfile}"
1247             COMMAND "${BIN2H_COMMAND}" "${infile}" "${outfile}" ${VARNAME}
1248             DEPENDS native-tools "${infile}"
1249             VERBATIM
1250         )
1251         SET(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1252     ENDMACRO()
1254     make_hrtf_header(default-44100.mhr "hrtf_default_44100")
1255     make_hrtf_header(default-48000.mhr "hrtf_default_48000")
1256 endif()
1258 ADD_CUSTOM_COMMAND(OUTPUT "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1259     COMMAND "${BSINCGEN_COMMAND}" "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1260     DEPENDS native-tools "${NATIVE_SRC_DIR}bsincgen.c"
1261     VERBATIM
1263 SET(ALC_OBJS  ${ALC_OBJS} "${OpenAL_BINARY_DIR}/bsinc_inc.h")
1266 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1267     add_subdirectory(utils/alsoft-config)
1268 ENDIF()
1269 IF(ALSOFT_EXAMPLES)
1270     IF(NOT SDL2_FOUND)
1271         FIND_PACKAGE(SDL2)
1272     ENDIF()
1273     IF(SDL2_FOUND)
1274         FIND_PACKAGE(SDL_sound)
1275         FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1276     ENDIF()
1277 ENDIF()
1279 IF(NOT WIN32)
1280     SET(LIBNAME "openal")
1281 ELSE()
1282     SET(LIBNAME "OpenAL32")
1283 ENDIF()
1285 # Needed for openal.pc.in
1286 SET(prefix ${CMAKE_INSTALL_PREFIX})
1287 SET(exec_prefix "\${prefix}")
1288 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1289 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1290 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1291 SET(PACKAGE_VERSION "${LIB_VERSION}")
1292 SET(PKG_CONFIG_CFLAGS )
1293 SET(PKG_CONFIG_PRIVATE_LIBS )
1294 IF(LIBTYPE STREQUAL "STATIC")
1295     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1296     FOREACH(FLAG  ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1297         # If this is already a linker flag, or is a full path+file, add it
1298         # as-is. Otherwise, it's a name intended to be dressed as -lname.
1299         IF(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1300             SET(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1301         ELSE()
1302             SET(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1303         ENDIF()
1304     ENDFOREACH()
1305 ENDIF()
1307 # End configuration
1308 CONFIGURE_FILE(
1309     "${OpenAL_SOURCE_DIR}/config.h.in"
1310     "${OpenAL_BINARY_DIR}/config.h")
1311 CONFIGURE_FILE(
1312     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1313     "${OpenAL_BINARY_DIR}/openal.pc"
1314     @ONLY)
1317 # Add a static library with common functions used by multiple targets
1318 ADD_LIBRARY(common STATIC ${COMMON_OBJS})
1319 TARGET_COMPILE_DEFINITIONS(common PRIVATE ${CPP_DEFS})
1320 TARGET_COMPILE_OPTIONS(common PRIVATE ${C_FLAGS})
1323 UNSET(HAS_ROUTER)
1324 SET(IMPL_TARGET OpenAL)
1325 SET(COMMON_LIB )
1326 SET(SUBSYS_FLAG )
1328 # Build main library
1329 IF(LIBTYPE STREQUAL "STATIC")
1330     SET(CPP_DEFS ${CPP_DEFS} AL_LIBTYPE_STATIC)
1331     IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1332         SET(CPP_DEFS ${CPP_DEFS} AL_NO_UID_DEFS)
1333     ENDIF()
1334     ADD_LIBRARY(OpenAL STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1335 ELSE()
1336     # Make sure to compile the common code with PIC, since it'll be linked into
1337     # shared libs that needs it.
1338     SET_PROPERTY(TARGET common PROPERTY POSITION_INDEPENDENT_CODE TRUE)
1339     SET(COMMON_LIB common)
1341     IF(WIN32)
1342         IF(MSVC)
1343             SET(SUBSYS_FLAG ${SUBSYS_FLAG} "/SUBSYSTEM:WINDOWS")
1344         ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1345             SET(SUBSYS_FLAG ${SUBSYS_FLAG} "-mwindows")
1346         ENDIF()
1347     ENDIF()
1349     IF(WIN32 AND ALSOFT_BUILD_ROUTER)
1350         ADD_LIBRARY(OpenAL SHARED router/router.cpp router/router.h router/alc.cpp router/al.cpp)
1351         TARGET_COMPILE_DEFINITIONS(OpenAL
1352             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1353         TARGET_COMPILE_OPTIONS(OpenAL PRIVATE ${C_FLAGS})
1354         TARGET_LINK_LIBRARIES(OpenAL PRIVATE ${COMMON_LIB} ${LINKER_FLAGS})
1355         SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "")
1356         SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1357         IF(TARGET build_version)
1358             ADD_DEPENDENCIES(OpenAL build_version)
1359         ENDIF()
1360         SET(HAS_ROUTER 1)
1362         SET(LIBNAME "soft_oal")
1363         SET(IMPL_TARGET soft_oal)
1364     ENDIF()
1366     ADD_LIBRARY(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
1367     IF(WIN32)
1368         SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES PREFIX "")
1369     ENDIF()
1370 ENDIF()
1371 SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1372     VERSION ${LIB_VERSION}
1373     SOVERSION ${LIB_MAJOR_VERSION}
1375 TARGET_COMPILE_DEFINITIONS(${IMPL_TARGET}
1376     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1377 TARGET_INCLUDE_DIRECTORIES(${IMPL_TARGET}
1378     PRIVATE "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc" ${INC_PATHS})
1379 TARGET_COMPILE_OPTIONS(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1380 TARGET_LINK_LIBRARIES(${IMPL_TARGET}
1381     PRIVATE ${COMMON_LIB} ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1382 IF(TARGET build_version)
1383     ADD_DEPENDENCIES(${IMPL_TARGET} build_version)
1384 ENDIF()
1386 IF(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1387     FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1388     FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1389     IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1390         MESSAGE(STATUS "")
1391         IF(NOT SED_EXECUTABLE)
1392             MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1393         ENDIF()
1394         IF(NOT DLLTOOL_EXECUTABLE)
1395             MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1396         ENDIF()
1397     ELSE()
1398         SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS
1399                         " -Wl,--output-def,OpenAL32.def")
1400         ADD_CUSTOM_COMMAND(TARGET OpenAL POST_BUILD
1401             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1402             COMMAND "${DLLTOOL_EXECUTABLE}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1403             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1404             VERBATIM
1405         )
1406     ENDIF()
1407 ENDIF()
1409 IF(ALSOFT_INSTALL)
1410     INSTALL(TARGETS OpenAL EXPORT OpenAL
1411             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1412             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1413             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1414             INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL
1415     )
1416     EXPORT(TARGETS OpenAL
1417            NAMESPACE OpenAL::
1418            FILE OpenALConfig.cmake)
1419     INSTALL(EXPORT OpenAL
1420             DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1421             NAMESPACE OpenAL::
1422             FILE OpenALConfig.cmake)
1423     INSTALL(FILES include/AL/al.h
1424                   include/AL/alc.h
1425                   include/AL/alext.h
1426                   include/AL/efx.h
1427                   include/AL/efx-creative.h
1428                   include/AL/efx-presets.h
1429             DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
1430     )
1431     INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1432             DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1433     IF(TARGET soft_oal)
1434         INSTALL(TARGETS soft_oal
1435                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1436         )
1437     ENDIF()
1438 ENDIF()
1441 if(HAS_ROUTER)
1442     message(STATUS "")
1443     message(STATUS "Building DLL router")
1444 endif()
1446 MESSAGE(STATUS "")
1447 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1448 MESSAGE(STATUS "    ${BACKENDS}")
1449 MESSAGE(STATUS "")
1450 MESSAGE(STATUS "Building with support for CPU extensions:")
1451 MESSAGE(STATUS "    ${CPU_EXTS}")
1452 MESSAGE(STATUS "")
1453 IF(FPMATH_SET)
1454     MESSAGE(STATUS "Building with SSE${FPMATH_SET} codegen")
1455     MESSAGE(STATUS "")
1456 ENDIF()
1458 IF(WIN32)
1459     IF(NOT HAVE_DSOUND)
1460         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
1461         MESSAGE(STATUS "         This is probably NOT what you want!")
1462         MESSAGE(STATUS "")
1463     ENDIF()
1464 ENDIF()
1466 if(ALSOFT_EMBED_HRTF_DATA)
1467     message(STATUS "Embedding HRTF datasets")
1468     message(STATUS "")
1469 endif()
1471 # Install alsoft.conf configuration file
1472 IF(ALSOFT_CONFIG)
1473     INSTALL(FILES alsoftrc.sample
1474             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal
1475     )
1476     MESSAGE(STATUS "Installing sample configuration")
1477     MESSAGE(STATUS "")
1478 ENDIF()
1480 # Install HRTF definitions
1481 IF(ALSOFT_HRTF_DEFS)
1482     INSTALL(FILES hrtf/default-44100.mhr
1483                   hrtf/default-48000.mhr
1484             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf
1485     )
1486     MESSAGE(STATUS "Installing HRTF definitions")
1487     MESSAGE(STATUS "")
1488 ENDIF()
1490 # Install AmbDec presets
1491 IF(ALSOFT_AMBDEC_PRESETS)
1492     INSTALL(FILES presets/3D7.1.ambdec
1493                   presets/hexagon.ambdec
1494                   presets/itu5.1.ambdec
1495                   presets/itu5.1-nocenter.ambdec
1496                   presets/rectangle.ambdec
1497                   presets/square.ambdec
1498                   presets/presets.txt
1499             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
1500     )
1501     MESSAGE(STATUS "Installing AmbDec presets")
1502     MESSAGE(STATUS "")
1503 ENDIF()
1505 IF(ALSOFT_UTILS)
1506     ADD_EXECUTABLE(openal-info utils/openal-info.c)
1507     TARGET_COMPILE_OPTIONS(openal-info PRIVATE ${C_FLAGS})
1508     TARGET_LINK_LIBRARIES(openal-info PRIVATE ${LINKER_FLAGS} OpenAL)
1510     SET(MAKEHRTF_SRCS  utils/makehrtf.c)
1511     IF(NOT HAVE_GETOPT)
1512         SET(MAKEHRTF_SRCS  ${MAKEHRTF_SRCS} utils/getopt.c utils/getopt.h)
1513     ENDIF()
1514     ADD_EXECUTABLE(makehrtf ${MAKEHRTF_SRCS})
1515     TARGET_COMPILE_DEFINITIONS(makehrtf PRIVATE ${CPP_DEFS})
1516     TARGET_COMPILE_OPTIONS(makehrtf PRIVATE ${C_FLAGS})
1517     IF(HAVE_LIBM)
1518         TARGET_LINK_LIBRARIES(makehrtf PRIVATE ${LINKER_FLAGS} m)
1519     ENDIF()
1521     IF(ALSOFT_INSTALL)
1522         INSTALL(TARGETS openal-info makehrtf
1523                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1524                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1525                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1526         )
1527     ENDIF()
1529     MESSAGE(STATUS "Building utility programs")
1530     IF(TARGET alsoft-config)
1531         MESSAGE(STATUS "Building configuration program")
1532     ENDIF()
1533     MESSAGE(STATUS "")
1534 ENDIF()
1536 IF(ALSOFT_TESTS)
1537     SET(TEST_COMMON_OBJS  examples/common/alhelpers.c)
1539     ADD_EXECUTABLE(altonegen examples/altonegen.c ${TEST_COMMON_OBJS})
1540     TARGET_COMPILE_DEFINITIONS(altonegen PRIVATE ${CPP_DEFS})
1541     TARGET_COMPILE_OPTIONS(altonegen PRIVATE ${C_FLAGS})
1542     TARGET_LINK_LIBRARIES(altonegen PRIVATE ${LINKER_FLAGS} common OpenAL ${MATH_LIB})
1544     IF(ALSOFT_INSTALL)
1545         INSTALL(TARGETS altonegen
1546                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1547                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1548                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1549         )
1550     ENDIF()
1552     MESSAGE(STATUS "Building test programs")
1553     MESSAGE(STATUS "")
1554 ENDIF()
1556 IF(ALSOFT_EXAMPLES)
1557     # Add a static library with common functions used by multiple targets
1558     ADD_LIBRARY(ex-common STATIC examples/common/alhelpers.c)
1559     TARGET_COMPILE_DEFINITIONS(ex-common PRIVATE ${CPP_DEFS})
1560     TARGET_COMPILE_OPTIONS(ex-common PRIVATE ${C_FLAGS})
1562     ADD_EXECUTABLE(alrecord examples/alrecord.c)
1563     TARGET_COMPILE_DEFINITIONS(alrecord PRIVATE ${CPP_DEFS})
1564     TARGET_COMPILE_OPTIONS(alrecord PRIVATE ${C_FLAGS})
1565     TARGET_LINK_LIBRARIES(alrecord PRIVATE ${LINKER_FLAGS} ex-common common OpenAL)
1567     IF(ALSOFT_INSTALL)
1568         INSTALL(TARGETS alrecord
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 example programs")
1577     IF(SDL2_FOUND)
1578         IF(SDL_SOUND_FOUND)
1579             ADD_EXECUTABLE(alplay examples/alplay.c)
1580             TARGET_COMPILE_DEFINITIONS(alplay PRIVATE ${CPP_DEFS})
1581             TARGET_INCLUDE_DIRECTORIES(alplay
1582                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1583             TARGET_COMPILE_OPTIONS(alplay PRIVATE ${C_FLAGS})
1584             TARGET_LINK_LIBRARIES(alplay
1585                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1586                         OpenAL)
1588             ADD_EXECUTABLE(alstream examples/alstream.c)
1589             TARGET_COMPILE_DEFINITIONS(alstream PRIVATE ${CPP_DEFS})
1590             TARGET_INCLUDE_DIRECTORIES(alstream
1591                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1592             TARGET_COMPILE_OPTIONS(alstream PRIVATE ${C_FLAGS})
1593             TARGET_LINK_LIBRARIES(alstream
1594                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1595                         OpenAL)
1597             ADD_EXECUTABLE(alreverb examples/alreverb.c)
1598             TARGET_COMPILE_DEFINITIONS(alreverb PRIVATE ${CPP_DEFS})
1599             TARGET_INCLUDE_DIRECTORIES(alreverb
1600                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1601             TARGET_COMPILE_OPTIONS(alreverb PRIVATE ${C_FLAGS})
1602             TARGET_LINK_LIBRARIES(alreverb
1603                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1604                         OpenAL)
1606             ADD_EXECUTABLE(almultireverb examples/almultireverb.c)
1607             TARGET_COMPILE_DEFINITIONS(almultireverb PRIVATE ${CPP_DEFS})
1608             TARGET_INCLUDE_DIRECTORIES(almultireverb
1609                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1610             TARGET_COMPILE_OPTIONS(almultireverb PRIVATE ${C_FLAGS})
1611             TARGET_LINK_LIBRARIES(almultireverb
1612                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1613                         OpenAL ${MATH_LIB})
1615             ADD_EXECUTABLE(allatency examples/allatency.c)
1616             TARGET_COMPILE_DEFINITIONS(allatency PRIVATE ${CPP_DEFS})
1617             TARGET_INCLUDE_DIRECTORIES(allatency
1618                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1619             TARGET_COMPILE_OPTIONS(allatency PRIVATE ${C_FLAGS})
1620             TARGET_LINK_LIBRARIES(allatency
1621                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1622                         OpenAL)
1624             ADD_EXECUTABLE(alloopback examples/alloopback.c)
1625             TARGET_COMPILE_DEFINITIONS(alloopback PRIVATE ${CPP_DEFS})
1626             TARGET_INCLUDE_DIRECTORIES(alloopback
1627                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1628             TARGET_COMPILE_OPTIONS(alloopback PRIVATE ${C_FLAGS})
1629             TARGET_LINK_LIBRARIES(alloopback
1630                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1631                         OpenAL ${MATH_LIB})
1633             ADD_EXECUTABLE(alhrtf examples/alhrtf.c)
1634             TARGET_COMPILE_DEFINITIONS(alhrtf PRIVATE ${CPP_DEFS})
1635             TARGET_INCLUDE_DIRECTORIES(alhrtf
1636                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1637             TARGET_COMPILE_OPTIONS(alhrtf PRIVATE ${C_FLAGS})
1638             TARGET_LINK_LIBRARIES(alhrtf
1639                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1640                         OpenAL ${MATH_LIB})
1642             IF(ALSOFT_INSTALL)
1643                 INSTALL(TARGETS alplay alstream alreverb almultireverb allatency alloopback alhrtf
1644                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1645                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1646                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1647                 )
1648             ENDIF()
1650             MESSAGE(STATUS "Building SDL_sound example programs")
1651         ENDIF()
1653         SET(FFVER_OK FALSE)
1654         IF(FFMPEG_FOUND)
1655             SET(FFVER_OK TRUE)
1656             IF(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1657                 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1658                 SET(FFVER_OK FALSE)
1659             ENDIF()
1660             IF(AVCODEC_VERSION VERSION_LESS "57.64.101")
1661                 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1662                 SET(FFVER_OK FALSE)
1663             ENDIF()
1664             IF(AVUTIL_VERSION VERSION_LESS "55.34.101")
1665                 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1666                 SET(FFVER_OK FALSE)
1667             ENDIF()
1668             IF(SWSCALE_VERSION VERSION_LESS "4.2.100")
1669                 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1670                 SET(FFVER_OK FALSE)
1671             ENDIF()
1672             IF(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1673                 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1674                 SET(FFVER_OK FALSE)
1675             ENDIF()
1676         ENDIF()
1677         IF(FFVER_OK)
1678             ADD_EXECUTABLE(alffplay examples/alffplay.cpp)
1679             TARGET_COMPILE_DEFINITIONS(alffplay PRIVATE ${CPP_DEFS})
1680             TARGET_INCLUDE_DIRECTORIES(alffplay
1681                 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1682             TARGET_COMPILE_OPTIONS(alffplay PRIVATE ${C_FLAGS})
1683             TARGET_LINK_LIBRARIES(alffplay
1684                 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common common
1685                         OpenAL)
1687             IF(ALSOFT_INSTALL)
1688                 INSTALL(TARGETS alffplay
1689                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1690                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1691                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1692                 )
1693             ENDIF()
1694             MESSAGE(STATUS "Building SDL+FFmpeg example programs")
1695         ENDIF()
1696         MESSAGE(STATUS "")
1697     ENDIF()
1698 ENDIF()