Install the itu5.1-nocenter.ambdec preset
[openal-soft.git] / CMakeLists.txt
blob2204f97bfbbd08c6f50123716530b3ba66f1471a
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 IF(WIN32)
66     ADD_DEFINITIONS("-D_WIN32 -D_WIN32_WINNT=0x0502")
68     OPTION(ALSOFT_BUILD_ROUTER  "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)"  OFF)
70     # This option is mainly for static linking OpenAL Soft into another project
71     # that already defines the IDs. It is up to that project to ensure all
72     # required IDs are defined.
73     OPTION(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
75     IF(MINGW)
76         OPTION(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
77         IF(NOT DLLTOOL)
78             IF(HOST)
79                 SET(DLLTOOL "${HOST}-dlltool")
80             ELSE()
81                 SET(DLLTOOL "dlltool")
82             ENDIF()
83         ENDIF()
84     ENDIF()
85 ENDIF()
88 SET(EXTRA_LIBS "")
89 SET(EXTRA_LDFLAGS "")
91 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
92 IF ("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
93     ADD_DEFINITIONS("-I/usr/include")
94     SET(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} -L/usr/lib")
95 ENDIF()
97 IF(NOT LIBTYPE)
98     SET(LIBTYPE SHARED)
99 ENDIF()
101 SET(LIB_MAJOR_VERSION "1")
102 SET(LIB_MINOR_VERSION "18")
103 SET(LIB_REVISION "1")
104 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
106 SET(EXPORT_DECL "")
107 SET(ALIGN_DECL "")
110 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
111 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
114 CHECK_C_COMPILER_FLAG(-std=c11 HAVE_STD_C11)
115 IF(HAVE_STD_C11)
116     SET(CMAKE_C_FLAGS "-std=c11 ${CMAKE_C_FLAGS}")
117 ELSE()
118     CHECK_C_COMPILER_FLAG(-std=c99 HAVE_STD_C99)
119     IF(HAVE_STD_C99)
120         SET(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
121     ENDIF()
122 ENDIF()
124 CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD_CXX11)
125 IF(HAVE_STD_CXX11)
126     SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
127 ENDIF()
129 if(NOT WIN32)
130     # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
131     CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
132     IF(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
133         SET(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
134         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
135         CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
136         IF(NOT HAVE_POSIX_MEMALIGN_POSIX)
137             SET(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
138         ELSE()
139             ADD_DEFINITIONS(-D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600)
140         ENDIF()
141     ENDIF()
142     UNSET(OLD_REQUIRED_FLAGS)
143 ENDIF()
145 # Set defines for large file support
146 CHECK_FILE_OFFSET_BITS()
147 IF(_FILE_OFFSET_BITS)
148     ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS})
149     SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
150 ENDIF()
151 ADD_DEFINITIONS(-D_LARGEFILE_SOURCE -D_LARGE_FILES)
152 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_LARGEFILE_SOURCE -D_LARGE_FILES")
154 # MSVC may need workarounds for C99 restrict and inline
155 IF(MSVC)
156     # TODO: Once we truly require C99, these restrict and inline checks should go
157     # away.
158     CHECK_C_SOURCE_COMPILES("int *restrict foo;
159                              int main() {return 0;}" HAVE_RESTRICT)
160     IF(NOT HAVE_RESTRICT)
161         ADD_DEFINITIONS("-Drestrict=")
162         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Drestrict=")
163     ENDIF()
165     CHECK_C_SOURCE_COMPILES("inline void foo(void) { }
166                              int main() {return 0;}" HAVE_INLINE)
167     IF(NOT HAVE_INLINE)
168         CHECK_C_SOURCE_COMPILES("__inline void foo(void) { }
169                                  int main() {return 0;}" HAVE___INLINE)
170         IF(NOT HAVE___INLINE)
171             MESSAGE(FATAL_ERROR "No inline keyword found, please report!")
172         ENDIF()
174         ADD_DEFINITIONS(-Dinline=__inline)
175         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Dinline=__inline")
176     ENDIF()
177 ENDIF()
179 # Make sure we have C99-style inline semantics with GCC (4.3 or newer).
180 IF(CMAKE_COMPILER_IS_GNUCC)
181     SET(CMAKE_C_FLAGS "-fno-gnu89-inline ${CMAKE_C_FLAGS}")
183     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
184     # Force no inlining for the next test.
185     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -fno-inline")
187     CHECK_C_SOURCE_COMPILES("extern inline int foo() { return 0; }
188                              int main() {return foo();}" INLINE_IS_C99)
189     IF(NOT INLINE_IS_C99)
190         MESSAGE(FATAL_ERROR "Your compiler does not seem to have C99 inline semantics!
191                              Please update your compiler for better C99 compliance.")
192     ENDIF()
194     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
195 ENDIF()
197 # Check if we have a proper timespec declaration
198 CHECK_STRUCT_HAS_MEMBER("struct timespec" tv_sec time.h HAVE_STRUCT_TIMESPEC)
199 IF(HAVE_STRUCT_TIMESPEC)
200     # Define it here so we don't have to include config.h for it
201     ADD_DEFINITIONS("-DHAVE_STRUCT_TIMESPEC")
202 ENDIF()
204 # Some systems may need libatomic for C11 atomic functions to work
205 SET(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
206 SET(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
207 CHECK_C_SOURCE_COMPILES("#include <stdatomic.h>
208 int _Atomic foo = ATOMIC_VAR_INIT(0);
209 int main()
211     return atomic_fetch_add(&foo, 2);
213 HAVE_LIBATOMIC)
214 IF(NOT HAVE_LIBATOMIC)
215     SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
216 ELSE()
217     SET(EXTRA_LIBS atomic ${EXTRA_LIBS})
218 ENDIF()
219 UNSET(OLD_REQUIRED_LIBRARIES)
221 # Include liblog for Android logging
222 CHECK_LIBRARY_EXISTS(log __android_log_print "" HAVE_LIBLOG)
223 IF(HAVE_LIBLOG)
224     SET(EXTRA_LIBS log ${EXTRA_LIBS})
225     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
226 ENDIF()
228 # Check if we have C99 variable length arrays
229 CHECK_C_SOURCE_COMPILES(
230 "int main(int argc, char *argv[])
232      volatile int tmp[argc];
233      tmp[0] = argv[0][0];
234      return tmp[0];
235  }"
236 HAVE_C99_VLA)
238 # Check if we have C99 bool
239 CHECK_C_SOURCE_COMPILES(
240 "int main(int argc, char *argv[])
242      volatile _Bool ret;
243      ret = (argc > 1) ? 1 : 0;
244      return ret ? -1 : 0;
245  }"
246 HAVE_C99_BOOL)
248 # Check if we have C11 static_assert
249 CHECK_C_SOURCE_COMPILES(
250 "int main()
252      _Static_assert(sizeof(int) == sizeof(int), \"What\");
253      return 0;
254  }"
255 HAVE_C11_STATIC_ASSERT)
257 # Check if we have C11 alignas
258 CHECK_C_SOURCE_COMPILES(
259 "_Alignas(16) int foo;
260  int main()
262      return 0;
263  }"
264 HAVE_C11_ALIGNAS)
266 # Check if we have C11 _Atomic
267 CHECK_C_SOURCE_COMPILES(
268 "#include <stdatomic.h>
269  int _Atomic foo = ATOMIC_VAR_INIT(0);
270  int main()
272      atomic_fetch_add(&foo, 2);
273      return 0;
274  }"
275 HAVE_C11_ATOMIC)
277 # Add definitions, compiler switches, etc.
278 INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_SOURCE_DIR}/common" "${OpenAL_BINARY_DIR}")
280 IF(NOT CMAKE_BUILD_TYPE)
281     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
282         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
283         FORCE)
284 ENDIF()
285 IF(NOT CMAKE_DEBUG_POSTFIX)
286     SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
287         "Library postfix for debug builds. Normally left blank."
288         FORCE)
289 ENDIF()
291 SET(EXTRA_CFLAGS "")
292 IF(MSVC)
293     ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
294     ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
295     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} /wd4098")
297     IF(NOT DXSDK_DIR)
298         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
299     ELSE()
300         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
301     ENDIF()
302     IF(DXSDK_DIR)
303         MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
304     ENDIF()
306     OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
307     IF(FORCE_STATIC_VCRT)
308         FOREACH(flag_var
309                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
310                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
311             IF(${flag_var} MATCHES "/MD")
312                 STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
313             ENDIF()
314         ENDFOREACH(flag_var)
315     ENDIF()
316 ELSE()
317     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Winline -Wall")
318     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
319     IF(HAVE_W_EXTRA)
320         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wextra")
321     ENDIF()
323     IF(ALSOFT_WERROR)
324         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror")
325     ENDIF()
327     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
328     # instead of NDEBUG)
329     FOREACH(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
330         IF(${flag_var} MATCHES "-DNDEBUG")
331             STRING(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
332         ENDIF()
333     ENDFOREACH()
335     CHECK_C_COMPILER_FLAG(-fno-math-errno HAVE_FNO_MATH_ERRNO)
336     IF(HAVE_FNO_MATH_ERRNO)
337         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fno-math-errno")
338     ENDIF()
340     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
341                              int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
343     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
344     if(ALSOFT_STATIC_LIBGCC)
345         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
346         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
347         check_c_source_compiles(
348 "#include <stdlib.h>
349 int main()
351     return 0;
353             HAVE_STATIC_LIBGCC_SWITCH
354         )
355         if(HAVE_STATIC_LIBGCC_SWITCH)
356             set(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} -static-libgcc")
357         endif()
358         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
359         unset(OLD_REQUIRED_LIBRARIES)
360     endif()
361 ENDIF()
363 # Set visibility/export options if available
364 IF(WIN32)
365     SET(EXPORT_DECL "__declspec(dllexport)")
366     IF(NOT MINGW)
367         SET(ALIGN_DECL "__declspec(align(x))")
368     ELSE()
369         SET(ALIGN_DECL "__declspec(aligned(x))")
370     ENDIF()
371 ELSE()
372     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
373     # Yes GCC, really don't accept visibility modes you don't support
374     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
376     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
377                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
378     IF(HAVE_GCC_PROTECTED_VISIBILITY)
379         SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
380     ELSE()
381         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
382                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
383         IF(HAVE_GCC_DEFAULT_VISIBILITY)
384             SET(EXPORT_DECL "__attribute__((visibility(\"default\")))")
385         ENDIF()
386     ENDIF()
388     IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
389         CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
390         IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
391             SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
392         ENDIF()
393     ENDIF()
395     CHECK_C_SOURCE_COMPILES("int foo __attribute__((aligned(16)));
396                              int main() {return 0;}" HAVE_ATTRIBUTE_ALIGNED)
397     IF(HAVE_ATTRIBUTE_ALIGNED)
398         SET(ALIGN_DECL "__attribute__((aligned(x)))")
399     ENDIF()
401     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
402 ENDIF()
404 CHECK_C_SOURCE_COMPILES("
405 int main()
407     float *ptr;
408     ptr = __builtin_assume_aligned(ptr, 16);
409     return 0;
410 }" HAVE___BUILTIN_ASSUME_ALIGNED)
411 IF(HAVE___BUILTIN_ASSUME_ALIGNED)
412     SET(ASSUME_ALIGNED_DECL "__builtin_assume_aligned(x, y)")
413 ELSE()
414     SET(ASSUME_ALIGNED_DECL "x")
415 ENDIF()
417 SET(SSE_SWITCH "")
418 SET(SSE2_SWITCH "")
419 SET(SSE3_SWITCH "")
420 SET(SSE4_1_SWITCH "")
421 SET(FPU_NEON_SWITCH "")
422 IF(NOT MSVC)
423     CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
424     IF(HAVE_MSSE_SWITCH)
425         SET(SSE_SWITCH "-msse")
426     ENDIF()
427     CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
428     IF(HAVE_MSSE2_SWITCH)
429         SET(SSE2_SWITCH "-msse2")
430     ENDIF()
431     CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
432     IF(HAVE_MSSE3_SWITCH)
433         SET(SSE3_SWITCH "-msse3")
434     ENDIF()
435     CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
436     IF(HAVE_MSSE4_1_SWITCH)
437         SET(SSE4_1_SWITCH "-msse4.1")
438     ENDIF()
439     CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
440     IF(HAVE_MFPU_NEON_SWITCH)
441         SET(FPU_NEON_SWITCH "-mfpu=neon")
442     ENDIF()
443 ENDIF()
445 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
446                          int main() {return 0;}" HAVE_GCC_FORMAT)
448 CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
449 CHECK_INCLUDE_FILE(stdalign.h HAVE_STDALIGN_H)
450 CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
451 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
452 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
453 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
454 CHECK_INCLUDE_FILE(intrin.h HAVE_INTRIN_H)
455 CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
456 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
457 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
458 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
459 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
460 IF(NOT HAVE_GUIDDEF_H)
461     CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
462 ENDIF()
464 # Some systems need libm for some of the following math functions to work
465 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
466 IF(HAVE_LIBM)
467     SET(EXTRA_LIBS m ${EXTRA_LIBS})
468     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
469 ENDIF()
471 # Check for the dlopen API (for dynamicly loading backend libs)
472 IF(ALSOFT_DLOPEN)
473     CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
474     IF(HAVE_LIBDL)
475         SET(EXTRA_LIBS dl ${EXTRA_LIBS})
476         SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
477     ENDIF()
479     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
480 ENDIF()
482 # Check for a cpuid intrinsic
483 IF(HAVE_CPUID_H)
484     CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
485         int main()
486         {
487             unsigned int eax, ebx, ecx, edx;
488             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
489         }" HAVE_GCC_GET_CPUID)
490 ENDIF()
491 IF(HAVE_INTRIN_H)
492     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
493         int main()
494         {
495             int regs[4];
496             __cpuid(regs, 0);
497             return regs[0];
498         }" HAVE_CPUID_INTRINSIC)
499 ENDIF()
501 CHECK_SYMBOL_EXISTS(aligned_alloc    stdlib.h HAVE_ALIGNED_ALLOC)
502 CHECK_SYMBOL_EXISTS(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
503 CHECK_SYMBOL_EXISTS(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
504 CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
505 CHECK_SYMBOL_EXISTS(modff  math.h HAVE_MODFF)
506 CHECK_SYMBOL_EXISTS(log2f  math.h HAVE_LOG2F)
507 IF(NOT HAVE_C99_VLA)
508     CHECK_SYMBOL_EXISTS(alloca malloc.h HAVE_ALLOCA)
509     IF(NOT HAVE_ALLOCA)
510         MESSAGE(FATAL_ERROR "No alloca function found, please report!")
511     ENDIF()
512 ENDIF()
514 IF(HAVE_FLOAT_H)
515     CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
516     CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
517 ENDIF()
519 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
520 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
521 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
522 IF(NOT HAVE_STRCASECMP)
523     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
524     IF(NOT HAVE__STRICMP)
525         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
526     ENDIF()
528     ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
529 ENDIF()
531 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
532 IF(NOT HAVE_STRNCASECMP)
533     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
534     IF(NOT HAVE__STRNICMP)
535         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
536     ENDIF()
538     ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
539 ENDIF()
541 CHECK_SYMBOL_EXISTS(strnlen string.h HAVE_STRNLEN)
542 CHECK_SYMBOL_EXISTS(snprintf stdio.h HAVE_SNPRINTF)
543 IF(NOT HAVE_SNPRINTF)
544     CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
545     IF(NOT HAVE__SNPRINTF)
546         MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
547     ENDIF()
549     ADD_DEFINITIONS(-Dsnprintf=_snprintf)
550 ENDIF()
552 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
553 IF(NOT HAVE_ISFINITE)
554     CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
555     IF(NOT HAVE_FINITE)
556         CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
557         IF(NOT HAVE__FINITE)
558             MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
559         ENDIF()
560         ADD_DEFINITIONS(-Disfinite=_finite)
561     ELSE()
562         ADD_DEFINITIONS(-Disfinite=finite)
563     ENDIF()
564 ENDIF()
566 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
567 IF(NOT HAVE_ISNAN)
568     CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
569     IF(NOT HAVE__ISNAN)
570         MESSAGE(FATAL_ERROR "No isnan function found, please report!")
571     ENDIF()
573     ADD_DEFINITIONS(-Disnan=_isnan)
574 ENDIF()
577 # Check if we have Windows headers
578 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0502)
579 IF(NOT HAVE_WINDOWS_H)
580     CHECK_SYMBOL_EXISTS(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
581     IF(NOT HAVE_GETTIMEOFDAY)
582         MESSAGE(FATAL_ERROR "No timing function found!")
583     ENDIF()
585     CHECK_SYMBOL_EXISTS(nanosleep time.h HAVE_NANOSLEEP)
586     IF(NOT HAVE_NANOSLEEP)
587         MESSAGE(FATAL_ERROR "No sleep function found!")
588     ENDIF()
590     # We need pthreads outside of Windows
591     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
592     IF(NOT HAVE_PTHREAD_H)
593         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
594     ENDIF()
595     # Some systems need pthread_np.h to get recursive mutexes
596     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
598     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
599     IF(HAVE_PTHREAD)
600         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pthread")
601         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
602         SET(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} -pthread")
603     ENDIF()
605     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
606     IF(HAVE_LIBPTHREAD)
607         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
608     ENDIF()
610     CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
612     IF(HAVE_PTHREAD_NP_H)
613         CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
614         IF(NOT HAVE_PTHREAD_SETNAME_NP)
615             CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
616         ELSE()
617             CHECK_C_SOURCE_COMPILES("
618 #include <pthread.h>
619 #include <pthread_np.h>
620 int main()
622     pthread_setname_np(\"testname\");
623     return 0;
625                 PTHREAD_SETNAME_NP_ONE_PARAM
626             )
627         ENDIF()
628         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np "pthread.h;pthread_np.h" HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
629     ELSE()
630         CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
631         IF(NOT HAVE_PTHREAD_SETNAME_NP)
632             CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
633         ELSE()
634             CHECK_C_SOURCE_COMPILES("
635 #include <pthread.h>
636 int main()
638     pthread_setname_np(\"testname\");
639     return 0;
641                 PTHREAD_SETNAME_NP_ONE_PARAM
642             )
643         ENDIF()
644         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np pthread.h HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
645     ENDIF()
647     CHECK_SYMBOL_EXISTS(pthread_mutex_timedlock pthread.h HAVE_PTHREAD_MUTEX_TIMEDLOCK)
649     CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
650     IF(HAVE_LIBRT)
651         SET(EXTRA_LIBS rt ${EXTRA_LIBS})
652     ENDIF()
653 ENDIF()
655 CHECK_SYMBOL_EXISTS(getopt unistd.h HAVE_GETOPT)
657 # Check for a 64-bit type
658 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
659 IF(NOT HAVE_STDINT_H)
660     IF(HAVE_WINDOWS_H)
661         CHECK_C_SOURCE_COMPILES("#define _WIN32_WINNT 0x0502
662                                  #include <windows.h>
663                                  __int64 foo;
664                                  int main() {return 0;}" HAVE___INT64)
665     ENDIF()
666     IF(NOT HAVE___INT64)
667         IF(NOT SIZEOF_LONG MATCHES "8")
668             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
669                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
670             ENDIF()
671         ENDIF()
672     ENDIF()
673 ENDIF()
676 SET(COMMON_OBJS  common/almalloc.c
677                  common/atomic.c
678                  common/rwlock.c
679                  common/threads.c
680                  common/uintmap.c
682 SET(OPENAL_OBJS  OpenAL32/alAuxEffectSlot.c
683                  OpenAL32/alBuffer.c
684                  OpenAL32/alEffect.c
685                  OpenAL32/alError.c
686                  OpenAL32/alExtension.c
687                  OpenAL32/alFilter.c
688                  OpenAL32/alListener.c
689                  OpenAL32/alSource.c
690                  OpenAL32/alState.c
691                  OpenAL32/alThunk.c
692                  OpenAL32/sample_cvt.c
694 SET(ALC_OBJS  Alc/ALc.c
695               Alc/ALu.c
696               Alc/alcConfig.c
697               Alc/alcRing.c
698               Alc/bs2b.c
699               Alc/converter.c
700               Alc/mastering.c
701               Alc/effects/chorus.c
702               Alc/effects/compressor.c
703               Alc/effects/dedicated.c
704               Alc/effects/distortion.c
705               Alc/effects/echo.c
706               Alc/effects/equalizer.c
707               Alc/effects/flanger.c
708               Alc/effects/modulator.c
709               Alc/effects/null.c
710               Alc/effects/reverb.c
711               Alc/helpers.c
712               Alc/hrtf.c
713               Alc/uhjfilter.c
714               Alc/ambdec.c
715               Alc/bformatdec.c
716               Alc/nfcfilter.c
717               Alc/panning.c
718               Alc/mixer.c
719               Alc/mixer_c.c
723 SET(CPU_EXTS "Default")
724 SET(HAVE_SSE        0)
725 SET(HAVE_SSE2       0)
726 SET(HAVE_SSE3       0)
727 SET(HAVE_SSE4_1     0)
728 SET(HAVE_NEON       0)
730 SET(HAVE_ALSA       0)
731 SET(HAVE_OSS        0)
732 SET(HAVE_SOLARIS    0)
733 SET(HAVE_SNDIO      0)
734 SET(HAVE_QSA        0)
735 SET(HAVE_DSOUND     0)
736 SET(HAVE_MMDEVAPI   0)
737 SET(HAVE_WINMM      0)
738 SET(HAVE_PORTAUDIO  0)
739 SET(HAVE_PULSEAUDIO 0)
740 SET(HAVE_COREAUDIO  0)
741 SET(HAVE_OPENSL     0)
742 SET(HAVE_WAVE       0)
744 # Check for SSE support
745 OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
746 CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE_SWITCH}")
747 IF(HAVE_XMMINTRIN_H)
748     OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
749     IF(ALSOFT_CPUEXT_SSE)
750         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
751             SET(HAVE_SSE 1)
752             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse.c)
753             IF(SSE_SWITCH)
754                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse.c PROPERTIES
755                                             COMPILE_FLAGS "${SSE_SWITCH}")
756             ENDIF()
757             SET(CPU_EXTS "${CPU_EXTS}, SSE")
758         ENDIF()
759     ENDIF()
760 ENDIF()
761 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
762     MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
763 ENDIF()
765 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
766 CHECK_INCLUDE_FILE(emmintrin.h HAVE_EMMINTRIN_H "${SSE2_SWITCH}")
767 IF(HAVE_EMMINTRIN_H)
768     OPTION(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
769     IF(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
770         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
771             SET(HAVE_SSE2 1)
772             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse2.c)
773             IF(SSE2_SWITCH)
774                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse2.c PROPERTIES
775                                             COMPILE_FLAGS "${SSE2_SWITCH}")
776             ENDIF()
777             SET(CPU_EXTS "${CPU_EXTS}, SSE2")
778         ENDIF()
779     ENDIF()
780 ENDIF()
781 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
782     MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
783 ENDIF()
785 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE3 support" OFF)
786 CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}")
787 IF(HAVE_EMMINTRIN_H)
788     OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
789     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
790         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
791             SET(HAVE_SSE3 1)
792             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse3.c)
793             IF(SSE2_SWITCH)
794                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse3.c PROPERTIES
795                                             COMPILE_FLAGS "${SSE3_SWITCH}")
796             ENDIF()
797             SET(CPU_EXTS "${CPU_EXTS}, SSE3")
798         ENDIF()
799     ENDIF()
800 ENDIF()
801 IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
802     MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
803 ENDIF()
805 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
806 CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}")
807 IF(HAVE_SMMINTRIN_H)
808     OPTION(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
809     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE4_1)
810         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
811             SET(HAVE_SSE4_1 1)
812             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse41.c)
813             IF(SSE4_1_SWITCH)
814                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse41.c PROPERTIES
815                                             COMPILE_FLAGS "${SSE4_1_SWITCH}")
816             ENDIF()
817             SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
818         ENDIF()
819     ENDIF()
820 ENDIF()
821 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
822     MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
823 ENDIF()
825 # Check for ARM Neon support
826 OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
827 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H)
828 IF(HAVE_ARM_NEON_H)
829     OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
830     IF(ALSOFT_CPUEXT_NEON)
831         SET(HAVE_NEON 1)
832         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_neon.c)
833         IF(FPU_NEON_SWITCH)
834             SET_SOURCE_FILES_PROPERTIES(Alc/mixer_neon.c PROPERTIES
835                                         COMPILE_FLAGS "${FPU_NEON_SWITCH}")
836         ENDIF()
837         SET(CPU_EXTS "${CPU_EXTS}, Neon")
838     ENDIF()
839 ENDIF()
840 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
841     MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
842 ENDIF()
845 IF(WIN32 OR HAVE_DLFCN_H)
846     SET(IS_LINKED "")
847     MACRO(ADD_BACKEND_LIBS _LIBS)
848     ENDMACRO()
849 ELSE()
850     SET(IS_LINKED " (linked)")
851     MACRO(ADD_BACKEND_LIBS _LIBS)
852         SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
853     ENDMACRO()
854 ENDIF()
856 SET(BACKENDS "")
857 SET(ALC_OBJS  ${ALC_OBJS}
858               Alc/backends/base.c
859               # Default backends, always available
860               Alc/backends/loopback.c
861               Alc/backends/null.c
864 # Check ALSA backend
865 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
866 FIND_PACKAGE(ALSA)
867 IF(ALSA_FOUND)
868     OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
869     IF(ALSOFT_BACKEND_ALSA)
870         SET(HAVE_ALSA 1)
871         SET(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
872         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/alsa.c)
873         ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
874     ENDIF()
875 ENDIF()
876 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
877     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
878 ENDIF()
880 # Check OSS backend
881 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
882 FIND_PACKAGE(OSS)
883 IF(OSS_FOUND)
884     OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
885     IF(ALSOFT_BACKEND_OSS)
886         SET(HAVE_OSS 1)
887         SET(BACKENDS  "${BACKENDS} OSS,")
888         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/oss.c)
889     ENDIF()
890 ENDIF()
891 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
892     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
893 ENDIF()
895 # Check Solaris backend
896 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
897 FIND_PACKAGE(AudioIO)
898 IF(AUDIOIO_FOUND)
899     OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
900     IF(ALSOFT_BACKEND_SOLARIS)
901         SET(HAVE_SOLARIS 1)
902         SET(BACKENDS  "${BACKENDS} Solaris,")
903         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/solaris.c)
904     ENDIF()
905 ENDIF()
906 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
907     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
908 ENDIF()
910 # Check SndIO backend
911 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
912 FIND_PACKAGE(SoundIO)
913 IF(SOUNDIO_FOUND)
914     OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
915     IF(ALSOFT_BACKEND_SNDIO)
916         SET(HAVE_SNDIO 1)
917         SET(BACKENDS  "${BACKENDS} SndIO (linked),")
918         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sndio.c)
919         SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
920     ENDIF()
921 ENDIF()
922 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
923     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
924 ENDIF()
926 # Check QSA backend
927 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
928 FIND_PACKAGE(QSA)
929 IF(QSA_FOUND)
930     OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
931     IF(ALSOFT_BACKEND_QSA)
932         SET(HAVE_QSA 1)
933         SET(BACKENDS  "${BACKENDS} QSA (linked),")
934         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/qsa.c)
935         SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
936     ENDIF()
937 ENDIF()
938 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
939     MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
940 ENDIF()
942 # Check Windows-only backends
943 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
944 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
945 OPTION(ALSOFT_REQUIRE_MMDEVAPI "Require MMDevApi backend" OFF)
946 IF(HAVE_WINDOWS_H)
947     # Check MMSystem backend
948     CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0502)
949     IF(HAVE_MMSYSTEM_H)
950         CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
951         IF(HAVE_LIBWINMM)
952             OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
953             IF(ALSOFT_BACKEND_WINMM)
954                 SET(HAVE_WINMM 1)
955                 SET(BACKENDS  "${BACKENDS} WinMM,")
956                 SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/winmm.c)
957                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
958             ENDIF()
959         ENDIF()
960     ENDIF()
962     # Check DSound backend
963     FIND_PACKAGE(DSound)
964     IF(DSOUND_FOUND)
965         OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
966         IF(ALSOFT_BACKEND_DSOUND)
967             SET(HAVE_DSOUND 1)
968             SET(BACKENDS  "${BACKENDS} DirectSound${IS_LINKED},")
969             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/dsound.c)
970             ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
971         ENDIF()
972     ENDIF()
974     # Check for MMDevApi backend
975     CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
976     IF(HAVE_MMDEVICEAPI_H)
977         OPTION(ALSOFT_BACKEND_MMDEVAPI "Enable MMDevApi backend" ON)
978         IF(ALSOFT_BACKEND_MMDEVAPI)
979             SET(HAVE_MMDEVAPI 1)
980             SET(BACKENDS  "${BACKENDS} MMDevApi,")
981             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/mmdevapi.c)
982         ENDIF()
983     ENDIF()
984 ENDIF()
985 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
986     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
987 ENDIF()
988 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
989     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
990 ENDIF()
991 IF(ALSOFT_REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
992     MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
993 ENDIF()
995 # Check PortAudio backend
996 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
997 FIND_PACKAGE(PortAudio)
998 IF(PORTAUDIO_FOUND)
999     OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1000     IF(ALSOFT_BACKEND_PORTAUDIO)
1001         SET(HAVE_PORTAUDIO 1)
1002         SET(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
1003         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/portaudio.c)
1004         ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
1005     ENDIF()
1006 ENDIF()
1007 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1008     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
1009 ENDIF()
1011 # Check PulseAudio backend
1012 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1013 FIND_PACKAGE(PulseAudio)
1014 IF(PULSEAUDIO_FOUND)
1015     OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1016     IF(ALSOFT_BACKEND_PULSEAUDIO)
1017         SET(HAVE_PULSEAUDIO 1)
1018         SET(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
1019         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/pulseaudio.c)
1020         ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
1021     ENDIF()
1022 ENDIF()
1023 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1024     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1025 ENDIF()
1027 # Check JACK backend
1028 OPTION(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1029 FIND_PACKAGE(JACK)
1030 IF(JACK_FOUND)
1031     OPTION(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1032     IF(ALSOFT_BACKEND_JACK)
1033         SET(HAVE_JACK 1)
1034         SET(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1035         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/jack.c)
1036         ADD_BACKEND_LIBS(${JACK_LIBRARIES})
1037     ENDIF()
1038 ENDIF()
1039 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1040     MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
1041 ENDIF()
1043 # Check CoreAudio backend
1044 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1045 FIND_LIBRARY(COREAUDIO_FRAMEWORK
1046              NAMES CoreAudio
1047              PATHS /System/Library/Frameworks
1049 IF(COREAUDIO_FRAMEWORK)
1050     OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1051     IF(ALSOFT_BACKEND_COREAUDIO)
1052         SET(HAVE_COREAUDIO 1)
1053         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/coreaudio.c)
1054         SET(BACKENDS  "${BACKENDS} CoreAudio,")
1055         SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
1056         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
1057         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1059         # Some versions of OSX may need the AudioToolbox framework. Add it if
1060         # it's found.
1061         FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
1062                      NAMES AudioToolbox
1063                      PATHS ~/Library/Frameworks
1064                            /Library/Frameworks
1065                            /System/Library/Frameworks
1066                     )
1067         IF(AUDIOTOOLBOX_LIBRARY)
1068             SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1069         ENDIF()
1070     ENDIF()
1071 ENDIF()
1072 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1073     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1074 ENDIF()
1076 # Check for OpenSL (Android) backend
1077 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1078 CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
1079 IF(HAVE_SLES_OPENSLES_ANDROID_H)
1080     CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
1081     IF(HAVE_LIBOPENSLES)
1082         OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1083         IF(ALSOFT_BACKEND_OPENSL)
1084             SET(HAVE_OPENSL 1)
1085             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/opensl.c)
1086             SET(BACKENDS  "${BACKENDS} OpenSL,")
1087             SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
1088         ENDIF()
1089     ENDIF()
1090 ENDIF()
1091 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1092     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1093 ENDIF()
1095 # Optionally enable the Wave Writer backend
1096 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1097 IF(ALSOFT_BACKEND_WAVE)
1098     SET(HAVE_WAVE 1)
1099     SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wave.c)
1100     SET(BACKENDS  "${BACKENDS} WaveFile,")
1101 ENDIF()
1103 # This is always available
1104 SET(BACKENDS  "${BACKENDS} Null")
1106 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" OFF)
1107 if(ALSOFT_EMBED_HRTF_DATA)
1108     SET(NATIVE_SRC_DIR  "${OpenAL_SOURCE_DIR}/native-tools/")
1109     SET(NATIVE_BIN_DIR  "${OpenAL_BINARY_DIR}/native-tools/")
1110     FILE(MAKE_DIRECTORY "${NATIVE_BIN_DIR}")
1112     SET(BIN2H_COMMAND  "${NATIVE_BIN_DIR}bin2h")
1113     ADD_CUSTOM_COMMAND(OUTPUT "${BIN2H_COMMAND}"
1114         COMMAND ${CMAKE_COMMAND} "${NATIVE_SRC_DIR}"
1115         COMMAND ${CMAKE_COMMAND} --build . --config "Release"
1116         WORKING_DIRECTORY "${NATIVE_BIN_DIR}"
1117         DEPENDS "${NATIVE_SRC_DIR}CMakeLists.txt" "${NATIVE_SRC_DIR}bin2h.c"
1118         VERBATIM
1119     )
1121     MACRO(make_hrtf_header FILENAME VARNAME)
1122         SET(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1123         SET(outfile  "${OpenAL_BINARY_DIR}/${FILENAME}.h")
1125         ADD_CUSTOM_COMMAND(OUTPUT "${outfile}"
1126             COMMAND "${BIN2H_COMMAND}" "${infile}" "${outfile}" ${VARNAME}
1127             DEPENDS "${BIN2H_COMMAND}" "${infile}"
1128             COMMENT "Generating ${FILENAME}.h"
1129             VERBATIM
1130         )
1132         SET(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1133     ENDMACRO()
1135     make_hrtf_header(default-44100.mhr "hrtf_default_44100")
1136     make_hrtf_header(default-48000.mhr "hrtf_default_48000")
1137 endif()
1140 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1141     add_subdirectory(utils/alsoft-config)
1142 ENDIF()
1143 IF(ALSOFT_EXAMPLES)
1144     FIND_PACKAGE(SDL2)
1145     IF(SDL2_FOUND)
1146         FIND_PACKAGE(SDL_sound)
1147         FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1148     ENDIF()
1149 ENDIF()
1151 IF(LIBTYPE STREQUAL "STATIC")
1152     ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC)
1153     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
1154 ENDIF()
1156 IF(NOT WIN32)
1157     SET(LIBNAME "openal")
1158 ELSE()
1159     SET(LIBNAME "OpenAL32")
1160 ENDIF()
1162 FIND_PACKAGE(Git)
1163 IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1164     # Get the current working branch and its latest abbreviated commit hash
1165     ADD_CUSTOM_TARGET(build_version
1166         ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
1167                          -D LIB_VERSION=${LIB_VERSION}
1168                          -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1169                          -D DST=${OpenAL_BINARY_DIR}/version.h
1170                          -P ${OpenAL_SOURCE_DIR}/version.cmake
1171         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1172         VERBATIM
1173     )
1174 ELSE()
1175     SET(GIT_BRANCH "UNKNOWN")
1176     SET(GIT_COMMIT_HASH "unknown")
1177     CONFIGURE_FILE(
1178         "${OpenAL_SOURCE_DIR}/version.h.in"
1179         "${OpenAL_BINARY_DIR}/version.h")
1180 ENDIF()
1182 # Needed for openal.pc.in
1183 SET(prefix ${CMAKE_INSTALL_PREFIX})
1184 SET(exec_prefix "\${prefix}")
1185 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1186 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1187 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1188 SET(PACKAGE_VERSION "${LIB_VERSION}")
1190 # End configuration
1191 CONFIGURE_FILE(
1192     "${OpenAL_SOURCE_DIR}/config.h.in"
1193     "${OpenAL_BINARY_DIR}/config.h")
1194 CONFIGURE_FILE(
1195     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1196     "${OpenAL_BINARY_DIR}/openal.pc"
1197     @ONLY)
1199 MACRO(ADD_INCLUDE_DIRS TRGT TESTVAR INCVAR)
1200     IF(${TESTVAR})
1201         SET_PROPERTY(TARGET ${TRGT} APPEND PROPERTY INCLUDE_DIRECTORIES ${${INCVAR}})
1202     ENDIF()
1203 ENDMACRO()
1205 UNSET(HAS_ROUTER)
1206 SET(IMPL_TARGET OpenAL)
1208 # Build main library
1209 IF(LIBTYPE STREQUAL "STATIC")
1210     ADD_LIBRARY(OpenAL STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1211 ELSE()
1212     IF(WIN32 AND ALSOFT_BUILD_ROUTER)
1213         ADD_LIBRARY(OpenAL SHARED router/router.c router/alc.c router/al.c ${COMMON_OBJS})
1214         SET_PROPERTY(TARGET OpenAL APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1215         SET_PROPERTY(TARGET OpenAL APPEND PROPERTY
1216             COMPILE_DEFINITIONS AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES
1217         )
1218         SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS ${EXTRA_LDFLAGS})
1219         IF(MSVC)
1220             SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:WINDOWS")
1221         ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1222             SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS " -mwindows")
1223         ENDIF()
1224         SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "")
1225         SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1226         IF(TARGET build_version)
1227             ADD_DEPENDENCIES(OpenAL build_version)
1228         ENDIF()
1229         SET(HAS_ROUTER 1)
1231         SET(LIBNAME "soft_oal")
1232         SET(IMPL_TARGET soft_oal)
1233     ENDIF()
1235     ADD_LIBRARY(${IMPL_TARGET} SHARED ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1236     IF(WIN32)
1237         SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES PREFIX "")
1238     ENDIF()
1239 ENDIF()
1240 SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1241     VERSION ${LIB_VERSION}
1242     SOVERSION ${LIB_MAJOR_VERSION}
1244 SET_PROPERTY(TARGET ${IMPL_TARGET} APPEND PROPERTY INCLUDE_DIRECTORIES
1245     "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc"
1247 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_ALSA       ALSA_INCLUDE_DIRS)
1248 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_OSS        OSS_INCLUDE_DIRS)
1249 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_SOLARIS    AUDIOIO_INCLUDE_DIRS)
1250 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_SNDIO      SOUNDIO_INCLUDE_DIRS)
1251 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_QSA        QSA_INCLUDE_DIRS)
1252 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_DSOUND     DSOUND_INCLUDE_DIRS)
1253 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_PORTAUDIO  PORTAUDIO_INCLUDE_DIRS)
1254 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_PULSEAUDIO PULSEAUDIO_INCLUDE_DIRS)
1255 ADD_INCLUDE_DIRS(${IMPL_TARGET} HAVE_JACK       JACK_INCLUDE_DIRS)
1256 SET_PROPERTY(TARGET ${IMPL_TARGET} APPEND PROPERTY
1257     COMPILE_DEFINITIONS AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES
1259 IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1260     SET_PROPERTY(TARGET ${IMPL_TARGET} APPEND PROPERTY COMPILE_DEFINITIONS AL_NO_UID_DEFS)
1261 ENDIF()
1262 SET_PROPERTY(TARGET ${IMPL_TARGET} APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1263 SET_PROPERTY(TARGET ${IMPL_TARGET} APPEND_STRING PROPERTY LINK_FLAGS ${EXTRA_LDFLAGS})
1265 TARGET_LINK_LIBRARIES(${IMPL_TARGET} ${EXTRA_LIBS})
1266 IF(TARGET build_version)
1267     ADD_DEPENDENCIES(${IMPL_TARGET} build_version)
1268 ENDIF()
1270 IF(WIN32)
1271     IF(MSVC)
1272         SET_PROPERTY(TARGET ${IMPL_TARGET} APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:WINDOWS")
1273     ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1274         SET_PROPERTY(TARGET ${IMPL_TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -mwindows")
1275     ENDIF()
1277     if(NOT LIBTYPE STREQUAL "STATIC")
1278         IF(MINGW AND ALSOFT_BUILD_IMPORT_LIB)
1279             FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1280             FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1281             IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1282                 MESSAGE(STATUS "")
1283                 IF(NOT SED_EXECUTABLE)
1284                     MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1285                 ENDIF()
1286                 IF(NOT DLLTOOL_EXECUTABLE)
1287                     MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1288                 ENDIF()
1289             ELSE()
1290                 SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS
1291                              " -Wl,--output-def,OpenAL32.def")
1292                 ADD_CUSTOM_COMMAND(TARGET OpenAL POST_BUILD
1293                     COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1294                     COMMAND "${DLLTOOL_EXECUTABLE}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1295                     COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1296                     VERBATIM
1297                 )
1298             ENDIF()
1299         ENDIF()
1300     ENDIF()
1301 ENDIF()
1303 IF(ALSOFT_INSTALL)
1304     INSTALL(TARGETS OpenAL EXPORT OpenAL
1305             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1306             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1307             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1308             INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL
1309     )
1310     EXPORT(TARGETS OpenAL
1311            NAMESPACE OpenAL::
1312            FILE OpenALConfig.cmake)
1313     INSTALL(EXPORT OpenAL
1314             DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1315             NAMESPACE OpenAL::
1316             FILE OpenALConfig.cmake)
1317     INSTALL(FILES include/AL/al.h
1318                   include/AL/alc.h
1319                   include/AL/alext.h
1320                   include/AL/efx.h
1321                   include/AL/efx-creative.h
1322                   include/AL/efx-presets.h
1323             DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
1324     )
1325     INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1326             DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1327     IF(TARGET soft_oal)
1328         INSTALL(TARGETS soft_oal
1329                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1330         )
1331     ENDIF()
1332 ENDIF()
1335 if(HAS_ROUTER)
1336     message(STATUS "")
1337     message(STATUS "Building DLL router")
1338 endif()
1340 MESSAGE(STATUS "")
1341 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1342 MESSAGE(STATUS "    ${BACKENDS}")
1343 MESSAGE(STATUS "")
1344 MESSAGE(STATUS "Building with support for CPU extensions:")
1345 MESSAGE(STATUS "    ${CPU_EXTS}")
1346 MESSAGE(STATUS "")
1348 IF(WIN32)
1349     IF(NOT HAVE_DSOUND)
1350         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
1351         MESSAGE(STATUS "         This is probably NOT what you want!")
1352         MESSAGE(STATUS "")
1353     ENDIF()
1354 ENDIF()
1356 if(ALSOFT_EMBED_HRTF_DATA)
1357     message(STATUS "Embedding HRTF datasets")
1358     message(STATUS "")
1359 endif()
1361 # Install alsoft.conf configuration file
1362 IF(ALSOFT_CONFIG)
1363     INSTALL(FILES alsoftrc.sample
1364             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal
1365     )
1366     MESSAGE(STATUS "Installing sample configuration")
1367     MESSAGE(STATUS "")
1368 ENDIF()
1370 # Install HRTF definitions
1371 IF(ALSOFT_HRTF_DEFS)
1372     INSTALL(FILES hrtf/default-44100.mhr
1373                   hrtf/default-48000.mhr
1374             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf
1375     )
1376     MESSAGE(STATUS "Installing HRTF definitions")
1377     MESSAGE(STATUS "")
1378 ENDIF()
1380 # Install AmbDec presets
1381 IF(ALSOFT_AMBDEC_PRESETS)
1382     INSTALL(FILES presets/3D7.1.ambdec
1383                   presets/hexagon.ambdec
1384                   presets/itu5.1.ambdec
1385                   presets/itu5.1-nocenter.ambdec
1386                   presets/rectangle.ambdec
1387                   presets/square.ambdec
1388                   presets/presets.txt
1389             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
1390     )
1391     MESSAGE(STATUS "Installing AmbDec presets")
1392     MESSAGE(STATUS "")
1393 ENDIF()
1395 IF(ALSOFT_UTILS)
1396     ADD_EXECUTABLE(openal-info utils/openal-info.c)
1397     SET_PROPERTY(TARGET openal-info APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1398     TARGET_LINK_LIBRARIES(openal-info OpenAL)
1400     SET(MAKEHRTF_SRCS  utils/makehrtf.c)
1401     IF(NOT HAVE_GETOPT)
1402         SET(MAKEHRTF_SRCS  ${MAKEHRTF_SRCS} utils/getopt.c)
1403     ENDIF()
1404     ADD_EXECUTABLE(makehrtf ${MAKEHRTF_SRCS})
1405     SET_PROPERTY(TARGET makehrtf APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1406     IF(HAVE_LIBM)
1407         TARGET_LINK_LIBRARIES(makehrtf m)
1408     ENDIF()
1409     IF(WIN32 AND CMAKE_COMPILER_IS_GNUCC)
1410         SET_PROPERTY(TARGET makehrtf APPEND_STRING PROPERTY LINK_FLAGS " -municode")
1411     ENDIF()
1413     ADD_EXECUTABLE(bsincgen utils/bsincgen.c)
1414     SET_PROPERTY(TARGET bsincgen APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1415     IF(HAVE_LIBM)
1416         TARGET_LINK_LIBRARIES(bsincgen m)
1417     ENDIF()
1419     IF(ALSOFT_INSTALL)
1420         INSTALL(TARGETS openal-info makehrtf bsincgen
1421                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1422                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1423                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1424         )
1425     ENDIF()
1427     MESSAGE(STATUS "Building utility programs")
1428     IF(TARGET alsoft-config)
1429         MESSAGE(STATUS "Building configuration program")
1430     ENDIF()
1431     MESSAGE(STATUS "")
1432 ENDIF()
1434 IF(ALSOFT_TESTS)
1435     SET(TEST_COMMON_OBJS  examples/common/alhelpers.c)
1437     ADD_EXECUTABLE(altonegen examples/altonegen.c ${COMMON_OBJS} ${TEST_COMMON_OBJS})
1438     TARGET_LINK_LIBRARIES(altonegen OpenAL)
1439     SET_PROPERTY(TARGET altonegen APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1441     IF(ALSOFT_INSTALL)
1442         INSTALL(TARGETS altonegen
1443                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1444                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1445                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1446         )
1447     ENDIF()
1449     MESSAGE(STATUS "Building test programs")
1450     MESSAGE(STATUS "")
1451 ENDIF()
1453 IF(ALSOFT_EXAMPLES)
1454     ADD_EXECUTABLE(alrecord examples/alrecord.c ${COMMON_OBJS})
1455     TARGET_LINK_LIBRARIES(alrecord OpenAL)
1456     SET_PROPERTY(TARGET alrecord APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1458     IF(ALSOFT_INSTALL)
1459         INSTALL(TARGETS alrecord
1460                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1461                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1462                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1463         )
1464     ENDIF()
1466     MESSAGE(STATUS "Building example programs")
1468     IF(SDL2_FOUND)
1469         IF(SDL_SOUND_FOUND)
1470             SET(EX_COMMON_OBJS  examples/common/alhelpers.c)
1472             ADD_EXECUTABLE(alstream examples/alstream.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1473             TARGET_LINK_LIBRARIES(alstream ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} OpenAL)
1474             SET_PROPERTY(TARGET alstream APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1475             SET_PROPERTY(TARGET alstream APPEND PROPERTY
1476                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1477             )
1479             ADD_EXECUTABLE(alreverb examples/alreverb.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1480             TARGET_LINK_LIBRARIES(alreverb ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} OpenAL)
1481             SET_PROPERTY(TARGET alreverb APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1482             SET_PROPERTY(TARGET alreverb APPEND PROPERTY
1483                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1484             )
1486             ADD_EXECUTABLE(allatency examples/allatency.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1487             TARGET_LINK_LIBRARIES(allatency ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} OpenAL)
1488             SET_PROPERTY(TARGET allatency APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1489             SET_PROPERTY(TARGET allatency APPEND PROPERTY
1490                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1491             )
1493             ADD_EXECUTABLE(alloopback examples/alloopback.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1494             TARGET_LINK_LIBRARIES(alloopback ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} OpenAL)
1495             SET_PROPERTY(TARGET alloopback APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1496             SET_PROPERTY(TARGET alloopback APPEND PROPERTY
1497                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1498             )
1500             ADD_EXECUTABLE(alhrtf examples/alhrtf.c ${COMMON_OBJS} ${EX_COMMON_OBJS})
1501             TARGET_LINK_LIBRARIES(alhrtf ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} OpenAL)
1502             SET_PROPERTY(TARGET alhrtf APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1503             SET_PROPERTY(TARGET alhrtf APPEND PROPERTY
1504                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}
1505             )
1507             IF(ALSOFT_INSTALL)
1508                 INSTALL(TARGETS alstream alreverb allatency alloopback alhrtf
1509                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1510                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1511                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1512                 )
1513             ENDIF()
1515             MESSAGE(STATUS "Building SDL_sound example programs")
1516         ENDIF()
1518         SET(FFVER_OK FALSE)
1519         IF(FFMPEG_FOUND)
1520             SET(FFVER_OK TRUE)
1521             IF(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1522                 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1523                 SET(FFVER_OK FALSE)
1524             ENDIF()
1525             IF(AVCODEC_VERSION VERSION_LESS "57.64.101")
1526                 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1527                 SET(FFVER_OK FALSE)
1528             ENDIF()
1529             IF(AVUTIL_VERSION VERSION_LESS "55.34.101")
1530                 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1531                 SET(FFVER_OK FALSE)
1532             ENDIF()
1533             IF(SWSCALE_VERSION VERSION_LESS "4.2.100")
1534                 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1535                 SET(FFVER_OK FALSE)
1536             ENDIF()
1537             IF(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1538                 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1539                 SET(FFVER_OK FALSE)
1540             ENDIF()
1541         ENDIF()
1542         IF(FFVER_OK)
1543             ADD_EXECUTABLE(alffplay examples/alffplay.cpp ${COMMON_OBJS})
1544             TARGET_LINK_LIBRARIES(alffplay ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} OpenAL)
1545             SET_PROPERTY(TARGET alffplay APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1546             SET_PROPERTY(TARGET alffplay APPEND PROPERTY
1547                 INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS}
1548             )
1550             IF(ALSOFT_INSTALL)
1551                 INSTALL(TARGETS alffplay
1552                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1553                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1554                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1555                 )
1556             ENDIF()
1557             MESSAGE(STATUS "Building SDL+FFmpeg example programs")
1558         ENDIF()
1559         MESSAGE(STATUS "")
1560     ENDIF()
1561 ENDIF()