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