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